09:49:51 [ERR][ Workbench]: Console redirection failed. 09:49:51 [INF][ Workbench]: Starting up Workbench 09:49:51 [INF][ Workbench]: Current environment: Command line: "C:\Program Files\MySQL\MySQL Workbench 8.0\MySQLWorkbench.exe" CurrentDirectory: C:\Program Files\MySQL\MySQL Workbench 8.0 HasShutdownStarted: False OSVersion: Microsoft Windows NT 6.2.9200.0 SystemDirectory: C:\WINDOWS\system32 TickCount: 789049296 UserInteractive: True Version: 4.0.30319.42000 WorkingSet: 42668032 09:49:51 [INF][ Workbench]: Environment variables: OneDriveConsumer = C:\Users\cliff\OneDrive\Documents\OneDrive ProgramFiles(x86) = C:\Program Files (x86) USERNAME = cliff ProgramW6432 = C:\Program Files ChocolateyInstall = C:\ProgramData\chocolatey PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 158 Stepping 9, GenuineIntel TMP = C:\Users\cliff\AppData\Local\Temp PROCESSOR_ARCHITECTURE = AMD64 Path = C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\iis express\PHP\v7.1;C:\Program Files\Microsoft MPI\Bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Users\cliff\AppData\Local\Microsoft\WindowsApps;C:\PHP;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\OpenSSL-Win64\bin;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\PuTTY\;C:\Program Files (x86)\IBM\Personal Communications\;C:\Program Files (x86)\IBM\Trace Facility\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\cliff\.nuget\packages\selenium.firefox.webdriver\0.24.0\driver;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Calibre2\;C:\downloads\Adobe\Scripting SDK\plugin_sdk_024\plugin\devtools\idmltools;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\dotnet\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\ HOMEPATH = \Users\cliff PROCESSOR_REVISION = 9e09 GTK_BASEPATH = C:\Program Files (x86)\GtkSharp\2.12\ ChocolateyLastPathUpdate = 132022047264224876 USERPROFILE = C:\Users\cliff CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files LOGONSERVER = \\DESKTOP-G2SM7UT TEMP = C:\Users\cliff\AppData\Local\Temp MYSQLCONNECTOR_ASSEMBLIESPATH = C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.23\Assemblies\v4.5 SystemRoot = C:\WINDOWS MSBuildSDKsPath = C:\Program Files\dotnet\sdk\3.1.119\Sdks MSMPI_BIN = C:\Program Files\Microsoft MPI\Bin\ OneDrive = C:\Users\cliff\OneDrive\Documents\OneDrive USERDOMAIN_ROAMINGPROFILE = DESKTOP-G2SM7UT CommonProgramFiles = C:\Program Files\Common Files ProgramData = C:\ProgramData PCOMM_Root = C:\Program Files (x86)\IBM\Personal Communications\ PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC COMPUTERNAME = DESKTOP-G2SM7UT ALLUSERSPROFILE = C:\ProgramData CommonProgramW6432 = C:\Program Files\Common Files SCITE_USERHOME = C:\Users\cliff\AppData\Local\AutoIt v3\SciTE FSHARPINSTALLDIR = C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0\ WIX = C:\Program Files (x86)\WiX Toolset v3.11\ SESSIONNAME = Console PYTHONPATH = C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\Scripts VS150COMCOMNTOOLS = C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\Tools\ DriverData = C:\Windows\System32\Drivers\DriverData HOMEDRIVE = C: windir = C:\WINDOWS SystemDrive = C: NUMBER_OF_PROCESSORS = 8 OS = Windows_NT ProgramFiles = C:\Program Files ComSpec = C:\WINDOWS\system32\cmd.exe OPENSSL_CONF = C:\OpenSSL-Win64\bin\openssl.cfg PSModulePath = C:\Program Files (x86)\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\;C:\Program Files (x86)\AutoIt3\AutoItX APPDATA = C:\Users\cliff\AppData\Roaming USERDOMAIN = DESKTOP-G2SM7UT PROCESSOR_LEVEL = 6 LOCALAPPDATA = C:\Users\cliff\AppData\Local VS150ENTCOMNTOOLS = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\ IDMLTOOLS_HOME = C:\downloads\Adobe\Scripting SDK\plugin_sdk_024\plugin\devtools\idmltools\bin PROG27B48B2C054 = 1 PROG27B48B2C051 = 1 PUBLIC = C:\Users\Public 09:49:51 [INF][ Workbench]: Current version given by meta info is: 8.0.25 09:49:51 [INF][ Workbench]: Setting PATH to: C:\WINDOWS\system32;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\iis express\PHP\v7.1;C:\Program Files\Microsoft MPI\Bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Users\cliff\AppData\Local\Microsoft\WindowsApps;C:\PHP;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\OpenSSL-Win64\bin;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\PuTTY\;C:\Program Files (x86)\IBM\Personal Communications\;C:\Program Files (x86)\IBM\Trace Facility\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\cliff\.nuget\packages\selenium.firefox.webdriver\0.24.0\driver;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Calibre2\;C:\downloads\Adobe\Scripting SDK\plugin_sdk_024\plugin\devtools\idmltools;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\dotnet\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\ 09:49:51 [INF][ mforms managed]: Initializing mforms wrapper 09:49:51 [INF][ WBContext UI]: Initializing workbench context UI with these values: base dir: C:\Program Files\MySQL\MySQL Workbench 8.0 plugin path: C:\Program Files\MySQL\MySQL Workbench 8.0 struct path: module path: C:\Program Files\MySQL\MySQL Workbench 8.0/modules library path: C:\Program Files\MySQL\MySQL Workbench 8.0 user data dir: C:\Users\cliff\AppData\Roaming\MySQL\Workbench open at start: open type: run at startup: run type: Force SW rendering: No Force OpenGL: No quit when done: No 09:49:51 [INF][ WBContext]: WbContext::init 09:49:51 [INF][ WBA]: Looking for extension modules for WBA... 09:49:51 [INF][ WBA]: 0 extension modules found 09:49:51 [WRN][ grt]: Duplicate plugin name wb.tools.cmdlineClient There is more than one plugin with the name wb.tools.cmdlineClient (in PyWbUtils and PyWbUtils). 09:49:51 [WRN][ grt]: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\connections.xml:26: link '{E2C5E485-4A4C-4CB5-B311-3BEC1B1C5B56}' key=owner could not be resolved 09:49:51 [WRN][ grt]: Duplicate plugin name wb.tools.cmdlineClient There is more than one plugin with the name wb.tools.cmdlineClient (in PyWbUtils and PyWbUtils). 09:49:51 [INF][ WBContext]: System info: MySQL Workbench Community (GPL) for Windows version 8.0.25 CE build 788958 (64 bit) Configuration Directory: C:\Users\cliff\AppData\Roaming\MySQL\Workbench Data Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 Cairo Version: 1.17.4 OS: Microsoft Windows 10 Home CPU: 8x Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, 15.9 GiB RAM Active video adapter Intel(R) HD Graphics 630 Installed video RAM: 1024 MB Current video mode: 1920 x 1080 x 4294967296 colors Used bit depth: 32 Driver version: 25.20.100.6373 Installed display drivers: C:\WINDOWS\System32\DriverStore\FileRepository\igdlh64.inf_amd64_24de78387e6208e4\igdumdim64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\igdlh64.inf_amd64_24de78387e6208e4\igd10iumd64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\igdlh64.inf_amd64_24de78387e6208e4\igd10iumd64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\igdlh64.inf_amd64_24de78387e6208e4\igd12umd64.dll Current user language: English (United Kingdom) 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\Local_instance_MySQL57-1.autosave 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\Local_instance_MySQL_Router-1.autosave 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\Production_Electrical_Essentials-1.autosave 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\SSH_DE_Invoicing_Live-1.autosave 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\SSH_Tunnel(shop4.shop4-electrical.com)-1.autosave 09:49:51 [INF][ WQE backend]: Found auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\SSH_Tunnel-1.autosave 09:49:51 [WRN][ WQE backend]: Found incomplete auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\unconnected-1.autosave 09:49:51 [WRN][ WQE backend]: Found incomplete auto-save workspace C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_workspaces\unconnected-2.autosave 09:49:51 [INF][ Workbench]: UI is up 09:49:52 [INF][ Workbench]: Running the application 09:51:54 [INF][SSHTunnelManager]: Wakeup socket port created: 9674 09:51:54 [INF][ SSH tunnel]: Starting tunnel 09:51:54 [INF][ SSH tunnel]: Existing SSH tunnel not found, opening new one 09:51:54 [INF][ SSH tunnel]: Opening SSH tunnel to 81.19.181.82:22 09:51:54 [INF][ SSHCommon]: libssh: ssh_connect ssh_connect: libssh 0.9.5 (c) 2003-2019 Aris Adamantiadis, Andreas Schneider and libssh contributors. Distributed under the LGPL, please refer to COPYING file for information about your rights, using threading threads_stdthread 09:51:54 [INF][ SSHCommon]: libssh: ssh_socket_connect ssh_socket_connect: Nonblocking connection socket: 1908 09:51:54 [INF][ SSHCommon]: libssh: ssh_connect ssh_connect: Socket connecting, now waiting for the callbacks to work 09:51:54 [INF][ SSHCommon]: libssh: ssh_client_connection_callback ssh_client_connection_callback: SSH server banner: SSH-2.0-OpenSSH_7.4 09:51:54 [INF][ SSHCommon]: libssh: ssh_analyze_banner ssh_analyze_banner: Analyzing banner: SSH-2.0-OpenSSH_7.4 09:51:54 [INF][ SSHCommon]: libssh: ssh_analyze_banner ssh_analyze_banner: We are talking to an OpenSSH client version: 7.4 (70400) 09:51:54 [INF][ SSHCommon]: libssh: ssh_kex_select_methods ssh_kex_select_methods: Negotiated curve25519-sha256,ssh-ed25519,aes256-gcm@openssh.com,aes256-gcm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-256-etm@openssh.com,none,none,, 09:51:54 [INF][ SSHCommon]: libssh: ssh_init_rekey_state ssh_init_rekey_state: Set rekey after 4294967296 blocks 09:51:54 [INF][ SSHCommon]: libssh: ssh_init_rekey_state ssh_init_rekey_state: Set rekey after 4294967296 blocks 09:51:55 [INF][ SSHCommon]: libssh: ssh_packet_client_curve25519_reply ssh_packet_client_curve25519_reply: SSH_MSG_NEWKEYS sent 09:51:55 [INF][ SSHCommon]: libssh: ssh_packet_newkeys ssh_packet_newkeys: Received SSH_MSG_NEWKEYS 09:51:55 [INF][ SSHCommon]: libssh: ssh_packet_newkeys ssh_packet_newkeys: Signature verified and valid 09:51:55 [INF][ SSHCommon]: libssh: ssh_packet_userauth_failure ssh_packet_userauth_failure: Access denied for 'none'. Authentication that can continue: publickey,gssapi-keyex,gssapi-with-mic 09:51:55 [INF][ SSHSession]: Banner: 09:51:55 [INF][ SSHCommon]: libssh: ssh_pki_import_privkey_base64 ssh_pki_import_privkey_base64: Trying to decode privkey passphrase=true 09:51:55 [INF][ SSH tunnel]: SSH tunnel opened on port: 9676 09:51:56 [INF][SQL Editor Form]: Opened connection 'Production Electrical Essentials' to MySQL Community Server (GPL) version 5.7.37 09:51:57 [INF][ WQE.net]: Launching SQL IDE 09:52:00 [INF][ WQE.net]: SQL IDE UI is ready 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, NEW.password, NEW.date, now(), -- needs clarification 0000-00-00, NEW.newsletter, NULL, NEW.date, 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, passwd = NEW.password, last_passwd_gen = NEW.date, birthday = now(), -- needs clarification 0000-00-00, newsletter = NEW.newsletter, ip_registration_newsletter = NULL, newsletter_date_add = NEW.date, optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = NEW.date, date_upd = NEW.date ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- already in the existing record Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, NEW.password, NEW.date, now(), -- needs clarification 0000-00-00, NEW.newsletter, NULL, NEW.date, 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, passwd = NEW.password, last_passwd_gen = NEW.date, birthday = now(), -- needs clarification 0000-00-00, newsletter = NEW.newsletter, ip_registration_newsletter = NULL, newsletter_date_add = NEW.date, optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = NEW.date, date_upd = NEW.date ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- already in the existing record Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", NEW.date, now(), -- needs clarification 0000-00-00, NEW.newsletter, NULL, NEW.date, 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = NEW.date, birthday = now(), -- needs clarification 0000-00-00, newsletter = NEW.newsletter, ip_registration_newsletter = NULL, newsletter_date_add = NEW.date, optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = NEW.date, date_upd = NEW.date ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- already in the existing record Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", NEW.date, now(), -- needs clarification 0000-00-00, NEW.newsletter, NULL, NEW.date, 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = NEW.date, birthday = now(), -- needs clarification 0000-00-00, newsletter = NEW.newsletter, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = NEW.date, date_upd = NEW.date ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- already in the existing record Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", NEW.date, now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address Id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = NEW.date, date_upd = now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, NEW.newsletter, NULL, Now(), 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = NEW.newsletter, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, NEW.password, NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, NEW.date, NEW.date ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER = CURRENT_USER TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If CustomerId = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerId; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisCustomerOrderId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisCustomerOrderId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryId, thisOrderInvoiceId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryId, id_address_invoice = thisOrderInvoiceId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclabe, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclible, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclabe = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclible, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclible = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][SQL Editor Form]: Error querying performance_schema.events_statements_current : Exception: SELECT command denied to user 'newprest_cliff'@'localhost' for table 'events_statements_current' 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.OrderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderId, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderId, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE Set thisOrderCustomerId = New.CustomerID; END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID SET thisOrderDeliveryAddressId = (Select id_address_id from ps_address where id_customer = NEW.customerID); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; SELECT 'Message Text' AS `Title`; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; /* INSERT INTO `prestash_cliff_test`.`debug` ( desc VALUES ( "Started Trigger" ); */ If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( message ) VALUES ( "Started Trigger"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************* this is the else to the openin if at the top ********************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliverayAlias Text; DECLARE thisOrderDelivaryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts so no need to separate - however... -- the deliveryName field need separation in lastname and firstname for the creation of the ps_order record SET fullname = replace(replace(replace(replace(NEW.delivaryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDelivaryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDelivaryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliverayAlias = Trim(Concat(thisOrderDelivaryFirstName, " ", thisOrderDelivaryLastName)); ELSE SET thisOrderDelivaryFirstName = fullname; SET thisOrderDelivaryLastName = ""; SET thisOrderDeliverayAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with no suffix SET thisOrderDeliveryAddressId = NEW.orderID; INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.delivaryCompany, NEW.surname, NEW.forename, NEW.deliveryAddress1, NEW.delivaryAddress2, NEW.delivaryPostcode, NEW.delivaryTown, NEW.delivaryCounty, NEW.delivaryTelephone, NEW.delivaryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts so no need to separate - however... -- the deliveryName field need separation in lastname and firstname for the creation of the ps_order record SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with no suffix SET thisOrderDeliveryAddressId = NEW.orderID; INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.delivaryCompany, NEW.surname, NEW.forename, NEW.deliveryAddress1, NEW.delivaryAddress2, NEW.delivaryPostcode, NEW.delivaryTown, NEW.delivaryCounty, NEW.delivaryTelephone, NEW.delivaryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ON DUPLICATE KEY UPDATE -- id_customer = NEW.customerID, -- should never occur as records must exist id_shop_group = 1, id_shop = 1, id_gender = CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, id_default_group = 3, id_lang = 1, id_risk = 0, company = NEW.company, siret = NULL, ape = NULL, firstname = NEW.forename, lastname = NEW.surname, email = NEW.email, -- passwd = "xxxxxxxxxxxx", should not be reset to default on a record that already exists last_passwd_gen = Now(), birthday = now(), -- needs clarification 0000-00-00, newsletter = 1, ip_registration_newsletter = NULL, newsletter_date_add = Now(), optin = 0, website = NULL, outstanding_allow_amount = "", show_public_prices = 0, max_payment_days = 0, -- secure_key = NEW.password, note = NULL, active = 1, is_guest = 0, deleted = 0, date_add = Now(), date_upd = Now() ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts so no need to separate - however... -- the deliveryName field need separation in lastname and firstname for the creation of the ps_order record SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with no suffix SET thisOrderDeliveryAddressId = NEW.orderID; INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* NEED TO EXAMINE THIS IS DETAIL - IF REG OR NON REG HOW DOW THESE FIELDS NEED TO BE SET - REMEMBER I HAVE CREATED NEW DELIVERY NAMES*/ Trim(CONCAT(NEW.forename, " ", NEW.surname)), /*****************************************************************/ NEW.deliveryCompany, NEW.surname, NEW.forename, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ) ; /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` ( id_customer, id_group ) VALUES ( thisOrderCustomerId, 3 ) ON DUPLICATE KEY UPDATE id_group = 3 ; /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- id_addresss - already an existing key id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ) ON DUPLICATE KEY UPDATE -- this is the keu - id_address id_country = 17, id_state = 0, id_customer = thisOrderCustomerId, id_manufacturer = 0, id_supplier = 0, id_warehouse = 0, alias = Trim(CONCAT(NEW.forename, " ", NEW.surname)), company = NEW.company, lastname = NEW.surname, firstname = NEW.forename, address1 = NEW.address1, address2 = NEW.address2, postcode = NEW.postcode, city = NEW.town, other = NEW.county, phone = NEW.telephone, phone_mobile = NEW.telephone, vat_number = "", dni = "", date_add = Now(), date_upd = Now(), active = 1, deleted = 0 ; END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts so no need to separate - however... -- the deliveryName field need separation in lastname and firstname for the creation of the ps_order record SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with no suffix SET thisOrderDeliveryAddressId = NEW.orderID; INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* NEED TO EXAMINE THIS IS DETAIL - IF REG OR NON REG HOW DOW THESE FIELDS NEED TO BE SET - REMEMBER I HAVE CREATED NEW DELIVERY NAMES*/ Trim(CONCAT(NEW.forename, " ", NEW.surname)), /*****************************************************************/ NEW.deliveryCompany, NEW.surname, NEW.forename, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ) ON DUPLICATE KEY UPDATE id_order = NEW.orderID, reference = "", id_shop_group = 1, id_shop = 1, id_carrier = 1, id_lang = 1, id_customer = thisOrderCustomerId, id_cart = 999999, id_currency = 1, id_address_delivery = thisOrderDeliveryAddressId, id_address_invoice = thisOrderInvoiceAddressId, current_state = 1, secure_key = 1, payment = 1, conversion_rate = 1, module = 1, recyclable = 1, gift = 1, gift_message = 1, mobile_theme = 1, shipping_number = 1, total_discounts = 1, total_discounts_tax_incl = 1, total_discounts_tax_excl = 1, total_paid = 1, total_paid_tax_incl = 1, total_paid_tax_excl = 1, total_paid_real = 1, total_products = 1, total_products_wt = 1, total_shipping = 1, total_shipping_tax_incl = 1, total_shipping_tax_excl = 1, carrier_tax_rate = 1, total_wrapping = 1, total_wrapping_tax_incl = 1, total_wrapping_tax_excl = 1, round_mode = 1, round_type = 1, invoice_number = 1, delivery_number = 1, invoice_date = Now(), delivery_date = Now(), valid = 1, date_add = Now(), date_upd = Now() ; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts so no need to separate - however... -- the deliveryName field need separation in lastname and firstname for the creation of the ps_order record SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with no suffix SET thisOrderDeliveryAddressId = NEW.orderID; INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* NEED TO EXAMINE THIS IS DETAIL - IF REG OR NON REG HOW DOW THESE FIELDS NEED TO BE SET - REMEMBER I HAVE CREATED NEW DELIVERY NAMES*/ Trim(CONCAT(NEW.forename, " ", NEW.surname)), /*****************************************************************/ NEW.deliveryCompany, NEW.surname, NEW.forename, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(NEW.thisOrderDeliveryFirstName, " ", NEW.thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, NEW.thisOrderDeliveryFirstName, NEW.thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(forename, " ", surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(Forename, " ", surname), /*****************************************************************/ NEW.company, NEW.foreame, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(NEW.thisOrderDeliveryFirstName, " ", NEW.thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, NEW.thisOrderDeliveryFirstName, NEW.thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(forename, " ", surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(Forename, " ", surname), /*****************************************************************/ NEW.company, NEW.foreame, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(forename, " ", surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(forename, " ", surname), /*****************************************************************/ NEW.company, NEW.foreame, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(forename, " ", surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.foreame, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.foreame, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode); SET thisOrderInvoiceAddressId = (Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = '",thisOrderDeliveryAddressId )); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = NULL" )); -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Select Delivery Address for Customer Id = ", NEW.customerID, " found = NULL" )); -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", tihsOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId integer; DECLARE thisOrderCustomerId integer; DECLARE thisOrderInvoiceAddressId integer; DECLARE thisOrderDeliveryAddressId integer; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, "", 1, 1, 1, 1, thisOrderCustomerId, 999999, 1, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( 99, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), NULL); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), NULL); IF thisOrderDeliveryAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = null then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", " MEMEME " , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address = '", " MEMEME " , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLaststName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLaststName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode = PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId,10); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(NEW.orderID,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(NEW.orderID,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( NEW.orderID, NEW.orderID, 1, 1, 28, 1, thisOrderCustomerId, NEW.orderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, NEW.orderID, NEW.orderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][SQL Editor Form]: Error querying performance_schema.event_waits_history : Exception: SELECT command denied to user 'newprest_cliff'@'localhost' for table 'events_waits_history_long' 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.custormeID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.custormeID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvocieAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If DelvieryPostcode != PostCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If NEW.deliveryPostcode != NEW.postCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records for ", NEW.orderID, " invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = thisOrderId; -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If NEW.deliveryPostcode != NEW.postCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "03"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ -- n.b. thisOrderId was set at the top and outside of the if conditiona Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId + "00"); -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If NEW.deliveryPostcode != NEW.postCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "01"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, "Processing"); If NEW.CustomerID = 0 THEN -- Ps_customer part Set thisOrderCustomerId = thisOrderId; -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId + "00"); -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If NEW.deliveryPostcode != NEW.postCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "01"); -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ Set thisOrderCustomerId = New.CustomerID; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Trim(CONCAT(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)), /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate - however... SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ Concat(NEW.forename, " ", NEW.surname), /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Creating ps_orders records with invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing............."); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, NEW.forename, NEW.surname, NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /****************************** ps_address - invoice Address *******************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId + "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- set fields according to the second block in the s/s -- Create ps_address record with id = thisOrderInvocieAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); /****************************** ps_address - Delivery Address *******************************/ If NEW.deliveryPostcode != NEW.postCode THEN SET thisOrderDeliveryAddressId = Concat(thisOrderId, "01"); -- create a new addres id using this order id with a suffix of "01" - the delivery address -- Set fields according to the third block in the S/S -- Create ps_address records with id = thisOrderDeliveryAddressId INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, Trim(CONCAT(NEW.forename, " ", NEW.surname)), NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ Set thisOrderCustomerId = New.CustomerID; -- already set outside the main if statement but do it again to be sure to be sure -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the deliver name is contained in one feild so no need to separate - SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Trim(Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName)); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- the invoice/registered name is split into two parts already so no need to separate just combine for the alias SET thisOrderInvoiceAlias = Trim(Concat(NEW.forename, " ", NEW.surname)); -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderInvoiceAlias, /*****************************************************************/ NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ -- Create the ps_orders record id=thisOrderId -- Addressdelivery = thisOrderDeliveryAddressId -- addressinvoice = thisOrderInvocieAddressId -- if (thisOrderDeliveryAddressId = null) then -- thisOrderDeliveryAddressId=9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records with delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records with invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text; DECLARE thisOrderInvoiceFirstName Text; DECLARE thisOrderInvoiceLastName Text; DECLARe thisOrderDeliveryAlias Text; DECLARE thisOrderDeliveryFirstName Text; DECLARE thisOrderDeliveryLastName Text; DECLARe thisOrderInvoiceAlias Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode ELSE /************************************************************************ this is the else to the openin if at the top *********************************************************/ Set thisOrderCustomerId = New.CustomerID; -- already set outside the main if statement but do it again to be sure to be sure -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, message ) VALUES ( NEW.orderID, CONCAT("Delivery adddress selection = ", NEW.customerID, " found = NULL" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); -- need to find Ids for the invoice address and the delivery addres for the registered CustomerID - use the jss_orders_headers address and delivery address to mathc on SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null END IF; -- end of test - if NEW.CustomerID = 0 /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records with delivery address id = '", thisOrderDeliveryAddressId , "'" )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records with invoice address id = '", thisOrderInvoiceAddressId , "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = Null; SET thisOrderDeliveryAddressId = Null; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode ELSE /************************************************************************ this is the else to the main if at the top ********************************************************* -- this section process the orders for registered customer (customerID != 0) ******************************************************************************************************************************************************************************/ Set thisOrderCustomerId = New.CustomerID; -- already set outside the main if statement but do it again to be sure to be sure END IF; -- end of test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address" , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address" , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = Null then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = Null then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = Null; SET thisOrderDeliveryAddressId = Null; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode ELSE /************************************************************************ this is the else to the main if at the top ********************************************************* -- this section process the orders for registered customer (customerID != 0) ******************************************************************************************************************************************************************************/ Set thisOrderCustomerId = New.CustomerID; -- already set outside the main if statement but do it again to be sure to be sure END IF; -- end of test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = Null then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = Null then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", 1, 1, NEW.discountTotal, 1, 1, 1, 1, 1, 1, 1, 1, NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the deliver name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias SET fullname = replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", ""); IF (locate(" ", fullname) > 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), -- needs clarification 0000-00-00, 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, Now(), Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, /* n.b. on the alias field - deliveryName from jss_orders_headers is in the format "Mr John Smyth" - so i will have to manipulate - already done above */ thisOrderDeliveryAlias, /*****************************************************************/ NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, NEW.deliveryCompany, thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, Now(), Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias -- Mr Miroslav Tomic -- Concierge SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias -- Mr Miroslav Tomic -- Concierge SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryFirstName, thisOrderDeliveryLastName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, firstname, lastname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.forename, NEW.surname, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias -- Mr Miroslav Tomic -- Concierge 20200616151701 20200616151701 /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, Concat("> 0 ", fullname)); SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, Concat("< 0 ", fullname)); SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - still to be completed, there is a preliminary creation of an order record just to test the implementation of the various id_address and Id_cautomer links to orders the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARe thisOrderInvoiceAlias Text Default ""; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -9999; SET thisOrderDeliveryAddressId = -9999; INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one feild so no need to separate - also filter out title prefixes -- first the delivery name and alias -- Mr Miroslav Tomic -- Concierge 20200616151701 20200616151701 /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, Concat("> 0 ", fullname)); SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); ELSE -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, Concat("< 0 ", fullname)); SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to null from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -9999 this means that they have not been set above i.e. this is a registered customer's order -- n.b. both select below only return 1 match - assuming it exist -- if an address cannot be found then the id - set to 99999 and the further tests below are actioned */ if thisOrderDeliveryAddressId = -9999 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -9999 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "and"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- no duplicate is possible here END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", Round((New.discountTotal * 1.2), 2), Round((New.discountTotal * 1.2), 2), NEW.discountTotal, Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal + New.taxTotal - New.discountTotal) * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.goodsTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), Round((New.shippingTotal * 1.2), 2), NEW.shippingTotal, 20.00, 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 213378; DECLARE thisVatRate float(4,3); /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (New.orderID >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: ock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_cliff_test`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 213378; DECLARE thisVatRate float(4,3); /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, 19, "cf69fcf039beb2a4def95a4a922d9151", "", 1.000000, "", 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: lock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE TRIGGER `discount_discount`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 212378; DECLARE thisVatRate float(4,3); DECLARE thisOrderStatus int; DECLARE thisPayment Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- set the order status SET thisOrderStatus = CASE NEW.status WHEN 1 THEN 15 WHEN 2 THEN 17 WHEN 3 THEN 21 WHEN 4 THEN 6 WHEN 5 THEN 22 WHEN 6 THEN 18 WHEN 7 THEN 20 WHEN 8 THEN 19 WHEN 9 THEN 23 END; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); -- set the payment type IF New.authInfo = "" THEN SET thisPayment = "Bank Wire"; ELSE SET thisPayment = "Card payment"; END IF; If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, thisOrderStatus, "cf69fcf039beb2a4def95a4a922d9151", thisPayment, 1.000000, thisPayment, 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); /****************************** -- ps_ordernotes_note *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_ordernotes_note` ( id_note, id_order, id_employee, text_note, date_added, modified ) VALUES ( thisOrderId, thisOrderId, 3, NEW.orderNotes, New.datetime, 0 ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: lock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE TRIGGER `discount_discount`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 212378; DECLARE thisVatRate float(4,3); DECLARE thisOrderStatus int; DECLARE thisPayment Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- set the order status SET thisOrderStatus = CASE NEW.status WHEN 1 THEN 15 WHEN 2 THEN 17 WHEN 3 THEN 21 WHEN 4 THEN 6 WHEN 5 THEN 22 WHEN 6 THEN 18 WHEN 7 THEN 20 WHEN 8 THEN 19 WHEN 9 THEN 23 END; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); -- set the payment type IF New.authInfo = "" THEN SET thisPayment = "Bank Wire"; ELSE SET thisPayment = "Card payment"; END IF; If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, thisOrderStatus, "cf69fcf039beb2a4def95a4a922d9151", thisPayment, 1.000000, thisPayment, 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); /****************************** -- ps_ordernotes_note *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_ordernotes_note` ( id_note, id_order, id_employee, text_note, date_added, modified ) VALUES ( thisOrderId, thisOrderId, 3, NEW.orderNotes, New.datetime, 0 ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: lock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE TRIGGER `prestash_discount`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 212378; DECLARE thisVatRate float(4,3); DECLARE thisOrderStatus int; DECLARE thisPayment Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- set the order status SET thisOrderStatus = CASE NEW.status WHEN 1 THEN 15 WHEN 2 THEN 17 WHEN 3 THEN 21 WHEN 4 THEN 6 WHEN 5 THEN 22 WHEN 6 THEN 18 WHEN 7 THEN 20 WHEN 8 THEN 19 WHEN 9 THEN 23 END; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); -- set the payment type IF New.authInfo = "" THEN SET thisPayment = "Bank Wire"; ELSE SET thisPayment = "Card payment"; END IF; If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 28, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, thisOrderStatus, "cf69fcf039beb2a4def95a4a922d9151", thisPayment, 1.000000, thisPayment, 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); /****************************** -- ps_ordernotes_note *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_ordernotes_note` ( id_note, id_order, id_employee, text_note, date_added, modified ) VALUES ( thisOrderId, thisOrderId, 3, NEW.orderNotes, New.datetime, 0 ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: lock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`prestash_cliff`@`localhost` TRIGGER `prestash_discount`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 212378; DECLARE thisVatRate float(4,3); DECLARE thisOrderStatus int; DECLARE thisPayment Text; DECLARE thisModule Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- set the order status SET thisOrderStatus = CASE NEW.status WHEN 1 THEN 15 WHEN 2 THEN 16 WHEN 3 THEN 27 WHEN 4 THEN 6 WHEN 5 THEN 21 WHEN 6 THEN 17 WHEN 7 THEN 19 WHEN 8 THEN 18 WHEN 9 THEN 20 END; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); -- set the payment type IF New.authInfo = "" THEN SET thisPayment = "Bank Wire"; ELSE SET thisPayment = "Card payment"; END IF; -- set the module type IF New.authInfo = "" THEN SET thisModule = "bankwire"; ELSE SET thisModule = "creditcardofflinepayment"; END IF; If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `prestash_shop4electrical`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `prestash_shop4electrical`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `prestash_shop4electrical`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 33, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, thisOrderStatus, "cf69fcf039beb2a4def95a4a922d9151", thisPayment, 1.000000, thisModule, 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); /****************************** -- ps_ordernotes_note *******************************/ INSERT INTO `prestash_shop4electrical`.`ps_ordernotes_note` ( id_note, id_order, id_employee, text_note, date_added, modified ) VALUES ( thisOrderId, thisOrderId, 3, NEW.orderNotes, New.datetime, 0 ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'ndash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: lock in the s/s -- Create ps_customer with id = thisOrderCustomerId – 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse CREATE DEFINER=`discount_cliff`@`localhost` TRIGGER `discount_discount`.`jss_orders_headers_AFTER_UPDATE` AFTER UPDATE ON `jss_orders_headers` FOR EACH ROW /* this tirgger implements the mapping provide by Alan's spreadsheet - Field_Mapping_Testing_Customers_Addresses_Orders_Version3 it creates records:- - ps_customer - ps_customer_group - ps_address - ps_order - ps_order_history - ps_order_invoice - ps_order_invoice_payment the basic logic is applied on a mass update of the jss_orders_headerts table (update jss_orders_headert set country = country) that logic:- if the order is for a non-regiatered customer (a guest - where the customerID = 0) create the invoice and delivery ps_address records and retain the keys to be used to create the ps_order - later else determine if there are addresses for invoice and delivery already on ps_address and use their ids for the creation of the ps_order - later of if an address cannot be found create a new address (for either invoice or delivery) using the orderID as the key (and orderID concat with "10" in the case of delivery address) these newly created keys will be used in the creation of the ps_order - later end if create a ps_order from the jss_orders_headers record */ BEGIN DECLARE thisOrderId int; DECLARE thisOrderCustomerId int; DECLARE thisOrderInvoiceAddressId int; DECLARE thisOrderDeliveryAddressId int; DECLARE fullname text Default ""; DECLARE thisOrderInvoiceFirstName Text Default ""; DECLARE thisOrderInvoiceLastName Text Default ""; DECLARe thisOrderDeliveryAlias Text Default ""; DECLARE thisOrderDeliveryFirstName Text Default ""; DECLARE thisOrderDeliveryLastName Text Default ""; DECLARE thisOrderInvoiceAlias Text Default ""; DECLARE vatChangeOrder int unsigned Default 212378; DECLARE thisVatRate float(4,3); DECLARE thisOrderStatus int; DECLARE thisPayment Text; DECLARE thisModule Text; /* the Jshop increment */ SET thisOrderId = NEW.orderID + 200000; -- ? for Alan SET thisOrderCustomerId = NEW.customerID; SET thisOrderInvoiceAddressId = -1; -- used to signify that the var has not been assigned a proper id yet SET thisOrderDeliveryAddressId = -1; -- ditto -- set the VAT rate n.b. changed at order 213378 IF (thisOrderId >= vatChangeOrder) THEN SET thisVatRate = 1.20; ELSE SET thisVatRate = 1.175; END IF; -- set the order status SET thisOrderStatus = CASE NEW.status WHEN 1 THEN 15 WHEN 2 THEN 16 WHEN 3 THEN 27 WHEN 4 THEN 6 WHEN 5 THEN 21 WHEN 6 THEN 17 WHEN 7 THEN 19 WHEN 8 THEN 18 WHEN 9 THEN 20 END; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Processing Order ............."); /************************************************************************************************* perform some manipulations on names for later use by both clauses of the if main if statement *************************************************************************************************/ -- the delivery name is contained in one field so no need to separate - also filter out title prefixes -- first the delivery name and alias /* if New.orderID != 322214 Then SET thisOrderCustomerId = NEW.customerID; Else */ SET fullname = Trim(replace(replace(replace(replace(NEW.deliveryName,"Mr ", ""),"Mrs ", ""),"Miss ", ""),"Dr ", "")); IF (position(" " IN fullname) != 0) THEN -- separate first and last if a space is found in the fullname SET thisOrderDeliveryFirstName = Trim(SUBSTRING_INDEX(fullname, ' ', 1)); SET thisOrderDeliveryLastName = Trim(SUBSTRING_INDEX(fullname, ' ', -1)); SET thisOrderDeliveryAlias = Concat(thisOrderDeliveryFirstName, " ", thisOrderDeliveryLastName); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); ELSE SET thisOrderDeliveryFirstName = fullname; SET thisOrderDeliveryLastName = ""; SET thisOrderDeliveryAlias = fullname; -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message, Param1, Param2, Param3, Param4) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, "No Spaces in fullname", Concat("'",fullname, "'"), Concat("'",thisOrderDeliveryFirstName, "'"), Concat("'",thisOrderDeliveryLastName, "'"), Concat("'",thisOrderDeliveryAlias, "'")); END IF; -- then the invoice/registered name and alias SET thisOrderInvoiceFirstName = Trim(NEW.forename); SET thisOrderInvoiceLastName = Trim(NEW.surname); SET thisOrderInvoiceAlias = Concat(thisOrderInvoiceFirstName, " ", thisOrderInvoiceLastName); -- set the payment type IF New.authInfo = "" THEN SET thisPayment = "Bank Wire"; ELSE SET thisPayment = "Card payment"; END IF; -- set the module type IF New.authInfo = "" THEN SET thisModule = "bankwire"; ELSE SET thisModule = "creditcardofflinepayment"; END IF; If NEW.CustomerID = 0 THEN Set thisOrderCustomerId = thisOrderId;-- the customer was a guest (id=0) so make the prestashop id = this order id -- Set fields according to the first block in the s/s -- Create ps_customer with id = thisOrderCustomerId – this JShopr orderId is unique /****************************** -- ps_customer *******************************/ INSERT INTO `discount_prestashop`.`ps_customer` ( id_customer, id_shop_group, id_shop, id_gender, id_default_group, id_lang, id_risk, company, siret, ape, firstname, lastname, email, passwd, last_passwd_gen, birthday, newsletter, ip_registration_newsletter, newsletter_date_add, optin, website, outstanding_allow_amount, show_public_prices, max_payment_days, secure_key, note, active, is_guest, deleted, date_add, date_upd ) VALUES ( thisOrderCustomerId, 1, 1, CASE NEW.title WHEN "Mr" THEN 1 WHEN "Mrs" THEN 2 WHEN "Dr" THEN 3 WHEN "Miss" THEN 4 -- ELSE 0 END, 3, 1, 0, NEW.company, NULL, NULL, Trim(NEW.forename), Trim(NEW.surname), NEW.email, "xxxxxxxxxx", Now(), Now(), 1, NULL, Now(), 0, NULL, "", 0, 0, "49f010ac3ed2baf4655838655a62cd47", NULL, 1, 0, 0, New.datetime, Now() ); /****************************** ps_customer_group *******************************/ INSERT INTO `discount_prestashop`.`ps_customer_group` (id_customer,id_group) VALUES (thisOrderCustomerId, 3); /*********************************************************************** ps_address - Invoice/Registerd Address - for guests (customerID = 0) ***********************************************************************/ SET thisOrderInvoiceAddressId = Concat(thisOrderId, "00"); -- create a new addres id using this order id with a suffix of "00" - the invoice address -- Set fields according to the third block in the S/S INSERT INTO `discount_prestashop`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); -- check if a new delivery address record is needed If NEW.deliveryPostcode != NEW.postCode THEN -- postcodes different so also need to create a new delivery address -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `discount_prestashop`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of if - NEW.deliveryPostcode != NEW.postCode END IF; -- end of main test - if NEW.CustomerID = 0 -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Delivery Address: " , new.customerID, " | ", new.deliveryAddress1, " | ", new.deliveryPostcode )); -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Invoice Address: " , new.customerID, " | ", new.address1, " | ", new.postcode )); /* -- if the ids for a particular address type have not already been created above then (i.e. equal to -1 from initialisation -- then need to find Ids for the invoice address and the delivery addres for the registered CustomerID -- use the jss_orders_headers address and delivery address to perform the sql select match on -- if either address variables are set to -1 this means that they have not been set above i.e. this means is a registered customer's order -- n.b. both selects below only return 1 match - assuming one exists -- if an address cannot be found then the id - set to 99999 and the a ps_address field is created accordingly */ -- n.b. the if null setting to 99999 in the following Select statements if thisOrderDeliveryAddressId = -1 then SET thisOrderDeliveryAddressId = IFNULL((Select id_address from `discount_prestashop`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.deliveryAddress1 AND postcode = NEW.deliveryPostcode Limit 1), 99999); -- 99999 is just an identifible token End If; if thisOrderInvoiceAddressId = -1 then SET thisOrderInvoiceAddressId = IFNULL((Select id_address from `discount_prestashop`.`ps_address` where id_customer = NEW.customerID AND address1 = NEW.address1 AND postcode = NEW.postcode Limit 1), 99999); End If; IF thisOrderDeliveryAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "01" - the delivery address SET thisOrderDeliveryAddressId = Concat(thisOrderId,"01"); INSERT INTO `discount_prestashop`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderDeliveryAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderDeliveryAlias, Replace(NEW.deliveryCompany, "&amp;", "&"), thisOrderDeliveryLastName, thisOrderDeliveryFirstName, NEW.deliveryAddress1, NEW.deliveryAddress2, NEW.deliveryPostcode, NEW.deliveryTown, NEW.deliveryCounty, NEW.deliveryTelephone, NEW.deliveryTelephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderDeliveryAddressId = null IF thisOrderInvoiceAddressId = 99999 then -- need to create a ps_address record and retain the id for the creation of the ps_order - later -- create a new ps_address with the orderID as the key with a suffix of "00" of "00" - the invoice address SET thisOrderInvoiceAddressId = Concat(thisOrderId,"00"); INSERT INTO `discount_prestashop`.`ps_address` ( id_address, Id_country, id_state, id_customer, id_manufacturer, id_supplier, id_warehouse, alias, company, lastname, firstname, address1, address2, postcode, city, other, phone, phone_mobile, vat_number, dni, date_add, date_upd, active, deleted ) VALUES ( thisOrderInvoiceAddressId, 17, 0, thisOrderCustomerId, 0, 0, 0, thisOrderInvoiceAlias, NEW.company, NEW.surname, NEW.forename, NEW.address1, NEW.address2, NEW.postcode, NEW.town, NEW.county, NEW.telephone, NEW.telephone, "", "", Now(), Now(), 1, 0 ); END IF; -- end of test - if thisOrderInvoiceAddressId = null /************************* -- ps_orders *************************/ -- INSERT INTO `prestash_cliff_test`.`debug` ( id_order, customerID, id_customer, message ) VALUES ( NEW.orderID, NEW.customerID, thisOrderCustomerId, CONCAT("Creating ps_orders records ids = Del:'", thisOrderDeliveryAddressId, "' & Inv:'", thisOrderInvoiceAddressId, "'" )); INSERT INTO `discount_prestashop`.`ps_orders` ( id_order, reference, id_shop_group, id_shop, id_carrier, id_lang, id_customer, id_cart, id_currency, id_address_delivery, id_address_invoice, current_state, secure_key, payment, conversion_rate, module, recyclable, gift, gift_message, mobile_theme, shipping_number, total_discounts, total_discounts_tax_incl, total_discounts_tax_excl, total_paid, total_paid_tax_incl, total_paid_tax_excl, total_paid_real, total_products, total_products_wt, total_shipping, total_shipping_tax_incl, total_shipping_tax_excl, carrier_tax_rate, total_wrapping, total_wrapping_tax_incl, total_wrapping_tax_excl, round_mode, round_type, invoice_number, delivery_number, invoice_date, delivery_date, valid, date_add, date_upd ) VALUES ( thisOrderID, thisOrderID, 1, 1, 33, 1, thisOrderCustomerId, thisOrderID, 3, thisOrderDeliveryAddressId, thisOrderInvoiceAddressId, thisOrderStatus, "cf69fcf039beb2a4def95a4a922d9151", thisPayment, 1.000000, thisModule, 0, 0, "", 0, "", New.discountTotal, Round((New.discountTotal * thisVatRate), 2), NEW.discountTotal, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), New.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), NEW.shippingTotal, Round((thisVatRate - 1)*100, 1), 0, 0, 0, 2, 0, thisOrderID, thisOrderID, Now(), Now(), 1, New.datetime, Now() ); /****************************** -- ps_order_history *******************************/ INSERT INTO `discount_prestashop`.`ps_order_history` ( id_order_history, id_employee, id_order, id_order_state, date_add ) VALUES ( thisOrderId, 1, thisOrderId, 19, NEW.datetime ); /****************************** -- ps_order_invoice *******************************/ INSERT INTO `discount_prestashop`.`ps_order_invoice` ( id_order_invoice, id_order, number, delivery_number, delivery_date, total_discount_tax_excl, total_discount_tax_incl, total_paid_tax_excl, total_paid_tax_incl, total_products, total_products_wt, total_shipping_tax_excl, total_shipping_tax_incl, shipping_tax_computation_method, total_wrapping_tax_excl, total_wrapping_tax_incl, shop_address, invoice_address, delivery_address, note, date_add ) VALUES ( thisOrderId, thisOrderId, thisOrderId, thisOrderId, NEW.datetime, 0, 0, Round((New.goodsTotal + New.shippingTotal - New.discountTotal), 2), Round(((New.goodsTotal + New.shippingTotal - New.discountTotal) * thisVatRate), 2), New.goodsTotal, Round((New.goodsTotal * thisVatRate), 2), NEW.shippingTotal, Round((New.shippingTotal * thisVatRate), 2), 0, 0, 0, "Shop4All Limited<br />United Kingdom<br />01406 381322", "", "", "", NEW.datetime ); /****************************** -- ps_order_invoice_payment *******************************/ INSERT INTO `discount_prestashop`.`ps_order_invoice_payment` ( id_order_invoice, id_order_payment, id_order ) VALUES ( thisOrderId, NEW.paymentID, thisOrderId ); /****************************** -- ps_ordernotes_note *******************************/ INSERT INTO `discount_prestashop`.`ps_ordernotes_note` ( id_note, id_order, id_employee, text_note, date_added, modified ) VALUES ( thisOrderId, thisOrderId, 3, NEW.orderNotes, New.datetime, 0 ); -- End if; END, of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:57 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm | Height: 19m' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:57 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm | Height: 19' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:57 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm | Height: 193' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:57 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:57 [ERR][ XML Functions]: LibXml: parser 09:57:57 [ERR][ XML Functions]: LibXml: error : 09:57:57 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:57 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:57 [ERR][ XML Functions]: LibXml: ^ 09:57:57 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm Height: 193' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:58 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:58 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm Height:| 193' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:58 [ERR][ XML Functions]: LibXml: N-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'Oslash' not defined 09:57:58 [ERR][ XML Functions]: LibXml: uminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestash_shop4electrical`.`ps_product_lang` SET `name` = 'Enlite EN-HB100C/40 Ariah2 Pro Black 1-10V Dimmable LED High Bay Luminaire With 120° Beam Angle Aluminium Reflector & Cool White LEDs IP65 100W 15000 Lumens 240V Dia Ø: 252mm | Height:- 193mm' WHERE (`id_product` = '406681764') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'bull' not defined 09:57:58 [ERR][ XML Functions]: LibXml: OM prestael_prestaelec.ps_product_extra_field_lang where technical like '%• 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse SELECT * FROM prestael_prestaelec.ps_product_extra_field_lang where technical like '%•%', of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'nbsp' not defined 09:57:58 [ERR][ XML Functions]: LibXml: t;/p><p>The Thorsman range of Plastic wall plugs are available in  09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'nbsp' not defined 09:57:58 [ERR][ XML Functions]: LibXml: t;p>The Thorsman range of Plastic wall plugs are available in both  09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `presta1e_prestaelec`.`ps_product_lang` SET `description` = '<h2>Schneider Electric 1090600 Description</h2><p>Schneider Electric 1090600 Thorsman Yellow TPA1 Economy Plastic Wall Plug (Pack Size 100)</p><p>The Thorsman range of Plastic wall plugs are available in both premium (TP) range and an economy (TPA) ranges.</p>\r <p>Available in red, brown, yellow, green and blue for use with screw sizes from 3.5mm-10mm and with dual expansion for high loads.</p>\r <p>Boxed in convenient pack sizes offering exceptional value for money.</p>\r <p>We also offer the latest Deligo 18th Edition metal wall plugs for fire-rated installations.</p>' WHERE (`id_product` = '391089565') and (`id_shop` = '1') and (`id_lang` = '1'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'sup2' not defined 09:57:58 [ERR][ XML Functions]: LibXml: :21'>UPDATE `prestael_luckins`.`catalogueproducts` SET `Col2` = '50mm 10mm² 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestael_luckins`.`catalogueproducts` SET `Col2` = '50mm 10mm²' WHERE (`ProductId` = '10') and (`CategoryId` = '900015'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'deg' not defined 09:57:58 [ERR][ XML Functions]: LibXml: prestael_luckins`.`catalogueproducts` SET `Col2` = '90� Flat Bend 90° 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestael_luckins`.`catalogueproducts` SET `Col2` = '90� Flat Bend 90° Flat Bend' WHERE (`ProductId` = '106') and (`CategoryId` = '900025'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'sup2' not defined 09:57:58 [ERR][ XML Functions]: LibXml: 5:45:11'>UPDATE `prestael_luckins`.`catalogueproducts` SET `Col3` = '1.0mm² 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestael_luckins`.`catalogueproducts` SET `Col3` = '1.0mm²' WHERE (`ProductId` = '334') and (`CategoryId` = '108750'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'sup2' not defined 09:57:58 [ERR][ XML Functions]: LibXml: ATE `prestael_luckins`.`catalogueproducts` SET `Col3` = '10mm� 10mm² 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestael_luckins`.`catalogueproducts` SET `Col3` = '10mm� 10mm²' WHERE (`ProductId` = '6527') and (`CategoryId` = '108752'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 09:57:58 [ERR][ XML Functions]: LibXml: Entity: line 1: 09:57:58 [ERR][ XML Functions]: LibXml: parser 09:57:58 [ERR][ XML Functions]: LibXml: error : 09:57:58 [ERR][ XML Functions]: LibXml: Entity 'sup2' not defined 09:57:58 [ERR][ XML Functions]: LibXml: TE `prestael_luckins`.`catalogueproducts` SET `Col3` = '1.0mm� 10mm² 09:57:58 [ERR][ XML Functions]: LibXml: ^ 09:57:58 [ERR][ sqlide-history]: Can't parse UPDATE `prestael_luckins`.`catalogueproducts` SET `Col3` = '1.0mm� 10mm²' WHERE (`ProductId` = '334') and (`CategoryId` = '108750'), of file: C:\Users\cliff\AppData\Roaming\MySQL\Workbench\sql_history\2018-02-23 10:00:18 [ERR][SQL Editor Form]: Error querying performance_schema.events_statements_current : Exception: SELECT command denied to user 'newprest_cliff'@'localhost' for table 'events_statements_current' 10:00:18 [ERR][SQL Editor Form]: Error querying performance_schema.event_stages_history : Exception: SELECT command denied to user 'newprest_cliff'@'localhost' for table 'events_stages_history_long' 10:00:18 [ERR][SQL Editor Form]: Error querying performance_schema.event_waits_history : Exception: SELECT command denied to user 'newprest_cliff'@'localhost' for table 'events_waits_history_long'