diff --git a/ChangeLog.md b/ChangeLog.md index 55758cd..a7486fb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,12 @@ # ChangeLog +## 4.1.35.0 +- Prise en compte de la synchronisation des entrepots de WooCommerce vers Dolibarr (Support du module Woocommerce "Stock Locations for WooCommerce" v2.4.2) +- Refonte de la page de configuration des sites +- Suppression de la variable global ECOMMERCENG_WOOCOMMERCE_ORDER_STATUS_LVL_CHECK, l'option est maintenant par site +- Ajout de la synchronisation asynchrone des stocks vers le site +- Refonte des appels aux API. Utilisation de la librarie GuzzleHTTP pour se connecter à Wordpress et WooCommerce + ## 4.1.34.0 - Correction de la prise en compte de l'adresse de livraison (si au moins le nom ou le prenom, et au moins un des 2 champs d'adresses, et le code postal et la ville sont renseignés alors on la traite comme adresse de livraison diff --git a/admin/actions_selectsite.inc.php b/admin/actions_selectsite.inc.php new file mode 100644 index 0000000..9e0f492 --- /dev/null +++ b/admin/actions_selectsite.inc.php @@ -0,0 +1,34 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/actions_selectsite.inc.php + * \ingroup ecommerceng + * \brief Include select site actions + */ + +/** + * Globals + * + * @global string $action + */ + +if ($action == 'select_site') { + $site_id = GETPOST('site_id', 'int'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $site_id); + exit; +} diff --git a/admin/class/gui/eCommerceMenu.class.php b/admin/class/gui/eCommerceMenu.class.php index 559512c..4de8aa7 100644 --- a/admin/class/gui/eCommerceMenu.class.php +++ b/admin/class/gui/eCommerceMenu.class.php @@ -96,7 +96,7 @@ function getMenu() 'type'=>'left', 'titre'=>'ECommerceMenuSetup', 'leftmenu'=>'ecommerceng_setup', - 'url'=>'/ecommerceng/admin/eCommerceSetup.php', + 'url'=>'/ecommerceng/admin/setup.php', 'langs'=>'ecommerce@ecommerceng', 'position'=>120, 'enabled'=>'$conf->ecommerceng->enabled', diff --git a/admin/eCommerceSetup.php b/admin/eCommerceSetup.php deleted file mode 100644 index b06cca0..0000000 --- a/admin/eCommerceSetup.php +++ /dev/null @@ -1,1121 +0,0 @@ - - * Copyright (C) 2016 Laurent Destailleur - * Copyright (C) 2017 Open-DSI - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * or see http://www.gnu.org/ - */ - -/* PAGE setup ecommerce */ - -// Load Dolibarr environment -$res=0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"); -// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME -$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1; -while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; } -if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php"); -if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php"); -// Try main.inc.php using relative path -if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php"); -if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php"); -if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php"); -if (! $res) die("Include of main fails"); - -require_once(DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'); -require_once(DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'); -require_once(DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'); -require_once DOL_DOCUMENT_ROOT . '/includes/OAuth/bootstrap.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; -require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; -dol_include_once('/ecommerceng/class/data/eCommerceSite.class.php'); -dol_include_once('/ecommerceng/admin/class/gui/eCommerceMenu.class.php'); -dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); -dol_include_once('/ecommerceng/class/data/eCommercePaymentGateways.class.php'); - -use OAuth\Common\Storage\DoliStorage; - -$langs->loadLangs(array("admin", "companies", "bills", "accountancy", "banks", "oauth", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); - -$siteId = null; -$errors = array(); -$success = array(); -//CHECK ACCESS -if (!$user->admin && !$user->rights->ecommerceng->site) - accessforbidden(); - -$error = GETPOST('error', 'alpha'); -if (!empty($error)) { - setEventMessage($error, 'errors'); -} - -//DATABASE ACCESS -$siteDb = new eCommerceSite($db); -$form = new Form($db); -$pay_gateways = new eCommercePaymentGateways($db); -$formaccounting = new FormAccounting($db); - -$sites = $siteDb->listSites(); -$siteTypes = $siteDb->getSiteTypes(); -$site_form_select_site = 0; - -// Set $site_form_select_site on first site. -if (count($sites)) -{ - foreach ($sites as $option) - { - $site_form_select_site = $option['id']; - break; - } -} - -//LOAD SELECTED SITE -$siteId = GETPOST('site_form_select_site', 'int'); -if ($siteId > 0) { - Header("Location: " . $_SERVER["PHP_SELF"] . "?ecommerce_id=" . $siteId); - exit; -} -if (empty($siteId)) $siteId = GETPOST('ecommerce_id', 'int'); -if (empty($siteId)) $siteId = $site_form_select_site; - -if ($siteId > 0) - $siteDb->fetch($siteId); - -$list_account = array(); -$list_account[] = '---Product---'; -$list_account[] = 'accounting_product_sold_account'; -if ($mysoc->isInEEC()) { - $list_account[] = 'accounting_product_sold_intra_account'; -} -$list_account[] = 'accounting_product_sold_export_account'; -$list_account[] = 'accounting_product_buy_account'; -if ($mysoc->isInEEC()) { - $list_account[] = 'accounting_product_buy_intra_account'; -} -$list_account[] = 'accounting_product_buy_export_account'; -$list_account[] = '---Service---'; -$list_account[] = 'accounting_service_sold_account'; -if ($mysoc->isInEEC()) { - $list_account[] = 'accounting_service_sold_intra_account'; -} -$list_account[] = 'accounting_service_sold_export_account'; -$list_account[] = 'accounting_service_buy_account'; -if ($mysoc->isInEEC()) { - $list_account[] = 'accounting_service_buy_intra_account'; -} -$list_account[] = 'accounting_service_buy_export_account'; - - -/* - * Actions - */ - -if ($_POST['site_form_detail_action'] == 'save') -{ - if (trim($_POST['ecommerce_name']) == '') - $errors[] = $langs->trans('ECommerceSetupNameEmpty'); - if ($_POST['ecommerce_fk_cat_product'] == 0) - $errors[] = $langs->trans('ECommerceSetupCatProductEmpty'); - if ($_POST['ecommerce_fk_cat_societe'] == 0) - $errors[] = $langs->trans('ECommerceSetupCatSocieteEmpty'); - if ($_POST['ecommerce_type'] == 0) - $errors[] = $langs->trans('ECommerceSetupTypeEmpty'); - if (! ($_POST['ecommerce_fk_warehouse'] > 0) && $_POST['ecommerce_stock_sync_direction'] == 'ecommerce2dolibarr') - setEventMessages($langs->trans('WarningStockProductNotFilled'), null, 'warnings'); - if (trim($_POST['ecommerce_webservice_address']) == '') - $errors[] = $langs->trans('ECommerceSetupAddressEmpty'); - /*if (trim($_POST['ecommerce_timeout']) == '') - $errors[] = $langs->trans('ECommerceSetupTimeoutEmpty'); - elseif (!ctype_digit($_POST['ecommerce_timeout'])) - $errors[] = $langs->trans('ECommerceSetupTimeoutMustBeInt');*/ - - if ($errors == array()) - { - $db->begin(); - $last_price_level = $siteDb->price_level; - $siteDb->name = $_POST['ecommerce_name']; - $siteDb->type = $_POST['ecommerce_type']; - $siteDb->webservice_address = $_POST['ecommerce_webservice_address']; - $siteDb->user_name = $_POST['ecommerce_user_name']; - $siteDb->user_password = $_POST['ecommerce_user_password']; - $siteDb->price_level = $_POST['ecommerce_price_level']; - $siteDb->filter_label = $_POST['ecommerce_filter_label']; - $siteDb->filter_value = $_POST['ecommerce_filter_value']; - $siteDb->fk_cat_societe = $_POST['ecommerce_fk_cat_societe']; - $siteDb->fk_cat_product = $_POST['ecommerce_fk_cat_product']; - $siteDb->fk_anonymous_thirdparty = $_POST['ecommerce_fk_anonymous_thirdparty']>0?$_POST['ecommerce_fk_anonymous_thirdparty']:null; - $siteDb->fk_warehouse = $_POST['ecommerce_fk_warehouse']; - $siteDb->stock_sync_direction = $_POST['ecommerce_stock_sync_direction']; - $siteDb->last_update = $_POST['ecommerce_last_update']; - //$siteDb->timeout = $_POST['ecommerce_timeout']; - $siteDb->magento_use_special_price = ($_POST['ecommerce_magento_use_special_price'] ? 1 : 0); - $siteDb->ecommerce_price_type = $_POST['ecommerce_price_type']; - - if ($siteDb->type == 2) { - $siteDb->oauth_id = $_POST['ecommerce_oauth_id']; - $siteDb->oauth_secret = $_POST['ecommerce_oauth_secret']; - - dolibarr_set_const($db, 'ECOMMERCENG_WOOCOMMERCE_ORDER_STATUS_LVL_CHECK', GETPOST('order_status_dtoe_check_lvl_status', 'alpha') == 'yes' ? 1 : 0, 'chaine', 0, '', $conf->entity); - - $ecommerceOrderActions = array(); - if ($conf->commande->enabled) { - $ecommerceOrderActions['create_order'] = GETPOST('ecommerce_create_order', 'int') ? 1 : 0; - $ecommerceOrderActions['valid_order_fk_warehouse'] = GETPOST('valid_order_fk_warehouse', 'int'); - } - if ($conf->facture->enabled) { - $ecommerceOrderActions['create_invoice'] = GETPOST('ecommerce_create_invoice', 'int') ? 1 : 0; - $ecommerceOrderActions['send_invoice_by_mail'] = GETPOST('ecommerce_send_invoice_by_mail', 'int') ? 1 : 0; - $ecommerceOrderActions['create_invoice_deposit_type'] = GETPOST('ecommerce_create_invoice_deposit_type', 'aZ09'); - $ecommerceOrderActions['create_invoice_deposit_value'] = GETPOST('ecommerce_create_invoice_deposit_value', 'int'); - $ecommerceOrderActions['create_invoice_if_amount_0'] = GETPOST('ecommerce_create_invoice_if_amount_0', 'int') ? 1 : 0; - if (empty($ecommerceOrderActions['create_invoice'])) { - $ecommerceOrderActions['send_invoice_by_mail'] = 0; - $ecommerceOrderActions['create_invoice_deposit_type'] = ''; - $ecommerceOrderActions['create_invoice_deposit_value'] = 0; - $ecommerceOrderActions['create_invoice_if_amount_0'] = 0; - } - } - if ($conf->supplier_invoice->enabled && !empty($ecommerceOrderActions['create_invoice'])) { - $ecommerceOrderActions['create_supplier_invoice'] = GETPOST('ecommerce_create_supplier_invoice', 'int') ? 1 : 0; - } - if ($conf->commande->enabled || $conf->facture->enabled) { - $ecommerceOrderActions['fee_line_as_item_line'] = GETPOST('ecommerce_fee_line_as_item_line', 'int') ? 1 : 0; - } - - $efields = new ExtraFields($db); - $ecommerceExtrafieldsCorrespondence = array(); - // fetch optionals attributes and labels - if ($conf->product->enabled) { - $product_table_element = 'product'; - $ecommerceProductExtrafieldsCorrespondenceAttributes = array(); - $ecommerceExtrafieldsCorrespondence[$product_table_element] = array(); - - $productExtrafields = $efields->fetch_name_optionals_label($product_table_element); - foreach ($productExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - - $options_saved = $siteDb->parameters['ef_crp_attribute'][$key]; - $activated = GETPOST('attribute_ef_crp_state_' . $key, 'alpha'); - $correspondence = GETPOST('attribute_ef_crp_value_' . $key, 'alpha'); - $ecommerceProductExtrafieldsCorrespondenceAttributes[$key] = array( - 'correspondences' => !empty($activated) ? $correspondence : (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => !empty($activated) ? 1 : 0, - ); - - $options_saved = $siteDb->parameters['ef_crp'][$product_table_element][$key]; - $activated = GETPOST('act_ef_crp_' . $product_table_element . '_' . $key, 'alpha'); - $correspondence = GETPOST('ef_crp_' . $product_table_element . '_' . $key, 'alpha'); - $ecommerceExtrafieldsCorrespondence[$product_table_element][$key] = array( - 'correspondences' => !empty($activated) ? $correspondence : (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => !empty($activated) ? 1 : 0, - ); - } - } - - if ($conf->societe->enabled) { - $thirdparty_table_element = 'societe'; - $ecommerceExtrafieldsCorrespondence[$thirdparty_table_element] = array(); - - $thirdpartyExtrafields = $efields->fetch_name_optionals_label($thirdparty_table_element); - foreach ($thirdpartyExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - - $options_saved = $siteDb->parameters['ef_crp'][$thirdparty_table_element][$key]; - $activated = GETPOST('act_ef_crp_' . $thirdparty_table_element . '_' . $key, 'alpha'); - $correspondence = GETPOST('ef_crp_' . $thirdparty_table_element . '_' . $key, 'alpha'); - $ecommerceExtrafieldsCorrespondence[$thirdparty_table_element][$key] = array( - 'correspondences' => !empty($activated) ? $correspondence : (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => !empty($activated) ? 1 : 0, - ); - } - } - - if ($conf->commande->enabled) { - $order_table_element = 'commande'; - $orderExtrafields = $efields->fetch_name_optionals_label($order_table_element, true); - - if (!isset($siteDb->parameters['order_status_etod'])) { - $ecommerceOrderStatusForECommerceToDolibarr = array( - "pending" => array('selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0), - "processing" => array('selected' => 's' . Commande::STATUS_VALIDATED, 'billed' => 0), - "on-hold" => array('selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0), - "completed" => array('selected' => 's' . Commande::STATUS_CLOSED, 'billed' => 1), - "cancelled" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0), - "refunded" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 1), - "failed" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0), - ); - } else { - $ecommerceOrderStatusForECommerceToDolibarr = array(); - if (version_compare(DOL_VERSION, "13.0.0") >= 0) { - $options_list = isset($efields->attributes[$order_table_element]['param']["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options']) ? $efields->attributes[$order_table_element]['param']["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options'] : null; - } else { - $options_list = isset($efields->attribute_param["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options']) ? $efields->attribute_param["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options'] : null; - } - if (is_array($options_list)) { - foreach ($options_list as $key => $value) { - if (($pos = strpos($key, '_')) > 0) $key = substr($key, $pos + 1); - $billed = GETPOST('order_status_etod_billed_' . $key, 'alpha'); - $synchronize = GETPOST('order_status_etod_synchronize_' . $key, 'alpha'); - $ecommerceOrderStatusForECommerceToDolibarr[$key] = array( - 'selected' => GETPOST('order_status_etod_' . $key, 'alpha'), - 'billed' => empty($billed) ? 0 : 1, - 'synchronize' => empty($synchronize) ? 0 : 1, - ); - } - } - } - - if (!empty($ecommerceOrderActions['create_order'])) { - if (!isset($siteDb->parameters['order_status_dtoe'])) { - $ecommerceOrderStatusForDolibarrToECommerce = array( - Commande::STATUS_CANCELED => 'cancelled', - Commande::STATUS_DRAFT => 'on-hold', - Commande::STATUS_VALIDATED => 'processing', - Commande::STATUS_ACCEPTED => 'processing', - Commande::STATUS_CLOSED => 'completed', - ); - } else { - $ecommerceOrderStatusForDolibarrToECommerce = array( - Commande::STATUS_CANCELED => GETPOST('order_status_dtoe_' . Commande::STATUS_CANCELED, 'alpha'), - Commande::STATUS_DRAFT => GETPOST('order_status_dtoe_' . Commande::STATUS_DRAFT, 'alpha'), - Commande::STATUS_VALIDATED => GETPOST('order_status_dtoe_' . Commande::STATUS_VALIDATED, 'alpha'), - Commande::STATUS_ACCEPTED => GETPOST('order_status_dtoe_' . Commande::STATUS_ACCEPTED, 'alpha'), - Commande::STATUS_CLOSED => GETPOST('order_status_dtoe_' . Commande::STATUS_CLOSED, 'alpha'), - ); - } - } - - $ecommerceExtrafieldsCorrespondence[$order_table_element] = array(); - foreach ($orderExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $options_saved = $siteDb->parameters['ef_crp'][$order_table_element][$key]; - $activated = GETPOST('act_ef_crp_' . $order_table_element . '_' . $key, 'int'); - $correspondence = GETPOST('ef_crp_' . $order_table_element . '_' . $key, 'alpha'); - $ecommerceExtrafieldsCorrespondence[$order_table_element][$key] = array( - 'correspondences' => !empty($activated) ? $correspondence : (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => !empty($activated) ? 1 : 0, - ); - } - - $order_line_table_element = 'commandedet'; - $ecommerceExtrafieldsCorrespondence[$order_line_table_element] = array(); - - $orderLinesExtrafields = $efields->fetch_name_optionals_label($order_line_table_element); - foreach ($orderLinesExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $options_saved = $siteDb->parameters['ef_crp'][$order_line_table_element][$key]; - $activated = GETPOST('act_ef_crp_' . $order_line_table_element . '_' . $key, 'int'); - $correspondence = GETPOST('ef_crp_' . $order_line_table_element . '_' . $key, 'alpha'); - $ecommerceExtrafieldsCorrespondence[$order_line_table_element][$key] = array( - 'correspondences' => !empty($activated) ? $correspondence : (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => !empty($activated) ? 1 : 0, - ); - } - } - - if (!isset($_POST['ecommerce_realtime_dtoe_thridparty']) && !isset($siteDb->parameters)) { - $ecommerceRealtimeDolibarrToECommerce = array( - 'thridparty' => 1, - 'contact' => 1, - 'product' => 1, - ); - } else { - $ecommerceRealtimeDolibarrToECommerce = array( - 'thridparty' => !empty($_POST['ecommerce_realtime_dtoe_thridparty']) ? 1 : 0, - 'contact' => !empty($_POST['ecommerce_realtime_dtoe_contact']) ? 1 : 0, - 'product' => !empty($_POST['ecommerce_realtime_dtoe_product']) ? 1 : 0, - ); - } - if ($conf->commande->enabled && !empty($ecommerceOrderActions['create_order'])) { - if (!isset($_POST['ecommerce_realtime_dtoe_order']) && !isset($siteDb->parameters['realtime_dtoe']['order'])) { - $ecommerceRealtimeDolibarrToECommerce['order'] = 1; - } else { - $ecommerceRealtimeDolibarrToECommerce['order'] = !empty($_POST['ecommerce_realtime_dtoe_order']) ? 1 : 0; - } - } - - $ecommerceProductSynchPrice = GETPOST('ecommerce_product_synch_price', 'alpha'); - $ecommerceWoocommerceCustomerRoles = GETPOST('ecommerce_woocommerce_customer_roles', 'alpha'); - $ecommerceOrderFirstDateForECommerceToDolibarr = dol_mktime(0, 0, 0, GETPOST('ecommerce_order_first_date_etodmonth', 'int'), GETPOST('ecommerce_order_first_date_etodday', 'int'), GETPOST('ecommerce_order_first_date_etodyear', 'int')); - - $ecommerceProductSynchDirection = array( - 'image' => isset($_POST['ecommerce_product_image_synch_direction']) ? GETPOST('ecommerce_product_image_synch_direction', 'alpha') : 'etod', - 'ref' => isset($_POST['ecommerce_product_ref_synch_direction']) ? GETPOST('ecommerce_product_ref_synch_direction', 'alpha') : 'etod', - 'description' => isset($_POST['ecommerce_product_description_synch_direction']) ? GETPOST('ecommerce_product_description_synch_direction', 'alpha') : 'etod', - 'short_description' => isset($_POST['ecommerce_product_short_description_synch_direction']) ? GETPOST('ecommerce_product_short_description_synch_direction', 'alpha') : 'etod', - 'tax' => isset($_POST['ecommerce_product_tax_synch_direction']) ? GETPOST('ecommerce_product_tax_synch_direction', 'alpha') : 'etod', - 'status' => isset($_POST['ecommerce_product_status_synch_direction']) ? GETPOST('ecommerce_product_status_synch_direction', 'alpha') : 'etod', - ); - if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) { - $ecommerceProductSynchDirection['weight'] = isset($_POST['ecommerce_product_weight_synch_direction']) ? GETPOST('ecommerce_product_weight_synch_direction', 'alpha') : 'etod'; - } - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { - $ecommerceProductSynchDirection['dimension'] = isset($_POST['ecommerce_product_dimension_synch_direction']) ? GETPOST('ecommerce_product_dimension_synch_direction', 'alpha') : 'etod'; - } - $ecommerceCreateInvoiceType = GETPOST('ecommerce_create_invoice_type', 'int'); - if (empty($ecommerceCreateInvoiceType)) $ecommerceCreateInvoiceType = Facture::TYPE_STANDARD; - - $ecommerceDefaultAccount = array(); - foreach ($list_account as $key) { - if (!preg_match('/---(.*)---/', $key, $reg)) { - $ecommerceDefaultAccount[$key] = GETPOST($key, 'alpha'); - } - } - - $siteDb->parameters = array( - 'shipping_service' => $_POST['ecommerce_fk_shipping_service'], - 'discount_code_service' => $_POST['ecommerce_fk_discount_code_service'], - 'pw_gift_cards_service' => $_POST['ecommerce_fk_pw_gift_cards_service'], - 'web_hooks_secret' => $_POST['ecommerce_web_hooks_secret'], - 'web_hooks_volumetry_alert' => $_POST['ecommerce_web_hooks_volumetry_alert'], - 'order_status_etod' => $ecommerceOrderStatusForECommerceToDolibarr, - 'order_status_dtoe' => $ecommerceOrderStatusForDolibarrToECommerce, - 'order_first_date_etod' => $ecommerceOrderFirstDateForECommerceToDolibarr, - 'ef_crp_attribute' => $ecommerceProductExtrafieldsCorrespondenceAttributes, - 'ef_crp' => $ecommerceExtrafieldsCorrespondence, - 'payment_cond' => $_POST['ecommerce_payment_cond'], - 'fk_warehouse_to_ecommerce' => GETPOST('ecommerce_fk_warehouse_to_ecommerce', 'array'), - 'realtime_dtoe' => $ecommerceRealtimeDolibarrToECommerce, - 'product_synch_direction' => $ecommerceProductSynchDirection, - 'product_synch_price' => $ecommerceProductSynchPrice, - 'product_variation_mode' => GETPOSTISSET('ecommerce_product_variation_mode') ? GETPOST('ecommerce_product_variation_mode', 'aZ09') : 'one_to_one', - 'customer_roles' => $ecommerceWoocommerceCustomerRoles, - 'create_invoice_type' => $ecommerceCreateInvoiceType, - 'order_metadata_product_lines_to_description_etod' => GETPOSTISSET('ecommerce_order_metadata_product_lines_to_description_etod') ? (GETPOST('ecommerce_order_metadata_product_lines_to_description_etod', 'int') > 0 ? 1 : 0) : 0, - 'order_filter_mode_metadata_product_lines_to_description_etod' => GETPOSTISSET('ecommerce_order_filter_mode_metadata_product_lines_to_description_etod') ? GETPOST('ecommerce_order_filter_mode_metadata_product_lines_to_description_etod', 'aZ09') : 'exclude', - 'order_filter_keys_metadata_product_lines_to_description_etod' => GETPOST('ecommerce_order_filter_keys_metadata_product_lines_to_description_etod', 'alpha'), - 'default_account' => $ecommerceDefaultAccount, - 'dont_update_dolibarr_company' => GETPOSTISSET('ecommerce_dont_update_dolibarr_company') ? (GETPOST('ecommerce_dont_update_dolibarr_company', 'int') > 0 ? 1 : 0) : 0, - ); - if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) { - $siteDb->parameters['product_weight_units'] = $_POST['ecommerce_product_weight_units']; - } - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { - $siteDb->parameters['product_dimension_units'] = $_POST['ecommerce_product_dimension_units']; - } - if ($conf->commande->enabled || $conf->facture->enabled || $conf->supplier_invoice->enabled) { - $siteDb->parameters['order_actions'] = $ecommerceOrderActions; - } - if ($ecommerceOrderActions['create_order'] || $ecommerceOrderActions['create_invoice'] || $ecommerceOrderActions['create_supplier_invoice']) { - $siteDb->parameters['default_sales_representative_follow'] = isset($_POST['default_sales_representative_follow']) ? GETPOST('default_sales_representative_follow', 'int') : 0; - } - } - - $result = 0; - if (intval($_POST['ecommerce_id']) > 0) - { - $siteDb->id = $_POST['ecommerce_id']; - $result = $siteDb->update($user); - } else - { - $result = $siteDb->create($user); - } - - $error = ''; - if ($result > 0) { - if ($siteDb->type == 2) { // Woocommerce - $result = ecommerceng_add_extrafields($db, $langs, [ - [ - 'attrname' => "ecommerceng_description_{$conf->entity}", - 'label' => 'ECommercengWoocommerceDescription', - 'type' => 'text', - 'pos' => 1, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_short_description_{$conf->entity}", - 'label' => 'ECommercengWoocommerceShortDescription', - 'type' => 'text', - 'pos' => 2, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceStatus', $siteDb->name), - 'type' => 'select', - 'pos' => 3, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => array('options' => array( - "draft" => $langs->trans('ECommercengWoocommerceStatusDraft'), - "pending" => $langs->trans('ECommercengWoocommerceStatusPending'), - "private" => $langs->trans('ECommercengWoocommerceStatusPrivate'), - "publish" => $langs->trans('ECommercengWoocommerceStatusPublish'), - )), - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_tax_class_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceTaxClass', $siteDb->name), - 'type' => 'sellist', - 'pos' => 4, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => array('options' => array("c_ecommerceng_tax_class:label:code::active=1 AND site_id={$siteDb->id} AND entity={$conf->entity}" => null)), - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - /*],[ - 'attrname' => "ecommerceng_wc_regular_price_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceRegularPrice', $siteDb->name), - 'type' => 'price', - 'pos' => 5, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1,*/ - ], [ - 'attrname' => "ecommerceng_wc_sale_price_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceSalePrice', $siteDb->name), - 'type' => 'price', - 'pos' => 6, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_date_on_sale_from_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceDateOnSaleFrom', $siteDb->name), - 'type' => 'date', - 'pos' => 7, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_date_on_sale_to_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceDateOnSaleTo', $siteDb->name), - 'type' => 'date', - 'pos' => 8, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_manage_stock_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceManageStock', $siteDb->name), - 'type' => 'boolean', - 'pos' => 9, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '1', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_dont_update_stock_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceDontUpdateStock', $siteDb->name), - 'type' => 'boolean', - 'pos' => 10, - 'size' => '', - 'elementtype' => 'product', - 'unique' => 0, - 'required' => 0, - 'default_value' => '0', - 'param' => '', - 'alwayseditable' => 1, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_online_payment_{$conf->entity}", - 'label' => 'ECommercengWoocommerceOnlinePayment', - 'type' => 'boolean', - 'pos' => 1, - 'size' => '1', - 'elementtype' => 'commande', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 0, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceOrderStatus', $siteDb->name), - 'type' => 'select', - 'pos' => 2, - 'size' => '', - 'elementtype' => 'commande', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => array('options' => array( - "0_pending" => $langs->trans('ECommercengWoocommerceOrderStatusPending'), - "1_on-hold" => $langs->trans('ECommercengWoocommerceOrderStatusOnHold'), - "2_processing" => $langs->trans('ECommercengWoocommerceOrderStatusProcessing'), - "3_completed" => $langs->trans('ECommercengWoocommerceOrderStatusCompleted'), - "3_cancelled" => $langs->trans('ECommercengWoocommerceOrderStatusCancelled'), - "3_refunded" => $langs->trans('ECommercengWoocommerceOrderStatusRefunded'), - "3_failed" => $langs->trans('ECommercengWoocommerceOrderStatusFailed'), - "3_trash" => $langs->trans('ECommercengWoocommerceOrderStatusTrash'), - )), - 'alwayseditable' => 0, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_link_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceOrderLink', $siteDb->name), - 'type' => 'url', - 'pos' => 3, - 'size' => '', - 'elementtype' => 'commande', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => null, - 'alwayseditable' => 0, - 'perms' => '', - 'list' => 1, - ], [ - 'attrname' => "ecommerceng_wc_role_{$siteDb->id}_{$conf->entity}", - 'label' => $langs->trans('ECommercengWoocommerceCompanyRole', $siteDb->name), - 'type' => 'varchar', - 'pos' => 0, - 'size' => '255', - 'elementtype' => 'societe', - 'unique' => 0, - 'required' => 0, - 'default_value' => '', - 'param' => '', - 'alwayseditable' => 0, - 'perms' => '', - 'list' => 1, - ], - ], $error); - - // Fix extrafields wc_update_stock to wc_manage_stock on product - $db->query("UPDATE " . MAIN_DB_PREFIX . "product_extrafields SET ecommerceng_wc_manage_stock_{$siteDb->id}_{$conf->entity} = ecommerceng_wc_update_stock_{$siteDb->id}_{$conf->entity}"); - $efields = new ExtraFields($db); - $efields->delete("ecommerceng_wc_update_stock_{$siteDb->id}_{$conf->entity}", 'product'); - } - - if ($result > 0 && (!empty($ecommerceOrderActions['create_order']) || !empty($ecommerceOrderActions['create_invoice']) || !empty($ecommerceOrderActions['create_supplier_invoice']))) { - // Payment gateways correspondence - $ecommercePaymentGateways = $pay_gateways->get_all($siteDb->id); - if (is_array($ecommercePaymentGateways)) { - foreach ($ecommercePaymentGateways as $payment_gateway_id => $infos) { - $ecommercePaymentGateways[$payment_gateway_id]['payment_mode_id'] = isset($_POST['payment_mode_id_' . $payment_gateway_id]) && (!empty($ecommerceOrderActions['create_order']) || !empty($ecommerceOrderActions['create_invoice']) || !empty($ecommerceOrderActions['create_supplier_invoice'])) ? GETPOST('payment_mode_id_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['bank_account_id'] = isset($_POST['bank_account_id_' . $payment_gateway_id]) && $conf->banque->enabled && (!empty($ecommerceOrderActions['create_invoice']) || !empty($ecommerceOrderActions['create_supplier_invoice'])) ? GETPOST('bank_account_id_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['create_invoice_payment'] = isset($_POST['create_invoice_payment_' . $payment_gateway_id]) && !empty($ecommerceOrderActions['create_invoice']) ? GETPOST('create_invoice_payment_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['mail_model_for_send_invoice'] = isset($_POST['mail_model_for_send_invoice_' . $payment_gateway_id]) && !empty($ecommerceOrderActions['send_invoice_by_mail']) ? GETPOST('mail_model_for_send_invoice_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['supplier_id'] = isset($_POST['supplier_id_' . $payment_gateway_id]) && !empty($ecommerceOrderActions['create_supplier_invoice']) ? GETPOST('supplier_id_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['product_id_for_fee'] = isset($_POST['product_id_for_fee_' . $payment_gateway_id]) && !empty($ecommerceOrderActions['create_supplier_invoice']) ? GETPOST('product_id_for_fee_' . $payment_gateway_id, 'int') : 0; - $ecommercePaymentGateways[$payment_gateway_id]['create_supplier_invoice_payment'] = isset($_POST['create_supplier_invoice_payment_' . $payment_gateway_id]) && !empty($ecommerceOrderActions['create_supplier_invoice']) ? GETPOST('create_supplier_invoice_payment_' . $payment_gateway_id, 'int') : 0; - } - - $result = $pay_gateways->set($siteDb->id, $ecommercePaymentGateways); - if ($result < 0) { - setEventMessages($pay_gateways->error, $pay_gateways->errors, 'errors'); - } - } else { - setEventMessages($pay_gateways->error, $pay_gateways->errors, 'errors'); - $result = -1; - } - } - } - - if ($result > 0) - { -// $eCommerceMenu = new eCommerceMenu($db, $siteDb); -// $eCommerceMenu->updateMenu(); - $db->commit(); - -// if ($siteDb->type == 2) { // Woocommerce -// ecommerceng_update_woocommerce_dict_tax_class($db, $siteDb); -// } - if (!empty($conf->global->PRODUIT_MULTIPRICES) && $siteDb->price_level != $last_price_level) { - updatePriceLevel($siteDb); - } - - setEventMessages($langs->trans('ECommerceSetupSaved'), null); - Header("Location: " . $_SERVER["PHP_SELF"] . "?ecommerce_id=".$siteDb->id); - exit; - } else - { - $db->rollback(); - if (!empty($error)) { - setEventMessage($error, 'errors'); - } else { - setEventMessages($siteDb->error, $siteDb->errors, 'errors'); - } - } - } - else - { - setEventMessages('', $errors, 'errors'); - } -} -//DELETE -elseif ($_POST['site_form_detail_action'] == 'delete') -{ - $db->begin(); - $siteDb->id = $_POST['ecommerce_id']; - $result = $siteDb->delete($user); - if ($result < 0) - { - setEventMessages($langs->trans('ECommerceDeleteErrorDb'), null, 'errors'); - } - else - { - $efields = new ExtraFields($db); - $efields->delete("ecommerceng_description_{$conf->entity}"); - $efields->delete("ecommerceng_short_description_{$conf->entity}"); - $efields->delete("ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_tax_class_{$siteDb->id}_{$conf->entity}"); -// $efields->delete("ecommerceng_wc_regular_price_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_wc_sale_price_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_wc_date_on_sale_from_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_wc_date_on_sale_to_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_online_payment_{$conf->entity}"); - $efields->delete("ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"); - $efields->delete("ecommerceng_wc_role_{$siteDb->id}_{$conf->entity}"); - - // Delete all VAT for the site - $resql = $db->query('DELETE FROM ' . MAIN_DB_PREFIX . 'c_ecommerceng_tax_class WHERE site_id = ' . $siteDb->id . ' AND entity = ' . $conf->entity); - - $pay_gateways->delete_all($siteDb->id); - -// $eCommerceMenu = new eCommerceMenu($db, $siteDb); -// $eCommerceMenu->updateMenu(); - $success[] = $langs->trans('ECommerceDeleteOk'); - $siteDb->id = null; - unset($_POST); - Header("Location: " . $_SERVER["PHP_SELF"]); - exit; - } -} -// Update dictionary for attribute of woocommerce -elseif ($_POST['site_form_detail_action'] == 'update_woocommerce_attribute') { - if (ecommerceng_update_woocommerce_attribute($db, $siteDb)) { - setEventMessage($langs->trans('ECommercengWoocommerceDictAttributesUpdated')); - } -} -// Update dictionary for tax class of woocommerce -elseif ($_POST['site_form_detail_action'] == 'update_woocommerce_tax_class') { - if (ecommerceng_update_woocommerce_dict_tax($db, $siteDb)) { - setEventMessage($langs->trans('ECommercengWoocommerceDictTaxClassUpdated')); - } -} -// Update payment gateways -elseif ($_POST['site_form_detail_action'] == 'update_payment_gateways') { - if (ecommerceng_update_payment_gateways($db, $siteDb)) { - setEventMessage($langs->trans('ECommercePaymentGatewaysUpdated')); - } -} - - - -/* - * View - */ - -/*if (! extension_loaded('soap')) -{ - llxHeader(); - - print info_admin($langs->trans("ErrorModuleSoapRequired")); - - llxFooter(); - exit; -}*/ - -if ($siteId > 0) - $siteDb->fetch($siteId); - -$classCategorie = new Categorie($db); -$productCategories = $classCategorie->get_full_arbo('product'); -$societeCategories = $classCategorie->get_full_arbo('customer'); - -if (!empty($conf->global->PRODUIT_MULTIPRICES)) { - $priceLevels = array(); - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { - $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i; - $priceLevels[$i] = !empty($conf->global->$keyforlabel) ? $langs->trans($conf->global->$keyforlabel) : $i; - } -} - -//SET VARIABLES -$ecommerceId = $siteId; -$ecommerceName = ($_POST['ecommerce_name'] ? $_POST['ecommerce_name'] : $siteDb->name); -$ecommerceType = ($_POST['ecommerce_type'] ? $_POST['ecommerce_type'] : intval($siteDb->type)); -$ecommerceWebserviceAddress = ($_POST['ecommerce_webservice_address'] ? $_POST['ecommerce_webservice_address'] : $siteDb->webservice_address); -$ecommerceWebserviceAddressTest = ''; -if (!empty($ecommerceWebserviceAddress)) { - switch ($ecommerceType) { - case 1: // Magento - $ecommerceWebserviceAddressTest = $ecommerceWebserviceAddress .(substr($ecommerceWebserviceAddress, -1, 1)!='/'?'/':''). 'api/?wsdl'; - break; - case 2: // Woocommerce - $ecommerceWebserviceAddressTest = $ecommerceWebserviceAddress .(substr($ecommerceWebserviceAddress, -1, 1)!='/'?'/':''). 'wp-json/'; - break; - } -} -$ecommerceUserName = ($_POST['ecommerce_user_name'] ? $_POST['ecommerce_user_name'] : $siteDb->user_name); -$ecommerceUserPassword = ($_POST['ecommerce_user_password'] ? $_POST['ecommerce_user_password'] : $siteDb->user_password); -$ecommercePriceLevel = ($_POST['ecommerce_price_level'] ? $_POST['ecommerce_price_level'] : $siteDb->price_level); -$ecommerceFilterLabel = ($_POST['ecommerce_filter_label'] ? $_POST['ecommerce_filter_label'] : $siteDb->filter_label); -$ecommerceFilterValue = ($_POST['ecommerce_filter_value'] ? $_POST['ecommerce_filter_value'] : $siteDb->filter_value); -$ecommerceFkCatSociete = ($_POST['ecommerce_fk_cat_societe'] ? $_POST['ecommerce_fk_cat_societe'] : intval($siteDb->fk_cat_societe)); -$ecommerceFkCatProduct = ($_POST['ecommerce_fk_cat_product'] ? $_POST['ecommerce_fk_cat_product'] : intval($siteDb->fk_cat_product)); -$ecommerceFkAnonymousThirdparty = ($_POST['ecommerce_fk_anonymous_thirdparty'] ? $_POST['ecommerce_fk_anonymous_thirdparty'] : intval($siteDb->fk_anonymous_thirdparty)); -$ecommerceFkWarehouseToECommerce = GETPOSTISSET('ecommerce_fk_warehouse_to_ecommerce') ? GETPOST('ecommerce_fk_warehouse_to_ecommerce', 'array') : (isset($siteDb->parameters['fk_warehouse_to_ecommerce']) ? $siteDb->parameters['fk_warehouse_to_ecommerce'] : array()); -$ecommerceFkWarehouse = ($_POST['ecommerce_fk_warehouse'] ? $_POST['ecommerce_fk_warehouse'] : intval($siteDb->fk_warehouse)); -$ecommerceStockSyncDirection = ($_POST['ecommerce_stock_sync_direction'] ? $_POST['ecommerce_stock_sync_direction'] : $siteDb->stock_sync_direction); -$ecommerceMagentoUseSpecialPrice = ($_POST['ecommerce_magento_use_special_price'] ? $_POST['ecommerce_magento_use_special_price'] : intval($siteDb->magento_use_special_price)); -$ecommercePriceType = ($_POST['ecommerce_price_type'] ? $_POST['ecommerce_price_type'] : $siteDb->ecommerce_price_type); -$ecommercePaymentCondition = ($_POST['ecommerce_payment_cond'] ? $_POST['ecommerce_payment_cond'] : (isset($siteDb->parameters['payment_cond']) ? $siteDb->parameters['payment_cond'] : '')); -$ecommerceRealtimeDtoe = (isset($siteDb->parameters['realtime_dtoe']) ? $siteDb->parameters['realtime_dtoe'] : array()); -$ecommerceOrderActions = (isset($siteDb->parameters['order_actions']) ? $siteDb->parameters['order_actions'] : array()); -$ecommerceDefaultSalesRepresentativeFollow = (isset($siteDb->parameters['default_sales_representative_follow']) ? $siteDb->parameters['default_sales_representative_follow'] : 0); -$ecommerceDontUpdateDolibarrCompany = (isset($siteDb->parameters['dont_update_dolibarr_company']) ? $siteDb->parameters['dont_update_dolibarr_company'] : 0); -/*$ecommerceTimeout = 300; -if (isset($_POST['ecommerce_timeout'])) - $ecommerceTimeout = $_POST['ecommerce_timeout']; -elseif (isset($siteDb->timeout)) - $ecommerceTimeout = $siteDb->timeout;*/ -$ecommerceOAuth = false; -$ecommerceOAuthGenerateToken = false; -$ecommerceOrderStatus = false; -if ($ecommerceId > 0) { - if ($ecommerceType == 2) { - $ecommerceOAuth = true; - $ecommerceOAuthWordpressOAuthSetupUri = $ecommerceWebserviceAddress . (substr($ecommerceWebserviceAddress, -1, 1) != '/' ? '/' : '') . 'wp-admin/admin.php?page=wo_settings#clients'; - $ecommerceOrderStatus = $conf->commande->enabled; - - $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); - $currentUri = $uriFactory->createFromAbsolute(dol_buildpath('/ecommerceng/webhooks.php', 2) . '?ecommerce_id=' . $siteId); - $eCommerceSiteWebHooksUrl = $currentUri->getAbsoluteUri(); - $eCommerceSiteWebHooksSecret = (!empty($_POST['ecommerce_web_hooks_secret']) ? $_POST['ecommerce_web_hooks_secret'] : (!empty($siteDb->parameters['web_hooks_secret']) ? $siteDb->parameters['web_hooks_secret'] : '')); - $eCommerceSiteWebHooksVolumetryAlert = (!empty($_POST['ecommerce_web_hooks_volumetry_alert']) ? $_POST['ecommerce_web_hooks_volumetry_alert'] : (!empty($siteDb->parameters['web_hooks_volumetry_alert']) ? $siteDb->parameters['web_hooks_volumetry_alert'] : '')); - - $ecommerceFkShippingService = (!empty($_POST['ecommerce_fk_shipping_service']) ? $_POST['ecommerce_fk_shipping_service'] : (!empty($siteDb->parameters['shipping_service']) ? $siteDb->parameters['shipping_service'] : '')); - $ecommerceFkDiscountCodeService = (!empty($_POST['ecommerce_fk_discount_code_service']) ? $_POST['ecommerce_fk_discount_code_service'] : (!empty($siteDb->parameters['discount_code_service']) ? $siteDb->parameters['discount_code_service'] : '')); - $ecommerceFkPwGiftCardsService = (!empty($_POST['ecommerce_fk_pw_gift_cards_service']) ? $_POST['ecommerce_fk_pw_gift_cards_service'] : (!empty($siteDb->parameters['pw_gift_cards_service']) ? $siteDb->parameters['pw_gift_cards_service'] : '')); - } - - if ($ecommerceOAuth) { - // Create callback URL - //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); - //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file - $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); - //$currentUri = $uriFactory->createFromAbsolute($urlwithroot.'/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php?ecommerce_id='.$siteId); - $currentUri = $uriFactory->createFromAbsolute(dol_buildpath('/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php', 2).'?ecommerce_id='.$siteId); - $ecommerceOAuthRedirectUri = $currentUri->getAbsoluteUri(); -// $ecommerceOAuthRedirectUri = dol_buildpath('/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php', 2).'?ecommerce_id='.$ecommerceId; - $ecommerceOAuthId = ($_POST['ecommerce_oauth_id'] ? $_POST['ecommerce_oauth_id'] : $siteDb->oauth_id); - $ecommerceOAuthSecret = ($_POST['ecommerce_oauth_secret'] ? $_POST['ecommerce_oauth_secret'] : $siteDb->oauth_secret); - - // Token - $ecommerceOAuthTokenObj = null; - $storage = new DoliStorage($db, $conf); - try { - $ecommerceOAuthTokenObj = $storage->retrieveAccessToken('ECommerce_'.$ecommerceId); - } catch(Exception $e) {} - $ecommerceOAuthGenerateToken = (!empty($ecommerceOAuthId) && !empty($ecommerceOAuthSecret) || is_object($ecommerceOAuthTokenObj)); - - $ecommerceOAuthBackToUri = urlencode(dol_buildpath('/ecommerceng/admin/eCommerceSetup.php', 1).'?ecommerce_id='.$ecommerceId); - - if (is_object($ecommerceOAuthTokenObj)) { - $ecommerceOAuthTokenExpired = ($ecommerceOAuthTokenObj->getEndOfLife() !== $ecommerceOAuthTokenObj::EOL_NEVER_EXPIRES && $ecommerceOAuthTokenObj->getEndOfLife() !== $ecommerceOAuthTokenObj::EOL_UNKNOWN && time() > ($ecommerceOAuthTokenObj->getEndOfLife() - 30)); - - $ecommerceOAuthHasRefreshToken = !empty($ecommerceOAuthTokenObj->getRefreshToken()); - - $endoflife = $ecommerceOAuthTokenObj->getEndOfLife(); - if ($endoflife == $ecommerceOAuthTokenObj::EOL_NEVER_EXPIRES) { - $ecommerceOAuthTokenExpireDate = $langs->trans("Never"); - } elseif ($endoflife == $ecommerceOAuthTokenObj::EOL_UNKNOWN) { - $ecommerceOAuthTokenExpireDate = $langs->trans("Unknown"); - } else { - $ecommerceOAuthTokenExpireDate = dol_print_date($endoflife, "dayhour"); - } - } - } - - if ($ecommerceOrderStatus) { - $efields = new ExtraFields($db); - $efields->fetch_name_optionals_label('commande', true); - $ecommerceOrderStatusForECommerceToDolibarr = array(); - $defaultOrderStatusForECommerceToDolibarr = array( - "pending" => array('selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0, 'synchronize' => 1), - "processing" => array('selected' => 's' . Commande::STATUS_VALIDATED, 'billed' => 0, 'synchronize' => 1), - "on-hold" => array('selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0, 'synchronize' => 1), - "completed" => array('selected' => 's' . Commande::STATUS_CLOSED, 'billed' => 1, 'synchronize' => 1), - "cancelled" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0, 'synchronize' => 1), - "refunded" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 1, 'synchronize' => 1), - "failed" => array('selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0, 'synchronize' => 1), - ); - - if (version_compare(DOL_VERSION, "13.0.0") >= 0) { - $options_list = isset($efields->attributes['commande']['param']["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options']) ? $efields->attributes['commande']['param']["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options'] : null; - } else { - $options_list = isset($efields->attribute_param["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options']) ? $efields->attribute_param["ecommerceng_wc_status_{$siteDb->id}_{$conf->entity}"]['options'] : null; - } - if (is_array($options_list)) { - foreach ($options_list as $key => $value) { - if (($pos = strpos($key , '_')) > 0) $key = substr($key, $pos + 1); - $selected = GETPOST('order_status_etod_' . $key, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_etod'][$key]['selected']) ? $siteDb->parameters['order_status_etod'][$key]['selected'] : $defaultOrderStatusForECommerceToDolibarr[$key]['selected']); - $billed = isset($_POST['order_status_etod_billed_' . $key]) ? GETPOST('order_status_etod_billed_' . $key, 'alpha') : - (isset($siteDb->parameters['order_status_etod'][$key]['billed']) ? $siteDb->parameters['order_status_etod'][$key]['billed'] : $defaultOrderStatusForECommerceToDolibarr[$key]['billed']); - $synchronize = isset($_POST['order_status_etod_synchronize_' . $key]) ? GETPOST('order_status_etod_synchronize_' . $key, 'alpha') : - (isset($siteDb->parameters['order_status_etod'][$key]['synchronize']) ? $siteDb->parameters['order_status_etod'][$key]['synchronize'] : $defaultOrderStatusForECommerceToDolibarr[$key]['synchronize']); - $ecommerceOrderStatusForECommerceToDolibarr[$key] = array('label' => $value, 'selected' => $selected, 'billed' => $billed, 'synchronize' => $synchronize); - } - } - - $commande = new Commande($db); - $langs->load('orders'); - $langs->load('bills'); - $ecommerceOrderStatusForDolibarrToECommerce = array(); - $defaultOrderStatusForDolibarrToECommerce = array( - Commande::STATUS_CANCELED => 'cancelled', - Commande::STATUS_DRAFT => 'on-hold', - Commande::STATUS_VALIDATED => 'processing', - Commande::STATUS_ACCEPTED => 'processing', - Commande::STATUS_CLOSED => 'completed', - ); - $selected = GETPOST('order_status_dtoe_' . Commande::STATUS_CANCELED, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_dtoe'][Commande::STATUS_CANCELED]) ? $siteDb->parameters['order_status_dtoe'][Commande::STATUS_CANCELED] : $defaultOrderStatusForDolibarrToECommerce[Commande::STATUS_CANCELED]); - $ecommerceOrderStatusForDolibarrToECommerce['s'.Commande::STATUS_CANCELED] = array( - 'label' => $commande->LibStatut(Commande::STATUS_CANCELED, 0, 0, 1), - 'selected' => $selected - ); - $selected = GETPOST('order_status_dtoe_' . Commande::STATUS_DRAFT, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_dtoe'][Commande::STATUS_DRAFT]) ? $siteDb->parameters['order_status_dtoe'][Commande::STATUS_DRAFT] : $defaultOrderStatusForDolibarrToECommerce[Commande::STATUS_DRAFT]); - $ecommerceOrderStatusForDolibarrToECommerce['s'.Commande::STATUS_DRAFT] = array( - 'label' => $commande->LibStatut(Commande::STATUS_DRAFT, 0, 0, 1), - 'selected' => $selected - ); - $selected = GETPOST('order_status_dtoe_' . Commande::STATUS_VALIDATED, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_dtoe'][Commande::STATUS_VALIDATED]) ? $siteDb->parameters['order_status_dtoe'][Commande::STATUS_VALIDATED] : $defaultOrderStatusForDolibarrToECommerce[Commande::STATUS_VALIDATED]); - $ecommerceOrderStatusForDolibarrToECommerce['s'.Commande::STATUS_VALIDATED] = array( - 'label' => $commande->LibStatut(Commande::STATUS_VALIDATED, 0, 0, 1), - 'selected' => $selected - ); - $selected = GETPOST('order_status_dtoe_' . Commande::STATUS_ACCEPTED, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_dtoe'][Commande::STATUS_ACCEPTED]) ? $siteDb->parameters['order_status_dtoe'][Commande::STATUS_ACCEPTED] : $defaultOrderStatusForDolibarrToECommerce[Commande::STATUS_ACCEPTED]); - $ecommerceOrderStatusForDolibarrToECommerce['s'.Commande::STATUS_ACCEPTED] = array( - 'label' => $commande->LibStatut(Commande::STATUS_ACCEPTED, 0, 0, 1), - 'selected' => $selected - ); - $selected = GETPOST('order_status_dtoe_' . Commande::STATUS_CLOSED, 'alpha'); - $selected = $selected ? $selected : (isset($siteDb->parameters['order_status_dtoe'][Commande::STATUS_CLOSED]) ? $siteDb->parameters['order_status_dtoe'][Commande::STATUS_CLOSED] : $defaultOrderStatusForDolibarrToECommerce[Commande::STATUS_CLOSED]); - $ecommerceOrderStatusForDolibarrToECommerce['s'.Commande::STATUS_CLOSED] = array( - 'label' => $commande->LibStatut(Commande::STATUS_CLOSED, 0, 0, 1), - 'selected' => $selected - ); - } - - // Payment gateways correspondence - if (!empty($ecommerceOrderActions['create_order']) || !empty($ecommerceOrderActions['create_invoice']) || !empty($ecommerceOrderActions['create_supplier_invoice'])) { - $ecommercePaymentGateways = $pay_gateways->get_all($siteDb->id); - if (!is_array($ecommercePaymentGateways) && $ecommercePaymentGateways < 0) { - setEventMessages($pay_gateways->error, $pay_gateways->errors, 'errors'); - } - } - - if ($ecommerceType == 2) { - // Extrafields correspondence - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($db); - - // Get all attributes in dictionary for this entity and site - dol_include_once('/ecommerceng/admin/class/data/eCommerceDict.class.php'); - $eCommerceDict = new eCommerceDict($db, MAIN_DB_PREFIX.'c_ecommerceng_attribute'); - $dict_attributes = $eCommerceDict->search(['entity'=>['value'=>$conf->entity],'site_id'=>['value'=>$siteDb->id]]); - $attributes_array = array(); - foreach ($dict_attributes as $attribute) { - $attributes_array[$attribute['attribute_id']] = $attribute['attribute_name']; - $attributes_name_array[$attribute['attribute_name']] = $attribute['attribute_id']; - } - - // fetch optionals attributes and labels - if ($conf->product->enabled) { - $product_table_element = 'product'; - $productExtrafields = array(); - $ecommerceProductExtrafieldsCorrespondenceAttributes = array(); - $ecommerceExtrafieldsCorrespondence[$product_table_element] = array(); - - $tempExtrafields = $extrafields->fetch_name_optionals_label($product_table_element); - foreach ($tempExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $productExtrafields[$key] = $label; - - $options_saved = $siteDb->parameters['ef_crp_attribute'][$key]; - $ecommerceProductExtrafieldsCorrespondenceAttributes[$key] = array( - 'correspondences' => (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => (isset($options_saved['activated']) ? $options_saved['activated'] : 0), - ); - - $options_saved = $siteDb->parameters['ef_crp'][$product_table_element][$key]; - $ecommerceExtrafieldsCorrespondence[$product_table_element][$key] = array( - 'correspondences' => (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => (isset($options_saved['activated']) ? $options_saved['activated'] : 0), - ); - } - } - if ($conf->societe->enabled) { - $thirdparty_table_element = 'societe'; - $thirdPartyExtrafields = array(); - $ecommerceExtrafieldsCorrespondence[$thirdparty_table_element] = array(); - - $tempExtrafields = $extrafields->fetch_name_optionals_label($thirdparty_table_element); - foreach ($tempExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $thirdPartyExtrafields[$key] = $label; - - $options_saved = $siteDb->parameters['ef_crp'][$thirdparty_table_element][$key]; - $ecommerceExtrafieldsCorrespondence[$thirdparty_table_element][$key] = array( - 'correspondences' => (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => (isset($options_saved['activated']) ? $options_saved['activated'] : 0), - ); - } - } - if ($conf->commande->enabled) { - $order_table_element = 'commande'; - $orderExtrafields = array(); - $ecommerceExtrafieldsCorrespondence[$order_table_element] = array(); - - $tempExtrafields = $extrafields->fetch_name_optionals_label($order_table_element); - foreach ($tempExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $orderExtrafields[$key] = $label; - $options_saved = $siteDb->parameters['ef_crp'][$order_table_element][$key]; - $ecommerceExtrafieldsCorrespondence[$order_table_element][$key] = array( - 'correspondences' => (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => (isset($options_saved['activated']) ? $options_saved['activated'] : 0), - ); - } - - $order_line_table_element = 'commandedet'; - $orderLinesExtrafields = array(); - $ecommerceExtrafieldsCorrespondence[$order_line_table_element] = array(); - - $tempExtrafields = $extrafields->fetch_name_optionals_label($order_line_table_element); - foreach ($tempExtrafields as $key => $label) { - if (preg_match('/^ecommerceng_/', $key)) continue; - $orderLinesExtrafields[$key] = $label; - $options_saved = $siteDb->parameters['ef_crp'][$order_line_table_element][$key]; - $ecommerceExtrafieldsCorrespondence[$order_line_table_element][$key] = array( - 'correspondences' => (isset($options_saved['correspondences']) ? $options_saved['correspondences'] : $key), - 'activated' => (isset($options_saved['activated']) ? $options_saved['activated'] : 0), - ); - } - $ecommerceOrderFirstDateForECommerceToDolibarr = isset($siteDb->parameters['order_first_date_etod']) ? $siteDb->parameters['order_first_date_etod'] : ''; - } - - if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) { - $ecommerceProductWeightSynchDirection = isset($siteDb->parameters['product_synch_direction']['weight']) ? $siteDb->parameters['product_synch_direction']['weight'] : 'etod'; - $ecommerceProductWeightUnits = (isset($siteDb->parameters['product_weight_units']) ? $siteDb->parameters['product_weight_units'] : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? 0 : $conf->global->MAIN_WEIGHT_DEFAULT_UNIT)); - } - if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { - $ecommerceProductDimensionSynchDirection = isset($siteDb->parameters['product_synch_direction']['dimension']) ? $siteDb->parameters['product_synch_direction']['dimension'] : 'etod'; - $ecommerceProductDimensionUnits = (isset($siteDb->parameters['product_dimension_units']) ? $siteDb->parameters['product_dimension_units'] : -2); // -2 = cm - } - - $ecommerceProductSynchPrice = isset($siteDb->parameters['product_synch_price']) ? $siteDb->parameters['product_synch_price'] : 'regular'; - $ecommerceProductImageSynchDirection = isset($siteDb->parameters['product_synch_direction']['image']) ? $siteDb->parameters['product_synch_direction']['image'] : 'etod'; - $ecommerceProductRefSynchDirection = isset($siteDb->parameters['product_synch_direction']['ref']) ? $siteDb->parameters['product_synch_direction']['ref'] : 'etod'; - $ecommerceProductDescriptionSynchDirection = isset($siteDb->parameters['product_synch_direction']['description']) ? $siteDb->parameters['product_synch_direction']['description'] : 'etod'; - $ecommerceProductShortDescriptionSynchDirection = isset($siteDb->parameters['product_synch_direction']['short_description']) ? $siteDb->parameters['product_synch_direction']['short_description'] : 'etod'; - $ecommerceProductTaxSynchDirection = isset($siteDb->parameters['product_synch_direction']['tax']) ? $siteDb->parameters['product_synch_direction']['tax'] : 'etod'; - $ecommerceProductStatusSynchDirection = isset($siteDb->parameters['product_synch_direction']['status']) ? $siteDb->parameters['product_synch_direction']['status'] : 'etod'; - $ecommerceProductVariationMode = isset($siteDb->parameters['product_variation_mode']) ? $siteDb->parameters['product_variation_mode'] : 'one_to_one'; - $ecommerceWoocommerceCustomerRoles = isset($siteDb->parameters['customer_roles']) ? $siteDb->parameters['customer_roles'] : 'customer'; - $ecommerceCreateInvoiceType = isset($siteDb->parameters['create_invoice_type']) ? $siteDb->parameters['create_invoice_type'] : Facture::TYPE_STANDARD; - $ecommerceOrderMetadataProductLinesToDescriptionEtod = isset($siteDb->parameters['order_metadata_product_lines_to_description_etod']) ? $siteDb->parameters['order_metadata_product_lines_to_description_etod'] : 0; - $ecommerceOrderFilterModeMetadataProductLinesToDescriptionEtod = isset($siteDb->parameters['order_filter_mode_metadata_product_lines_to_description_etod']) ? $siteDb->parameters['order_filter_mode_metadata_product_lines_to_description_etod'] : ''; - $ecommerceOrderFilterKeysMetadataProductLinesToDescriptionEtod = isset($siteDb->parameters['order_filter_keys_metadata_product_lines_to_description_etod']) ? $siteDb->parameters['order_filter_keys_metadata_product_lines_to_description_etod'] : ''; - $ecommerceDefaultAccount = isset($siteDb->parameters['default_account']) ? $siteDb->parameters['default_account'] : array(); - } -} - -$ecommerceLastUpdate = $siteDb->last_update; -$var = true; -$linkback = '' . $langs->trans("BackToModuleList") . ''; -$title = ''; -if ($siteDb->name) - $title = $langs->trans('ECommerceSetupSite') . ' ' . $siteDb->name; -else - $title = $langs->trans('ECommerceCreateSite'); - -//SHOW PAGE -$urltpl=dol_buildpath('/ecommerceng/admin/tpl/eCommerceSetup.tpl.php',0); -include($urltpl); - -if ($siteDb->type == 1) { - $soapwsdlcacheon = ini_get('soap.wsdl_cache_enabled'); - $soapwsdlcachedir = ini_get('soap.wsdl_cache_dir'); - if ($soapwsdlcacheon) { - print img_warning('') . ' ' . $langs->trans("WarningSoapCacheIsOn", $soapwsdlcachedir) . ' '; - print $langs->trans("WarningSoapCacheIsOn2", $langs->transnoentitiesnoconv("ECommerceSiteAddress")) . '
'; - } else { - print $langs->trans("SoapCacheIsOff", $soapwsdlcachedir) . '
'; - } - -} -llxFooter(); - - -$db->close(); -clearstatcache(); diff --git a/admin/order.php b/admin/order.php new file mode 100644 index 0000000..e4b037c --- /dev/null +++ b/admin/order.php @@ -0,0 +1,690 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/setup.php + * \ingroup ecommerceng + * \brief Page to setup ecommerceng module + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; +require_once(DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; +dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); +dol_include_once('/ecommerceng/admin/class/data/eCommerceDict.class.php'); +dol_include_once('/ecommerceng/class/data/eCommercePaymentGateways.class.php'); + +$langs->loadLangs(array("admin", "orders", "companies", "bills", "accountancy", "banks", "oauth", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); + +if (!$user->admin && !$user->rights->ecommerceng->site) accessforbidden(); + +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'aZ09'); + +include dol_buildpath('/ecommerceng/admin/actions_selectsite.inc.php'); + +$object = new eCommerceSite($db); +if (!($id > 0)) { + $sites = $object->listSites(); + $id = array_values($sites)[0]['id']; + $action = ''; +} +if ($id > 0) { + $result = $object->fetch($id); + if ($result < 0) { + accessforbidden($object->errorsToString()); + } elseif ($result == 0) { + $langs->load('errors'); + accessforbidden($langs->trans('ErrorRecordNotFound')); + } +} else { + accessforbidden($langs->trans('ErrorRecordNotFound')); +} + +if (empty($conf->facture->enabled) && empty($conf->facture->enabled)) { + accessforbidden($langs->trans('ModuleDisabled')); +} + +$order_static = new Commande($db); +$order_lines_static = new OrderLine($db); +$extrafields = new ExtraFields($db); +$extrafields_order_labels = $extrafields->fetch_name_optionals_label($order_static->table_element); +$extrafields_order_labels_clean = array(); +foreach ($extrafields_order_labels as $key => $label) { + if (preg_match('/^ecommerceng_/', $key)) continue; + $extrafields_order_labels_clean[$key] = $label; +} +if (isset($extrafields->attributes['commande']['param']["ecommerceng_wc_status_{$object->id}_{$conf->entity}"]['options'])) { + $status_extra_fields_options = $extrafields->attributes['commande']['param']["ecommerceng_wc_status_{$object->id}_{$conf->entity}"]['options']; +} elseif (isset($extrafields->attribute_param["ecommerceng_wc_status_{$object->id}_{$conf->entity}"]['options'])) { + $status_extra_fields_options = $extrafields->attribute_param["ecommerceng_wc_status_{$object->id}_{$conf->entity}"]['options']; +} else { + $status_extra_fields_options = array(); +} +$extrafields_order_lines_labels = $extrafields->fetch_name_optionals_label($order_lines_static->table_element); +$extrafields_order_lines_labels_clean = array(); +foreach ($extrafields_order_lines_labels as $key => $label) { + if (preg_match('/^ecommerceng_/', $key)) continue; + $extrafields_order_lines_labels_clean[$key] = $label; +} + +$extrafields_list = array( + $order_static->table_element => array('label' => 'Order', 'extrafields' => $extrafields_order_labels_clean), + $order_lines_static->table_element => array('label' => 'OrderLine', 'extrafields' => $extrafields_order_lines_labels_clean), +); + +$order_dtoe_status = array( + Commande::STATUS_CANCELED => $langs->trans('StatusOrderCanceled'), + Commande::STATUS_DRAFT => $langs->trans('StatusOrderDraft'), + Commande::STATUS_VALIDATED => $langs->trans('StatusOrderValidated'), + Commande::STATUS_SHIPMENTONPROCESS => $langs->trans('StatusOrderSent'), + Commande::STATUS_CLOSED => $langs->trans('StatusOrderProcessed'), +); + +$eCommercePaymentGateways = new eCommercePaymentGateways($db); +$payment_gateways = $eCommercePaymentGateways->get_all($object->id); +if (!is_array($payment_gateways)) { + setEventMessages($eCommercePaymentGateways->error, $eCommercePaymentGateways->errors, 'errors'); +} + +/* + * Actions + */ + +if ($action == 'set_options') { + $object->oldcopy = clone $object; + + $object->parameters['order_actions']['create_order'] = GETPOST('create_order', 'int') ? 1 : 0; + $object->parameters['realtime_dtoe']['order'] = GETPOST('realtime_dtoe_order', 'int') ? 1 : 0; + $object->parameters['order_actions']['create_invoice'] = GETPOST('create_invoice', 'int') ? 1 : 0; + $object->parameters['order_actions']['create_invoice_type'] = GETPOST('create_invoice_type', 'int'); + $object->parameters['order_actions']['create_invoice_deposit_type'] = GETPOST('create_invoice_deposit_type', 'az09'); + $object->parameters['order_actions']['create_invoice_deposit_value'] = GETPOST('create_invoice_deposit_value', 'int'); + $object->parameters['order_actions']['create_invoice_if_amount_0'] = GETPOST('create_invoice_if_amount_0', 'int') ? 1 : 0; + $object->parameters['order_actions']['send_invoice_by_mail'] = GETPOST('send_invoice_by_mail', 'int') ? 1 : 0; + $object->parameters['order_actions']['create_supplier_invoice'] = GETPOST('create_supplier_invoice', 'int') ? 1 : 0; + $object->parameters['default_sales_representative_follow'] = GETPOST('default_sales_representative_follow', 'int'); + $object->parameters['order_first_date_etod'] = GETPOST('order_first_date_etod', 'alphanohtml') ? dol_mktime(0, 0, 0, GETPOST('order_first_date_etodmonth', 'int'), GETPOST('order_first_date_etodday', 'int'), GETPOST('order_first_date_etodyear', 'int')) : null; + $object->parameters['order_actions']['fee_line_as_item_line'] = GETPOST('fee_line_as_item_line', 'int') ? 1 : 0; + $object->parameters['order_metadata_product_lines_to_description_etod'] = GETPOST('order_metadata_product_lines_to_description_etod', 'int') ? 1 : 0; + $object->parameters['order_filter_mode_metadata_product_lines_to_description_etod'] = GETPOST('order_filter_mode_metadata_product_lines_to_description_etod', 'az09'); + $object->parameters['order_filter_keys_metadata_product_lines_to_description_etod'] = GETPOST('order_filter_keys_metadata_product_lines_to_description_etod', 'alphanohtml'); + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_status_options') { + $object->oldcopy = clone $object; + + $object->parameters['order_status_dtoe_check_lvl_status'] = GETPOST('order_status_dtoe_check_lvl_status', 'int') ? 1 : 0; + + $values = array(); + foreach ($order_dtoe_status as $d_status => $d_label) { + $values[$d_status]['selected'] = GETPOST('order_status_dtoe_' . $d_status, 'alphanohtml'); + } + $object->parameters['order_status_dtoe'] = $values; + + $values = array(); + foreach ($status_extra_fields_options as $key => $value) { + if (($pos = strpos($key, '_')) > 0) $key = substr($key, $pos + 1); + + $values[$key]['selected'] = GETPOST('order_status_etod_' . $key, 'alphanohtml'); + $values[$key]['billed'] = GETPOST('order_status_etod_billed_' . $key, 'int') ? 1 : 0; + $values[$key]['synchronize'] = GETPOST('order_status_etod_synchronize_' . $key, 'int') ? 1 : 0; + } + $object->parameters['order_status_etod'] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_metadata_matching_extrafields_options') { + $table_element = GETPOST('table_element', 'alphanohtml'); + if (isset($extrafields_list[$table_element])) { + $object->oldcopy = clone $object; + + $values = array(); + foreach ($extrafields_list[$table_element]['extrafields'] as $key => $label) { + $activated = GETPOST("act_ef_crp_{$table_element}_{$key}", 'int') ? 1 : 0; + $correspondences = $activated ? GETPOST("ef_crp_{$table_element}_{$key}", 'alphanohtml') : + (!empty($object->parameters['ef_crp'][$table_element][$key]['correspondences']) ? $object->parameters['ef_crp'][$table_element][$key]['correspondences'] : $key); + + $values[$key] = [ + 'correspondences' => $correspondences, + 'activated' => $activated, + ]; + } + $object->parameters['ef_crp'][$table_element] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } else { + setEventMessage("Wrong table element", 'errors'); + } +} elseif ($action == 'set_payment_gateways_options') { + foreach ($payment_gateways as $key => $infos) { + $payment_gateways[$key]['payment_mode_id'] = GETPOST('payment_mode_id_' . $key, 'int'); + $payment_gateways[$key]['payment_mode_id'] = $payment_gateways[$key]['payment_mode_id'] > 0 ? $payment_gateways[$key]['payment_mode_id'] : 0; + $payment_gateways[$key]['bank_account_id'] = GETPOST('bank_account_id_' . $key, 'int'); + $payment_gateways[$key]['bank_account_id'] = $payment_gateways[$key]['bank_account_id'] > 0 ? $payment_gateways[$key]['bank_account_id'] : 0; + $payment_gateways[$key]['create_invoice_payment'] = GETPOST('create_invoice_payment_' . $key, 'int') ? 1 : 0; + $payment_gateways[$key]['mail_model_for_send_invoice'] = GETPOST('mail_model_for_send_invoice_' . $key, 'int'); + $payment_gateways[$key]['mail_model_for_send_invoice'] = $payment_gateways[$key]['mail_model_for_send_invoice'] > 0 ? $payment_gateways[$key]['mail_model_for_send_invoice'] : 0; + $payment_gateways[$key]['supplier_id'] = GETPOST('supplier_id_' . $key, 'int'); + $payment_gateways[$key]['supplier_id'] = $payment_gateways[$key]['supplier_id'] > 0 ? $payment_gateways[$key]['supplier_id'] : 0; + $payment_gateways[$key]['product_id_for_fee'] = GETPOST('product_id_for_fee_' . $key, 'int'); + $payment_gateways[$key]['product_id_for_fee'] = $payment_gateways[$key]['product_id_for_fee'] > 0 ? $payment_gateways[$key]['product_id_for_fee'] : 0; + $payment_gateways[$key]['create_supplier_invoice_payment'] = GETPOST('create_supplier_invoice_payment_' . $key, 'int') ? 1 : 0; + } + + $result = $eCommercePaymentGateways->set($object->id, $payment_gateways); + + if ($result < 0) { + setEventMessages($eCommercePaymentGateways->error, $eCommercePaymentGateways->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'confirm_synchronize_payment_gateways' && $confirm == "yes") { + $result = ecommerceng_update_payment_gateways($db, $object); + if ($result) setEventMessage($langs->trans('ECommercePaymentGatewaysUpdated'), 'mesgs'); + + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; +} + + +/* + * View + */ + +$form = new Form($db); +$formmail = new FormMail($db); + +$wikihelp=''; +llxHeader('', $langs->trans("ECommerceSetup"), $wikihelp, '', 0, 0, array( + '/ecommerceng/js/form.js', +)); + +$formconfirm = ''; + +if ($action == 'synchronize_payment_gateways') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ECommerceUpdatePaymentGateways'), $langs->trans('ECommerceConfirmUpdatePaymentGateways'), 'confirm_synchronize_payment_gateways', '', 0, 1, 200, 800); +} + +// Call Hook formConfirm +$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); +$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} + +// Print form confirm +print $formconfirm; + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'title_setup'); + +include dol_buildpath('/ecommerceng/admin/tpl/selectsite.tpl.php'); + +$head=ecommercengConfigSitePrepareHead($object); + +dol_fiche_head($head, 'order_invoice', $langs->trans("Module107100Name"), 0, 'eCommerce@ecommerceng'); + +print ''; + +/** + * Settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("Parameters"), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +if (!empty($conf->commande->enabled)) { + // Create order + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Synchronize order real time from dolibarr to site + print '' . "\n"; + print ''."\n"; + print ''."\n"; + print '' . "\n"; +} + +if (!empty($conf->facture->enabled)) { + // Create invoice + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +if (!empty($object->parameters['order_actions']['create_invoice'])) { + // Invoice type + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + if ($object->parameters['order_actions']['create_invoice_type'] == Facture::TYPE_DEPOSIT) { + // Invoice deposit type + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + if (in_array($object->parameters['order_actions']['create_invoice_deposit_type'], [ 'variable', 'variablealllines' ])) { + // Invoice deposit value + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + } + + // Create invoice if amount 0 + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Send invoice by mail + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + if (!empty($conf->supplier_invoice->enabled)) { + // Create supplier invoice + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } +} + +if (!empty($object->parameters['order_actions']['create_order']) || + !empty($object->parameters['order_actions']['create_invoice']) +) { + // Default sale representative + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // First date of the order to be synchronize + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Add fees as product line + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Add meta data in product line description + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + if (!empty($object->parameters['order_metadata_product_lines_to_description_etod'])) { + // Filter added meta data in product line description + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } +} + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
' . $langs->trans("ECommerceCreateOrder") . '' . $langs->trans("ECommerceCreateOrderDescription") . '' . "\n"; + print 'parameters['order_actions']['create_order']) ? ' checked' : '') . ' />' . "\n"; + print '
'.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceOrder").''.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceOrderDescription").'' . "\n"; + print 'parameters['realtime_dtoe']['order']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceCreateInvoice") . '' . $langs->trans("ECommerceCreateInvoiceDescription") . '' . "\n"; + print 'parameters['order_actions']['create_invoice']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceCreateInvoiceType") . '' . $langs->trans("ECommerceCreateInvoiceTypeDescription") . '' . "\n"; + $invoice_types = array( + Facture::TYPE_STANDARD => $langs->trans('InvoiceStandard'), + Facture::TYPE_DEPOSIT => $langs->trans('InvoiceDeposit') + ); + print $form->selectarray('create_invoice_type', $invoice_types, $object->parameters['order_actions']['create_invoice_type'], 0, 0, 0, '', 0, 0, 0, '', 'minwidth300'); + print '
' . $langs->trans("ECommerceSendInvoiceByMail") . '' . $langs->trans("ECommerceSendInvoiceByMailDescription") . '' . "\n"; + $invoice_deposit_types = array( + 'amount' => $langs->trans('FixAmount', $langs->transnoentitiesnoconv('Deposit')), + 'variable' => $langs->trans('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), + 'variablealllines' => $langs->trans('VarAmountAllLines') + ); + print $form->selectarray('create_invoice_deposit_type', $invoice_deposit_types, $object->parameters['order_actions']['create_invoice_deposit_type'], 0, 0, 0, '', 0, 0, 0, '', 'minwidth300'); + print '
' . $langs->trans("ECommerceSendInvoiceByMail") . '' . $langs->trans("ECommerceSendInvoiceByMailDescription") . '' . "\n"; + print '' . "\n"; + print '
' . $langs->trans("ECommerceCreateInvoiceIfAmount0") . '' . $langs->trans("ECommerceCreateInvoiceIfAmount0Description") . '' . "\n"; + print 'parameters['order_actions']['create_invoice_if_amount_0']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceSendInvoiceByMail") . '' . $langs->trans("ECommerceSendInvoiceByMailDescription") . '' . "\n"; + print 'parameters['order_actions']['send_invoice_by_mail']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceCreateSupplierInvoiceFromFee") . '' . $langs->trans("ECommerceCreateSupplierInvoiceFromFeeDescription") . '' . "\n"; + print 'parameters['order_actions']['create_supplier_invoice']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceCreateOrderSalesRepresentativeFollowByDefault") . '' . $langs->trans("ECommerceCreateOrderSalesRepresentativeFollowByDefaultDescription") . '' . "\n"; + print $form->select_dolusers($object->parameters['default_sales_representative_follow'], 'default_sales_representative_follow', 1, null, 0, null, null, 0, 56, '', 0, '', 'minwidth200imp'); + print '
' . $langs->trans("ECommerceWoocommerceOrderFirstDateForECommerceToDolibarr") . '' . $langs->trans("ECommerceWoocommerceOrderFirstDateForECommerceToDolibarrDescription") . '' . "\n"; + $value = isset($object->parameters['order_first_date_etod']) ? $object->parameters['order_first_date_etod'] : -1; + print $form->select_date($value, 'order_first_date_etod', 0, 0, 0, '', 1, 1); + print '
' . $langs->trans("ECommerceFeeLineAsItemLine") . '' . $langs->trans("ECommerceFeeLineAsItemLineDescription") . '' . "\n"; + print 'parameters['order_actions']['fee_line_as_item_line']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceWoocommerceOrderMetaDataInProductLineToDescriptionForECommerceToDolibarr") . '' . $langs->trans("ECommerceWoocommerceOrderMetaDataInProductLineToDescriptionForECommerceToDolibarrDescription") . '' . "\n"; + print 'parameters['order_metadata_product_lines_to_description_etod']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceWoocommerceOrderFilterMetaDataInProductLineToDescriptionForECommerceToDolibarr") . '' . $langs->trans("ECommerceWoocommerceOrderFilterMetaDataInProductLineToDescriptionForECommerceToDolibarrDescription") . '' . "\n"; + $filter_mode = array( + 'exclude' => $langs->trans('ECommerceExclude'), + 'include' => $langs->trans('ECommerceInclude'), + ); + $value_mode = isset($object->parameters['order_filter_mode_metadata_product_lines_to_description_etod']) ? $object->parameters['order_filter_mode_metadata_product_lines_to_description_etod'] : 'exclude'; + print $form->selectarray('order_filter_mode_metadata_product_lines_to_description_etod', $filter_mode, $value_mode, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300'); + print '' . "\n"; + print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +if (!empty($object->parameters['order_actions']['create_order'])) { + /** + * Status settings. + */ + + print '
'; + print load_fiche_titre($langs->trans("ECommerceOrderStatusSetup"), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + + if (!empty($object->parameters['realtime_dtoe']['order'])) { + // Synchronize status from dolibarr to site + print ''; + print '' . "\n"; + print "\n"; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + // Do not synchronize status if this rank is below the current remote status + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + foreach ($order_dtoe_status as $d_status => $d_label) { + $selected = isset($object->parameters['order_status_dtoe'][$d_status]['selected']) ? $object->parameters['order_status_dtoe'][$d_status]['selected'] : ''; + + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + } + + print ''; + print ''."\n"; + print "\n"; + print ''; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print "\n"; + + foreach ($status_extra_fields_options as $key => $value) { + if (($pos = strpos($key, '_')) > 0) $key = substr($key, $pos + 1); + $selected = isset($object->parameters['order_status_etod'][$key]['selected']) ? $object->parameters['order_status_etod'][$key]['selected'] : ''; + $billed = isset($object->parameters['order_status_etod'][$key]['billed']) ? $object->parameters['order_status_etod'][$key]['billed'] : ''; + $synchronize = isset($object->parameters['order_status_etod'][$key]['synchronize']) ? $object->parameters['order_status_etod'][$key]['synchronize'] : ''; + + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("DolibarrToECommerce") . '
' . $langs->trans("Parameters") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans("ECommerceOrderStatusDtoECheckLvlStatus") . '' . $langs->trans("ECommerceOrderStatusDtoECheckLvlStatusDescription") . '' . "\n"; + print 'parameters['order_status_dtoe_check_lvl_status']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $d_label . '' . $langs->trans("ECommerceOrderStatusSetupDescription") . '' . "\n"; + $array_list = array(); + foreach ($status_extra_fields_options as $key => $value) { + if (($pos = strpos($key, '_')) > 0) $key = substr($key, $pos + 1); + $array_list[$key] = $value; + } + print $form->selectarray('order_status_dtoe_' . $d_status, $array_list, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth300'); + print '
'.$langs->trans("ECommerceToDolibarr").'
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").''.$langs->trans("Billed").''.$langs->trans("ECommerceSynchronize").'
' . $value . '' . $langs->trans("ECommerceOrderStatusSetupDescription") . '' . "\n"; + $array_list = array(); + foreach ($order_dtoe_status as $d_status => $d_label) { + $array_list['s' . $d_status] = $d_label; + } + print $form->selectarray('order_status_etod_' . $key, $array_list, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth300'); + print '
'."\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; +} + +if (!empty($object->parameters['order_actions']['create_order']) || + !empty($object->parameters['order_actions']['create_invoice']) +) { + /** + * Remote meta data with extra fields. + */ + + foreach ($extrafields_list as $table_element => $info) { + if (!empty($info['extrafields'])) { + print '
'; + print load_fiche_titre($langs->trans('ECommercengWoocommerceExtrafieldsCorrespondenceOf', $langs->transnoentitiesnoconv($info['label'])), '', ''); + + print '
'; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + foreach ($info['extrafields'] as $key => $label) { + if (!empty($extrafields->attributes[$table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$table_element]['langfile'][$key]); + elseif (!empty($extrafields->attribute_langfile[$key])) $langs->load($extrafields->attribute_langfile[$key]); + + $options_saved = $object->parameters['ef_crp'][$table_element][$key]; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("ExtraFields") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans($label) . '' . $langs->transnoentities('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) . '' . "\n"; + $value = !empty($options_saved['correspondences']) ? $options_saved['correspondences'] : $key; + print ''; + print '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + } + } + + /** + * Payment gateways. + */ + print '
'; + print load_fiche_titre($langs->trans('ECommercePaymentGatewaysCorrespondence'), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + if (!empty($object->parameters['order_actions']['create_invoice'])) { + print '' . "\n"; + if (!empty($object->parameters['order_actions']['send_invoice_by_mail'])) { + print '' . "\n"; + } + if (!empty($object->parameters['order_actions']['create_supplier_invoice'])) { + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + } + print "\n"; + + // Get email templates + $type_template = 'facture_send'; + $email_templates = array(); + $result = $formmail->fetchAllEMailTemplate($type_template, $user, $langs); + if ($result < 0) { + setEventMessages($formmail->error, $formmail->errors, 'errors'); + } + foreach ($formmail->lines_model as $line) { + if (preg_match('/\((.*)\)/', $line->label, $reg)) { + $email_templates[$line->id] = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ + } else { + $email_templates[$line->id] = $line->label; + } + if ($line->lang) $email_templates[$line->id] .= ' (' . $line->lang . ')'; + if ($line->private) $email_templates[$line->id] .= ' - ' . $langs->trans("Private"); + } + + foreach ($payment_gateways as $key => $infos) { + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + if (!empty($object->parameters['order_actions']['create_invoice'])) { + print '' . "\n"; + if (!empty($object->parameters['order_actions']['send_invoice_by_mail'])) { + print '' . "\n"; + } + if (!empty($object->parameters['order_actions']['create_supplier_invoice'])) { + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + } + print '' . "\n"; + } + + print '
' . $langs->trans("ECommercePaymentGatewayLabel") . '' . $langs->trans("PaymentMode") . '' . $langs->trans("BankAccount") . '' . $langs->trans("ECommerceCreateAssociatePaymentForInvoice") . '' . $langs->trans("ECommerceSelectMailModelForSendInvoice") . '' . $langs->trans("Supplier") . '' . $langs->trans("ECommerceProductForFee") . '' . $langs->trans("ECommerceCreateAssociatePaymentForSupplierInvoice") . '
' . $infos['payment_gateway_label'] . ''; + $form->select_types_paiements($infos['payment_mode_id'], 'payment_mode_id_' . $key); + print ''; + $form->select_comptes($infos['bank_account_id'], 'bank_account_id_' . $key, 0, '', 1); + print '' . "\n"; + // Zone to select email template + if (count($email_templates) > 0) { + print $form->selectarray('mail_model_for_send_invoice_' . $key, $email_templates, $infos['mail_model_for_send_invoice'], 1, 0, 0, '', 0, 0, 0, '', 'minwidth100'); + } else { + print ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. + } + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup') . ' - ' . $langs->transnoentitiesnoconv('EMails')), 1); + print '' . $form->select_company($infos['supplier_id'], 'supplier_id_' . $key, 's.fournisseur=1 AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300') . ''; + $form->select_produits($infos['product_id_for_fee'], 'product_id_for_fee_' . $key, '', $conf->product->limit_size, 0, -1, 2, '', 0, array(), 0, '1', 0, 'maxwidth300'); + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; +} + +print dol_get_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/admin/product.php b/admin/product.php new file mode 100644 index 0000000..e130d37 --- /dev/null +++ b/admin/product.php @@ -0,0 +1,744 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/setup.php + * \ingroup ecommerceng + * \brief Page to setup ecommerceng module + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); +dol_include_once('/ecommerceng/admin/class/data/eCommerceDict.class.php'); + +$langs->loadLangs(array("admin", "companies", "bills", "accountancy", "banks", "oauth", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); + +if (!$user->admin && !$user->rights->ecommerceng->site) accessforbidden(); + +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'aZ09'); + +include dol_buildpath('/ecommerceng/admin/actions_selectsite.inc.php'); + +$object = new eCommerceSite($db); +if (!($id > 0)) { + $sites = $object->listSites(); + $id = array_values($sites)[0]['id']; + $action = ''; +} +if ($id > 0) { + $result = $object->fetch($id); + if ($result < 0) { + accessforbidden($object->errorsToString()); + } elseif ($result == 0) { + $langs->load('errors'); + accessforbidden($langs->trans('ErrorRecordNotFound')); + } +} else { + accessforbidden($langs->trans('ErrorRecordNotFound')); +} + +if (empty($conf->product->enabled)) { + accessforbidden($langs->trans('ModuleDisabled')); +} +if (empty($conf->categorie->enabled)) { + accessforbidden($langs->trans('ModuleDisabled') . ' : ' . $langs->trans('Categories')); +} + +$product_static = new Product($db); +$extrafields = new ExtraFields($db); +$extrafields_labels = $extrafields->fetch_name_optionals_label($product_static->table_element); +$extrafields_labels_clean = array(); +foreach ($extrafields_labels as $key => $label) { + if (preg_match('/^ecommerceng_/', $key)) continue; + $extrafields_labels_clean[$key] = $label; +} + +$list_account = array(); +$list_account[] = '---Product---'; +$list_account[] = 'accounting_product_sold_account'; +if ($mysoc->isInEEC()) { + $list_account[] = 'accounting_product_sold_intra_account'; +} +$list_account[] = 'accounting_product_sold_export_account'; +$list_account[] = 'accounting_product_buy_account'; +if ($mysoc->isInEEC()) { + $list_account[] = 'accounting_product_buy_intra_account'; +} +$list_account[] = 'accounting_product_buy_export_account'; +$list_account[] = '---Service---'; +$list_account[] = 'accounting_service_sold_account'; +if ($mysoc->isInEEC()) { + $list_account[] = 'accounting_service_sold_intra_account'; +} +$list_account[] = 'accounting_service_sold_export_account'; +$list_account[] = 'accounting_service_buy_account'; +if ($mysoc->isInEEC()) { + $list_account[] = 'accounting_service_buy_intra_account'; +} +$list_account[] = 'accounting_service_buy_export_account'; + +// Get all attributes in dictionary for this entity and site +$eCommerceDict = new eCommerceDict($db, MAIN_DB_PREFIX . 'c_ecommerceng_attribute'); +$dict_attributes = $eCommerceDict->search([ 'entity'=> ['value' => $conf->entity], 'site_id' => ['value' => $object->id] ]); +$remote_attributes = array(); +foreach ($dict_attributes as $attribute) { + $remote_attributes[$attribute['attribute_id']] = $attribute['attribute_name']; +} + +/* + * Actions + */ +$error = 0; + +if ($action == 'set_options') { + $object->oldcopy = clone $object; + + $object->fk_cat_product = GETPOST('fk_cat_product', 'int'); + $object->fk_cat_product = $object->fk_cat_product > 0 ? $object->fk_cat_product : 0; + $object->parameters['realtime_dtoe']['product'] = GETPOST('realtime_dtoe_product', 'int') ? 1 : 0; + $object->ecommerce_price_type = GETPOST('base_price_type', 'az09'); + $object->parameters['shipping_service'] = GETPOST('shipping_service', 'int'); + $object->parameters['shipping_service'] = $object->parameters['shipping_service'] > 0 ? $object->parameters['shipping_service'] : 0; + $object->parameters['discount_code_service'] = GETPOST('discount_code_service', 'int'); + $object->parameters['discount_code_service'] = $object->parameters['discount_code_service'] > 0 ? $object->parameters['discount_code_service'] : 0; + $object->parameters['pw_gift_cards_service'] = GETPOST('pw_gift_cards_service', 'int'); + $object->parameters['pw_gift_cards_service'] = $object->parameters['pw_gift_cards_service'] > 0 ? $object->parameters['pw_gift_cards_service'] : 0; + $object->parameters['product_synch_price'] = GETPOST('product_synch_price', 'az09'); + $object->parameters['product_weight_units'] = empty($conf->global->PRODUCT_DISABLE_WEIGHT) ? GETPOST('product_weight_units', 'int') : 0; // 0 = Kg + $object->parameters['product_dimension_units'] = empty($conf->global->PRODUCT_DISABLE_SIZE) ? GETPOST('product_dimension_units', 'int') : 2; // 2 = cm + $object->parameters['product_variation_mode'] = GETPOST('product_variation_mode', 'az09'); + + if(empty($object->fk_cat_product)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceCatProduct")), 'errors'); + $error++; + } + + if (!$error) { + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + $object->price_level = GETPOST('price_level', 'int'); + + if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->parameters['realtime_dtoe']['product']) && + $object->price_level > 0 && $object->price_level <= intval($conf->global->PRODUIT_MULTIPRICES_LIMIT) && + $object->oldcopy->price_level != $object->price_level + ) { + $action = 'update_level_price'; + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } + } +} elseif ($action == 'set_synchronize_sens_options') { + $object->oldcopy = clone $object; + + $object->parameters['product_synch_direction']['ref'] = GETPOST('product_synch_direction_ref', 'az09'); + $object->parameters['product_synch_direction']['description'] = GETPOST('product_synch_direction_description', 'az09'); + $object->parameters['product_synch_direction']['short_description'] = GETPOST('product_synch_direction_short_description', 'az09'); + $object->parameters['product_synch_direction']['weight'] = empty($conf->global->PRODUCT_DISABLE_WEIGHT) ? GETPOST('product_synch_direction_weight', 'az09') : 'etod'; + $object->parameters['product_synch_direction']['dimension'] = empty($conf->global->PRODUCT_DISABLE_SIZE) ? GETPOST('product_synch_direction_dimension', 'az09') : 'etod'; + $object->parameters['product_synch_direction']['tax'] = GETPOST('product_synch_direction_tax', 'az09'); + $object->parameters['product_synch_direction']['status'] = GETPOST('product_synch_direction_status', 'az09'); + $object->parameters['product_synch_direction']['image'] = GETPOST('product_synch_direction_image', 'az09'); + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_metadata_matching_extrafields_options') { + $table_element = $product_static->table_element; + $object->oldcopy = clone $object; + + $values = array(); + foreach ($extrafields_labels_clean as $key => $label) { + $activated = GETPOST("act_ef_crp_{$table_element}_{$key}", 'int') ? 1 : 0; + $correspondences = $activated ? GETPOST("ef_crp_{$table_element}_{$key}", 'alphanohtml') : + (!empty($object->parameters['ef_crp'][$table_element][$key]['correspondences']) ? $object->parameters['ef_crp'][$table_element][$key]['correspondences'] : $key); + + $values[$key] = [ + 'correspondences' => $correspondences, + 'activated' => $activated, + ]; + } + $object->parameters['ef_crp'][$table_element] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_attributes_matching_extrafields_options') { + $object->oldcopy = clone $object; + + $values = array(); + foreach ($extrafields_labels_clean as $key => $label) { + $activated = GETPOST("attribute_ef_crp_state_{$key}", 'int') ? 1 : 0; + $correspondences = $activated ? GETPOST("attribute_ef_crp_value_{$key}", 'alphanohtml') : + (!empty($object->parameters['ef_crp_attribute'][$key]['correspondences']) ? $object->parameters['ef_crp_attribute'][$key]['correspondences'] : $key); + + $values[$key] = [ + 'correspondences' => $correspondences, + 'activated' => $activated, + ]; + } + $object->parameters['ef_crp_attribute'] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_accounting_codes_options' && !empty($conf->accounting->enabled)) { + $object->oldcopy = clone $object; + + $values = array(); + foreach ($list_account as $key) { + if (!preg_match('/---(.*)---/', $key, $reg)) { + $values[$key] = GETPOST($key, 'alphanohtml'); + } + } + $object->parameters['default_account'] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'confirm_update_price_level' && $confirm == "yes" && !empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->parameters['realtime_dtoe']['product'])) { + $object->oldcopy = clone $object; + + $object->price_level = GETPOST('price_level', 'int'); + + if ($object->price_level > 0 && $object->price_level <= intval($conf->global->PRODUIT_MULTIPRICES_LIMIT) && $object->oldcopy->price_level != $object->price_level) { + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + updatePriceLevel($object); + + setEventMessages($langs->trans('SetupSaved'), null); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } +} elseif ($action == 'confirm_synchronize_attributes' && $confirm == "yes") { + $result = ecommerceng_update_woocommerce_attribute($db, $object); + if ($result) setEventMessage($langs->trans('ECommercengWoocommerceDictAttributesUpdated'), 'mesgs'); + + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; +} elseif ($action == 'confirm_synchronize_taxes' && $confirm == "yes") { + $result = ecommerceng_update_woocommerce_dict_tax($db, $object); + if ($result) setEventMessage($langs->trans('ECommercengWoocommerceDictTaxClassUpdated'), 'mesgs'); + + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; +} + + +/* + * View + */ + +$form = new Form($db); +$formproduct = new FormProduct($db); +$formaccounting = new FormAccounting($db); +$category_static = new Categorie($db); + +$v10p = version_compare(DOL_VERSION, "10.0.0") >= 0; +$wikihelp=''; +llxHeader('', $langs->trans("ECommerceSetup"), $wikihelp, '', 0, 0, array( + '/ecommerceng/js/form.js', +)); + +$formconfirm = ''; + +if ($action == 'synchronize_attributes') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ECommerceWoocommerceUpdateDictAttributes'), $langs->trans('ECommerceWoocommerceConfirmUpdateDictAttributes'), 'confirm_synchronize_attributes', '', 0, 1, 200, 800); +} elseif ($action == 'synchronize_taxes') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ECommerceWoocommerceUpdateDictTaxClasses'), $langs->trans('ECommerceWoocommerceConfirmUpdateDictTaxClasses'), 'confirm_synchronize_taxes', '', 0, 1, 200, 800); +} elseif ($action == 'update_level_price' && !empty($conf->global->PRODUIT_MULTIPRICES)) { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&price_level='.$object->price_level, $langs->trans('ECommerceUpdateLevelPrice'), $langs->trans('ECommerceConfirmUpdatePriceLevel'), 'confirm_update_level_price', '', 0, 1, 200, 800); +} + +// Call Hook formConfirm +$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); +$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} + +// Print form confirm +print $formconfirm; + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'title_setup'); + +include dol_buildpath('/ecommerceng/admin/tpl/selectsite.tpl.php'); + +$head=ecommercengConfigSitePrepareHead($object); + +dol_fiche_head($head, 'product', $langs->trans("Module107100Name"), 0, 'eCommerce@ecommerceng'); + +print ''; + +/** + * Settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("Parameters"), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +// Root category +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Synchronize product real time from dolibarr to site +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Base price type +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Price level +if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + $price_levels = array(); + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { + $key_for_label = 'PRODUIT_MULTIPRICES_LABEL'.$i; + $price_levels[$i] = !empty($conf->global->$key_for_label) ? $langs->trans($conf->global->$key_for_label) : $i; + } + + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +// Shipping service +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Discount code service +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// PW gift cards service +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Synchronize prices +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) { + // Weight units + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { + // Dimension units + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +// Product variation mode +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
'.$langs->trans("ECommerceCatProduct").''.$langs->transnoentities("ECommerceCatProductDescription").'' . "\n"; +$categories = $category_static->get_full_arbo(Categorie::TYPE_PRODUCT); +$categories_list = array(); +foreach ($categories as $category) { + $categories_list[$category['id']] = $category['label']; +} +print $form->selectarray('fk_cat_product', $categories_list, $object->fk_cat_product, 1, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
'.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceProduct").''.$langs->transnoentities("ECommerceRealTimeSynchroDolibarrToECommerceProductDescription").'' . "\n"; +print 'parameters['realtime_dtoe']['product']) ? ' checked' : '') . ' />' . "\n"; +print '
'.$langs->trans("ECommercePriceType").'' . $langs->transnoentities("ECommercePriceTypeDescription") . '' . "\n"; +$base_price_types = array( + 'HT' => 'ECommercePriceTypeHT', + 'TTC' => 'ECommercePriceTypeTTC', +); +print $form->selectarray('base_price_type', $base_price_types, $object->ecommerce_price_type, 1, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
' . $langs->trans("ECommercePriceLevel") . '' . $langs->transnoentities("ECommercePriceLevelDescription") . '' . "\n"; + print $form->selectarray('price_level', $price_levels, $object->price_level, 1, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n"; + print '
'.$langs->trans("ECommerceShippingService").'' . $langs->transnoentities("ECommerceShippingServiceDescription") . '' . "\n"; +print $form->select_produits($object->parameters['shipping_service'], 'shipping_service', 1, 0) . "\n"; +print '
'.$langs->trans("ECommerceDiscountCodeService").'' . $langs->transnoentities("ECommerceDiscountCodeServiceDescription") . '' . "\n"; +print $form->select_produits($object->parameters['discount_code_service'], 'discount_code_service', 1, 0) . "\n"; +print '
'.$langs->trans("ECommercePwGiftCardsService").'' . $langs->transnoentities("ECommercePwGiftCardsServiceDescription") . '' . "\n"; +print $form->select_produits($object->parameters['pw_gift_cards_service'], 'pw_gift_cards_service', 1, 0) . "\n"; +print '
'.$langs->trans("ECommerceWoocommerceProductSyncPrice").'' . $langs->transnoentities("ECommerceWoocommerceProductSyncPriceDescription") . '' . "\n"; +$sync_prices_array = array( +// 'selling'=>$langs->trans('ECommerceWoocommerceSellingPrice'), + 'regular'=>$langs->trans('ECommerceWoocommerceRegularPrice'), +); +print $form->selectarray('product_synch_price', $sync_prices_array, $object->parameters['product_synch_price'], 0, 0, 0, '', 0, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
' . $langs->trans("ECommerceProductWeightUnits") . '' . $langs->transnoentities("ECommerceProductWeightUnitsDescription") . '' . "\n"; + $value = isset($object->parameters['product_weight_units']) ? $object->parameters['product_weight_units'] : ''; // 0 = kg + if ($v10p) { + print $formproduct->selectMeasuringUnits("product_weight_units", "weight", $value, 0, 2); + } else { + print $formproduct->select_measuring_units("product_weight_units", "weight", $value); + } + print '
' . $langs->trans("ECommerceProductDimensionUnits") . '' . $langs->transnoentities("ECommerceProductDimensionUnitsDescription") . '' . "\n"; + $value = isset($object->parameters['product_dimension_units']) ? $object->parameters['product_dimension_units'] : ''; + if ($v10p) { + print $formproduct->selectMeasuringUnits("product_dimension_units", "size", $value, 0, 2); + } else { + print $formproduct->select_measuring_units("product_dimension_units", "size", $value); + } + print '
'.$langs->trans("ECommerceWoocommerceProductVariationMode").'' . $langs->transnoentities("ECommerceWoocommerceProductVariationModeDescription") . '' . "\n"; +$variation_modes = array( + 'one_to_one'=>$langs->trans('ECommerceWoocommerceProductVariationOneToOne'), + 'all_to_one'=>$langs->trans('ECommerceWoocommerceProductVariationAllToOne'), +); +$value = isset($object->parameters['product_variation_mode']) ? $object->parameters['product_variation_mode'] : 'one_to_one'; +print $form->selectarray('product_variation_mode', $variation_modes, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +/** + * Synchronize sens settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("ProductsSyncSetup"), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +$sync_direction_array = array( + '' => $langs->trans('None'), + 'etod' => $langs->trans('ECommerceToDolibarr'), + 'dtoe' => $langs->trans('DolibarrToECommerce'), + 'all' => $langs->trans('AllDirection'), +); + +// Synchronize ref sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Synchronize description sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Synchronize short description sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) { + // Synchronize weight sens + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +if (empty($conf->global->PRODUCT_DISABLE_SIZE)) { + // Synchronize dimension sens + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +// Synchronize tax sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Synchronize status sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Synchronize image sens +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
'.$langs->trans("ECommerceProductRefSyncDirection").'' . $langs->transnoentities("ECommerceProductRefSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['ref']) ? $object->parameters['product_synch_direction']['ref'] : ''; +print $form->selectarray('product_synch_direction_ref', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
'.$langs->trans("ECommerceProductDescriptionSyncDirection").'' . $langs->transnoentities("ECommerceProductDescriptionSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['description']) ? $object->parameters['product_synch_direction']['description'] : ''; +print $form->selectarray('product_synch_direction_description', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
'.$langs->trans("ECommerceProductShortDescriptionSyncDirection").'' . $langs->transnoentities("ECommerceProductShortDescriptionSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['short_description']) ? $object->parameters['product_synch_direction']['short_description'] : ''; +print $form->selectarray('product_synch_direction_short_description', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
' . $langs->trans("ECommerceProductWeightSyncDirection") . '' . $langs->transnoentities("ECommerceProductWeightSyncDirectionDescription") . '' . "\n"; + $value = !empty($object->parameters['product_synch_direction']['weight']) ? $object->parameters['product_synch_direction']['weight'] : ''; + print $form->selectarray('product_synch_direction_weight', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; + print '
' . $langs->trans("ECommerceProductDimensionSyncDirection") . '' . $langs->transnoentities("ECommerceProductDimensionSyncDirectionDescription") . '' . "\n"; + $value = !empty($object->parameters['product_synch_direction']['dimension']) ? $object->parameters['product_synch_direction']['dimension'] : ''; + print $form->selectarray('product_synch_direction_dimension', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; + print '
'.$langs->trans("ECommerceProductTaxSyncDirection").'' . $langs->transnoentities("ECommerceProductTaxSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['tax']) ? $object->parameters['product_synch_direction']['tax'] : ''; +print $form->selectarray('product_synch_direction_tax', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
'.$langs->trans("ECommerceProductStatusSyncDirection").'' . $langs->transnoentities("ECommerceProductStatusSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['status']) ? $object->parameters['product_synch_direction']['status'] : ''; +print $form->selectarray('product_synch_direction_status', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
'.$langs->trans("ECommerceProductImageSyncDirection").'' . $langs->transnoentities("ECommerceProductImageSyncDirectionDescription") . '' . "\n"; +$value = !empty($object->parameters['product_synch_direction']['image']) ? $object->parameters['product_synch_direction']['image'] : ''; +print $form->selectarray('product_synch_direction_image', $sync_direction_array, $value, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300') . "\n"; +print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +if (!empty($extrafields_labels_clean)) { + /** + * Remote meta data with extra fields. + */ + + $table_element = $product_static->table_element; + print '
'; + print load_fiche_titre($langs->trans("ECommercengWoocommerceExtrafieldsCorrespondence"), '', ''); + + print '
'; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + foreach ($extrafields_labels_clean as $key => $label) { + if (!empty($extrafields->attributes[$table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$table_element]['langfile'][$key]); + elseif (!empty($extrafields->attribute_langfile[$key])) $langs->load($extrafields->attribute_langfile[$key]); + + $options_saved = $object->parameters['ef_crp'][$table_element][$key]; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("ExtraFields") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans($label) . '' . $langs->transnoentities('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) . '' . "\n"; + $value = !empty($options_saved['correspondences']) ? $options_saved['correspondences'] : $key; + print ''; + print '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + + if (!empty($remote_attributes)) { + /** + * Remote attributes matching with extra fields. + */ + + print '
'; + print load_fiche_titre($langs->trans("ECommercengWoocommerceProductExtrafieldsCorrespondenceAttribute"), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + $remote_attributes_label = array_flip($remote_attributes); + foreach ($extrafields_labels_clean as $key => $label) { + $options_saved = $object->parameters['ef_crp_attribute'][$key]; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("ExtraFields") . '' . $langs->trans("Description") . '' . $langs->trans("ECommercengWoocommerceProductAttribute") . '
' . $langs->trans($label) . '' . $langs->transnoentities('ECommercengWoocommerceProductExtrafieldsCorrespondenceAttributeSetupDescription', $key) . '' . "\n"; + $value = !empty($options_saved['correspondences']) ? $options_saved['correspondences'] : (isset($remote_attributes_label[$label]) ? $remote_attributes_label[$label] : $key); + print $form->selectarray('attribute_ef_crp_value_' . $key, $remote_attributes, $value, 1, 0, 0, '', 0, 0, empty($options_saved['activated']) ? 1 : 0, '', 'ef_crp_value minwidth300'); + print '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + } +} + +if (!empty($conf->accounting->enabled)) { + /** + * Accounting code settings. + */ + + print '
'; + print load_fiche_titre($langs->trans("MenuDefaultAccounts"), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + foreach ($list_account as $key) { + if (preg_match('/---(.*)---/', $key, $matches)) { + print ''; + } else { + $const_name = strtoupper($key); + print '' . "\n"; + print ''."\n"; + print '' . "\n"; + print '' . "\n"; + } + } + + print '
' . $langs->trans("Parameters") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans($matches[1]) . '
'.$langs->trans('ECOMMERCE_' . $const_name).'' . $langs->transnoentities('DefaultValue') . ' : ' . (empty($conf->global->$const_name) || $conf->global->$const_name == -1 ? $langs->trans('NotDefined') : $conf->global->$const_name) . '' . "\n"; + print $formaccounting->select_account($object->parameters['default_account'][$key], $key, 1, '', 1, 1); + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; +} + +print dol_get_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/admin/setup.php b/admin/setup.php new file mode 100644 index 0000000..e22265a --- /dev/null +++ b/admin/setup.php @@ -0,0 +1,564 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/setup.php + * \ingroup ecommerceng + * \brief Page to setup ecommerceng module + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once(DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'); +require_once DOL_DOCUMENT_ROOT . '/includes/OAuth/bootstrap.php'; +dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); + +use OAuth\Common\Storage\DoliStorage; + +$langs->loadLangs(array("admin", "companies", "bills", "accountancy", "banks", "oauth", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); + +if (!$user->admin && !$user->rights->ecommerceng->site) accessforbidden(); + +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'aZ09'); + +$object = new eCommerceSite($db); +if (empty($action) && !($id > 0) && strlen($id) == 0) { + $sites = $object->listSites(); + $id = array_values($sites)[0]['id']; +} +if ($id > 0) { + $result = $object->fetch($id); + if ($result < 0) { + accessforbidden($object->errorsToString()); + } elseif ($result == 0) { + $langs->load('errors'); + accessforbidden($langs->trans('ErrorRecordNotFound')); + } +} + +$extrafields = new ExtraFields($db); + + +/* + * Actions + */ +$error = 0; + +include dol_buildpath('/ecommerceng/admin/actions_selectsite.inc.php'); + +if ($action == 'set_options') { + if ($object->id > 0) $object->oldcopy = clone $object; + + $object->type = 2; // WooCommerce + $object->name = GETPOST('site_name', 'alphanohtml'); + $object->webservice_address = GETPOST('site_webservice_address', 'alphanohtml'); + $object->authentication_type = GETPOST('site_authentication_type', 'az09'); + $object->user_name = GETPOST('site_user_name', 'alphanohtml'); + $object->user_password = GETPOST('site_user_password', 'none'); + $object->timeout = GETPOST('site_timeout', 'int'); + $object->debug = GETPOST('site_debug', 'int') ? 1 : 0; + + if(empty($object->name)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceSiteName")), 'errors'); + $error++; + } + if(empty($object->webservice_address)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceSiteAddress")), 'errors'); + $error++; + } + if(empty($object->authentication_type)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceAuthenticationType")), 'errors'); + $error++; + } + if(empty($object->user_name)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceUserName")), 'errors'); + $error++; + } + if(empty($object->user_password)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceUserPassword")), 'errors'); + $error++; + } + + if (!$error) { + $db->begin(); + + if ($object->id > 0) { + $result = $object->update($user); + } else { + // Default values + //---------------- + // Product + $object->parameters['realtime_dtoe']['product'] = 1; + $object->ecommerce_price_type = 'HT'; + $object->parameters['product_synch_price'] = 'regular'; + $object->parameters['product_weight_units'] = 0; // 0 = Kg + $object->parameters['product_dimension_units'] = 2; // 2 = cm + $object->parameters['product_variation_mode'] = 'one_to_one'; + $object->price_level = 1; + $object->parameters['product_synch_direction']['ref'] = 'all'; + $object->parameters['product_synch_direction']['description'] = 'etod'; + $object->parameters['product_synch_direction']['short_description'] = 'etod'; + $object->parameters['product_synch_direction']['weight'] = 'etod'; + $object->parameters['product_synch_direction']['dimension'] = 'etod'; + $object->parameters['product_synch_direction']['tax'] = 'etod'; + $object->parameters['product_synch_direction']['status'] = 'etod'; + $object->parameters['product_synch_direction']['image'] = ''; + // Order + $object->parameters['order_actions']['create_order'] = 1; + $object->parameters['realtime_dtoe']['order'] = 1; + $object->parameters['order_status_dtoe_check_lvl_status'] = 1; + $order_dtoe_default_status = array( + Commande::STATUS_CANCELED => 'cancelled', + Commande::STATUS_DRAFT => 'on-hold', + Commande::STATUS_VALIDATED => 'processing', + Commande::STATUS_SHIPMENTONPROCESS => 'processing', + Commande::STATUS_CLOSED => 'completed', + ); + $values = array(); + foreach ($order_dtoe_default_status as $d_status => $default) { + $values[$d_status]['selected'] = $default; + } + $object->parameters['order_status_dtoe'] = $values; + $order_stod_default_status = array( + "pending" => [ 'selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0, 'synchronize' => 1 ], + "processing" => [ 'selected' => 's' . Commande::STATUS_VALIDATED, 'billed' => 0, 'synchronize' => 1 ], + "on-hold" => [ 'selected' => 's' . Commande::STATUS_DRAFT, 'billed' => 0, 'synchronize' => 1 ], + "completed" => [ 'selected' => 's' . Commande::STATUS_CLOSED, 'billed' => 1, 'synchronize' => 1 ], + "cancelled" => [ 'selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0, 'synchronize' => 1 ], + "refunded" => [ 'selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 1, 'synchronize' => 1 ], + "failed" => [ 'selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0, 'synchronize' => 1 ], + "trash" => [ 'selected' => 's' . Commande::STATUS_CANCELED, 'billed' => 0, 'synchronize' => 1 ], + ); + $values = array(); + foreach ($order_stod_default_status as $s_status => $s_default) { + $values[$s_status]['selected'] = $s_default['selected']; + $values[$s_status]['billed'] = $s_default['billed']; + $values[$s_status]['synchronize'] = $s_default['synchronize']; + } + $object->parameters['order_status_etod'] = $values; + + $result = $object->create($user); + } + + // Create all extrafields + if ($result > 0) { + // Product + $res = $extrafields->addExtraField("ecommerceng_description_{$conf->entity}", 'ECommercengWoocommerceDescription', 'text', 1, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_short_description_{$conf->entity}", 'ECommercengWoocommerceShortDescription', 'text', 2, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_status_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceStatus', $object->name), 'select', 3, '', 'product', 0, 0, '', array('options' => array( + "draft" => $langs->trans('ECommercengWoocommerceStatusDraft'), + "pending" => $langs->trans('ECommercengWoocommerceStatusPending'), + "private" => $langs->trans('ECommercengWoocommerceStatusPrivate'), + "publish" => $langs->trans('ECommercengWoocommerceStatusPublish'), + )), 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_tax_class_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceTaxClass', $object->name), 'sellist', 4, '', 'product', 0, 0, '', array('options' => array("c_ecommerceng_tax_class:label:code::active=1 AND site_id={$object->id} AND entity={$conf->entity}" => null)), 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); +// if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_regular_price_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceRegularPrice', $object->name), 'price', 5, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_sale_price_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceSalePrice', $object->name), 'price', 6, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_date_on_sale_from_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceDateOnSaleFrom', $object->name), 'date', 7, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_date_on_sale_to_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceDateOnSaleTo', $object->name), 'date', 8, '', 'product', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_manage_stock_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceManageStock', $object->name), 'boolean', 9, '', 'product', 0, 0, '1', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_dont_update_stock_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceDontUpdateStock', $object->name), 'boolean', 10, '', 'product', 0, 0, '0', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + // Order + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_online_payment_{$conf->entity}", 'ECommercengWoocommerceOnlinePayment', 'boolean', 1, '', 'commande', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_status_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceOrderStatus', $object->name), 'select', 2, '', 'commande', 0, 0, '', array('options' => array( + "0_pending" => $langs->trans('ECommercengWoocommerceOrderStatusPending'), + "1_on-hold" => $langs->trans('ECommercengWoocommerceOrderStatusOnHold'), + "2_processing" => $langs->trans('ECommercengWoocommerceOrderStatusProcessing'), + "3_completed" => $langs->trans('ECommercengWoocommerceOrderStatusCompleted'), + "3_cancelled" => $langs->trans('ECommercengWoocommerceOrderStatusCancelled'), + "3_refunded" => $langs->trans('ECommercengWoocommerceOrderStatusRefunded'), + "3_failed" => $langs->trans('ECommercengWoocommerceOrderStatusFailed'), + "3_trash" => $langs->trans('ECommercengWoocommerceOrderStatusTrash'), + )), 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_link_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceOrderLink', $object->name), 'url', 3, '', 'commande', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + // Third party + if ($res > 0) $res = $extrafields->addExtraField("ecommerceng_wc_role_{$object->id}_{$conf->entity}", $langs->trans('ECommercengWoocommerceCompanyRole', $object->name), 'varchar', 1, '255', 'societe', 0, 0, '', null, 0, '0', 1, 0, '', '', 'ecommerceng@ecommerceng', '1', 'false'); + if ($res < 0) setEventMessages($extrafields->error, $extrafields->errors, 'errors'); + + if ($res > 0) { + // Fix extrafields wc_update_stock to wc_manage_stock on product + $db->query("UPDATE " . MAIN_DB_PREFIX . "product_extrafields SET ecommerceng_wc_manage_stock_{$object->id}_{$conf->entity} = ecommerceng_wc_update_stock_{$object->id}_{$conf->entity}"); + $extrafields->delete("ecommerceng_wc_update_stock_{$object->id}_{$conf->entity}", 'product'); + } + } + + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + + if ($result < 0) { + $db->rollback(); + } else { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } +} elseif ($action == 'set_web_hooks_options' && $object->id > 0) { + $object->oldcopy = clone $object; + $object->parameters['web_hooks_secret'] = GETPOST('site_web_hooks_secret', 'none'); + $object->parameters['web_hooks_volumetry_alert'] = GETPOST('site_web_hooks_volumetry_alert', 'int'); + + $result = $object->update($user); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_wordpress_api_options' && $object->id > 0) { + $object->oldcopy = clone $object; + + $object->wordpress_authentication_type = GETPOST('wordpress_authentication_type', 'az09'); + $object->wordpress_authentication_login = !empty($object->wordpress_authentication_type) ? GETPOST('wordpress_authentication_login', 'none') : ''; + $object->wordpress_authentication_password = !empty($object->wordpress_authentication_type) ? GETPOST('wordpress_authentication_password', 'none') : ''; + $object->wordpress_timeout = !empty($object->wordpress_authentication_type) ? GETPOST('wordpress_timeout', 'int') : 0; + $object->wordpress_debug = GETPOST('wordpress_debug', 'int') ? 1 : 0; + + if(!empty($object->wordpress_authentication_type)) { + if (empty($object->wordpress_authentication_login)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceWordpressAuthenticationLogin")), 'errors'); + $error++; + } + if (empty($object->wordpress_authentication_password)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceWordpressAuthenticationPassword")), 'errors'); + $error++; + } + } + + if (!$error) { + $result = $object->update($user); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } +} elseif ($action == 'confirm_delete' && $confirm == "yes" && $object->id > 0) { + $result = $object->delete($user); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("RecordDeleted")); + header("Location: " . $_SERVER["PHP_SELF"]); + exit; + } +} + + +/* + * View + */ + +$form = new Form($db); + +$wikihelp=''; +llxHeader('', $langs->trans("ECommerceSetup"), $wikihelp); + +$formconfirm = ''; + +if ($action == 'delete') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ECommerceConfirmDelete'), 'confirm_delete', '', 0, 1, 200, 800); +} + +// Call Hook formConfirm +$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); +$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} + +// Print form confirm +print $formconfirm; + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'title_setup'); + +include dol_buildpath('/ecommerceng/admin/tpl/selectsite.tpl.php'); + +$head=ecommercengConfigSitePrepareHead($object); + +dol_fiche_head($head, 'settings', $langs->trans("Module107100Name"), 0, 'eCommerce@ecommerceng'); + +if ($object->id > 0) { + print '
'; + print '' . $langs->trans('Delete') . ''; + print '
'; +} + +/** + * Settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("Parameters"), '', ''); + +print '
id > 0 ? '?id=' . $object->id : '') . '#options">'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +// Site name +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Site url +if (!empty($object->webservice_address)) $test_url = rtrim($object->webservice_address, '/') . '/wp-json/'; +else $test_url = ''; +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Site API authentication type +print '' . "\n"; +print ''."\n"; +print '' . "\n"; +print '' . "\n"; + +// Site API login +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Site API password +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Site API timeout +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Site API debug +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
'.$langs->trans("ECommerceSiteName").''.$langs->transnoentities("ECommerceSiteNameDescription").'' . "\n"; +print '' . "\n"; +print '
'.$langs->trans("ECommerceSiteAddress").''.$langs->transnoentities("ECommerceSiteAddressDescription").(!empty($test_url) ? '
'.$langs->trans("ECommerceClickUrlToTestUrl").'' : '') . '
' . "\n"; +print '' . "\n"; +print '
'.$langs->trans("ECommerceAuthenticationType").'' . $langs->transnoentities("ECommerceAuthenticationTypeDescription") . '' . "\n"; +$authentication_types = array( + 'oauth1_header' => 'ECommerceAuthenticationTypeOauth1Header', + 'oauth1_query' => 'ECommerceAuthenticationTypeOauth1Query', + 'basic' => 'ECommerceAuthenticationTypeBasic', + 'query' => 'ECommerceAuthenticationTypeQuery', +); +print $form->selectarray('site_authentication_type', $authentication_types, $object->authentication_type, 0, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
'.$langs->trans("ECommerceUserName").''.$langs->transnoentities("ECommerceUserNameDescription").'' . "\n"; +print '' . "\n"; +print '
'.$langs->trans("ECommerceUserPassword").''.$langs->transnoentities("ECommerceUserPasswordDescription").'' . "\n"; +print '' . "\n"; +print '
'.$langs->trans("ECommerceTimeout").''.$langs->transnoentities("ECommerceTimeoutDescription").'' . "\n"; +print '' . "\n"; +print '
'.$langs->trans("ECommerceDebug").''.$langs->trans("ECommerceDebugDescription").'' . "\n"; +print 'debug) ? ' checked' : '') . ' />' . "\n"; +print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +if ($object->id > 0) { + /** + * WebHooks. + */ + + print '
'; + print load_fiche_titre($langs->trans("ECommerceSiteWebHooksSetup"), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + // Site web hooks url + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Site web hooks secret + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Site web hooks volumetry alert + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + print '
' . $langs->trans("Parameters") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans("ECommerceSiteWebHooksUrl") . '' . $langs->transnoentities("ECommerceSiteWebHooksUrlDescription") . '' . "\n"; + $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); + $currentUri = $uriFactory->createFromAbsolute(dol_buildpath('/ecommerceng/webhooks.php', 2) . '?ecommerce_id=' . $object->id); + $web_hooks_url = $currentUri->getAbsoluteUri(); + print '' . "\n"; + print '
' . $langs->trans("ECommerceSiteWebHooksSecret") . '' . $langs->transnoentities("ECommerceSiteWebHooksSecretDescription") . '' . "\n"; + print '
' . "\n"; + print '' . "\n"; + if (!empty($conf->use_javascript_ajax)) { + print '' . img_picto($langs->trans('Generate'), 'refresh', 'id="generate_web_hooks_secret" class="linkobject"'); + print "\n" . ''; + } + print '
' . "\n"; + print '
' . $langs->trans("ECommerceSiteWebHooksVolumetryAlert") . '' . $langs->transnoentities("ECommerceSiteWebHooksVolumetryAlertDescription") . '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + + if (!empty($object->webservice_address)) { + /** + * Wordpress API (wordpress token connexion or plugin "WordPress REST API Authentication by miniOrange"). + */ + + print '
'; + $setup_help = ''; + if ($object->wordpress_authentication_type == 'wordpress_application') { + $setup_help = ' ' . $langs->trans("ECommerceWordpressAuthenticationSetup", rtrim($object->webservice_address, "/") . '/wp-admin/users.php'); + } elseif ($object->wordpress_authentication_type == 'jwt_authentication') { + $setup_help = ' ' . $langs->trans("ECommerceWordpressAuthenticationSetup", rtrim($object->webservice_address, "/") . '/wp-admin/admin.php?page=mo_api_authentication_settings'); + } + print load_fiche_titre($langs->trans("ECommerceWordpressAuthenticationOptions") . $setup_help, '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + // Wordpress authentication type + print '' . "\n"; + print ''."\n"; + print '' . "\n"; + print '' . "\n"; + + if (!empty($object->wordpress_authentication_type)) { + // Wordpress authentication login + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Wordpress authentication password + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + // Wordpress timeout + print '' . "\n"; + print ''."\n"; + print ''."\n"; + print '' . "\n"; + + // Wordpress debug + print '' . "\n"; + print ''."\n"; + print ''."\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("Parameters") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
'.$langs->trans("ECommerceWordpressAuthenticationType").'' . $langs->transnoentities("ECommerceWordpressAuthenticationTypeDescription") . '' . "\n"; + $wordpress_authentication_types = array( + '' => 'None', + 'wordpress_application' => 'ECommerceWordpressAuthenticationTypeWordpressApplication', + 'jwt_authentication' => 'ECommerceWordpressAuthenticationTypeJWTAuthentication', + ); + print $form->selectarray('wordpress_authentication_type', $wordpress_authentication_types, $object->wordpress_authentication_type, 0, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n"; + print '
' . $langs->trans("ECommerceWordpressAuthenticationLogin") . '' . $langs->transnoentities("ECommerceWordpressAuthenticationLoginDescription") . '' . "\n"; + print '' . "\n"; + print '
' . $langs->trans("ECommerceWordpressAuthenticationPassword") . '' . $langs->transnoentities("ECommerceWordpressAuthenticationPasswordDescription") . '' . "\n"; + print '' . "\n"; + print '
'.$langs->trans("ECommerceWordpressTimeout").''.$langs->transnoentities("ECommerceWordpressTimeoutDescription").'' . "\n"; + print '' . "\n"; + print '
'.$langs->trans("ECommerceWordpressDebug").''.$langs->trans("ECommerceWordpressDebugDescription").'' . "\n"; + print 'wordpress_debug) ? ' checked' : '') . ' />' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + } +} + +print dol_get_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/admin/stock.php b/admin/stock.php new file mode 100644 index 0000000..67ec1f5 --- /dev/null +++ b/admin/stock.php @@ -0,0 +1,311 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/setup.php + * \ingroup ecommerceng + * \brief Page to setup ecommerceng module + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; +dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); +dol_include_once('/ecommerceng/class/html.formecommerceng.class.php'); +dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php'); + +$langs->loadLangs(array("admin", "stocks", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); + +if (!$user->admin && !$user->rights->ecommerceng->site) accessforbidden(); + +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'aZ09'); + +include dol_buildpath('/ecommerceng/admin/actions_selectsite.inc.php'); + +$object = new eCommerceSite($db); +if (!($id > 0)) { + $sites = $object->listSites(); + $id = array_values($sites)[0]['id']; + $action = ''; +} +if ($id > 0) { + $result = $object->fetch($id); + if ($result < 0) { + accessforbidden($object->errorsToString()); + } elseif ($result == 0) { + $langs->load('errors'); + accessforbidden($langs->trans('ErrorRecordNotFound')); + } +} else { + accessforbidden($langs->trans('ErrorRecordNotFound')); +} + +if (empty($conf->product->enabled) && empty($conf->stock->enabled)) { + accessforbidden($langs->trans('ModuleDisabled')); +} + +if (!empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + $eCommerceRemoteWarehouses = new eCommerceRemoteWarehouses($db); + $remote_warehouses = $eCommerceRemoteWarehouses->get_all($object->id); + if (!is_array($remote_warehouses)) { + setEventMessages($eCommerceRemoteWarehouses->error, $eCommerceRemoteWarehouses->errors, 'errors'); + } +} + + +/* + * Actions + */ + +if ($action == 'set_options') { + $object->oldcopy = clone $object; + + $object->parameters['order_actions']['valid_order_fk_warehouse'] = !empty($object->parameters['order_actions']['create_order']) ? GETPOST('valid_order_fk_warehouse', 'int') : -1; + $object->parameters['order_actions']['valid_invoice_fk_warehouse'] = !empty($object->parameters['order_actions']['create_invoice']) ? GETPOST('valid_invoice_fk_warehouse', 'int') : -1; + $object->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] = !empty($object->parameters['order_actions']['create_supplier_invoice']) ? GETPOST('valid_supplier_invoice_fk_warehouse', 'int') : -1; + $object->stock_sync_direction = GETPOST('stock_sync_direction', 'az09'); + $object->parameters['enable_warehouse_plugin_sl_support'] = $object->stock_sync_direction != 'none' && GETPOST('enable_warehouse_plugin_sl_support', 'int') ? 1 : 0; + $object->fk_warehouse = $object->stock_sync_direction == 'ecommerce2dolibarr' && empty($object->parameters['enable_warehouse_plugin_sl_support']) ? GETPOST('fk_warehouse', 'int') : 0; + $object->fk_warehouse = $object->fk_warehouse > 0 ? $object->fk_warehouse : 0; + $object->parameters['fk_warehouse_to_ecommerce'] = $object->stock_sync_direction == 'dolibarr2ecommerce' && empty($object->parameters['enable_warehouse_plugin_sl_support']) ? GETPOST('fk_warehouse_to_ecommerce', 'array') : array(); + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'set_remote_warehouse_options' && !empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + foreach ($remote_warehouses as $remote_code => $infos) { + $remote_warehouses[$remote_code]['warehouse_id'] = GETPOST('warehouse_id_' . $remote_code, 'int'); + $remote_warehouses[$remote_code]['warehouse_id'] = $remote_warehouses[$remote_code]['warehouse_id'] > 0 ? $remote_warehouses[$remote_code]['warehouse_id'] : 0; + $remote_warehouses[$remote_code]['set_even_if_empty_stock'] = GETPOST('set_even_if_empty_stock_' . $remote_code, 'int') ? 1 : 0; + } + + $result = $eCommerceRemoteWarehouses->set($object->id, $remote_warehouses); + + if ($result < 0) { + setEventMessages($eCommerceRemoteWarehouses->error, $eCommerceRemoteWarehouses->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } +} elseif ($action == 'confirm_update_remote_warehouses' && $confirm == "yes" && !empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + $result = ecommerceng_update_remote_warehouses($db, $object); + if ($result) setEventMessage($langs->trans('ECommerceRemoteWarehousesUpdated'), 'mesgs'); + + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; +} + + +/* + * View + */ + +$form = new Form($db); +$formproduct = new FormProduct($db); +$formecommerceng = new FormECommerceNg($db); + +$wikihelp=''; +llxHeader('', $langs->trans("ECommerceSetup"), $wikihelp); + +$formconfirm = ''; + +if ($action == 'update_remote_warehouses' && !empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&plugin=' . $plugin, $langs->trans('ECommerceUpdateRemoteWarehouses'), $langs->trans('ECommerceConfirmUpdateRemoteWarehouses'), 'confirm_update_remote_warehouses', '', 0, 1, 200, 800); +} + +// Call Hook formConfirm +$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); +$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; +} elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; +} + +// Print form confirm +print $formconfirm; + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'title_setup'); + +include dol_buildpath('/ecommerceng/admin/tpl/selectsite.tpl.php'); + +$head=ecommercengConfigSitePrepareHead($object); + +dol_fiche_head($head, 'stock', $langs->trans("Module107100Name"), 0, 'eCommerce@ecommerceng'); + +if (!empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + print ''; +} + +/** + * Settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("Parameters"), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +if (!empty($object->parameters['order_actions']['create_order'])) { + // Warehouse used when valid a order + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +if (!empty($object->parameters['order_actions']['create_invoice'])) { + // Warehouse used when valid a invoice + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +if (!empty($object->parameters['order_actions']['create_supplier_invoice'])) { + // Warehouse used when valid a supplier invoice + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; +} + +// Synchronize sens +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +if (in_array($object->stock_sync_direction, [ 'dolibarr2ecommerce', 'ecommerce2dolibarr' ])) { + // Support of WooCommerce plugin : Stock Locations for WooCommerce + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + if (empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + // Warehouses + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } +} + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
' . $langs->trans("ECommerceValidOrderWarehouse") . '' . $langs->transnoentities("ECommerceValidOrderWarehouseDescription") . '' . "\n"; + print $formproduct->selectWarehouses($object->parameters['order_actions']['valid_order_fk_warehouse'], 'valid_order_fk_warehouse', 0, 1); + print '
' . $langs->trans("ECommerceValidInvoiceWarehouse") . '' . $langs->transnoentities("ECommerceValidInvoiceWarehouseDescription") . '' . "\n"; + print $formproduct->selectWarehouses($object->parameters['order_actions']['valid_invoice_fk_warehouse'], 'valid_invoice_fk_warehouse', 0, 1); + print '
' . $langs->trans("ECommerceValidSupplierInvoiceWarehouse") . '' . $langs->transnoentities("ECommerceValidSupplierInvoiceWarehouseDescription") . '' . "\n"; + print $formproduct->selectWarehouses($object->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'], 'valid_supplier_invoice_fk_warehouse', 0, 1); + print '
'.$langs->trans("ECommerceStockSyncDirection").''.$langs->transnoentities("ECommerceStockSyncDirectionDescription").'' . "\n"; +$synchronize_sens = array( + 'none' => $langs->trans('None'), + 'ecommerce2dolibarr' => $langs->trans('ECommerceToDolibarr'), + 'dolibarr2ecommerce' => $langs->trans('DolibarrToECommerce'), +); +print $form->selectarray('stock_sync_direction', $synchronize_sens, $object->stock_sync_direction, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
' . $langs->trans("ECommerceWoocommerceEnableWarehouseSlPluginSupport") . '' . $langs->transnoentities("ECommerceWoocommerceEnableWarehousePluginSlSupportDescription") . '' . "\n"; + print 'parameters['enable_warehouse_plugin_sl_support']) ? ' checked' : '') . ' />' . "\n"; + print '
' . $langs->trans("ECommerceStockProduct") . '' . $langs->transnoentities("ECommerceStockProductDescription") . '' . "\n"; + if ($object->stock_sync_direction == 'dolibarr2ecommerce') { + $value = isset($object->parameters['fk_warehouse_to_ecommerce']) ? $object->parameters['fk_warehouse_to_ecommerce'] : array(); + print $formecommerceng->multiselectWarehouses($value, 'fk_warehouse_to_ecommerce'); + } else { + print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 0, 1); + } + print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +if (!empty($object->parameters['enable_warehouse_plugin_sl_support'])) { + /** + * Remote warehouses + */ + print '
'; + print load_fiche_titre($langs->trans('ECommerceRemoteWarehousesCorrespondence'), '', ''); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + foreach ($remote_warehouses as $remote_code => $infos) { + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("Code") . '' . $langs->trans("ECommerceRemoteID") . '' . $langs->trans("Label") . '' . $langs->trans("Warehouse") . '' . $langs->trans("ECommerceWarehouseSetToZeroEvenIfEmptyStock") . '' . $langs->trans("ECommerceWarehouseOldEntry") . '
' . $remote_code . '' . $infos['remote_id'] . '' . $infos['remote_name'] . '' . $formproduct->selectWarehouses($infos['warehouse_id'], 'warehouse_id_' . $remote_code, 0, 1) . '' . yn($infos['old_entry']) . '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; +} + +print dol_get_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/admin/thirdparty.php b/admin/thirdparty.php new file mode 100644 index 0000000..be5e787 --- /dev/null +++ b/admin/thirdparty.php @@ -0,0 +1,316 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/admin/setup.php + * \ingroup ecommerceng + * \brief Page to setup ecommerceng module + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once(DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'); +require_once(DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'); +require_once(DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'); +require_once(DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'); +dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); +dol_include_once('/ecommerceng/admin/class/data/eCommerceDict.class.php'); + +$langs->loadLangs(array("admin", "companies", "bills", "accountancy", "banks", "oauth", "ecommerce@ecommerceng", "woocommerce@ecommerceng")); + +if (!$user->admin && !$user->rights->ecommerceng->site && !empty($conf->societe->enabled)) accessforbidden(); + +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm', 'aZ09'); + +include dol_buildpath('/ecommerceng/admin/actions_selectsite.inc.php'); + +$object = new eCommerceSite($db); +if (!($id > 0)) { + $sites = $object->listSites(); + $id = array_values($sites)[0]['id']; + $action = ''; +} +if ($id > 0) { + $result = $object->fetch($id); + if ($result < 0) { + accessforbidden($object->errorsToString()); + } elseif ($result == 0) { + $langs->load('errors'); + accessforbidden($langs->trans('ErrorRecordNotFound')); + } +} else { + accessforbidden($langs->trans('ErrorRecordNotFound')); +} + +if (empty($conf->societe->enabled)) { + accessforbidden($langs->trans('ModuleDisabled')); +} +if (empty($conf->categorie->enabled)) { + accessforbidden($langs->trans('ModuleDisabled') . ' : ' . $langs->trans('Categories')); +} + +$thirdparty_static = new Societe($db); +$contact_static = new Contact($db); +$extrafields = new ExtraFields($db); +$extrafields_thirdparty_labels = $extrafields->fetch_name_optionals_label($thirdparty_static->table_element); +$extrafields_thirdparty_labels_clean = array(); +foreach ($extrafields_thirdparty_labels as $key => $label) { + if (preg_match('/^ecommerceng_/', $key)) continue; + $extrafields_thirdparty_labels_clean[$key] = $label; +} +$extrafields_contact_labels = $extrafields->fetch_name_optionals_label($contact_static->table_element); +$extrafields_contact_labels_clean = array(); +foreach ($extrafields_contact_labels as $key => $label) { + if (preg_match('/^ecommerceng_/', $key)) continue; + $extrafields_contact_labels_clean[$key] = $label; +} + +$extrafields_list = array( + $thirdparty_static->table_element => array('label' => 'ThirdParty', 'extrafields' => $extrafields_thirdparty_labels_clean), + $contact_static->table_element => array('label' => 'Contact', 'extrafields' => $extrafields_contact_labels_clean), +); + + +/* + * Actions + */ +$error = 0; + +if ($action == 'set_options') { + $object->oldcopy = clone $object; + + $object->fk_cat_societe = GETPOST('fk_cat_societe', 'int'); + $object->fk_cat_societe = $object->fk_cat_societe > 0 ? $object->fk_cat_societe : 0; + $object->parameters['realtime_dtoe']['thridparty'] = GETPOST('realtime_dtoe_thridparty', 'int') ? 1 : 0; + $object->parameters['realtime_dtoe']['contact'] = GETPOST('realtime_dtoe_contact', 'int') ? 1 : 0; + $object->fk_anonymous_thirdparty = GETPOST('fk_anonymous_thirdparty', 'int'); + $object->fk_anonymous_thirdparty = $object->fk_anonymous_thirdparty > 0 ? $object->fk_anonymous_thirdparty : 0; + $object->parameters['customer_roles'] = GETPOST('customer_roles', 'alphanohtml'); + $object->parameters['dont_update_dolibarr_company'] = GETPOST('dont_update_dolibarr_company', 'int') ? 1 : 0; + + if(empty($object->fk_cat_societe)) { + setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceCatSociete")), 'errors'); + $error++; + } + + if (!$error) { + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } +} elseif ($action == 'set_metadata_matching_extrafields_options') { + $table_element = GETPOST('table_element', 'alphanohtml'); + if (isset($extrafields_list[$table_element])) { + $object->oldcopy = clone $object; + + $values = array(); + foreach ($extrafields_list[$table_element]['extrafields'] as $key => $label) { + $activated = GETPOST("act_ef_crp_{$table_element}_{$key}", 'int') ? 1 : 0; + $correspondences = $activated ? GETPOST("ef_crp_{$table_element}_{$key}", 'alphanohtml') : + (!empty($object->parameters['ef_crp'][$table_element][$key]['correspondences']) ? $object->parameters['ef_crp'][$table_element][$key]['correspondences'] : $key); + + $values[$key] = [ + 'correspondences' => $correspondences, + 'activated' => $activated, + ]; + } + $object->parameters['ef_crp'][$table_element] = $values; + + $result = $object->update($user); + + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessage($langs->trans("SetupSaved")); + header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } + } else { + setEventMessage("Wrong table element", 'errors'); + } +} + + +/* + * View + */ + +$form = new Form($db); +$category_static = new Categorie($db); + +$wikihelp=''; +llxHeader('', $langs->trans("ECommerceSetup"), $wikihelp, '', 0, 0, array( + '/ecommerceng/js/form.js', +)); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'title_setup'); + +include dol_buildpath('/ecommerceng/admin/tpl/selectsite.tpl.php'); + +$head=ecommercengConfigSitePrepareHead($object); + +dol_fiche_head($head, 'thirdparty', $langs->trans("Module107100Name"), 0, 'eCommerce@ecommerceng'); + +/** + * Settings. + */ + +print '
'; +print load_fiche_titre($langs->trans("Parameters"), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print "\n"; + +// Third party category +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Synchronize third party real time from dolibarr to site +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Synchronize contact real time from dolibarr to site +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Third party anonymous +print '' . "\n"; +print ''."\n"; +print ''."\n"; +print '' . "\n"; + +// Supported customer roles +print '' . "\n"; +print '' . "\n"; +print '' . "\n"; +print '' . "\n"; + +// Don't update the third party +print '' . "\n"; +print '' . "\n"; +print '' . "\n"; +print '' . "\n"; + +print '
'.$langs->trans("Parameters").''.$langs->trans("Description").''.$langs->trans("Value").'
'.$langs->trans("ECommerceCatSociete").''.$langs->trans("ECommerceCatSocieteDescription").'' . "\n"; +$categories = $category_static->get_full_arbo(Categorie::TYPE_CUSTOMER); +$categories_list = array(); +foreach ($categories as $category) { + $categories_list[$category['id']] = $category['label']; +} +print $form->selectarray('fk_cat_societe', $categories_list, $object->fk_cat_societe, 1, 0, 0, '', 0, 0, 0, '', 'minwidth200 centpercent') . "\n"; +print '
'.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceThirdParty").''.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceThirdPartyDescription").'' . "\n"; +print 'parameters['realtime_dtoe']['thridparty']) ? ' checked' : '') . ' />' . "\n"; +print '
'.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceContact").''.$langs->trans("ECommerceRealTimeSynchroDolibarrToECommerceContactDescription").'' . "\n"; +print 'parameters['realtime_dtoe']['contact']) ? ' checked' : '') . ' />' . "\n"; +print '
'.$langs->trans("ThirdPartyForNonLoggedUsers").''.$langs->trans("SynchUnkownCustomersOnThirdParty").'' . "\n"; +print $form->select_company($object->fk_anonymous_thirdparty, 'fk_anonymous_thirdparty', '', 1) . "\n"; +print '
' . $langs->trans("ECommerceWoocommerceCustomerRolesSupported") . '' . $langs->trans("ECommerceWoocommerceCustomerRolesSupportedDescription") . '' . "\n"; +$value = isset($object->parameters['customer_roles']) ? $object->parameters['customer_roles'] : 'customer'; +print '' . "\n"; +print '
' . $langs->trans("ECommerceDontUpdateDolibarrCompany") . '' . $langs->trans("ECommerceDontUpdateDolibarrCompanyDescription") . '' . "\n"; +print 'parameters['dont_update_dolibarr_company']) ? ' checked' : '') . ' />' . "\n"; +print '
'."\n"; + +print '
'; +print '
'; +print ''; +print '
'; + +print '
'; + +/** + * Remote meta data with extra fields. + */ + +foreach ($extrafields_list as $table_element => $info) { + if (!empty($info['extrafields'])) { + print '
'; + print load_fiche_titre($langs->trans('ECommercengWoocommerceExtrafieldsCorrespondenceOf', $langs->transnoentitiesnoconv($info['label'])), '', ''); + + print '
'; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print "\n"; + + foreach ($info['extrafields'] as $key => $label) { + if (!empty($extrafields->attributes[$table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$table_element]['langfile'][$key]); + elseif (!empty($extrafields->attribute_langfile[$key])) $langs->load($extrafields->attribute_langfile[$key]); + + $options_saved = $object->parameters['ef_crp'][$table_element][$key]; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + } + + print '
' . $langs->trans("ExtraFields") . '' . $langs->trans("Description") . '' . $langs->trans("Value") . '
' . $langs->trans($label) . '' . $langs->transnoentities('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) . '' . "\n"; + $value = !empty($options_saved['correspondences']) ? $options_saved['correspondences'] : $key; + print ''; + print '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print '
'; + print ''; + print '
'; + + print '
'; + } +} + +print dol_get_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/admin/tpl/eCommerceSetup.tpl.php b/admin/tpl/eCommerceSetup.tpl.php deleted file mode 100644 index 6e2ef80..0000000 --- a/admin/tpl/eCommerceSetup.tpl.php +++ /dev/null @@ -1,1457 +0,0 @@ - - * Copyright (C) 2013 Laurent Destailleur - * Copyright (C) 2017 Open-DSI - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * or see http://www.gnu.org/ - */ - -include_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; -include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; -dol_include_once('/ecommerceng/class/html.formecommerceng.class.php'); - -$formproduct = new FormProduct($db); -$formecommerceng = new FormECommerceNg($db); - -llxHeader(); - -print_fiche_titre($langs->trans("ECommerceSetup"),$linkback,'setup'); - -?> - -
-
- - -
-
- - trans("MainSyncSetup")); ?> - -
- - - - - - - - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - - - > - - - - - - > - - - - - - > - - - - -global->PRODUIT_MULTIPRICES)) { - $var = !$var; -?> - > - - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - commande->enabled)) { - if ($ecommerceType == 2) { - $var = !$var; -?> - > - - - - -commande->enabled || $conf->facture->enabled || ($conf->supplier_invoice->enabled && !empty($ecommerceOrderActions['create_invoice']))) { -?> - > - - - - - - > - - - - - - > - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans('ECommerceSiteType') ?> - - trans('ECommerceSiteTypeDescription') ?>
trans('ECommerceSiteName') ?> - - trans('ECommerceSiteNameDescription') ?>
trans('ECommerceCatProduct') ?> - - trans('ECommerceCatProductDescription') ?>
trans('ECommerceCatSociete') ?> - - trans('ECommerceCatSocieteDescription') ?>
trans('ThirdPartyForNonLoggedUsers') ?> - select_company($ecommerceFkAnonymousThirdparty, 'ecommerce_fk_anonymous_thirdparty', '', 1); ?> - trans('SynchUnkownCustomersOnThirdParty') ?>
trans('ECommerceSiteAddress') ?> - - '.$langs->trans("ECommerceClickUrlToTestUrl").''; - ?> - trans('ECommerceSiteAddressDescription') ?>
trans('ECommerceUserName') ?> - - trans('ECommerceUserNameDescription') ?>
trans('ECommerceUserPassword') ?>trans('ECommerceUserPasswordDescription') ?>
trans('ECommercePriceLevel') ?> - - trans('ECommercePriceLevelDescription') ?>
trans('ECommerceTimeout') ?> - - trans('ECommerceTimeoutDescription') ?>
trans('ECommerceMagentoUseSpecialPrice') ?> - /> - trans('ECommerceMagentoUseSpecialPriceDescription') ?>
trans('ECommercePriceType') ?> - - trans('ECommercePriceTypeDescription') ?>
trans('ECommerceShippingService') ?> - select_produits($ecommerceFkShippingService, 'ecommerce_fk_shipping_service', 1, 0); ?> - trans('ECommerceShippingServiceDescription') ?>
trans('ECommerceDiscountCodeService') ?> - select_produits($ecommerceFkDiscountCodeService, 'ecommerce_fk_discount_code_service', 1, 0); ?> - trans('ECommerceDiscountCodeServiceDescription') ?>
trans('ECommercePwGiftCardsService') ?> - select_produits($ecommerceFkPwGiftCardsService, 'ecommerce_fk_pw_gift_cards_service', 1, 0); ?> - trans('ECommercePwGiftCardsServiceDescription') ?>
trans('ECommerceWoocommerceCustomerRolesSupported') ?>trans('ECommerceWoocommerceCustomerRolesSupportedDescription') ?>
trans('ECommerceCreateOrderInvoiceWhenSyncOrder') ?> - commande->enabled) { - ?> - - facture->enabled) { - ?> -
- >  -   - selectarray('ecommerce_create_invoice_type', array(Facture::TYPE_STANDARD => $langs->trans('InvoiceStandard'), Facture::TYPE_DEPOSIT => $langs->trans('InvoiceDeposit')), $ecommerceCreateInvoiceType); - ?> -  >  - - '; - $arraylist = array( - 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), - 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), - 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') - ); - print '
'; - print $form->selectarray('ecommerce_create_invoice_deposit_type', $arraylist, $ecommerceOrderActions['create_invoice_deposit_type'], 0, 0, 0, '', 1); - print ' '.$langs->trans('Value'); - print ': '; - print ''; - ?> - -
-   - supplier_invoice->enabled && !empty($ecommerceOrderActions['create_invoice'])) { - ?> -
-   - -
-   -
trans('ECommerceCreateOrderDescription') ?>
trans('ECommerceCreateOrderSalesRepresentativeFollowByDefault') ?> - select_dolusers($ecommerceDefaultSalesRepresentativeFollow > 0 ? $ecommerceDefaultSalesRepresentativeFollow : -1, 'default_sales_representative_follow', 1, (! empty($userAlreadySelected)?$userAlreadySelected:null), 0, null, null, 0, 56, '', 0, '', 'minwidth200imp'); - ?> - trans('ECommerceCreateOrderSalesRepresentativeFollowByDefaultDescription') ?>
trans('ECommerceDontUpdateDolibarrCompany') ?> - > - trans('ECommerceDontUpdateDolibarrCompanyDescription') ?>
- - -
- trans("ECommerceSiteWebHooksSetup")); - ?> - - - - - - - - - > - - - - - - > - - - - - - > - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans("ECommerceSiteWebHooksUrl"); ?>trans('ECommerceSiteWebHooksUrlDescription') ?>
trans("ECommerceSiteWebHooksSecret"); ?>'; - if (! empty($conf->use_javascript_ajax)) - print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"'); - print "\n".''; - ?>trans('ECommerceSiteWebHooksSecretDescription') ?>
trans('ECommerceSiteWebHooksVolumetryAlert') ?>trans('ECommerceSiteWebHooksVolumetryAlertDescription') ?>
- - -$langs->trans('None'), 'etod'=>$langs->trans('ECommerceToDolibarr'), 'dtoe'=>$langs->trans('DolibarrToECommerce'), 'all'=>$langs->trans('AllDirection')); -?> -
-trans("ProductsSyncSetup")); -?> - - - - - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - > - - - - - - > - - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans('ECommerceWoocommerceProductSyncPrice') ?> - selectarray('ecommerce_product_synch_price', array(/*'selling'=>$langs->trans('ECommerceWoocommerceSellingPrice'),*/ 'regular'=>$langs->trans('ECommerceWoocommerceRegularPrice')), $ecommerceProductSyncPrice); - ?> - trans('ECommerceWoocommerceProductSyncPriceDescription') ?>
trans('ECommerceProductImageSyncDirection') ?> - selectarray('ecommerce_product_image_synch_direction', $sync_direction_array, $ecommerceProductImageSynchDirection); - ?> - trans('ECommerceProductImageSyncDirectionDescription') ?>
trans('ECommerceProductRefSyncDirection') ?> - selectarray('ecommerce_product_ref_synch_direction', $sync_direction_array, $ecommerceProductRefSynchDirection); - ?> - trans('ECommerceProductRefSyncDirectionDescription') ?>
trans('ECommerceProductDescriptionSyncDirection') ?> - selectarray('ecommerce_product_description_synch_direction', $sync_direction_array, $ecommerceProductDescriptionSynchDirection); - ?> - trans('ECommerceProductDescriptionSyncDirectionDescription') ?>
trans('ECommerceProductShortDescriptionSyncDirection') ?> - selectarray('ecommerce_product_short_description_synch_direction', $sync_direction_array, $ecommerceProductShortDescriptionSynchDirection); - ?> - trans('ECommerceProductShortDescriptionSyncDirectionDescription') ?>
trans('ECommerceProductWeightSyncDirection') ?> - selectarray('ecommerce_product_weight_synch_direction', $sync_direction_array, $ecommerceProductWeightSynchDirection); - ?> - trans('ECommerceProductWeightSyncDirectionDescription') ?>
trans('ECommerceProductWeightUnits') ?> - select_measuring_units("ecommerce_product_weight_units", "weight", $ecommerceProductWeightUnits); - } else { - print $formproduct->selectMeasuringUnits("ecommerce_product_weight_units", "weight", $ecommerceProductWeightUnits, 0, 2); - } - ?> - trans('ECommerceProductWeightUnitsDescription') ?>
trans('ECommerceProductDimensionSyncDirection') ?> - selectarray('ecommerce_product_dimension_synch_direction', $sync_direction_array, $ecommerceProductDimensionSynchDirection); - ?> - trans('ECommerceProductDimensionSyncDirectionDescription') ?>
trans('ECommerceProductDimensionUnits') ?> - select_measuring_units("ecommerce_product_dimension_units", "size", $ecommerceProductDimensionUnits); - } else { - print $formproduct->selectMeasuringUnits("ecommerce_product_dimension_units", "size", $ecommerceProductDimensionUnits, 0, 2); - } - ?> - trans('ECommerceProductDimensionUnitsDescription') ?>
trans('ECommerceProductTaxSyncDirection') ?> - selectarray('ecommerce_product_tax_synch_direction', $sync_direction_array, $ecommerceProductTaxSynchDirection); - ?> - trans('ECommerceProductTaxSyncDirectionDescription') ?>
trans('ECommerceProductStatusSyncDirection') ?> - selectarray('ecommerce_product_status_synch_direction', $sync_direction_array, $ecommerceProductStatusSynchDirection); - ?> - trans('ECommerceProductStatusSyncDirectionDescription') ?>
trans('ECommerceWoocommerceProductVariationMode') ?> - $langs->trans('ECommerceWoocommerceProductVariationOneToOne'), 'all_to_one'=>$langs->trans('ECommerceWoocommerceProductVariationAllToOne')); - print $form->selectarray('ecommerce_product_variation_mode', $array, $ecommerceProductVariationMode); - ?> - trans('ECommerceWoocommerceProductVariationModeDescription') ?>
- -accounting->enabled)) { - print_titre($langs->trans("MenuDefaultAccounts")); -?> - - '; - } else { - print ''; - // Param - $label = $langs->trans('ECOMMERCE_' . strtoupper($key)); - print ''; - // Value - print ''; - print ''; - } - } - ?> -
' . $langs->trans($reg[1]) . '
' . $label . ''; // Do not force class=right, or it align also the content of the select box - print $formaccounting->select_account($ecommerceDefaultAccount[$key], $key, 1, '', 1, 1); - $const_name = strtoupper($key); - print ' ( ' . $langs->trans('DefaultValue') . ' : ' . (empty($conf->global->$const_name) || $conf->global->$const_name == -1 ? $langs->trans('NotDefined') : $conf->global->$const_name) . ' )'; - print '
- - - - - - -
-
-trans("ECommerceOAuthWordpressSetup", $ecommerceOAuthWordpressOAuthSetupUri)); -?> - - - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - - > - - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans("ECommerceSiteOAuthRedirectUri"); ?>trans('ECommerceSiteOAuthRedirectUriDescription') ?>
trans("ECommerceSiteOAuthId"); ?>trans('ECommerceSiteOAuthIdDescription') ?>
trans("ECommerceSiteOAuthSecret"); ?>trans('ECommerceSiteOAuthSecretDescription') ?>
trans("IsTokenGenerated"); ?>trans("HasAccessToken") : $langs->trans("NoAccessToken")); ?> -' . $langs->trans('DeleteAccess') . '

'; - } - // Request remote token - print '' . $langs->trans('RequestAccess') . '

'; - // Check remote access - if ($ecommerceOAuthCheckTokenUri) { - print $langs->trans("ECommerceOAuthCheckToken", $ecommerceOAuthCheckTokenUri); - } -?> -
trans("Token"); ?>getAccessToken() : ''); ?>
trans("TOKEN_REFRESH"); ?>
trans("TOKEN_EXPIRED"); ?>
trans("TOKEN_EXPIRE_AT"); ?>
-
- - - - -
-trans("ECommerceRealTimeSynchroDolibarrToECommerceSetup")); -?> - - - - - - - -societe->enabled) { - $var = !$var; -?> - > - - - - - - > - - - - - -product->enabled) { - $var = !$var; -?> - > - - - - - -commande->enabled && (!isset($ecommerceOrderActions['create_order']) || !empty($ecommerceOrderActions['create_order']))) { - $var = !$var; -?> - > - - - - - -
trans('Parameter') ?>trans('Enabled') ?>trans('Description') ?>
trans('ECommerceThirdParty') ?>>trans('ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription') ?>
trans('ECommerceContact') ?>>trans('ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription') ?>
trans('ECommerceProduct') ?>>trans('ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription') ?>
trans('ECommerceOrder') ?>>trans('ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription') ?>
- -stock->enabled) -{ - $var=!$var; -?> -
-trans("StockSyncSetup")); -?> - - - - - - - - > - - - - - - > - - - - - - > - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans('ECommerceValidOrderWarehouse') ?> - selectWarehouses($ecommerceOrderActions['valid_order_fk_warehouse'], 'valid_order_fk_warehouse', 0, 1) ?> - trans('ECommerceValidOrderWarehouseDescription') ?>
trans('ECommerceStockSyncDirection') ?> - $langs->trans('None'), 'ecommerce2dolibarr'=>$langs->trans('ECommerceToDolibarr'), 'dolibarr2ecommerce'=>$langs->trans('DolibarrToECommerce')); - print $form->selectarray('ecommerce_stock_sync_direction', $array, $ecommerceStockSyncDirection); - ?> - trans('ECommerceStockSyncDirectionDescription') ?>
trans('ECommerceStockProduct') ?> - multiselectWarehouses($ecommerceFkWarehouseToECommerce, 'ecommerce_fk_warehouse_to_ecommerce') ?> - selectWarehouses($ecommerceFkWarehouse, 'ecommerce_fk_warehouse', 0, 1) ?> - trans('ECommerceStockProductDescription', $langs->transnoentitiesnoconv('ECommerceStockSyncDirection')) ?>
- - - - -trans("ECommerceOrdersSyncSetup")); - ?> - - - - - - - > - - - - - > - - - - - > - - - - -
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans('ECommerceWoocommerceOrderFirstDateForECommerceToDolibarr') ?> - select_date($ecommerceOrderFirstDateForECommerceToDolibarr !== '' ? $ecommerceOrderFirstDateForECommerceToDolibarr : -1, 'ecommerce_order_first_date_etod'); - ?> - trans('ECommerceWoocommerceOrderFirstDateForECommerceToDolibarrDescription') ?>
trans('ECommerceWoocommerceOrderMetaDataInProductLineToDescriptionForECommerceToDolibarr') ?>>trans('ECommerceWoocommerceOrderMetaDataInProductLineToDescriptionForECommerceToDolibarrDescription') ?>
trans('ECommerceWoocommerceOrderFilterMetaDataInProductLineToDescriptionForECommerceToDolibarr') ?> - $langs->trans('ECommerceExclude'), 'include'=>$langs->trans('ECommerceInclude')); - print $form->selectarray('ecommerce_order_filter_mode_metadata_product_lines_to_description_etod', $array, $ecommerceOrderFilterModeMetadataProductLinesToDescriptionEtod); - ?> - trans('ECommerceWoocommerceOrderFilterMetaDataInProductLineToDescriptionForECommerceToDolibarrDescription') ?>
- -
-trans("ECommerceOrderStatusSetup")); -?> - - - - - - - - - - - - $value) { - $var = !$var; -?> - > - - - - - - - - - - - - - - - - - - - > - - - - - $value) { - $var = !$var; -?> - > - - - - - -
trans('ECommerceToDolibarr') ?>
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
- $value2) { - $array_list[$key2] = $value2['label']; - } - print $form->selectarray('order_status_etod_'.$key, $array_list, $value['selected']); - print ' '.$langs->trans('Billed').' ? : '; - ?> - > - trans('ECommerceSynchronize').' ? : '; - ?> - > - trans('ECommerceOrderStatusSetupDescription') ?>
trans('DolibarrToECommerce') ?>
trans('Parameter') ?>trans('Value') ?>trans('Description') ?>
trans('ECommerceOrderStatusDtoECheckLvlStatus') ?>selectyesno('order_status_dtoe_check_lvl_status', $conf->global->ECOMMERCENG_WOOCOMMERCE_ORDER_STATUS_LVL_CHECK) ?>trans('ECommerceOrderStatusDtoECheckLvlStatusDescription') ?>
- $value2) { - $array_list[$key2] = $value2['label']; - } - print $form->selectarray('order_status_dtoe_'.substr($key, 1), $array_list, $value['selected']) - ?> - trans('ECommerceOrderStatusSetupDescription') ?>
- - - - - - - -
- trans("ECommercengWoocommerceProductExtrafieldsCorrespondenceAttribute")); - ?> - - - - - - - - - - - - $label) { - $var = !$var; - $options_saved = $ecommerceProductExtrafieldsCorrespondenceAttributes[$key]; - ?> - - - - - - - -
trans('ExtraFields') . ' : ' . $langs->trans('Products') ?>trans('Enabled') ?>
trans('ExtraFields') ?>trans('ECommercengWoocommerceProductAttribute') ?>trans('Description') ?>
- selectarray('attribute_ef_crp_value_'.$key, $attributes_array, $value, 1, 0, 0, '', 0, 0, empty($options_saved['activated']) ? 1 : 0, '', 'ef_crp_value minwidth300'); - ?> - trans('ECommercengWoocommerceProductExtrafieldsCorrespondenceAttributeSetupDescription', $key) ?> /> -
- -
- trans("ECommercengWoocommerceExtrafieldsCorrespondence")); - ?> - - - - - - - - - - - - $label) { - $var = !$var; - $options_saved = $ecommerceExtrafieldsCorrespondence[$product_table_element][$key]; - ?> - > - - - - - - -
trans('ExtraFields') . ' : ' . $langs->trans('Products') ?>trans('Enabled') ?>
trans('Label') ?>trans('Value') ?>trans('Description') ?>
- /> - trans('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) ?> /> -
- - - - - - - - - - - - - $label) { - $var = !$var; - $options_saved = $ecommerceExtrafieldsCorrespondence[$thirdparty_table_element][$key]; - ?> - > - - - - - - -
trans('ExtraFields') . ' : ' . $langs->trans('ThirdParty') ?>trans('Enabled') ?>
trans('Label') ?>trans('Value') ?>trans('Description') ?>
- /> - trans('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) ?> /> -
- - - - - - - - - - - - - $label) { - $var = !$var; - $options_saved = $ecommerceExtrafieldsCorrespondence[$order_table_element][$key]; - ?> - > - - - - - - -
trans('ExtraFields') . ' : ' . $langs->trans('Orders') ?>trans('Enabled') ?>
trans('Label') ?>trans('Value') ?>trans('Description') ?>
- /> - trans('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) ?> /> -
- - - - - - - - - - - - - $label) { - $var = !$var; - $options_saved = $ecommerceExtrafieldsCorrespondence[$order_line_table_element][$key]; - ?> - > - - - - - - -
trans('ExtraFieldsLines') . ' : ' . $langs->trans('Orders') ?>trans('Enabled') ?>
trans('Label') ?>trans('Value') ?>trans('Description') ?>
- /> - trans('ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription', $key) ?> /> -
- -
- trans("ECommercePaymentGatewaysCorrespondence")); - ?> - - - - - - - - - - - - - - - - - - fetchAllEMailTemplate($type_template, $user, $langs); - if ($result < 0) { - setEventMessages($formmail->error, $formmail->errors, 'errors'); - } - foreach ($formmail->lines_model as $line) { - if (preg_match('/\((.*)\)/', $line->label, $reg)) { - $modelmail_array[$line->id] = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ - } else { - $modelmail_array[$line->id] = $line->label; - } - if ($line->lang) $modelmail_array[$line->id] .= ' (' . $line->lang . ')'; - if ($line->private) $modelmail_array[$line->id] .= ' - ' . $langs->trans("Private"); - } - - foreach ($ecommercePaymentGateways as $key => $infos) { - $var = !$var; - ?> - > - - - - banque->enabled) { - ?> - - - - - - - - - - - - -
trans('ECommercePaymentGatewayLabel') ?>trans('PaymentMode') ?>trans('BankAccount') ?>trans('ECommerceCreateAssociatePaymentForInvoice') ?>trans('ECommerceSelectMailModelForSendInvoice') ?>trans('Supplier') ?>trans('ECommerceProductForFee') ?>trans('ECommerceCreateAssociatePaymentForSupplierInvoice') ?>
select_types_paiements($infos['payment_mode_id'], 'payment_mode_id_' . $key) ?>select_comptes($infos['bank_account_id'], 'bank_account_id_' . $key, 0, '', 1) ?>> - 0) { - print $form->selectarray('mail_model_for_send_invoice_' . $key, $modelmail_array, $infos['mail_model_for_send_invoice'], 1, 0, 0, '', 0, 0, 0, '', 'minwidth100'); - } else { - print ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. - } - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup') . ' - ' . $langs->transnoentitiesnoconv('EMails')), 1); - } - ?> - select_company($infos['supplier_id'], 'supplier_id_' . $key, 's.fournisseur=1 AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300') ?>select_produits($infos['product_id_for_fee'], 'product_id_for_fee_' . $key, '', $conf->product->limit_size, 0, -1, 2, '', 0, array(), 0, '1', 0, 'maxwidth300') ?>> -
- - -
-
-id) -{ -?> - -type == 2) -{ -?> - ")'>trans('ECommerceWoocommerceUpdateDictAttributes') ?> - ")'>trans('ECommerceWoocommerceUpdateDictTaxClasses') ?> - ")'>trans('ECommerceUpdatePaymentGateways') ?> - - ")'>trans('Delete') ?> - - - -
-
- -'.$succes.'

'; -?> -
diff --git a/admin/tpl/selectsite.tpl.php b/admin/tpl/selectsite.tpl.php new file mode 100644 index 0000000..6062f9f --- /dev/null +++ b/admin/tpl/selectsite.tpl.php @@ -0,0 +1,57 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', 1); +} + +// Protection to avoid direct call of template +if (empty($conf) || !is_object($conf)) { + print "Error, template page can't be called as URL"; + exit; +} + +/** + * Globals + * + * @global int $id + * @global eCommerceSite $object + * @global string $self_url + */ + +print '
'; +print ''; +print ''; +print $langs->trans('ECommerceNgSelectSite') . ' : '; +$sites = $object->listSites(); +$sites_list = array( + 0 => $langs->trans('ECommerceAddNewSite') +); +foreach ($sites as $site) { + $sites_list[$site['id']] = $site['name']; +} +print $form->selectarray('site_id', $sites_list, $id, 0, 0, 0, '', 0, 0, 0, '', 'minwidth300'); +print '
'; +print << +SCRIPT; diff --git a/class/business/eCommerceSynchro.class.php b/class/business/eCommerceSynchro.class.php index 7bb660d..547e6bc 100755 --- a/class/business/eCommerceSynchro.class.php +++ b/class/business/eCommerceSynchro.class.php @@ -607,67 +607,61 @@ public function getNbFactureInDolibarrLinkedToE() * @param boolean $force Force analysis of list, even if array list $this->categoryToUpdate is already defined */ public function getCategoriesToUpdate($force = false) - { - try { - if (!isset($this->categoryToUpdate) || $force == true) - { - $this->categoryToUpdate = array(); - - // get a magento category tree in a one-leveled array - $tmp=$this->eCommerceRemoteAccess->getRemoteCategoryTree(); - if (is_array($tmp)) - { - $resanswer = array(); - eCommerceCategory::cuttingCategoryTreeFromMagentoToDolibarrNew($tmp, $resanswer); - - $this->initECommerceCategory(); // Initialise 2 properties eCommerceCategory and eCommerceMotherCategory + { + if (!isset($this->categoryToUpdate) || $force == true) { + $this->categoryToUpdate = array(); + + // get a magento category tree in a one-leveled array + $tmp = $this->eCommerceRemoteAccess->getRemoteCategoryTree(); + if (is_array($tmp)) { + $resanswer = array(); + eCommerceCategory::cuttingCategoryTreeFromMagentoToDolibarrNew($tmp, $resanswer); + + $this->initECommerceCategory(); // Initialise 2 properties eCommerceCategory and eCommerceMotherCategory + + // $resanswer is array with all categories + // We must loop on each categorie. + foreach ($resanswer as $remoteCatToCheck) // Check update for each entry into $resanswer -> $remoteCatToCheck = array('category_id'=>, 'parent_id'=>...) + { + // Test if category is disabled or not + if (isset($remoteCatToCheck['is_active']) && empty($remoteCatToCheck['is_active'])) // We keep because children may not be disabled. + { + dol_syslog("Category remote_id=" . $remoteCatToCheck['category_id'] . ", category is disabled."); + } + //else + //{ + if (!isset($remoteCatToCheck['updated_at'])) { // The api that returns list of category did not return the updated_at property + // This is very long if there is a lot of categories because we make a WS call to get the 'updated_at' info at each loop pass. + dol_syslog("Process category remote_id=" . $remoteCatToCheck['category_id'] . ", updated_at unknow."); - // $resanswer is array with all categories - // We must loop on each categorie. - foreach ($resanswer as $remoteCatToCheck) // Check update for each entry into $resanswer -> $remoteCatToCheck = array('category_id'=>, 'parent_id'=>...) - { - // Test if category is disabled or not - if (isset($remoteCatToCheck['is_active']) && empty($remoteCatToCheck['is_active'])) // We keep because children may not be disabled. - { - dol_syslog("Category remote_id=".$remoteCatToCheck['category_id'].", category is disabled."); - } - //else - //{ - if (! isset($remoteCatToCheck['updated_at'])) { // The api that returns list of category did not return the updated_at property - // This is very long if there is a lot of categories because we make a WS call to get the 'updated_at' info at each loop pass. - dol_syslog("Process category remote_id=".$remoteCatToCheck['category_id'].", updated_at unknow."); + // Complete info of $remoteCatToCheck['category_id'] + $tmp = $this->eCommerceRemoteAccess->getCategoryData($remoteCatToCheck['category_id']); // This make a SOAP call - // Complete info of $remoteCatToCheck['category_id'] - $tmp=$this->eCommerceRemoteAccess->getCategoryData($remoteCatToCheck['category_id']); // This make a SOAP call + $remoteCatToCheck['updated_at'] = $tmp['updated_at']; // Complete data we are missing + } else { + dol_syslog("Process category remote_id=" . $remoteCatToCheck['category_id'] . ", updated_at is defined to " . $remoteCatToCheck['updated_at']); + } - $remoteCatToCheck['updated_at']=$tmp['updated_at']; // Complete data we are missing - } - else - { - dol_syslog("Process category remote_id=".$remoteCatToCheck['category_id'].", updated_at is defined to ".$remoteCatToCheck['updated_at']); - } + // If the category was updated before the max limit date this->toDate + if (strtotime($remoteCatToCheck['updated_at']) <= $this->toDate) { + // Check into link table ecommerce_category if record is older (so if has been modified on magento or not) + if ($this->eCommerceCategory->checkForUpdate($this->eCommerceSite->id, $this->toDate, $remoteCatToCheck)) // compare date in remoteCatToCheck and date in sync table. $this->toDate is not used. + $this->categoryToUpdate[] = $remoteCatToCheck; + } + //} + } - // If the category was updated before the max limit date this->toDate - if (strtotime($remoteCatToCheck['updated_at']) <= $this->toDate) - { - // Check into link table ecommerce_category if record is older (so if has been modified on magento or not) - if ($this->eCommerceCategory->checkForUpdate($this->eCommerceSite->id, $this->toDate, $remoteCatToCheck)) // compare date in remoteCatToCheck and date in sync table. $this->toDate is not used. - $this->categoryToUpdate[] = $remoteCatToCheck; - } - //} - } + //var_dump($this->categoryToUpdate);exit; + dol_syslog("Now tree are in an array ordered by hierarchy. Nb of record = " . count($this->categoryToUpdate)); + return $this->categoryToUpdate; + } else { + $this->errors[] = $this->langs->trans('ECommerceErrorGetCategoryToUpdate'); + $this->errors[] = $this->eCommerceRemoteAccess->errorsToString(); + } + } - //var_dump($this->categoryToUpdate);exit; - dol_syslog("Now tree are in an array ordered by hierarchy. Nb of record = ".count($this->categoryToUpdate)); - return $this->categoryToUpdate; - } - } - } catch (Exception $e) { - dol_syslog($e->getMessage(), LOG_ERR); - $this->errors[] = $this->langs->trans('ECommerceErrorGetCategoryToUpdate'); - } - return false; - } + return false; + } /** * Get modified product since the last update @@ -1973,7 +1967,7 @@ public function synchDtoECategory($toNb=0) */ public function synchDtoEProduct($toNb=0) { - global $langs, $user; + global $conf, $langs, $user; $langs->load('ecommerceng@ecommerceng'); $error = 0; @@ -2033,6 +2027,7 @@ public function synchDtoEProduct($toNb=0) $this->eCommerceProduct->fk_site = $this->eCommerceSite->id; $this->eCommerceProduct->fk_product = $product_static->id; $this->eCommerceProduct->last_update = dol_print_date($now, '%Y-%m-%d %H:%M:%S'); + if ($this->eCommerceSite->stock_sync_direction == 'dolibarr2ecommerce') $this->eCommerceProduct->last_update_stock = $this->eCommerceProduct->last_update; if ($this->eCommerceProduct->create($user) < 0) { $error++; $error_msg = $langs->trans('ECommerceCreateRemoteProductLink', $product_static->id, $this->eCommerceSite->name, $this->eCommerceProduct->error); @@ -2053,6 +2048,7 @@ public function synchDtoEProduct($toNb=0) $now = dol_now(); $this->eCommerceProduct->fetchByRemoteId($obj->remote_id, $this->eCommerceSite->id); $this->eCommerceProduct->last_update = dol_print_date($now, '%Y-%m-%d %H:%M:%S'); + if ($this->eCommerceSite->stock_sync_direction == 'dolibarr2ecommerce') $this->eCommerceProduct->last_update_stock = $this->eCommerceProduct->last_update; if ($this->eCommerceProduct->update($user) < 0) { $error++; $error_msg = $langs->trans('ECommerceUpdateRemoteProductLink', $product_static->id, $this->eCommerceSite->name, $this->eCommerceProduct->error); @@ -2516,7 +2512,27 @@ function getContactIdFromInfos($contact) */ public function getAllPaymentGateways() { - return $this->eCommerceRemoteAccess->getAllPaymentGateways(); + $result = $this->eCommerceRemoteAccess->getAllPaymentGateways(); + if (!$result) { + $this->error = $this->eCommerceRemoteAccess->error; + $this->errors = $this->eCommerceRemoteAccess->errors; + } + return $result; + } + + /** + * Get all remote warehouses + * + * @return array|false List of payment gateways or false if error + */ + public function getAllRemoteWarehouses() + { + $result = $this->eCommerceRemoteAccess->getAllRemoteWarehouses(); + if (!$result) { + $this->error = $this->eCommerceRemoteAccess->error; + $this->errors = $this->eCommerceRemoteAccess->errors; + } + return $result; } /** @@ -2526,38 +2542,14 @@ public function getAllPaymentGateways() */ public function getAllWebHooks() { - return $this->eCommerceRemoteAccess->getAllWebHooks(); + $result = $this->eCommerceRemoteAccess->getAllWebHooks(); + if (!$result) { + $this->error = $this->eCommerceRemoteAccess->error; + $this->errors = $this->eCommerceRemoteAccess->errors; + } + return $result; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Synchronize order to update from raw data * @@ -3567,37 +3559,66 @@ public function synchronizeProduct($product_data, $object_origin = null) $this->eCommerceSite->stock_sync_direction == 'ecommerce2dolibarr' && !empty($product->array_options["options_ecommerceng_wc_manage_stock_{$this->eCommerceSite->id}_{$conf->entity}"]) && empty($product->array_options["options_ecommerceng_wc_dont_update_stock_{$this->eCommerceSite->id}_{$conf->entity}"]) ) { - if (empty($this->eCommerceSite->fk_warehouse)) { - $error++; - $this->errors[] = 'SetupOfWarehouseNotDefinedForThisSite'; - } else { - $product->load_stock(); - $current_stock = isset($product->stock_warehouse[$this->eCommerceSite->fk_warehouse]->real) ? $product->stock_warehouse[$this->eCommerceSite->fk_warehouse]->real : 0; - - $new_stock = price2num($product_data['stock_qty'] - $current_stock); - if ($new_stock != 0) { - // Update/init stock - include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; - $movement = new MouvementStock($this->db); - $movement->context['fromsyncofecommerceid'] = $this->eCommerceSite->id; - - if (isset($object_origin->element) && isset($object_origin->id) && $object_origin->id > 0) { - $movement->origin = $object_origin; - } - $lot = $product->status_batch ? '000000' : null; - if ($new_stock < 0) { - $result = $movement->livraison($this->user, $product->id, $this->eCommerceSite->fk_warehouse, abs($new_stock), 0, $langs->trans($new_product ? 'ECommerceStockInitFromWooSync' : 'ECommerceStockUpdateFromWooSync'), '', '', $lot); - } else { - $result = $movement->reception($this->user, $product->id, $this->eCommerceSite->fk_warehouse, $new_stock, 0, $langs->trans($new_product ? 'ECommerceStockInitFromWooSync' : 'ECommerceStockUpdateFromWooSync'), '', '', $lot); - } - if ($result <= 0) { - $this->errors[] = $this->langs->trans('ECommerceErrorUpdateProductStock'); - if (!empty($movement->error)) $this->errors[] = $movement->error; - $this->errors = array_merge($this->errors, $movement->errors); - $error++; - } - } - } + $product->load_stock(); + + $new_warehouses_stock = array(); + if (!empty($this->eCommerceSite->parameters['enable_warehouse_plugin_sl_support'])) { + dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php'); + $eCommerceRemoteWarehouses = new eCommerceRemoteWarehouses($this->db); + $remote_warehouses = $eCommerceRemoteWarehouses->get_all($this->eCommerceSite->id); + if (!is_array($remote_warehouses)) { + $error++; + $this->errors[] = $eCommerceRemoteWarehouses->errorsToString(); + } + + if (!$error && !empty($product_data['stock_by_warehouse'])) { + foreach ($product_data['stock_by_warehouse'] as $remote_warehouse_code => $stock) { + $local_warehouse_id = isset($remote_warehouses[$remote_warehouse_code]['warehouse_id']) && $remote_warehouses[$remote_warehouse_code]['warehouse_id'] > 0 ? $remote_warehouses[$remote_warehouse_code]['warehouse_id'] : 0; + if (empty($local_warehouse_id)) { + $error++; + $this->errors[] = 'Error - Unknown remote warehouse : ' . $remote_warehouse_code; + } else { + $current_stock = isset($product->stock_warehouse[$local_warehouse_id]->real) ? $product->stock_warehouse[$local_warehouse_id]->real : 0; + $new_warehouses_stock[$this->eCommerceSite->fk_warehouse] = price2num($stock - $current_stock); + } + } + } + } else { + if ($this->eCommerceSite->fk_warehouse > 0) { + $current_stock = isset($product->stock_warehouse[$this->eCommerceSite->fk_warehouse]->real) ? $product->stock_warehouse[$this->eCommerceSite->fk_warehouse]->real : 0; + $new_warehouses_stock[$this->eCommerceSite->fk_warehouse] = price2num($product_data['stock_qty'] - $current_stock); + } else { + $error++; + $this->errors[] = 'SetupOfWarehouseNotDefinedForThisSite'; + } + } + + if (!$error) { + foreach ($new_warehouses_stock as $warehouse_id => $new_stock_delta) { + if (empty($new_stock_delta)) continue; + + // Update/init stock + include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; + $movement = new MouvementStock($this->db); + $movement->context['fromsyncofecommerceid'] = $this->eCommerceSite->id; + + if (isset($object_origin->element) && isset($object_origin->id) && $object_origin->id > 0) { + $movement->origin = $object_origin; + } + $lot = $product->status_batch ? '000000' : null; + if ($new_stock_delta < 0) { + $result = $movement->livraison($this->user, $product->id, $warehouse_id, abs($new_stock_delta), 0, $langs->trans($new_product ? 'ECommerceStockInitFromWooSync' : 'ECommerceStockUpdateFromWooSync'), '', '', $lot); + } else { + $result = $movement->reception($this->user, $product->id, $warehouse_id, $new_stock_delta, 0, $langs->trans($new_product ? 'ECommerceStockInitFromWooSync' : 'ECommerceStockUpdateFromWooSync'), '', '', $lot); + } + if ($result <= 0) { + $this->errors[] = $this->langs->trans('ECommerceErrorUpdateProductStock'); + if (!empty($movement->error)) $this->errors[] = $movement->error; + $this->errors = array_merge($this->errors, $movement->errors); + $error++; + } + } + } } // Set update date of the product with last update date from site @@ -3794,6 +3815,7 @@ public function synchronizeProduct($product_data, $object_origin = null) //-------------------------------------------- if (!$error && !empty($product_data['remote_id'])) { $this->eCommerceProduct->last_update = $product_data['last_update']; + if ($this->eCommerceSite->stock_sync_direction == 'ecommerce2dolibarr') $this->eCommerceProduct->last_update_stock = $product_data['last_update']; $this->eCommerceProduct->fk_product = $product->id > 0 ? $product->id : 0; $this->eCommerceProduct->remote_id = $product_data['remote_id']; @@ -5752,7 +5774,7 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ } // Get warehouse ID - $warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_order_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_order_fk_warehouse'] : 0; + $warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] : 0; if ($isDepositType) { $save_WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER = $conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER; @@ -5927,9 +5949,12 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ } } - // Validate invoice + // Validate supplier invoice if (!$error) { - $result = $supplier_invoice->validate($this->user); + // Get warehouse ID + $warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] : 0; + + $result = $supplier_invoice->validate($this->user, '', $warehouse_id); if ($result < 0) { $this->errors[] = $this->langs->trans('ECommerceErrorSupplierInvoiceValidate'); if (!empty($supplier_invoice->error)) $this->errors[] = $supplier_invoice->error; diff --git a/class/business/eCommerceUtils.class.php b/class/business/eCommerceUtils.class.php index b27806a..d7dea6d 100755 --- a/class/business/eCommerceUtils.class.php +++ b/class/business/eCommerceUtils.class.php @@ -35,7 +35,9 @@ class eCommerceUtils public $langs; public $user; - //Data access + /** + * @var DoliDB Database handler + */ public $db; /** @@ -47,10 +49,7 @@ class eCommerceUtils /** * Constructor * - * @param Database $db Database handler - * @param eCommerceSite $site Object eCommerceSite - * @param datetime $toDate Ending date to synch all data modified before this date (null by default = until now) - * @param int $toNb Max nb of record to count or synch (Used only for synch, not for count for the moment !) + * @param DoliDB $db Database handler */ function __construct($db) { @@ -61,6 +60,120 @@ function __construct($db) $this->db = $db; } + /** + * Synchronize all new movement stocks from dolibarr to site (cron) + * + * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) + */ + public function cronSynchronizeStocksToSite() + { + global $conf, $user, $langs; + + $langs->load('ecommerceng@ecommerceng'); + $error = 0; + $output = ''; + + $stopwatch_id = eCommerceUtils::startAndLogStopwatch(__METHOD__); + + $sql = "SELECT sm.fk_product, MAX(sm.datem) AS update_date, GROUP_CONCAT(CONCAT(ep.rowid, ':', ep.fk_site, ':', ep.remote_id) SEPARATOR ';') AS links"; + $sql .= " FROM " . MAIN_DB_PREFIX . "stock_mouvement AS sm"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "ecommerce_product AS ep ON ep.fk_product = sm.fk_product"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "ecommerce_site AS es ON es.rowid = ep.fk_site"; + $sql .= " WHERE es.entity IN (" . getEntity('ecommerceng') . ")"; + $sql .= " AND (ep.last_update_stock IS NULL OR sm.datem > ep.last_update_stock)"; + $sql .= " GROUP BY sm.fk_product"; + + $resql = $this->db->query($sql); + if (!$resql) { + $output .= '' . $langs->trans('Error') . ': ' . $this->db->lasterror() . '' . "
"; + $error++; + } elseif ($this->db->num_rows($resql) > 0) { + $eCommerceSite = new eCommerceSite($this->db); + $sites = $eCommerceSite->listSites('object'); + + while ($obj = $this->db->fetch_object($resql)) { + $update_date = $obj->update_date; + $links = explode(';', $obj->links); + + $product = new Product($this->db); + $product->fetch($obj->fk_product); + + foreach ($links as $link) { + $sub_error = 0; + $link_info = explode(':', $link); + $link_id = $link_info[0]; + $site_id = $link_info[1]; + $remote_id = $link_info[2]; + + if (isset($sites[$site_id])) { + $site = $sites[$site_id]; + + if ($site->stock_sync_direction == 'dolibarr2ecommerce') { + try { + // Connect to site + $eCommerceSynchro = new eCommerceSynchro($this->db, $site); + $eCommerceSynchro->connect(); + if (count($eCommerceSynchro->errors)) { + $output .= '' . $langs->trans('Error') . ' - Connect to site ' . $site->name . ' : ' . $eCommerceSynchro->errorsToString() . '' . "
"; + $sub_error++; + } + + if (!$sub_error) { + $result = $eCommerceSynchro->eCommerceRemoteAccess->updateRemoteStockProduct($remote_id, $product); + if (!$result) { + $output .= '' . $langs->trans('Error') . ' - Update stock of ' . $product->ref . ' to site ' . $site->name . ' : ' . $eCommerceSynchro->eCommerceRemoteAccess->errorsToString() . '' . "
"; + $sub_error++; + } + } + } catch (Exception $e) { + $output .= '' . $langs->trans('Error') . ' - Update stock of ' . $product->ref . ' to site ' . $site->name . ' : ' . $e->getMessage() . '' . "
"; + $sub_error++; + } + + if (!$sub_error) { + // Update link + $eCommerceProduct = new eCommerceProduct($this->db); + $result = $eCommerceProduct->fetch($link_id); + if ($result > 0) { + $eCommerceProduct->last_update_stock = $update_date; + $result = $eCommerceProduct->update($user); + } + if ($result < 0) { + $output .= '' . $langs->trans('ECommerceUpdateRemoteProductLink', $product->id, $site->name) . ': ' . $eCommerceProduct->error . '' . "
"; + $sub_error++; + } + } + } + } else { + $output .= '' . $langs->trans('Error') . ': Site not found (ID: ' . $site_id . ')' . "
"; + $sub_error++; + } + + if ($sub_error) $error++; + } + } + $this->db->free($resql); + } + + eCommerceUtils::stopAndLogStopwatch($stopwatch_id); + + if (!$error) { + $output .= $langs->trans('ECommerceSynchronizeStocksToSiteSuccess'); + $this->error = ""; + $this->errors = array(); + $this->output = $output; + $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => ""); + + return 0; + } else { + $output = $langs->trans('ECommerceErrorWhenSynchronizeStocksToSite') . ":
" . $output; + dol_syslog(__METHOD__ . " Error: " . $output, LOG_ERR); + + $this->error = $output; + $this->errors = array(); + return -1; + } + } /** * Sync all diff --git a/class/client/eCommerceClientApi.class.php b/class/client/eCommerceClientApi.class.php new file mode 100644 index 0000000..cf5165f --- /dev/null +++ b/class/client/eCommerceClientApi.class.php @@ -0,0 +1,270 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/class/business/eCommerceClientApi.class.php + * \ingroup ecommerceng + * \brief This file for managing Client API + */ + +dol_include_once('/ecommerceng/class/business/eCommerceUtils.class.php'); +if (!class_exists('ComposerAutoloaderInite5f8183b6b110d1bbf5388358e7ebc94', false)) dol_include_once('/ecommerceng/vendor/autoload.php'); +use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; + +/** + * Class to manage Client API + */ +class eCommerceClientApi +{ + /** + * @var DoliDB Database handler. + */ + public $db; + /** + * @var string Error + */ + public $error = ''; + /** + * @var array Errors + */ + public $errors = array(); + + /** + * @var bool Debug mode + */ + public $debug_mode = false; + + /** + * @var Client Client REST handler + */ + public $client; + /** + * @var string API URL + */ + public $api_url; + /** + * @var string API URL prefix for requesting the API + */ + public $api_url_prefix; + + const METHOD_GET = 'GET'; + const METHOD_HEAD = 'HEAD'; + const METHOD_DELETE = 'DELETE'; + const METHOD_PUT = 'PUT'; + const METHOD_PATCH = 'PATCH'; + const METHOD_POST = 'POST'; + + + /** + * Constructor + * + * @param DoliDB $_db Database handler + * @param bool $debug_mode Debug mode + */ + public function __construct($_db, $debug_mode = false) + { + global $db; + $this->db = is_object($_db) ? $_db : $db; + $this->debug_mode = !empty($debug_mode); + } + + /** + * Send to the Api + * + * @param string $method Method request + * @param string $url Url request + * @param array $options Options request + * @param bool $without_prefix Without api url prefix + * @param int $status_code Status code returned + * @param int $error_info Error info returned + * @return array null if KO otherwise result data + */ + public function sendToApi($method, $url, $options = [], $without_prefix = false, &$status_code = null, &$error_info = null) + { + dol_syslog(__METHOD__ . " - method=" . $method . " url=" . $url . " options=" . json_encode($options) . " without_prefix=" . $without_prefix, LOG_NOTICE); + global $conf, $langs; + + $stopwatch_id = -1; + try { + if (isset($status_code)) $status_code = 0; + $request_url = rtrim($this->api_url, '/') . '/' . ($without_prefix ? '' : trim($this->api_url_prefix, '/') . '/') . ltrim($url, '/'); + + // Disabled send data to site + if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_DELETE, self::METHOD_PATCH]) && !empty($conf->global->ECOMMERCE_DISABLED_SEND_DATA_TO_API)) { + return []; + } + + $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - {$method} {$request_url}"); + switch ($method) { + case self::METHOD_HEAD: + $response = $this->client->head($request_url, $options); + break; + case self::METHOD_GET: + $response = $this->client->get($request_url, $options); + break; + case self::METHOD_POST: + $response = $this->client->post($request_url, $options); + break; + case self::METHOD_PUT: + $response = $this->client->put($request_url, $options); + break; + case self::METHOD_DELETE: + $response = $this->client->delete($request_url, $options); + break; + case self::METHOD_PATCH: + $response = $this->client->patch($request_url, $options); + break; + default: + $this->errors[] = 'Bad REST Method'; + dol_syslog(__METHOD__ . " Errors: " . $this->errorsToString(), LOG_ERR); + return null; + } + eCommerceUtils::stopAndLogStopwatch($stopwatch_id); + + if (isset($status_code)) $status_code = $response->getStatusCode(); + $request_data = trim($response->getBody()->getContents()); + $msg_error = "Method: " . $method . " Url: " . $request_url . " - Options: " . json_encode($options) . " - Data: " . $request_data; + dol_syslog(__METHOD__ . " - " . $msg_error, LOG_DEBUG); + + $data = json_decode($request_data, true); + if (!is_array($data)) { + if ($this->debug_mode) { + $this->errors[] = $langs->trans('ECommerceErrorBadConvertResult') . ' - ' . $msg_error . ' - Converted data: ' . $data . " - Error: " . json_last_error_msg(); + } else { + $this->errors[] = $langs->trans('ECommerceErrorBadConvertResult') . " - Error: " . json_last_error_msg(); + } + } + return $data; + } catch (RequestException $e) { + eCommerceUtils::stopAndLogStopwatch($stopwatch_id); + + $request = $e->getRequest(); + $response = $e->getResponse(); + + if (isset($response) && isset($status_code)) $status_code = $response->getStatusCode(); + if (isset($response)) $error_info = json_decode(trim($response->getBody()->getContents()), true); + if (empty($error_info)) $error_info = []; + + $errors_details = array(); + if (isset($request)) $errors_details[] = $this->_requestToString($request); + if (isset($response)) $errors_details[] = $this->_responseToString($response); + else $errors_details[] = '
' . dol_nl2br((string)$e) . '
'; + + if ($this->debug_mode) { + $this->errors = array_merge($this->errors, $errors_details); + } else { + if (isset($response)) { + $boby = strip_tags($response->getBody()); + $this->errors[] = '' . $langs->trans('ECommerceResponseCode') . ': ' . $response->getStatusCode() . '
' . + '' . $langs->trans('ECommerceResponseReasonPhrase') . ': ' . $response->getReasonPhrase() . + (!empty($boby) ? '
' . $boby . '' : ''); + } else $this->errors[] = $e->getMessage(); + } + + dol_syslog(__METHOD__ . " Error: " . dol_htmlentitiesbr_decode(implode(', ', $errors_details)), LOG_ERR); + return null; + } catch (Exception $e) { + eCommerceUtils::stopAndLogStopwatch($stopwatch_id); + if ($this->debug_mode) { + $this->errors[] = (string)$e; + } else { + $this->errors[] = $e->getMessage(); + } + + dol_syslog(__METHOD__ . " Error: " . $e, LOG_ERR); + return null; + } + } + + /** + * Format the request to a string + * + * @param RequestInterface $request Request handler + * @return string Formatted string of the request + */ + protected function _requestToString(RequestInterface $request) + { + global $langs; + + $out = ''; + $out .= '' . $langs->trans('ECommerceRequestData') . ':

'; + $out .= '
'; + $out .= '' . $langs->trans('ECommerceRequestProtocolVersion') . ': ' . $request->getProtocolVersion() . '
'; + $out .= '' . $langs->trans('ECommerceRequestUri') . ': ' . $request->getUri() . '
'; + $out .= '' . $langs->trans('ECommerceRequestTarget') . ': ' . $request->getRequestTarget() . '
'; + $out .= '' . $langs->trans('ECommerceRequestMethod') . ': ' . $request->getMethod() . '
'; + $out .= '' . $langs->trans('ECommerceRequestHeaders') . ':
    '; + foreach ($request->getHeaders() as $name => $values) { + $out .= '
  • ' . $name . ': ' . implode(', ', $values) . '
  • '; + } + $out .= '
'; + $out .= '' . $langs->trans('ECommerceRequestBody') . ': '; + $out .= '
' . $request->getBody() . '
'; + $out .= '
'; + return $out; + } + + /** + * Format the response to a string + * + * @param ResponseInterface $response Response handler + * @return string Formatted string of the response + */ + protected function _responseToString(ResponseInterface $response) + { + global $langs; + + $out = ''; + $out .= '' . $langs->trans('ECommerceResponseData') . ':

'; + $out .= '
'; + $out .= '' . $langs->trans('ECommerceResponseProtocolVersion') . ': ' . $response->getProtocolVersion() . '
'; + $out .= '' . $langs->trans('ECommerceResponseCode') . ': ' . $response->getStatusCode() . '
'; + $out .= '' . $langs->trans('ECommerceResponseReasonPhrase') . ': ' . $response->getReasonPhrase() . '
'; + $out .= '' . $langs->trans('ECommerceResponseHeaders') . ':
    '; + foreach ($response->getHeaders() as $name => $values) { + $out .= '
  • ' . $name . ': ' . implode(', ', $values) . '
  • '; + } + $out .= '
'; + $out .= '' . $langs->trans('ECommerceResponseBody') . ': '; + $body = json_decode($response->getBody(), true); + if (is_array($body)) { + $out .= '
    '; + foreach ($body as $name => $values) { + $out .= '
  • ' . $name . ': ' . (is_array($values) || is_object($values) ? json_encode($values) : $values) . '
  • '; + } + $out .= '
'; + } else { + $out .= '
' . strip_tags($response->getBody()) . '
'; + } + $out .= '
'; + return $out; + } + + /** + * Method to output saved errors + * + * @param string $separator Separator between each error + * @return string String with errors + */ + public function errorsToString($separator = ', ') + { + return $this->error . (is_array($this->errors) ? (!empty($this->error) ? $separator : '') . join($separator, $this->errors) : ''); + } +} diff --git a/class/client/eCommerceClientWooCommerceApi.class.php b/class/client/eCommerceClientWooCommerceApi.class.php new file mode 100644 index 0000000..2236a3c --- /dev/null +++ b/class/client/eCommerceClientWooCommerceApi.class.php @@ -0,0 +1,127 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/class/business/eCommerceClientWooCommerceApi.class.php + * \ingroup ecommerceng + * \brief This file for managing Client WooCommerce API + */ + +dol_include_once('/ecommerceng/class/client/eCommerceClientApi.class.php'); +dol_include_once('/ecommerceng/includes/oauth-subscriber-woocommerce/src/Oauth1.php'); +use GuzzleHttp\Client; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Subscriber\Oauth\Oauth1; + +/** + * Class to manage Client WooCommerce API + */ +class eCommerceClientWooCommerceApi extends eCommerceClientApi +{ + /** + * @var string Authentication type + */ + public $authentication_type; + /** + * @var string Authentication login + */ + public $authentication_login; + /** + * @var string Authentication password + */ + public $authentication_password; + + /** + * Connect to the Wordpress + * + * @param eCommerceSite $site eCommerceSite object + * @return int <0 if KO, >0 if OK + */ + public function connection($site) + { + global $conf, $langs; + dol_syslog(__METHOD__ . " - authentication_type={$site->authentication_type}, user_name={$site->user_name}, user_password={$site->user_password}, timeout={$site->timeout}", LOG_DEBUG); + $this->errors = array(); + + $this->api_url = rtrim($site->webservice_address, '/'); + $this->api_url_prefix = '/wp-json/wc/v3'; + + $this->authentication_type = $site->authentication_type; + $this->authentication_login = $site->user_name; + $this->authentication_password = $site->user_password; + $timeout = $site->timeout > 0 ? $site->timeout : 30; + + try { + $options = [ + // Base URI is used with relative requests + 'base_uri' => $this->api_url, + // You can set any number of default request options. + 'timeout' => $timeout, + ]; + if (!empty($conf->global->ECOMMERCENG_WOOCOMMERCE_NO_VERIFY_SSL)) $options['verify'] = false; + + if (in_array($this->authentication_type, [ 'oauth1_header', 'oauth1_query' ])) { + $stack = HandlerStack::create(); + + $middleware = new Oauth1([ + 'consumer_key' => $this->authentication_login, + 'consumer_secret' => $this->authentication_password, + 'request_method' => $this->authentication_type == 'oauth1_header' ? Oauth1::REQUEST_METHOD_HEADER : Oauth1::REQUEST_METHOD_QUERY, + 'signature_method' => Oauth1::SIGNATURE_METHOD_HMACSHA256 + ]); + $stack->push($middleware); + + $options['handler'] = $stack; + $options['auth'] = 'oauth'; + } + + $this->client = new Client($options); + } catch (Exception $e) { + $this->errors[] = $langs->trans('ECommerceErrorConnectAPI', $site->name); + $this->errors[] = $e->getMessage(); + dol_syslog(__METHOD__ . " Error: " . $this->errorsToString(), LOG_ERR); + return -1; + } + + return 1; + } + + /** + * Send to the Api + * + * @param string $method Method request + * @param string $url Url request + * @param array $options Options request + * @param bool $without_prefix Without api url prefix + * @param int $status_code Status code returned + * @param int $error_info Error info returned + * @return array null if KO otherwise result data + */ + public function sendToApi($method, $url, $options = [], $without_prefix = false, &$status_code = null, &$error_info = null) + { + dol_syslog(__METHOD__ . " method=" . $method . " url=" . $url . " options=" . json_encode($options), LOG_DEBUG); + + if ($this->authentication_type == 'basic') { + $options['headers']['Authorization'] = 'Basic ' . base64_encode($this->authentication_login . ':' . $this->authentication_password); + } elseif ($this->authentication_type == 'query') { + $options[GuzzleHttp\RequestOptions::QUERY]['consumer_key'] = $this->authentication_login; + $options[GuzzleHttp\RequestOptions::QUERY]['consumer_secret'] = $this->authentication_password; + } + + return parent::sendToApi($method, $url, $options, $without_prefix, $status_code, $error_info); + } +} diff --git a/class/client/eCommerceClientWordpressApi.class.php b/class/client/eCommerceClientWordpressApi.class.php new file mode 100644 index 0000000..d91cc90 --- /dev/null +++ b/class/client/eCommerceClientWordpressApi.class.php @@ -0,0 +1,212 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/class/business/eCommerceClientWordpressApi.class.php + * \ingroup ecommerceng + * \brief This file for managing Client Wordpress API + */ + +dol_include_once('/ecommerceng/class/client/eCommerceClientApi.class.php'); + +/** + * Class to manage Client Wordpress API + */ +class eCommerceClientWordpressApi extends eCommerceClientApi +{ + /** + * @var string Authentication type + */ + public $authentication_type; + /** + * @var string Authentication login + */ + public $authentication_login; + /** + * @var string Authentication password + */ + public $authentication_password; + + const SERVICE_NAME = 'ECOMMERCENG_WORDPRESS'; + + /** + * Connect to the Wordpress + * + * @param eCommerceSite $site eCommerceSite object + * @return int <0 if KO, >0 if OK + */ + public function connection($site) + { + global $conf, $langs; + dol_syslog(__METHOD__ . " - wordpress_authentication_type={$site->wordpress_authentication_type}, wordpress_authentication_login={$site->wordpress_authentication_login}, wordpress_authentication_password={$site->wordpress_authentication_password}, wordpress_timeout={$site->wordpress_timeout}", LOG_DEBUG); + $this->errors = array(); + + $this->api_url = rtrim($site->webservice_address, '/'); + $this->api_url_prefix = '/wp-json/wp/v2'; + + $this->authentication_type = $site->wordpress_authentication_type; + $this->authentication_login = $site->wordpress_authentication_login; + $this->authentication_password = $site->wordpress_authentication_password; + $timeout = $site->wordpress_timeout > 0 ? $site->wordpress_timeout : 30; + + try { + $options = [ + // Base URI is used with relative requests + 'base_uri' => $this->api_url, + // You can set any number of default request options. + 'timeout' => $timeout, + ]; + if (!empty($conf->global->ECOMMERCENG_WORDPRESS_NO_VERIFY_SSL)) $options['verify'] = false; + + $this->client = new GuzzleHttp\Client($options); + } catch (Exception $e) { + $this->errors[] = $langs->trans('ECommerceErrorConnectAPI', $site->name); + $this->errors[] = $e->getMessage(); + dol_syslog(__METHOD__ . " Error: " . $this->errorsToString(), LOG_ERR); + return -1; + } + + return 1; + } + + /** + * Load code + * + * @return int <0 if KO, >0 if OK + */ + public function fetchCode() + { + global $langs; + dol_syslog(__METHOD__, LOG_DEBUG); + $langs->load('ecommerceng@ecommerceng'); + $this->errors = array(); + + $api_bearer_token = $this->getTemporaryCode(); + if (is_numeric($api_bearer_token) && $api_bearer_token < 0) { + return null; + } + + return (string) $api_bearer_token; + } + + /** + * Get the temporary code for Wordpress + * + * @return string|int <0 if KO, Temporary code for Wordpress + */ + protected function getTemporaryCode() + { + global $conf; + dol_syslog(__METHOD__, LOG_DEBUG); + + $storage = new DoliStorage($this->db, $conf); + + try { + // Check if we have temporary code + $token = $storage->retrieveAccessToken(self::SERVICE_NAME . '_' . $conf->entity); + } catch (Exception $e) { + if ('Token not found in db, are you sure you stored it?' != $e->getMessage()) { + $this->errors[] = $e->getMessage(); + dol_syslog(__METHOD__ . " Error: " . $this->errorsToString(), LOG_ERR); + return -1; + } else { + // Retrieve temporary code from Wordpress + $token = $this->retrieveTemporaryCode(); + if (!is_object($token)) { + return -1; + } + } + } + + // Is token expired or will temporary code expire in the next 30 seconds + $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); + + // Token expired so we refresh it + if ($expire) { + // Retrieve temporary code from Wordpress + $token = $this->retrieveTemporaryCode(); + if (!is_object($token)) { + return -1; + } + } + + return $token->getAccessToken(); + } + + /** + * Retrieve the temporary code from Wordpress + * + * @return string|int <0 if KO, Temporary code for Wordpress + */ + protected function retrieveTemporaryCode() + { + global $conf; + dol_syslog(__METHOD__, LOG_DEBUG); + + $results = $this->_sendToApi(self::METHOD_POST, '/wp-json/api/v1/token', [ + GuzzleHttp\RequestOptions::FORM_PARAMS => [ + 'username' => $this->authentication_login, + 'password' => $this->authentication_password, + ] + ], true); + if (!is_array($results)) { + return -1; + } + + $storage = new DoliStorage($this->db, $conf); + $token = new StdOAuth2Token(); + + $token->setAccessToken($results['jwt_token']); + $token->setLifetime($results['expires_in']); + $token->setExtraParams($results); + + $storage->storeAccessToken(self::SERVICE_NAME . '_' . $conf->entity, $token); + + return $token; + } + + /** + * Send to the Api + * + * @param string $method Method request + * @param string $url Url request + * @param array $options Options request + * @param bool $without_prefix Without api url prefix + * @param int $status_code Status code returned + * @param int $error_info Error info returned + * @return array null if KO otherwise result data + */ + public function sendToApi($method, $url, $options = [], $without_prefix = false, &$status_code = null, &$error_info = null) + { + global $conf; + dol_syslog(__METHOD__ . " method=" . $method . " url=" . $url . " options=" . json_encode($options), LOG_DEBUG); + + if (!empty($this->authentication_type)) { + if ($this->authentication_type == 'wordpress_application') { + $options['headers']['Authorization'] = 'Basic ' . base64_encode($this->authentication_login . ':' . $this->authentication_password); + } else { + $api_bearer_token = $this->fetchCode(); + if (!isset($api_bearer_token)) { + return -1; + } + $options['headers']['Authorization'] = 'Bearer ' . $api_bearer_token; + } + } + + return parent::sendToApi($method, $url, $options, $without_prefix, $status_code, $error_info); + } +} diff --git a/class/data/eCommerceProduct.class.php b/class/data/eCommerceProduct.class.php index 8554368..0a68202 100644 --- a/class/data/eCommerceProduct.class.php +++ b/class/data/eCommerceProduct.class.php @@ -20,17 +20,18 @@ class eCommerceProduct // extends CommonObject { - var $db; //!< To store db handler - var $error; //!< To return error code (or message) - var $errors=array(); //!< To return several error codes (or messages) - //var $element='ecommerce_product'; //!< Id that identify managed objects - //var $table_element='ecommerce_product'; //!< Name of table without prefix where object is stored - - var $id; - var $fk_product; - var $fk_site; - var $remote_id; - var $last_update; + public $db; //!< To store db handler + public $error; //!< To return error code (or message) + public $errors=array(); //!< To return several error codes (or messages) + //public $element='ecommerce_product'; //!< Id that identify managed objects + //public $table_element='ecommerce_product'; //!< Name of table without prefix where object is stored + + public $id; + public $fk_product; + public $fk_site; + public $remote_id; + public $last_update; + public $last_update_stock; /** * Constructor @@ -59,7 +60,8 @@ function create($user, $notrigger=0) if (isset($this->fk_product)) $this->fk_product=intval($this->fk_product); if (isset($this->fk_site)) $this->fk_site=intval($this->fk_site); if (isset($this->remote_id)) $this->remote_id=trim($this->remote_id); - if (isset($this->last_update)) $this->last_update=trim($this->last_update); + if (isset($this->last_update)) $this->last_update=trim($this->last_update); + if (isset($this->last_update_stock)) $this->last_update_stock=trim($this->last_update_stock); // Check parameters // Put here code to add control on parameters values @@ -69,12 +71,14 @@ function create($user, $notrigger=0) $sql.= "fk_product,"; $sql.= "fk_site,"; $sql.= "remote_id,"; - $sql.= "last_update"; + $sql.= "last_update,"; + $sql.= "last_update_stock"; $sql.= ") VALUES ("; $sql.= " ".(isset($this->fk_product)?intval($this->fk_product):0).","; $sql.= " ".(isset($this->fk_site)?intval($this->fk_site):0).","; $sql.= " ".(isset($this->remote_id)?"'".$this->db->escape($this->remote_id)."'":"").","; - $sql.= " ".(isset($this->last_update)?"'".$this->last_update."'" : 'null').""; + $sql.= " ".(isset($this->last_update)?"'".$this->last_update."'" : 'null').","; + $sql.= " ".(isset($this->last_update_stock)?"'".$this->last_update_stock."'" : 'null').""; $sql.= ")"; $this->db->begin(); @@ -134,7 +138,8 @@ function fetch($id) $sql.= " t.fk_product,"; $sql.= " t.fk_site,"; $sql.= " t.remote_id,"; - $sql.= " t.last_update"; + $sql.= " t.last_update,"; + $sql.= " t.last_update_stock"; $sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_product as t"; $sql.= " WHERE t.rowid = ".$id; @@ -151,6 +156,7 @@ function fetch($id) $this->fk_site = $obj->fk_site; $this->remote_id = $obj->remote_id; $this->last_update = $obj->last_update; + $this->last_update_stock = $obj->last_update_stock; } $this->db->free($resql); return 1; @@ -181,6 +187,7 @@ function update($user=0, $notrigger=0) if (isset($this->fk_site)) $this->fk_site=intval($this->fk_site); if (isset($this->remote_id)) $this->remote_id=trim($this->remote_id); if (isset($this->last_update)) $this->last_update=trim($this->last_update); + if (isset($this->last_update_stock)) $this->last_update_stock=trim($this->last_update_stock); // Check parameters // Put here code to add control on parameters values @@ -191,7 +198,8 @@ function update($user=0, $notrigger=0) $sql.= " fk_product=".(isset($this->fk_product)?intval($this->fk_product):0).","; $sql.= " fk_site=".(isset($this->fk_site)?intval($this->fk_site):0).","; $sql.= " remote_id='".$this->db->escape($this->remote_id)."',"; - $sql.= " last_update=".(isset($this->last_update)?"'".$this->last_update."'" : 'null').""; + $sql.= " last_update=".(isset($this->last_update)?"'".$this->last_update."'" : 'null').","; + $sql.= " last_update_stock=".(isset($this->last_update_stock)?"'".$this->last_update_stock."'" : 'null').""; $sql.= " WHERE rowid=".$this->id; @@ -340,7 +348,8 @@ public function fetchByRemoteId($remoteId, $siteId) $sql .= " t.fk_product,"; $sql .= " t.fk_site,"; $sql .= " t.remote_id,"; - $sql .= " t.last_update"; + $sql .= " t.last_update,"; + $sql .= " t.last_update_stock"; $sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_product as t"; $sql .= " WHERE t.fk_site = " . $siteId; $sql .= " AND t.remote_id LIKE '" . $this->db->escape($remoteId) . "'"; @@ -355,6 +364,7 @@ public function fetchByRemoteId($remoteId, $siteId) $this->fk_site = $obj->fk_site; $this->remote_id = $obj->remote_id; $this->last_update = $obj->last_update; + $this->last_update_stock = $obj->last_update_stock; $this->db->free($resql); return 1; } elseif ($num > 1) { @@ -390,7 +400,8 @@ public function fetchByProductId($productId, $siteId) $sql.= " t.fk_product,"; $sql.= " t.fk_site,"; $sql.= " t.remote_id,"; - $sql.= " t.last_update"; + $sql.= " t.last_update,"; + $sql.= " t.last_update_stock"; $sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_product as t"; $sql.= " WHERE t.fk_site = ".$siteId; $sql.= " AND t.fk_product = ".$productId; @@ -406,6 +417,7 @@ public function fetchByProductId($productId, $siteId) $this->fk_site = $obj->fk_site; $this->remote_id = $obj->remote_id; $this->last_update = $obj->last_update; + $this->last_update_stock = $obj->last_update_stock; $this->db->free($resql); return 1; } diff --git a/class/data/eCommerceRemoteAccess.class.php b/class/data/eCommerceRemoteAccess.class.php index 6a7b0d5..1dad09a 100644 --- a/class/data/eCommerceRemoteAccess.class.php +++ b/class/data/eCommerceRemoteAccess.class.php @@ -364,13 +364,12 @@ public function updateRemoteProduct($remote_product_id, $object) * Update remote stock of product * * @param int $remote_product_id Id of product on remote ecommerce - * @param MouvementStock $object Movement stock object * @param Product $product Product object * @return bool */ - public function updateRemoteStockProduct($remote_product_id, $object, $product) + public function updateRemoteStockProduct($remote_product_id, $product) { - $result=$this->class->updateRemoteStockProduct($remote_product_id, $object, $product); + $result=$this->class->updateRemoteStockProduct($remote_product_id, $product); $this->error=$this->class->error; $this->errors=$this->class->errors; return $result; @@ -524,6 +523,19 @@ public function getAllPaymentGateways() return $result; } + /** + * Get all remote warehouses + * + * @return array|false List of remote warehouses or false if error + */ + public function getAllRemoteWarehouses() + { + $result=$this->class->getAllRemoteWarehouses(); + $this->error=$this->class->error; + $this->errors=$this->class->errors; + return $result; + } + /** * Get all webhooks * @@ -536,4 +548,15 @@ public function getAllWebHooks() $this->errors=$this->class->errors; return $result; } + + /** + * Method to output saved errors + * + * @param string $separator Separator between each error + * @return string String with errors + */ + public function errorsToString($separator = ', ') + { + return $this->error . (is_array($this->errors) ? (!empty($this->error) ? $separator : '') . join($separator, $this->errors) : ''); + } } diff --git a/class/data/eCommerceRemoteWarehouses.class.php b/class/data/eCommerceRemoteWarehouses.class.php new file mode 100644 index 0000000..3dee82b --- /dev/null +++ b/class/data/eCommerceRemoteWarehouses.class.php @@ -0,0 +1,264 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php + * \ingroup ecommerceng + * \brief + */ + + +/** + * Class eCommerceRemoteWarehouses + * + * Put here description of your class + */ +class eCommerceRemoteWarehouses +{ + /** + * @var DoliDB Database handler. + */ + public $db; + /** + * @var string Error + */ + public $error = ''; + /** + * @var array Errors + */ + public $errors = array(); + + public $table_element = 'ecommerceng_remote_warehouses'; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Set all remote warehouse of a site + * + * @param int $site_id Site ID + * @param array $remote_warehouses List of infos of each remote warehouse + * @return int >0 if OK, <0 if KO + * @throws Exception + */ + public function set($site_id, $remote_warehouses) + { + global $conf, $langs; + dol_syslog(__METHOD__ . " site_id=$site_id, remote_warehouses=" . json_encode($remote_warehouses)); + + $errors = 0; + $this->errors = array(); + + // Clean values + $site_id = $site_id > 0 ? $site_id : 0; + $remote_warehouses = is_array($remote_warehouses) ? $remote_warehouses : array(); + + // Check values + if ($site_id == 0) { + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ECommerceSite")); + return -1; + } + + $this->db->begin(); + + foreach ($remote_warehouses as $remote_code => $infos) { + // Search warehouse + $sql = 'SELECT rowid'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE site_id = ' . $site_id; + $sql .= ' AND entity = ' . $conf->entity; + $sql .= " AND remote_code = '" . $this->db->escape($remote_code) . "'"; + + $resql = $this->db->query($sql); + if (!$resql) { + dol_syslog(__METHOD__ . ' SQL: ' . $sql . '; Errors: ' . $this->db->lasterror(), LOG_ERR); + $this->errors[] = $this->db->lasterror(); + $errors++; + break; + } + + $line_id = 0; + if ($obj = $this->db->fetch_object($resql)) { + $line_id = $obj->rowid; + } + + $this->db->free($resql); + + if ($line_id > 0) { + // Update values + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + $sql .= " remote_id = '" . $this->db->escape($infos['remote_id']) . "'"; + $sql .= ", remote_name = '" . $this->db->escape($infos['remote_name']) . "'"; + $sql .= ", warehouse_id = " . ($infos['warehouse_id'] > 0 ? $infos['warehouse_id'] : 'NULL'); + $sql .= ', set_even_if_empty_stock = ' . (!empty($infos['set_even_if_empty_stock']) ? 1 : 'NULL'); + $sql .= ', old_entry = ' . (!empty($infos['old_entry']) ? 1 : 'NULL'); + $sql .= ' WHERE rowid = ' . $line_id; + + $resql = $this->db->query($sql); + } else { + // Insert values + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(site_id, remote_code, remote_id, remote_name, warehouse_id, set_even_if_empty_stock, old_entry, entity) VALUES ('; + $sql .= $site_id; + $sql .= ", '" . $this->db->escape($remote_code) . "'"; + $sql .= ", '" . $this->db->escape($infos['remote_id']) . "'"; + $sql .= ", '" . $this->db->escape($infos['remote_name']) . "'"; + $sql .= ', ' . ($infos['warehouse_id'] > 0 ? $infos['warehouse_id'] : 'NULL'); + $sql .= ', ' . (!empty($infos['set_even_if_empty_stock']) ? 1 : 'NULL'); + $sql .= ', ' . (!empty($infos['old_entry']) ? 1 : 'NULL'); + $sql .= ', ' . $conf->entity; + $sql .= ')'; + $resql = $this->db->query($sql); + } + if (!$resql) { + dol_syslog(__METHOD__ . ' SQL: ' . $sql . '; Errors: ' . $this->db->lasterror(), LOG_ERR); + $this->errors[] = $this->db->lasterror(); + $errors++; + break; + } + } + + if ($errors) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return 1; + } + } + + /** + * Get a remote warehouse of a site by the remote warehouse code or warehouse id + * + * @param int $site_id Site ID + * @param string $remote_code Remote warehouse code on site + * @param int $warehouse_id Warehouse ID on Dolibarr + * @return array|int 0 if not found, <0 if errors or array of infos + * @throws Exception + */ + public function get($site_id, $remote_code='', $warehouse_id=0) + { + global $conf; + dol_syslog(__METHOD__ . " site_id=$site_id, remote_code=$remote_code, warehouse_id=$warehouse_id"); + + $sql = 'SELECT remote_code, remote_id, remote_name, warehouse_id, set_even_if_empty_stock, old_entry FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE site_id = ' . $site_id . ' AND entity = ' . $conf->entity; + if ($warehouse_id > 0) { + $sql .= ' AND warehouse_id = ' . $warehouse_id; + $sql .= ' AND old_entry IS NULL'; + } else { + $sql .= " AND remote_code = '" . $this->db->escape($remote_code) . "'"; + } + $resql = $this->db->query($sql); + if ($resql) { + if ($this->db->num_rows($resql) == 0) + return 0; + + if ($obj = $this->db->fetch_object($resql)) { + return array( + 'remote_code' => $obj->remote_code, + 'remote_id' => $obj->remote_id, + 'remote_name' => $obj->remote_name, + 'warehouse_id' => $obj->warehouse_id > 0 ? $obj->warehouse_id : 0, + 'set_even_if_empty_stock' => !empty($obj->set_even_if_empty_stock) ? 1 : 0, + 'old_entry' => !empty($obj->old_entry) ? 1 : 0, + ); + } + } else { + dol_syslog(__METHOD__ . ' SQL: ' . $sql . '; Errors: ' . $this->db->lasterror(), LOG_ERR); + $this->errors[] = $this->db->lasterror(); + return -1; + } + } + + /** + * Get all remote warehouses of a site + * + * @param int $site_id Site ID + * @return array|int List of all remote warehouses infos + * @throws Exception + */ + public function get_all($site_id) + { + global $conf; + dol_syslog(__METHOD__ . " site_id=$site_id"); + + $warehouses = array(); + + $sql = 'SELECT remote_code, remote_id, remote_name, warehouse_id, set_even_if_empty_stock, old_entry FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE site_id = ' . $site_id . ' AND entity = ' . $conf->entity; + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $warehouses[$obj->remote_code] = array( + 'remote_id' => $obj->remote_id, + 'remote_name' => $obj->remote_name, + 'warehouse_id' => $obj->warehouse_id, + 'set_even_if_empty_stock' => !empty($obj->set_even_if_empty_stock) ? 1 : 0, + 'old_entry' => !empty($obj->old_entry) ? 1 : 0, + ); + } + } else { + dol_syslog(__METHOD__ . ' SQL: ' . $sql . '; Errors: ' . $this->db->lasterror(), LOG_ERR); + $this->errors[] = $this->db->lasterror(); + return -1; + } + + return $warehouses; + } + + /** + * Delete all remote warehouses of a site + * + * @param int $site_id Site ID + * @return int >0 if OK, <0 if KO + * @throws Exception + */ + public function delete_all($site_id) + { + global $conf; + dol_syslog(__METHOD__ . " site_id=$site_id"); + + // Delete all line for the site + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE site_id = ' . $site_id . ' AND entity = ' . $conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + dol_syslog(__METHOD__ . ' SQL: ' . $sql . '; Errors: ' . $this->db->lasterror(), LOG_ERR); + $this->errors[] = $this->db->lasterror(); + return -1; + } + + return 1; + } + + /** + * Method to output saved errors + * + * @param string $separator Separator between each error + * @return string String with errors + */ + public function errorsToString($separator = ', ') + { + return (is_array($this->errors) ? join($separator, $this->errors) : ''); + } +} \ No newline at end of file diff --git a/class/data/eCommerceSite.class.php b/class/data/eCommerceSite.class.php index 06d57b0..9cf2176 100644 --- a/class/data/eCommerceSite.class.php +++ b/class/data/eCommerceSite.class.php @@ -24,37 +24,42 @@ class eCommerceSite // extends CommonObject { - var $db; //!< To store db handler - var $error; //!< To return error code (or message) - var $errors=array(); //!< To return several error codes (or messages) - //var $element='ecommerce_site'; //!< Id that identify managed objects - //var $table_element='ecommerce_site'; //!< Name of table without prefix where object is stored - - var $id; - - var $name; - var $type; - var $webservice_address; - var $user_name; - var $user_password; - var $price_level; - var $filter_label; - var $filter_value; - var $fk_cat_societe; - var $fk_cat_product; - var $fk_anonymous_thirdparty; - var $fk_warehouse; - var $stock_sync_direction; - var $last_update; - var $timeout; - var $magento_use_special_price; - var $ecommerce_price_type; - var $entity; - - var $oauth_id; - var $oauth_secret; - - var $parameters; + public $db; //!< To store db handler + public $error; //!< To return error code (or message) + public $errors=array(); //!< To return several error codes (or messages) + //public $element='ecommerce_site'; //!< Id that identify managed objects + //public $table_element='ecommerce_site'; //!< Name of table without prefix where object is stored + + public $id; + + public $name; + public $type; + public $webservice_address; + public $authentication_type; + public $user_name; + public $user_password; + public $price_level; + public $filter_label; + public $filter_value; + public $fk_cat_societe; + public $fk_cat_product; + public $fk_anonymous_thirdparty; + public $fk_warehouse; + public $stock_sync_direction; + public $last_update; + public $timeout; + public $debug; + public $magento_use_special_price; + public $ecommerce_price_type; + public $entity; + + public $wordpress_authentication_type; + public $wordpress_authentication_login; + public $wordpress_authentication_password; + public $wordpress_timeout; + public $wordpress_debug; + + public $parameters; //The site type name is used to define class name in eCommerceRemoteAccess class private $siteTypes = array(2=>'woocommerce'); @@ -139,6 +144,7 @@ function create($user, $notrigger=0) if (isset($this->name)) $this->name=trim($this->name); if (isset($this->type)) $this->type=trim($this->type); if (isset($this->webservice_address)) $this->webservice_address=trim($this->webservice_address); + if (isset($this->authentication_type)) $this->authentication_type=trim($this->authentication_type); if (isset($this->user_name)) $this->user_name=trim($this->user_name); if (isset($this->user_password)) $this->user_password=trim($this->user_password); if (isset($this->price_level)) $this->price_level=trim($this->price_level); @@ -151,8 +157,10 @@ function create($user, $notrigger=0) if (isset($this->stock_sync_direction)) $this->stock_sync_direction=trim($this->stock_sync_direction); if (isset($this->timeout)) $this->timeout=trim($this->timeout); - if (isset($this->oauth_id)) $this->oauth_id=trim($this->oauth_id); - if (isset($this->oauth_secret)) $this->oauth_secret=trim($this->oauth_secret); + if (isset($this->wordpress_authentication_type)) $this->wordpress_authentication_type=trim($this->wordpress_authentication_type); + if (isset($this->wordpress_authentication_login)) $this->wordpress_authentication_login=trim($this->wordpress_authentication_login); + if (isset($this->wordpress_authentication_password)) $this->wordpress_authentication_password=trim($this->wordpress_authentication_password); + if (isset($this->wordpress_timeout)) $this->wordpress_timeout=trim($this->wordpress_timeout); // Check parameters // Put here code to add control on parameters values @@ -162,6 +170,7 @@ function create($user, $notrigger=0) $sql.= "name,"; $sql.= "type,"; $sql.= "webservice_address,"; + $sql.= "authentication_type,"; $sql.= "user_name,"; $sql.= "user_password,"; $sql.= "price_level,"; @@ -174,32 +183,41 @@ function create($user, $notrigger=0) $sql.= "stock_sync_direction,"; $sql.= "last_update,"; $sql.= "timeout,"; + $sql.= "debug,"; $sql.= "magento_use_special_price,"; $sql.= "ecommerce_price_type,"; - $sql.= "oauth_id,"; - $sql.= "oauth_secret,"; + $sql.= "wordpress_authentication_type,"; + $sql.= "wordpress_authentication_login,"; + $sql.= "wordpress_authentication_password,"; + $sql.= "wordpress_timeout,"; + $sql.= "wordpress_debug,"; $sql.= "parameters,"; $sql.= "entity"; $sql.= ") VALUES ("; $sql.= " ".(! isset($this->name)?'NULL':"'".$this->db->escape($this->name)."'").","; $sql.= " ".(! isset($this->type)?'NULL':"'".$this->type."'").","; $sql.= " ".(! isset($this->webservice_address)?'NULL':"'".$this->db->escape($this->webservice_address)."'").","; + $sql.= " ".(! isset($this->authentication_type)?'NULL':"'".$this->db->escape($this->authentication_type)."'").","; $sql.= " ".(! isset($this->user_name)?'NULL':"'".$this->db->escape($this->user_name)."'").","; $sql.= " ".(! isset($this->user_password)?'NULL':"'".$this->db->escape($this->user_password)."'").","; $sql.= " ".(! isset($this->price_level)?'1':"'".$this->db->escape($this->price_level)."'").","; $sql.= " ".(! isset($this->filter_label)?'NULL':"'".$this->db->escape($this->filter_label)."'").","; $sql.= " ".(! isset($this->filter_value)?'NULL':"'".$this->db->escape($this->filter_value)."'").","; - $sql.= " ".($this->fk_cat_societe > 0 ? $this->fk_cat_societe : "NULL").","; - $sql.= " ".($this->fk_cat_product > 0 ? $this->fk_cat_product : "NULL").","; + $sql.= " ".($this->fk_cat_societe > 0 ? $this->fk_cat_societe : "0").","; + $sql.= " ".($this->fk_cat_product > 0 ? $this->fk_cat_product : "0").","; $sql.= " ".($this->fk_anonymous_thirdparty > 0 ? $this->fk_anonymous_thirdparty : "NULL").","; $sql.= " ".($this->fk_warehouse > 0 ? $this->fk_warehouse : "NULL").","; $sql.= " ".($this->stock_sync_direction ? "'".$this->stock_sync_direction."'" : "'none'").","; $sql.= " ".(! isset($this->last_update) || strlen($this->last_update)==0?'NULL':"'".$this->db->idate($this->last_update)."'").","; - $sql.= " ".(! isset($this->timeout)?'300':"'".intval($this->timeout)."'").","; + $sql.= " ".(! isset($this->timeout)?'30':"'".intval($this->timeout)."'").","; + $sql.= " ".(! empty($this->debug)?'1':"NULL").","; $sql.= " ".(! isset($this->magento_use_special_price)?'0':"'".intval($this->magento_use_special_price)."'").","; - $sql.= " ".(! isset($this->ecommerce_price_type)?'HT':"'".$this->ecommerce_price_type."'").","; - $sql.= " ".(! isset($this->oauth_id)?"NULL":"'".$this->db->escape($this->oauth_id)."'").","; - $sql.= " ".(! isset($this->oauth_secret)?"NULL":"'".$this->db->escape($this->oauth_secret)."'").","; + $sql.= " ".(! isset($this->ecommerce_price_type)?"'HT'":"'".$this->ecommerce_price_type."'").","; + $sql.= " ".(! isset($this->wordpress_authentication_type)?"NULL":"'".$this->db->escape($this->wordpress_authentication_type)."'").","; + $sql.= " ".(! isset($this->wordpress_authentication_login)?"NULL":"'".$this->db->escape($this->wordpress_authentication_login)."'").","; + $sql.= " ".(! isset($this->wordpress_authentication_password)?"NULL":"'".$this->db->escape($this->wordpress_authentication_password)."'").","; + $sql.= " ".(! isset($this->wordpress_timeout)?'30':"'".intval($this->wordpress_timeout)."'").","; + $sql.= " ".(! empty($this->wordpress_debug)?'1':"NULL").","; $sql.= " ".(! isset($this->parameters)?"NULL":"'".$this->db->escape(json_encode($this->parameters))."'").","; $sql.= " ".$conf->entity.""; $sql.= ")"; @@ -259,6 +277,7 @@ function fetch($id) $sql.= " t.name,"; $sql.= " t.type,"; $sql.= " t.webservice_address,"; + $sql.= " t.authentication_type,"; $sql.= " t.user_name,"; $sql.= " t.user_password,"; $sql.= " t.price_level,"; @@ -271,10 +290,14 @@ function fetch($id) $sql.= " t.stock_sync_direction,"; $sql.= " t.last_update,"; $sql.= " t.timeout,"; + $sql.= " t.debug,"; $sql.= " t.magento_use_special_price,"; $sql.= " t.ecommerce_price_type,"; - $sql.= " t.oauth_id,"; - $sql.= " t.oauth_secret,"; + $sql.= " t.wordpress_authentication_type,"; + $sql.= " t.wordpress_authentication_login,"; + $sql.= " t.wordpress_authentication_password,"; + $sql.= " t.wordpress_timeout,"; + $sql.= " t.wordpress_debug,"; $sql.= " t.parameters,"; $sql.= " t.entity"; $sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_site as t"; @@ -293,6 +316,7 @@ function fetch($id) $this->name = $obj->name; $this->type = $obj->type; $this->webservice_address = $obj->webservice_address; + $this->authentication_type = $obj->authentication_type; $this->user_name = $obj->user_name; $this->user_password = $obj->user_password; $this->price_level = $obj->price_level; @@ -304,13 +328,17 @@ function fetch($id) $this->fk_warehouse = $obj->fk_warehouse; $this->stock_sync_direction = $obj->stock_sync_direction; $this->last_update = $this->db->jdate($obj->last_update); - $this->timeout = $obj->timeout; + $this->timeout = $obj->timeout > 0 ? $obj->timeout : ''; + $this->debug = !empty($obj->debug); $this->magento_use_special_price = $obj->magento_use_special_price; $this->ecommerce_price_type = $obj->ecommerce_price_type; $this->entity = $obj->entity; - $this->oauth_id = $obj->oauth_id; - $this->oauth_secret = $obj->oauth_secret; + $this->wordpress_authentication_type = $obj->wordpress_authentication_type; + $this->wordpress_authentication_login = $obj->wordpress_authentication_login; + $this->wordpress_authentication_password = $obj->wordpress_authentication_password; + $this->wordpress_timeout = $obj->wordpress_timeout > 0 ? $obj->wordpress_timeout : ''; + $this->wordpress_debug = !empty($obj->wordpress_debug); $this->parameters = json_decode($obj->parameters, true); @@ -346,6 +374,7 @@ function update($user=0, $notrigger=0) if (isset($this->name)) $this->name=trim($this->name); if (isset($this->type)) $this->type=trim($this->type); if (isset($this->webservice_address)) $this->webservice_address=trim($this->webservice_address); + if (isset($this->authentication_type)) $this->authentication_type=trim($this->authentication_type); if (isset($this->user_name)) $this->user_name=trim($this->user_name); if (isset($this->user_password)) $this->user_password=trim($this->user_password); if (isset($this->price_level)) $this->price_level=trim($this->price_level); @@ -356,8 +385,10 @@ function update($user=0, $notrigger=0) if (isset($this->fk_anonymous_thirdparty)) $this->fk_anonymous_thirdparty=trim($this->fk_anonymous_thirdparty); if (isset($this->fk_warehouse)) $this->fk_warehouse=trim($this->fk_warehouse); if (isset($this->timeout)) $this->timeout=trim($this->timeout); - if (isset($this->oauth_id)) $this->oauth_id=trim($this->oauth_id); - if (isset($this->oauth_secret)) $this->oauth_secret=trim($this->oauth_secret); + if (isset($this->wordpress_authentication_type)) $this->wordpress_authentication_type=trim($this->wordpress_authentication_type); + if (isset($this->wordpress_authentication_login)) $this->wordpress_authentication_login=trim($this->wordpress_authentication_login); + if (isset($this->wordpress_authentication_password)) $this->wordpress_authentication_password=trim($this->wordpress_authentication_password); + if (isset($this->wordpress_timeout)) $this->wordpress_timeout=trim($this->wordpress_timeout); // Check parameters // Put here code to add control on parameters values @@ -368,22 +399,27 @@ function update($user=0, $notrigger=0) $sql.= " name=".(isset($this->name)?"'".$this->db->escape($this->name)."'":"null").","; $sql.= " type=".(isset($this->type)?$this->type:"null").","; $sql.= " webservice_address=".(isset($this->webservice_address)?"'".$this->db->escape($this->webservice_address)."'":"null").","; + $sql.= " authentication_type=".(isset($this->authentication_type)?"'".$this->db->escape($this->authentication_type)."'":"null").","; $sql.= " user_name=".(isset($this->user_name)?"'".$this->db->escape($this->user_name)."'":"null").","; $sql.= " user_password=".(isset($this->user_password)?"'".$this->db->escape($this->user_password)."'":"null").","; $sql.= " price_level=".(isset($this->price_level)?"'".$this->db->escape($this->price_level)."'":"1").","; $sql.= " filter_label=".(isset($this->filter_label)?"'".$this->db->escape($this->filter_label)."'":"null").","; $sql.= " filter_value=".(isset($this->filter_value)?"'".$this->db->escape($this->filter_value)."'":"null").","; - $sql.= " fk_cat_societe=".($this->fk_cat_societe > 0 ? $this->fk_cat_societe:"null").","; - $sql.= " fk_cat_product=".($this->fk_cat_product > 0 ? $this->fk_cat_product:"null").","; + $sql.= " fk_cat_societe=".($this->fk_cat_societe > 0 ? $this->fk_cat_societe:"0").","; + $sql.= " fk_cat_product=".($this->fk_cat_product > 0 ? $this->fk_cat_product:"0").","; $sql.= " fk_anonymous_thirdparty=".($this->fk_anonymous_thirdparty > 0 ? $this->fk_anonymous_thirdparty:"null").","; $sql.= " fk_warehouse=".($this->fk_warehouse > 0 ? $this->fk_warehouse:"null").","; $sql.= " stock_sync_direction=".($this->stock_sync_direction ? "'".$this->stock_sync_direction."'":"'none'").","; $sql.= " last_update=".((isset($this->last_update) && $this->last_update != '') ? "'".$this->db->idate($this->last_update)."'" : 'null').","; - $sql.= " timeout=".(isset($this->timeout)? "'".intval($this->timeout)."'" : '300').","; + $sql.= " timeout=".(isset($this->timeout)? "'".intval($this->timeout)."'" : '30').","; + $sql.= " debug=".(!empty($this->debug)? "1" : 'NULL').","; $sql.= " magento_use_special_price=".(isset($this->magento_use_special_price)? "'".intval($this->magento_use_special_price)."'" : '0').","; $sql.= " ecommerce_price_type=".(isset($this->ecommerce_price_type)? "'".$this->ecommerce_price_type."'" : 'HT').","; - $sql.= " oauth_id=".(isset($this->oauth_id)?"'".$this->db->escape($this->oauth_id)."'":"NULL").","; - $sql.= " oauth_secret=".(isset($this->oauth_secret)?"'".$this->db->escape($this->oauth_secret)."'":"NULL").","; + $sql.= " wordpress_authentication_type=".(isset($this->wordpress_authentication_type)?"'".$this->db->escape($this->wordpress_authentication_type)."'":"NULL").","; + $sql.= " wordpress_authentication_login=".(isset($this->wordpress_authentication_login)?"'".$this->db->escape($this->wordpress_authentication_login)."'":"NULL").","; + $sql.= " wordpress_authentication_password=".(isset($this->wordpress_authentication_password)?"'".$this->db->escape($this->wordpress_authentication_password)."'":"NULL").","; + $sql.= " wordpress_timeout=".(isset($this->wordpress_timeout)? "'".intval($this->wordpress_timeout)."'" : '30').","; + $sql.= " wordpress_debug=".(!empty($this->wordpress_debug)? "1" : 'NULL').","; $sql.= " parameters=".(isset($this->parameters)?"'".$this->db->escape(json_encode($this->parameters))."'":"NULL").""; $sql.= " WHERE rowid=".$this->id; @@ -582,6 +618,7 @@ function initAsSpecimen() $this->name=''; $this->type=''; $this->webservice_address=''; + $this->authentication_type=''; $this->user_name=''; $this->user_password=''; $this->price_level=''; @@ -594,11 +631,15 @@ function initAsSpecimen() $this->stock_sync_direction='none'; $this->last_update=''; $this->timeout=''; + $this->debug=''; $this->magento_use_special_price=''; $this->ecommerce_price_type=''; - $this->oauth_id=''; - $this->oauth_secret=''; - $this->parameters=''; + $this->wordpress_authentication_type=''; + $this->wordpress_authentication_login=''; + $this->wordpress_authentication_password=''; + $this->wordpress_timeout=''; + $this->wordpress_debug=''; + $this->parameters=''; } /** @@ -630,13 +671,13 @@ function listSites($mode='array') $obj = $this->db->fetch_object($result); if ($mode == 'array') { - $list[$i]=array('id'=>$obj->rowid, 'name'=>$obj->name, 'last_update'=>$this->db->jdate($obj->last_update)); + $list[$obj->rowid]=array('id'=>$obj->rowid, 'name'=>$obj->name, 'last_update'=>$this->db->jdate($obj->last_update)); } else { $tmpsite=new eCommerceSite($this->db); $tmpsite->fetch($obj->rowid); - $list[$i]=$tmpsite; + $list[$obj->rowid]=$tmpsite; } $i++; } diff --git a/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php b/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php index 930d398..aa3262b 100755 --- a/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php +++ b/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php @@ -23,24 +23,14 @@ dol_include_once('/ecommerceng/class/data/eCommerceCommande.class.php'); dol_include_once('/ecommerceng/class/business/eCommerceUtils.class.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/Client.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/BasicAuth.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/HttpClient.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/HttpClientException.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/OAuth.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/Options.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/Request.php'); -dol_include_once('/ecommerceng/includes/WooCommerce/HttpClient/Response.php'); - dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); -dol_include_once('/ecommerceng/includes/WordPressClient.php'); +dol_include_once('/ecommerceng/class/client/eCommerceClientWooCommerceApi.class.php'); +dol_include_once('/ecommerceng/class/client/eCommerceClientWordpressApi.class.php'); require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -use Automattic\WooCommerce\Client; -use Automattic\WooCommerce\HttpClient\HttpClientException; /** * Class for access remote sites @@ -68,21 +58,15 @@ class eCommerceRemoteAccessWoocommerce private $eCommerceCommande; /** - * Woocommerce client new API v2. + * Woocommerce client. * - * @var Client + * @var eCommerceClientWooCommerceApi */ private $client; - /** - * Woocommerce client old API v3. - * - * @var Client - */ - private $clientOld; /** * WordPress client. * - * @var WordPressClient + * @var eCommerceClientWordpressApi */ private $worpressclient; @@ -213,67 +197,26 @@ private function initECommerceCommande() */ public function connect() { - dol_syslog(__METHOD__ . ": Connect to API webservice_address=" . $this->site->webservice_address . " user_name=" . - $this->site->user_name . " user_password=" . $this->site->user_password . " for site ID {$this->site->id}", LOG_DEBUG); - global $conf, $langs; - + dol_syslog(__METHOD__ . " - site ID {$this->site->id}", LOG_DEBUG); $this->errors = array(); - $response_timeout = (empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT); // Response timeout - -// $stopwatch_id = -1; - try { - $this->client = new Client( - $this->site->webservice_address, - $this->site->user_name, - $this->site->user_password, - [ - 'wp_api' => true, - 'version' => 'wc/v3', - 'timeout' => $response_timeout, - 'verify_ssl' => empty($conf->global->ECOMMERCENG_WOOCOMMERCE_NO_VERIFY_SSL), - 'query_string_auth' => !empty($conf->global->ECOMMERCENG_WOOCOMMERCE_QUERY_STRING_AUTH), - ] - ); -// $filters = [ 'page' => 1, 'per_page' => 1 ]; -// $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/categories (filters: " . json_encode($filters). ")"); -// $this->client->get('products/categories', $filters); -// eCommerceUtils::stopAndLogStopwatch($stopwatch_id); -// -// $this->clientOld = new Client( -// $this->site->webservice_address, -// $this->site->user_name, -// $this->site->user_password, -// [ -// 'wp_api' => false, -// 'version' => 'v3', -// 'timeout' => $response_timeout, -// 'query_string_auth' => !empty($conf->global->ECOMMERCENG_WOOCOMMERCE_QUERY_STRING_AUTH), -// ] -// ); -// $this->clientOld->get('products/categories', [ 'page' => 1, 'filter' => [ 'limit' => 1 ] ]); - } catch (HttpClientException $fault) { -// eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConnect', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConnect', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } - try { - $this->worpressclient = new WordPressClient( - $this->site->webservice_address, - $this->site->oauth_id, - $this->site->oauth_secret, - dol_buildpath('/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php', 2) . '?ecommerce_id=' . $this->site->id - ); - } catch (Exception $e) { - $this->errors[] = $langs->trans('ECommerceWoocommerceConnect', $this->site->name, $e->getMessage()); - dol_syslog(__METHOD__ . ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConnect', $this->site->name, $e->getMessage()), LOG_ERR); - return false; - } + $this->client = new eCommerceClientWooCommerceApi($this->db, $this->site->debug); + $result = $this->client->connection($this->site); + if ($result < 0) { + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ' - Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + $this->worpressclient = new eCommerceClientWordpressApi($this->db, $this->site->wordpress_debug); + $result = $this->worpressclient->connection($this->site); + if ($result < 0) { + $this->errors[] = $this->worpressclient->errorsToString(); + dol_syslog(__METHOD__ . ' - Error:' . $this->errorsToString(), LOG_ERR); + return false; + } - dol_syslog(__METHOD__ . ": end, ok", LOG_DEBUG); + dol_syslog(__METHOD__ . " - end, ok", LOG_DEBUG); return true; } @@ -301,7 +244,7 @@ public function getSocieteToUpdate($fromDate, $toDate) $to_date = isset($toDate) && !empty($toDate) ? new DateTime(dol_print_date($toDate, 'standard')) : null; $no_more = false; - while (true) { + do { $filters = [ 'page' => $idxPage++, 'per_page' => $per_page, @@ -309,24 +252,20 @@ public function getSocieteToUpdate($fromDate, $toDate) 'order' => 'desc', 'role' => empty($this->site->parameters['customer_roles']) ? 'all' : $this->site->parameters['customer_roles'], ]; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/categories (filters: " . json_encode($filters). ")"); - try { - $page = $this->client->get('customers', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetSocieteToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetSocieteToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } - if (!is_array($page) || ($nbCustomers = count($page)) == 0) break; + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'customers', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetSocieteToUpdate', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + if (!isset($page)) $page = array(); foreach ($page as $customer) { - $id = $customer->id; - $date_customer = $this->getDateTimeFromGMTDateTime(/*!empty($customer->date_modified_gmt) ? $customer->date_modified_gmt : */$customer->date_created_gmt); + $id = $customer['id']; + $date_customer = $this->getDateTimeFromGMTDateTime(/*!empty($customer['date_modified_gmt']) ? $customer['date_modified_gmt'] : */$customer['date_created_gmt']); $update_customer = false; if ($from_date == $date_customer) { if ($this->eCommerceSociete->fetchByRemoteId($id, $this->site->id) > 0) { @@ -352,7 +291,7 @@ public function getSocieteToUpdate($fromDate, $toDate) } if ($no_more) break; - } + } while (count($page) == $per_page); //important - order by last update if (count($result)) { @@ -391,30 +330,27 @@ public function getProductToUpdate($fromDate, $toDate) if (isset($fromDate) && !empty($fromDate)) $filter['updated_at_min'] = dol_print_date($fromDate - (24 * 60 * 60), 'dayrfc'); if (isset($toDate) && !empty($toDate)) $filter['updated_at_max'] = dol_print_date($toDate + (24 * 60 * 60), 'dayrfc'); - while (true) { - try { - $page = $this->clientOld->get('products', - [ - 'page' => $idxPage++, - 'filter' => $filter, - 'fields' => 'id,created_at,updated_at,variations', - ] - ); - } catch (HttpClientException $fault) { - $this->errors[] = $langs->trans('ECommerceWoocommerceGetProductToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetProductToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + do { + $filters = [ + 'page' => $idxPage++, + 'filter' => $filter, + 'fields' => 'id,created_at,updated_at,variations', + ]; - if (!isset($page->products) || ($nbProducts = count($page->products)) == 0) break; - $page = $page->products; + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetProductToUpdate', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + if (!isset($page) || !isset($page['products'])) $page['products'] = array(); - foreach ($page as $product) { - $id = $product->id; + foreach ($page['products'] as $product) { + $id = $product['id']; $update = false; - $date_product = $this->getDateTimeFromGMTDateTime(!empty($product->updated_at) ? $product->updated_at : $product->created_at); + $date_product = $this->getDateTimeFromGMTDateTime(!empty($product['updated_at']) ? $product['updated_at'] : $product['created_at']); $update_parent = false; if ($from_date == $date_product) { if ($this->eCommerceProduct->fetchByRemoteId($id, $this->site->id) > 0) { @@ -438,9 +374,9 @@ public function getProductToUpdate($fromDate, $toDate) } // Variations - foreach ($product->variations as $variation) { - $id = $product->id . '|' . $variation->id; - $date_variation = $this->getDateTimeFromGMTDateTime(!empty($variation->updated_at) ? $variation->updated_at : $variation->created_at); + foreach ($product['variations'] as $variation) { + $id = $product['id'] . '|' . $variation['id']; + $date_variation = $this->getDateTimeFromGMTDateTime(!empty($variation['updated_at']) ? $variation['updated_at'] : $variation['created_at']); $update_variante = false; if ($from_date == $date_product) { if ($this->eCommerceProduct->fetchByRemoteId($id, $this->site->id) > 0) { @@ -462,7 +398,7 @@ public function getProductToUpdate($fromDate, $toDate) } } } - } + } while (count($page['products']) == $per_page); //important - order by last update if (count($result)) { @@ -508,29 +444,26 @@ public function getCommandeToUpdate($fromDate, $toDate) if (isset($fromDate) && !empty($fromDate)) $filter['updated_at_min'] = dol_print_date($fromDate - (24 * 60 * 60), 'dayrfc'); if (isset($toDate) && !empty($toDate)) $filter['updated_at_max'] = dol_print_date($toDate + (24 * 60 * 60), 'dayrfc'); - while (true) { - try { - $page = $this->clientOld->get('orders', - [ - 'page' => $idxPage++, - 'filter' => $filter, - 'fields' => 'id,created_at,updated_at' - ] - ); - } catch (HttpClientException $fault) { - $this->errors[] = $langs->trans('ECommerceWoocommerceGetCommandeToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetCommandeToUpdate', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + do { + $filters = [ + 'page' => $idxPage++, + 'filter' => $filter, + 'fields' => 'id,created_at,updated_at' + ]; - if (!isset($page->orders) || ($nbOrders = count($page->orders)) == 0) break; - $page = $page->orders; + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'orders', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetCommandeToUpdate', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } - foreach ($page as $order) { - $id = $order->id; - $date_order = $this->getDateTimeFromGMTDateTime(!empty($order->updated_at) ? $order->updated_at : $order->created_at); + if (!isset($page) || !isset($page['orders'])) $page['orders'] = array(); + + foreach ($page['orders'] as $order) { + $id = $order['id']; + $date_order = $this->getDateTimeFromGMTDateTime(!empty($order['updated_at']) ? $order['updated_at'] : $order['created_at']); $update_order = false; if ($from_date == $date_order) { if ($this->eCommerceCommande->fetchByRemoteId($id, $this->site->id) > 0) { @@ -550,7 +483,7 @@ public function getCommandeToUpdate($fromDate, $toDate) $last_update[$id] = $date_order->format('Y-m-d H:i:s'); } } - } + } while (count($page['orders']) == $per_page); //important - order by last update if (count($result)) { @@ -611,23 +544,18 @@ public function convertRemoteObjectIntoDolibarrSociete($from_date = null, $to_da $idxPage = 1; $nbTotalRecords = 0; - while (true) { + do { $filters['page'] = $idxPage++; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET customers (filters: " . json_encode($filters). ")"); - $page = $this->client->get('customers', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'customers', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (!isset($page) || count($page) == 0) break; + if (!isset($page)) $page = array(); foreach ($page as $company) { $company_data = $this->convertCustomerDataIntoProcessedData($company); @@ -637,7 +565,7 @@ public function convertRemoteObjectIntoDolibarrSociete($from_date = null, $to_da } if ($toNb > 0 && $nbTotalRecords >= $toNb) break; - } + } while (count($page) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, converted " . count($companies) . " remote companies", LOG_DEBUG); return $companies; @@ -656,28 +584,28 @@ public function convertCustomerDataIntoProcessedData($remote_data) $this->errors = array(); - $create_date = $this->getDateTimeFromGMTDateTime($remote_data->date_created_gmt); - $last_update = $this->getDateTimeFromGMTDateTime(/*!empty($remote_data->date_modified_gmt) ? $remote_data->date_modified_gmt :*/ $remote_data->date_created_gmt); + $create_date = $this->getDateTimeFromGMTDateTime($remote_data['date_created_gmt']); + $last_update = $this->getDateTimeFromGMTDateTime(/*!empty($remote_data['date_modified_gmt']) ? $remote_data['date_modified_gmt'] :*/ $remote_data['date_created_gmt']); // Global infos $item = [ 'create_date' => $create_date->getTimestamp(), 'last_update' => $last_update->format('Y-m-d H:i:s'), - 'remote_id' => $remote_data->id, + 'remote_id' => $remote_data['id'], 'name_alias' => null, - 'email_key' => $remote_data->email, + 'email_key' => $remote_data['email'], 'client' => 1, 'vatnumber' => null, - 'note_private' => "Site: '{$this->site->name}' - ID: {$remote_data->id}", - 'address' => $remote_data->billing->address_1 . (!empty($remote_data->billing->address_1) && !empty($remote_data->billing->address_2) ? "\n" : "") . $remote_data->billing->address_2, - 'zip' => $remote_data->billing->postcode, - 'town' => $remote_data->billing->city, - 'country_id' => getCountry($remote_data->billing->country, 3), - 'phone' => $remote_data->billing->phone, + 'note_private' => "Site: '{$this->site->name}' - ID: {$remote_data['id']}", + 'address' => $remote_data['billing']['address_1'] . (!empty($remote_data['billing']['address_1']) && !empty($remote_data['billing']['address_2']) ? "\n" : "") . $remote_data['billing']['address_2'], + 'zip' => $remote_data['billing']['postcode'], + 'town' => $remote_data['billing']['city'], + 'country_id' => getCountry($remote_data['billing']['country'], 3), + 'phone' => $remote_data['billing']['phone'], 'default_lang' => $mysoc->default_lang, 'remote_datas' => $remote_data, 'extrafields' => [ - "ecommerceng_wc_role_{$this->site->id}_{$conf->entity}" => $langs->trans('ECommercengWoocommerceCompanyRole_' . $remote_data->role), + "ecommerceng_wc_role_{$this->site->id}_{$conf->entity}" => $langs->trans('ECommercengWoocommerceCompanyRole_' . $remote_data['role']), ], ]; @@ -688,27 +616,27 @@ public function convertCustomerDataIntoProcessedData($remote_data) // Meta datas if (!empty($conf->global->ECOMMERCENG_WOOCOMMERCE_VAT_NUMBER_META_NAME)) { - foreach ($remote_data->meta_data as $data) { - if ($data->key == $conf->global->ECOMMERCENG_WOOCOMMERCE_VAT_NUMBER_META_NAME) { - $item['vatnumber'] = $data->value; + foreach ($remote_data['meta_data'] as $data) { + if ($data['key'] == $conf->global->ECOMMERCENG_WOOCOMMERCE_VAT_NUMBER_META_NAME) { + $item['vatnumber'] = $data['value']; break; } } } // Company - if (!empty($remote_data->billing->company)) { + if (!empty($remote_data['billing']['company'])) { $item['type'] = 'company'; - $item['name'] = $remote_data->billing->company; - $item['email'] = !empty($conf->global->ECOMMERCENG_WOOCOMMERCE_GET_EMAIL_ON_COMPANY) ? $remote_data->email : null; + $item['name'] = $remote_data['billing']['company']; + $item['email'] = !empty($conf->global->ECOMMERCENG_WOOCOMMERCE_GET_EMAIL_ON_COMPANY) ? $remote_data['email'] : null; } // User else { - if (!empty($remote_data->billing->first_name) || !empty($remote_data->billing->last_name)) { - $firstname = $remote_data->billing->first_name; - $lastname = $remote_data->billing->last_name; + if (!empty($remote_data['billing']['first_name']) || !empty($remote_data['billing']['last_name'])) { + $firstname = $remote_data['billing']['first_name']; + $lastname = $remote_data['billing']['last_name']; }else { - $firstname = $remote_data->first_name; - $lastname = $remote_data->last_name; + $firstname = $remote_data['first_name']; + $lastname = $remote_data['last_name']; } if (!empty($conf->global->ECOMMERCENG_UPPERCASE_LASTNAME)) { $firstname = dol_ucwords(dol_strtolower($firstname)); @@ -723,14 +651,14 @@ public function convertCustomerDataIntoProcessedData($remote_data) } $item['type'] = 'user'; $item['name'] = $name; - $item['email'] = $remote_data->email; + $item['email'] = $remote_data['email']; } // Get metadata $metas_data = array(); - if (is_array($remote_data->meta_data)) { - foreach ($remote_data->meta_data as $meta) { - $metas_data[$meta->key] = $meta; + if (is_array($remote_data['meta_data'])) { + foreach ($remote_data['meta_data'] as $meta) { + $metas_data[$meta['key']] = $meta; } } @@ -743,8 +671,8 @@ public function convertCustomerDataIntoProcessedData($remote_data) } } foreach ($metas_data as $meta) { - if (isset($correspondences[$meta->key])) { - $item['extrafields'][$correspondences[$meta->key]] = $meta->value; + if (isset($correspondences[$meta['key']])) { + $item['extrafields'][$correspondences[$meta['key']]] = $meta['value']; } } } @@ -760,20 +688,20 @@ public function convertCustomerDataIntoProcessedData($remote_data) */ public function convertRemoteObjectIntoDolibarrSocpeople($remoteCompany) { - dol_syslog(__METHOD__ . ": Get remote contacts ID: {$remoteCompany->id} for site ID {$this->site->id}", LOG_DEBUG); + dol_syslog(__METHOD__ . ": Get remote contacts ID: {$remoteCompany['id']} for site ID {$this->site->id}", LOG_DEBUG); global $conf, $langs; $this->errors = array(); $contacts = []; - $last_update = $this->getDateTimeFromGMTDateTime(/*!empty($remoteCompany->date_modified_gmt) ? $remoteCompany->date_modified_gmt :*/ $remoteCompany->date_created_gmt); + $last_update = $this->getDateTimeFromGMTDateTime(/*!empty($remoteCompany['date_modified_gmt']) ? $remoteCompany['date_modified_gmt'] :*/ $remoteCompany['date_created_gmt']); - $bContact = $remoteCompany->billing; - if (!empty($bContact->address_1) || !empty($bContact->address_2) || !empty($bContact->postcode) || - !empty($bContact->city) || !empty($bContact->country) || - !empty($bContact->email) || !empty($bContact->company) || !empty($bContact->phone) + $bContact = $remoteCompany['billing']; + if (!empty($bContact['address_1']) || !empty($bContact['address_2']) || !empty($bContact['postcode']) || + !empty($bContact['city']) || !empty($bContact['country']) || + !empty($bContact['email']) || !empty($bContact['company']) || !empty($bContact['phone']) ) { - $firstname = !empty($bContact->first_name) ? $bContact->first_name : $remoteCompany->first_name; - $lastname = !empty($bContact->last_name) ? $bContact->last_name : $remoteCompany->last_name; + $firstname = !empty($bContact['first_name']) ? $bContact['first_name'] : $remoteCompany['first_name']; + $lastname = !empty($bContact['last_name']) ? $bContact['last_name'] : $remoteCompany['last_name']; if (!empty($conf->global->ECOMMERCENG_UPPERCASE_LASTNAME)) { $firstname = dol_ucwords(dol_strtolower($firstname)); $lastname = dol_strtoupper($lastname); @@ -788,28 +716,28 @@ public function convertRemoteObjectIntoDolibarrSocpeople($remoteCompany) 'last_update' => $last_update->format('Y-m-d H:i:s'), 'firstname' => $firstname, 'lastname' => $lastname, - 'address' => $bContact->address_1 . (!empty($bContact->address_1) && !empty($bContact->address_2) ? "\n" : "") . $bContact->address_2, - 'zip' => $bContact->postcode, - 'town' => $bContact->city, - 'country_id' => getCountry($bContact->country, 3), - 'email' => !empty($bContact->email) ? $bContact->email : $remoteCompany->email, - 'phone' => $bContact->phone, + 'address' => $bContact['address_1'] . (!empty($bContact['address_1']) && !empty($bContact['address_2']) ? "\n" : "") . $bContact['address_2'], + 'zip' => $bContact['postcode'], + 'town' => $bContact['city'], + 'country_id' => getCountry($bContact['country'], 3), + 'email' => !empty($bContact['email']) ? $bContact['email'] : $remoteCompany['email'], + 'phone' => $bContact['phone'], 'fax' => null, ]; } - $sContact = $remoteCompany->shipping; - if (!empty($sContact->address_1) || !empty($sContact->address_2) || - !empty($sContact->postcode) || !empty($sContact->city) || - !empty($sContact->country) + $sContact = $remoteCompany['shipping']; + if (!empty($sContact['address_1']) || !empty($sContact['address_2']) || + !empty($sContact['postcode']) || !empty($sContact['city']) || + !empty($sContact['country']) ) { - if ($bContact->first_name != $sContact->first_name || $bContact->last_name != $sContact->last_name || - $bContact->address_1 != $sContact->address_1 || $bContact->address_2 != $sContact->address_2 || - $bContact->postcode != $sContact->postcode || $bContact->city != $sContact->city || - $bContact->country != $sContact->country + if ($bContact['first_name'] != $sContact['first_name'] || $bContact['last_name'] != $sContact['last_name'] || + $bContact['address_1'] != $sContact['address_1'] || $bContact['address_2'] != $sContact['address_2'] || + $bContact['postcode'] != $sContact['postcode'] || $bContact['city'] != $sContact['city'] || + $bContact['country'] != $sContact['country'] ) { - $firstname = !empty($sContact->first_name) ? $sContact->first_name : $remoteCompany->first_name; - $lastname = !empty($sContact->last_name) ? $sContact->last_name : $remoteCompany->last_name; + $firstname = !empty($sContact['first_name']) ? $sContact['first_name'] : $remoteCompany['first_name']; + $lastname = !empty($sContact['last_name']) ? $sContact['last_name'] : $remoteCompany['last_name']; if (!empty($conf->global->ECOMMERCENG_UPPERCASE_LASTNAME)) { $firstname = dol_ucwords(dol_strtolower($firstname)); $lastname = dol_strtoupper($lastname); @@ -824,10 +752,10 @@ public function convertRemoteObjectIntoDolibarrSocpeople($remoteCompany) 'last_update' => $last_update->format('Y-m-d H:i:s'), 'firstname' => $firstname, 'lastname' => $lastname, - 'address' => $sContact->address_1 . (!empty($sContact->address_1) && !empty($sContact->address_2) ? "\n" : "") . $sContact->address_2, - 'zip' => $sContact->postcode, - 'town' => $sContact->city, - 'country_id' => getCountry($sContact->country, 3), + 'address' => $sContact['address_1'] . (!empty($sContact['address_1']) && !empty($sContact['address_2']) ? "\n" : "") . $sContact['address_2'], + 'zip' => $sContact['postcode'], + 'town' => $sContact['city'], + 'country_id' => getCountry($sContact['country'], 3), 'email' => null, 'phone' => null, 'fax' => null, @@ -899,72 +827,64 @@ public function convertRemoteObjectIntoDolibarrProduct($from_date = null, $to_da $idxPage = 1; $nbTotalRecords = 0; - while (true) { + do { $filters['page'] = $idxPage++; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products (filters: " . json_encode($filters). ")"); - try { - $page = $this->client->get('products'.$one_product_id, $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products' . $one_product_id, [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (!isset($page) || (!empty($one_product_id) && empty($page)) || count($page) == 0) break; + if (!isset($page)) $page = array(); if (!empty($one_product_id) && !empty($page)) $page = [$page]; foreach ($page as $product) { // Don't synchronize the variation parent - if (empty($product->variations) || !empty($product->parent_id)) { + if (empty($product['variations']) || !empty($product['parent_id'])) { $data = $this->convertProductDataIntoProcessedData($product); if (!is_array($data)) { - $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertProductData', $product->id)), $this->errors); + $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertProductData', $product['id'])), $this->errors); return false; } $products[] = $data; } // Synchronize all the variations of the product if only the parent is provided - if (!empty($product->variations) && empty($include_variation_ids[$product->id])) { - $include_variation_ids[$product->id] = $product->variations; + if (!empty($product['variations']) && empty($include_variation_ids[$product['id']])) { + $include_variation_ids[$product['id']] = $product['variations']; } // Variations - if (!empty($include_variation_ids[$product->id])) { + if (!empty($include_variation_ids[$product['id']])) { if ($product_variation_mode_all_to_one) { - $tmp = array_values($include_variation_ids[$product->id]); - $include_variation_ids[$product->id] = array($tmp[0]); + $tmp = array_values($include_variation_ids[$product['id']]); + $include_variation_ids[$product['id']] = array($tmp[0]); } - $requestGroupsVariations = $this->getRequestGroups($include_variation_ids[$product->id], $nb_max_by_request); + $requestGroupsVariations = $this->getRequestGroups($include_variation_ids[$product['id']], $nb_max_by_request); foreach ($requestGroupsVariations as $requestVariations) { - dol_syslog(__METHOD__ . ": Get " . count($requestVariations) . " products variations of remote product (ID:{$product->id}): " . implode(', ', $requestVariations), LOG_DEBUG); - $filters = [ + dol_syslog(__METHOD__ . ": Get " . count($requestVariations) . " products variations of remote product (ID:{$product['id']}): " . implode(', ', $requestVariations), LOG_DEBUG); + $variation_filters = [ 'per_page' => $nb_max_by_request, 'include' => implode(',', $requestVariations), ]; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$product->id}/variations (filters: " . json_encode($filters). ")"); - try { - $results = $this->client->get('products/' . $product->id . '/variations', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + $variations = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products/' . $product['id'] . '/variations', [GuzzleHttp\RequestOptions::QUERY => $variation_filters]); + if (!isset($variations)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (is_array($results)) { - foreach ($results as $variation) { + if (is_array($variations)) { + foreach ($variations as $variation) { $data = $this->convertProductDataIntoProcessedData($variation, $product); if (!is_array($data)) { - $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertProductData', $product->id . '|' . $variation->id)), $this->errors); + $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertProductData', $product['id'] . '|' . $variation['id'])), $this->errors); return false; } $products[] = $data; @@ -977,7 +897,7 @@ public function convertRemoteObjectIntoDolibarrProduct($from_date = null, $to_da } if ($toNb > 0 && $nbTotalRecords >= $toNb) break; - } + } while (count($page) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, converted " . count($products) . " remote products", LOG_DEBUG); return $products; @@ -1002,21 +922,15 @@ public function checkRemoteProductExist($remote_id) $product_variation_id = $ids[1]; } - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET product {$remote_id}"); - try { - $page = $this->client->get('products/' . $product_id . (!empty($product_variation_id) ? '/variations/'.$product_variation_id : '')); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - - if ($fault->getCode() == 404 && strpos($fault->getMessage(), '[woocommerce_rest_product_invalid_id]') !== false) { + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products/' . $product_id . (!empty($product_variation_id) ? '/variations/'.$product_variation_id : ''), [], false, $status_code); + if (!isset($page)) { + if ($status_code == 404) { return 0; } - $this->errors[] = $langs->trans('ECommerceWoocommerceCheckRemoteProductExist', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceCheckRemoteProductExist', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $this->errors[] = $langs->trans('ECommerceWoocommerceCheckRemoteProductExist', $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return -1; } @@ -1036,25 +950,20 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote global $conf, $langs; $this->errors = array(); - $isVariation = isset($parent_remote_data) || $remote_data->parent_id > 0; - $parent_id = isset($parent_remote_data) ? $parent_remote_data->id : ($remote_data->parent_id > 0 ? $remote_data->parent_id : 0); + $isVariation = isset($parent_remote_data) || $remote_data['parent_id'] > 0; + $parent_id = isset($parent_remote_data) ? $parent_remote_data['id'] : ($remote_data['parent_id'] > 0 ? $remote_data['parent_id'] : 0); if ($isVariation && empty($parent_remote_data) && !empty($parent_id)) { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$parent_id}"); - try { - $parent_remote_data = $this->client->get('products/' . $parent_id); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $parent_remote_data = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products/' . $parent_id); + if (!isset($parent_remote_data)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } // if the parent has no variations (ex: webhook of a variation transformed in a simple product before the webhook is precessed) - if ($isVariation && empty($parent_remote_data->variations)) { + if ($isVariation && empty($parent_remote_data['variations'])) { $isVariation = false; $parent_id = 0; $remote_data = $parent_remote_data; @@ -1071,43 +980,43 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote $productDimensionSynchDirection = isset($this->site->parameters['product_synch_direction']['dimension']) ? $this->site->parameters['product_synch_direction']['dimension'] : ''; $productTaxSynchDirection = isset($this->site->parameters['product_synch_direction']['tax']) ? $this->site->parameters['product_synch_direction']['tax'] : ''; $productStatusSynchDirection = isset($this->site->parameters['product_synch_direction']['status']) ? $this->site->parameters['product_synch_direction']['status'] : ''; - $productWeightUnits = isset($this->site->parameters['product_weight_units']) ? $this->site->parameters['product_weight_units'] : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?0:$conf->global->MAIN_WEIGHT_DEFAULT_UNIT); + $productWeightUnits = isset($this->site->parameters['product_weight_units']) ? $this->site->parameters['product_weight_units'] : 0; // 0 = Kg $productDimensionUnits = isset($this->site->parameters['product_dimension_units']) ? $this->site->parameters['product_dimension_units'] : -2; // -2 = cm $product_variation_mode_all_to_one = !empty($this->site->parameters['product_variation_mode']) && $this->site->parameters['product_variation_mode'] == 'all_to_one'; // Categories $categories = []; - $parent_categories = is_array($parent_remote_data->categories) ? $parent_remote_data->categories : array(); - $categories_data = is_array($remote_data->categories) ? $remote_data->categories : array(); + $parent_categories = is_array($parent_remote_data['categories']) ? $parent_remote_data['categories'] : array(); + $categories_data = is_array($remote_data['categories']) ? $remote_data['categories'] : array(); $categories_data = array_merge($categories_data, $parent_categories); foreach ($categories_data as $category) { $categories[$category->id] = $category->id; } // Label - $label = $remote_data->name; + $label = $remote_data['name']; if ($isVariation && (empty($label) || $product_variation_mode_all_to_one)) { - $label = $parent_remote_data->name; + $label = $parent_remote_data['name']; // Attributes of the variation - if (is_array($remote_data->attributes) && !$product_variation_mode_all_to_one) { - foreach ($remote_data->attributes as $attribute) { - $label .= ' - ' . $attribute->option; + if (is_array($remote_data['attributes']) && !$product_variation_mode_all_to_one) { + foreach ($remote_data['attributes'] as $attribute) { + $label .= ' - ' . $attribute['option']; } } } - $last_update_product = $this->getDateTimeFromGMTDateTime(!empty($remote_data->date_modified_gmt) ? $remote_data->date_modified_gmt : $remote_data->date_created_gmt); + $last_update_product = $this->getDateTimeFromGMTDateTime(!empty($remote_data['date_modified_gmt']) ? $remote_data['date_modified_gmt'] : $remote_data['date_created_gmt']); $last_update = $last_update_product->format('Y-m-d H:i:s'); - $price = $productSynchPrice == 'selling' ? $remote_data->price : $remote_data->regular_price; - if (!empty($remote_data->date_on_sale_from_gmt)) { - $date_on_sale_from = $this->getDateTimeFromGMTDateTime($remote_data->date_on_sale_from_gmt); + $price = $productSynchPrice == 'selling' ? $remote_data['price'] : $remote_data['regular_price']; + if (!empty($remote_data['date_on_sale_from_gmt'])) { + $date_on_sale_from = $this->getDateTimeFromGMTDateTime($remote_data['date_on_sale_from_gmt']); $date_on_sale_from = isset($date_on_sale_from) ? $date_on_sale_from->getTimestamp() : ''; } else { $date_on_sale_from = ''; } - if (!empty($remote_data->date_on_sale_to_gmt)) { - $date_on_sale_to = $this->getDateTimeFromGMTDateTime($remote_data->date_on_sale_to_gmt); + if (!empty($remote_data['date_on_sale_to_gmt'])) { + $date_on_sale_to = $this->getDateTimeFromGMTDateTime($remote_data['date_on_sale_to_gmt']); $date_on_sale_to = isset($date_on_sale_to) ? $date_on_sale_to->getTimestamp() : ''; } else { $date_on_sale_to = ''; @@ -1117,8 +1026,8 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote $variations = array(); if (!$product_variation_mode_all_to_one) { $variations_list = array(); - if (!empty($parent_remote_data->variations)) { - foreach ($parent_remote_data->variations as $v) { + if (!empty($parent_remote_data['variations'])) { + foreach ($parent_remote_data['variations'] as $v) { $variations_list[] = $parent_id . '|' . $v; } $variations = array( @@ -1126,43 +1035,43 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote 'filter' => $parent_id . '|%', 'list' => $variations_list, ); - } elseif (!empty($remote_data->variations)) { - foreach ($remote_data->variations as $v) { - $variations_list[] = $remote_data->id . '|' . $v; + } elseif (!empty($remote_data['variations'])) { + foreach ($remote_data['variations'] as $v) { + $variations_list[] = $remote_data['id'] . '|' . $v; } $variations = array( - 'parent_remote_id' => $remote_data->id, - 'filter' => $remote_data->id . '|%', + 'parent_remote_id' => $remote_data['id'], + 'filter' => $remote_data['id'] . '|%', 'list' => $variations_list, ); } } - $remote_id = $remote_data->id; + $remote_id = $remote_data['id']; $remote_parent_id = 0; if ($isVariation) { if ($product_variation_mode_all_to_one) { - $remote_id = $parent_id . '|' . implode('|', $parent_remote_data->variations); + $remote_id = $parent_id . '|' . implode('|', $parent_remote_data['variations']); $remote_parent_id = $parent_id; } else { - $remote_id = $parent_id . '|' . $remote_data->id; + $remote_id = $parent_id . '|' . $remote_data['id']; $remote_parent_id = $parent_id; } - } elseif (!empty($remote_data->variations) && $product_variation_mode_all_to_one) { - $remote_id = $remote_data->id . '|' . implode('|', $remote_data->variations); - $remote_parent_id = $remote_data->id; + } elseif (!empty($remote_data['variations']) && $product_variation_mode_all_to_one) { + $remote_id = $remote_data['id'] . '|' . implode('|', $remote_data['variations']); + $remote_parent_id = $remote_data['id']; } $product = [ - 'create_date' => strtotime($remote_data->date_created), + 'create_date' => strtotime($remote_data['date_created']), 'remote_id' => $remote_id, 'remote_parent_id' => $remote_parent_id, 'last_update' => $last_update, - 'fk_product_type' => ($remote_data->virtual ? 1 : 0), // 0 (product) or 1 (service) - 'status' => $remote_data->status, + 'fk_product_type' => ($remote_data['virtual'] ? 1 : 0), // 0 (product) or 1 (service) + 'status' => $remote_data['status'], 'label' => $label, 'price' => $price, - 'envente' => ($isVariation || $product_variation_mode_all_to_one || empty($remote_data->variations) ? 1 : 0), + 'envente' => ($isVariation || $product_variation_mode_all_to_one || empty($remote_data['variations']) ? 1 : 0), 'enachat' => null, 'finished' => 1, // 1 = manufactured, 0 = raw material 'canvas' => $canvas, @@ -1170,48 +1079,48 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote 'categories' => $categories, 'price_min' => '', 'fk_country' => '', - 'url' => $isVariation && $product_variation_mode_all_to_one ? $parent_remote_data->permalink : $remote_data->permalink, + 'url' => $isVariation && $product_variation_mode_all_to_one ? $parent_remote_data['permalink'] : $remote_data['permalink'], // Stock - 'stock_qty' => $remote_data->stock_quantity, - 'is_in_stock' => $remote_data->in_stock, // not used + 'stock_qty' => $remote_data['stock_quantity'], + 'is_in_stock' => $remote_data['in_stock'], // not used 'variations' => $variations, - 'has_variations' => !empty($remote_data->variations), + 'has_variations' => !empty($remote_data['variations']), 'extrafields' => [ - "ecommerceng_wc_regular_price_{$this->site->id}_{$conf->entity}" => $remote_data->regular_price, - "ecommerceng_wc_sale_price_{$this->site->id}_{$conf->entity}" => $remote_data->sale_price, + "ecommerceng_wc_regular_price_{$this->site->id}_{$conf->entity}" => $remote_data['regular_price'], + "ecommerceng_wc_sale_price_{$this->site->id}_{$conf->entity}" => $remote_data['sale_price'], "ecommerceng_wc_date_on_sale_from_{$this->site->id}_{$conf->entity}" => $date_on_sale_from, "ecommerceng_wc_date_on_sale_to_{$this->site->id}_{$conf->entity}" => $date_on_sale_to, - "ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}" => !empty($remote_data->manage_stock) ? 1 : 0, + "ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}" => !empty($remote_data['manage_stock']) ? 1 : 0, ], ]; // Synchronize ref if ($productRefSynchDirection == 'etod' || $productRefSynchDirection == 'all') { - $product['ref'] = $remote_data->sku; + $product['ref'] = $remote_data['sku']; } // Synchronize short and long description if ($productDescriptionSynchDirection == 'etod' || $productDescriptionSynchDirection == 'all') { - $product['extrafields']["ecommerceng_description_{$conf->entity}"] = $this->replace4byte(empty($remote_data->description) ? $parent_remote_data->description : $remote_data->description); + $product['extrafields']["ecommerceng_description_{$conf->entity}"] = $this->replace4byte(empty($remote_data['description']) ? $parent_remote_data['description'] : $remote_data['description']); } if ($productShortDescriptionSynchDirection == 'etod' || $productShortDescriptionSynchDirection == 'all') { - $product['extrafields']["ecommerceng_short_description_{$conf->entity}"] = $this->replace4byte(empty($remote_data->short_description) ? $parent_remote_data->short_description : $remote_data->short_description); + $product['extrafields']["ecommerceng_short_description_{$conf->entity}"] = $this->replace4byte(empty($remote_data['short_description']) ? $parent_remote_data['short_description'] : $remote_data['short_description']); } // Synchronize weight if ($productWeightSynchDirection == 'etod' || $productWeightSynchDirection == 'all') { - $product['weight'] = empty($remote_data->weight) ? $parent_remote_data->weight : $remote_data->weight; + $product['weight'] = empty($remote_data['weight']) ? $parent_remote_data['weight'] : $remote_data['weight']; $product['weight_units'] = $productWeightUnits; } // Synchronize weight if ($productDimensionSynchDirection == 'etod' || $productDimensionSynchDirection == 'all') { - $product['width'] = empty($remote_data->dimensions->width) ? $parent_remote_data->dimensions->width : $remote_data->dimensions->width; + $product['width'] = empty($remote_data['dimensions']['width']) ? $parent_remote_data['dimensions']['width'] : $remote_data['dimensions']['width']; $product['width_units'] = $productDimensionUnits; - $product['height'] = empty($remote_data->dimensions->height) ? $parent_remote_data->dimensions->height : $remote_data->dimensions->height; + $product['height'] = empty($remote_data['dimensions']['height']) ? $parent_remote_data['dimensions']['height'] : $remote_data['dimensions']['height']; $product['height_units'] = $productDimensionUnits; - $product['length'] = empty($remote_data->dimensions->length) ? $parent_remote_data->dimensions->length : $remote_data->dimensions->length; + $product['length'] = empty($remote_data['dimensions']['length']) ? $parent_remote_data['dimensions']['length'] : $remote_data['dimensions']['length']; $product['length_units'] = $productDimensionUnits; } // Synchronize tax - $tax_info = $this->getTaxInfoFromTaxClass(empty($remote_data->tax_class) ? $parent_remote_data->tax_class : $remote_data->tax_class, empty($remote_data->tax_status) ? $parent_remote_data->tax_status : $remote_data->tax_status); + $tax_info = $this->getTaxInfoFromTaxClass(empty($remote_data['tax_class']) ? $parent_remote_data['tax_class'] : $remote_data['tax_class'], empty($remote_data['tax_status']) ? $parent_remote_data['tax_status'] : $remote_data['tax_status']); if (!$isVariation) $product['tax_rate'] = $tax_info['tax_rate']; if ($productTaxSynchDirection == 'etod' || $productTaxSynchDirection == 'all') { if ($isVariation) $product['tax_rate'] = $tax_info['tax_rate']; @@ -1219,17 +1128,17 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote } // Synchronize status if ($productStatusSynchDirection == 'etod' || $productStatusSynchDirection == 'all') { - $product['extrafields']["ecommerceng_wc_status_{$this->site->id}_{$conf->entity}"] = empty($remote_data->status) ? $parent_remote_data->status : $remote_data->status; + $product['extrafields']["ecommerceng_wc_status_{$this->site->id}_{$conf->entity}"] = empty($remote_data['status']) ? $parent_remote_data['status'] : $remote_data['status']; } // Synchronize images if ($productImageSynchDirection == 'etod' || $productImageSynchDirection == 'all') { $images = []; // Image of the product or the parent product if is a variation - $images_data = $isVariation ? $parent_remote_data->images : $remote_data->images; + $images_data = $isVariation ? $parent_remote_data['images'] : $remote_data['images']; $images_data = is_array($images_data) ? $images_data : array(); // Image of the variation - if ($isVariation && !empty($remote_data->image)) $images_data[] = $remote_data->image; + if ($isVariation && !empty($remote_data['image'])) $images_data[] = $remote_data['image']; if (!empty($images_data)) { $media_url = $this->site->webservice_address . (substr($this->site->webservice_address, -1, 1) != '/' ? '/' : '') . 'wp-content/uploads/'; @@ -1251,17 +1160,17 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote // Get metadata $metas_data = array(); if (!empty($this->site->parameters['ef_crp']['product']) || - $remote_data->type == 'woosb' + $remote_data['type'] == 'woosb' ) { - if (is_array($remote_data->meta_data)) { - foreach ($remote_data->meta_data as $meta) { - $metas_data[$meta->key] = $meta; + if (is_array($remote_data['meta_data'])) { + foreach ($remote_data['meta_data'] as $meta) { + $metas_data[$meta['key']] = $meta; } } - if ($isVariation && is_array($parent_remote_data->meta_data)) { - foreach ($parent_remote_data->meta_data as $meta) { - if (!isset($metas_data[$meta->key])) { - $metas_data[$meta->key] = $meta; + if ($isVariation && is_array($parent_remote_data['meta_data'])) { + foreach ($parent_remote_data['meta_data'] as $meta) { + if (!isset($metas_data[$meta['key']])) { + $metas_data[$meta['key']] = $meta; } } } @@ -1276,8 +1185,8 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote } } foreach ($metas_data as $meta) { - if (isset($correspondences[$meta->key])) { - $product['extrafields'][$correspondences[$meta->key]] = $meta->value; + if (isset($correspondences[$meta['key']])) { + $product['extrafields'][$correspondences[$meta['key']]] = $meta['value']; } } } @@ -1285,15 +1194,15 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote // Synchronize attribute to extra fields if (!empty($this->site->parameters['ef_crp_attribute'])) { $attributes = array(); - if (is_array($remote_data->attributes)) { - foreach ($remote_data->attributes as $attribute) { - $attributes[$attribute->name] = $attribute; + if (is_array($remote_data['attributes'])) { + foreach ($remote_data['attributes'] as $attribute) { + $attributes[$attribute['name']] = $attribute; } } - if ($isVariation && is_array($parent_remote_data->attributes)) { - foreach ($parent_remote_data->attributes as $attribute) { - if (!isset($attributes[$attribute->name])) { - $attributes[$attribute->name] = $attribute; + if ($isVariation && is_array($parent_remote_data['attributes'])) { + foreach ($parent_remote_data['attributes'] as $attribute) { + if (!isset($attributes[$attribute['name']])) { + $attributes[$attribute['name']] = $attribute; } } } @@ -1306,17 +1215,17 @@ public function convertProductDataIntoProcessedData($remote_data, $parent_remote } } foreach ($attributes as $attribute) { - if (isset($correspondences[$attribute->id])) { - $product['extrafields'][$correspondences[$attribute->id]] = implode(',', $attribute->options); + if (isset($correspondences[$attribute['id']])) { + $product['extrafields'][$correspondences[$attribute['id']]] = implode(',', $attribute['options']); } } } } // Synchronize bundle to virtual product - if ($remote_data->type == 'woosb' && !empty($metas_data['woosb_ids'])) { + if ($remote_data['type'] == 'woosb' && !empty($metas_data['woosb_ids'])) { // $components = []; -// $list = explode(',', $metas_data['woosb_ids']->value); +// $list = explode(',', $metas_data['woosb_ids']['value']); // foreach ($list as $item) { // $tmp = explode('/', $item); // $components[$tmp[0]] = $tmp[1]; @@ -1380,27 +1289,23 @@ public function convertRemoteObjectIntoDolibarrCommande($from_date = null, $to_d $idxPage = 1; $nbTotalRecords = 0; - while (true) { + do { $filters['page'] = $idxPage++; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET orders (filters: " . json_encode($filters). ")"); - try { - $page = $this->client->get('orders', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'orders', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (!isset($page) || count($page) == 0) break; + if (!isset($page)) $page = array(); foreach ($page as $order) { $order_data = $this->convertOrderDataIntoProcessedData($order); if ($order_data === false) { - $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertOrderData', $order->id)), $this->errors); + $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertOrderData', $order['id'])), $this->errors); return false; } $orders[] = $order_data; @@ -1408,7 +1313,7 @@ public function convertRemoteObjectIntoDolibarrCommande($from_date = null, $to_d } if ($toNb > 0 && $nbTotalRecords >= $toNb) break; - } + } while (count($page) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, converted " . count($orders) . " remote orders", LOG_DEBUG); return $orders; @@ -1429,15 +1334,15 @@ public function convertOrderDataIntoProcessedData($remote_data) // Get provided taxes info $tax_list = array(); - if (!empty($remote_data->tax_lines)) { - foreach ($remote_data->tax_lines as $tax) { - if (!empty($tax->rate_percent)) $tax_list[$tax->rate_id] = price2num($tax->rate_percent); + if (!empty($remote_data['tax_lines'])) { + foreach ($remote_data['tax_lines'] as $tax) { + if (!empty($tax['rate_percent'])) $tax_list[$tax['rate_id']] = price2num($tax['rate_percent']); } } // Set product lines $items = []; - if (!empty($remote_data->line_items)) { + if (!empty($remote_data['line_items'])) { $product_variation_mode_all_to_one = !empty($this->site->parameters['product_variation_mode']) && $this->site->parameters['product_variation_mode'] == 'all_to_one'; $order_metadata_product_lines_to_description_etod = !empty($this->site->parameters['order_metadata_product_lines_to_description_etod']); $order_filter_mode_metadata_product_lines_to_description_etod = !empty($this->site->parameters['order_filter_mode_metadata_product_lines_to_description_etod']) ? $this->site->parameters['order_filter_mode_metadata_product_lines_to_description_etod'] : 'exclude'; @@ -1445,30 +1350,30 @@ public function convertOrderDataIntoProcessedData($remote_data) $bundles_ids = []; $parent_match = array(); - foreach ($remote_data->line_items as $item) { + foreach ($remote_data['line_items'] as $item) { // Get metadata $metas_data = array(); - if (is_array($item->meta_data)) { - foreach ($item->meta_data as $meta) { - $metas_data[$meta->key] = $meta; + if (is_array($item['meta_data'])) { + foreach ($item['meta_data'] as $meta) { + $metas_data[$meta['key']] = $meta; } } // Set prices - $price = $item->subtotal != $item->total ? ($item->subtotal / $item->quantity) : $item->price; - $total_ht = $item->subtotal; - $total_tva = $item->subtotal_tax; - $total_ttc = $item->subtotal + $item->subtotal_tax; + $price = $item['subtotal'] != $item['total'] ? ($item['subtotal'] / $item['quantity']) : $item['price']; + $total_ht = $item['subtotal']; + $total_tva = $item['subtotal_tax']; + $total_ttc = $item['subtotal'] + $item['subtotal_tax']; // Support module bundle to virtual product $item_id = null; if (!empty($metas_data['_woosb_ids'])) { - $bundles_ids[$item->product_id] = $item->id; - if ($item->subtotal != 0) { - $total_ht = $metas_data['_woosb_price']->value / (1 + ($item->subtotal_tax / $item->subtotal)); - $total_tva = $metas_data['_woosb_price']->value - $total_ht; - $total_ttc = $metas_data['_woosb_price']->value; - $price = $total_ht / $item->quantity; + $bundles_ids[$item['product_id']] = $item['id']; + if ($item['subtotal'] != 0) { + $total_ht = $metas_data['_woosb_price']['value'] / (1 + ($item['subtotal_tax'] / $item['subtotal'])); + $total_tva = $metas_data['_woosb_price']['value'] - $total_ht; + $total_ttc = $metas_data['_woosb_price']['value']; + $price = $total_ht / $item['quantity']; } else { $total_ht = 0; $total_tva = 0; @@ -1476,10 +1381,10 @@ public function convertOrderDataIntoProcessedData($remote_data) $price = 0; } } - if (!empty($metas_data['_woosb_parent_id']) && isset($bundles_ids[$metas_data['_woosb_parent_id']->value])) { - $item_id = $bundles_ids[$metas_data['_woosb_parent_id']->value]; + if (!empty($metas_data['_woosb_parent_id']) && isset($bundles_ids[$metas_data['_woosb_parent_id']['value']])) { + $item_id = $bundles_ids[$metas_data['_woosb_parent_id']['value']]; if (!isset($items[$item_id]['additional_description'])) $items[$item_id]['additional_description'] = $langs->trans('ECommerceWooCommerceBundleComposite'); - $items[$item_id]['additional_description'] .= "\n - " . $item->quantity . ' x ' . $item->name; + $items[$item_id]['additional_description'] .= "\n - " . $item['quantity'] . ' x ' . $item['name']; // continue; $total_ht = 0; $total_tva = 0; @@ -1488,30 +1393,30 @@ public function convertOrderDataIntoProcessedData($remote_data) } // Support produits composés - if (!empty($item->composite_children) && is_array($item->composite_children)) { - foreach ($item->composite_children as $child_id) { - $parent_match[$child_id] = $item->id; + if (!empty($item['composite_children']) && is_array($item['composite_children'])) { + foreach ($item['composite_children'] as $child_id) { + $parent_match[$child_id] = $item['id']; } } $item_data = [ - 'parent_item_id' => isset($item_id) ? $item_id : (isset($parent_match[$item->id]) ? $parent_match[$item->id] : 0), - 'item_id' => $item->id, - 'ref' => $item->sku, - 'label' => $item->name, - 'id_remote_product' => !empty($item->variation_id) ? (!$product_variation_mode_all_to_one ? $item->product_id . '|' . $item->variation_id : $item->product_id . '|%') : $item->product_id, + 'parent_item_id' => isset($item_id) ? $item_id : (isset($parent_match[$item['id']]) ? $parent_match[$item['id']] : 0), + 'item_id' => $item['id'], + 'ref' => $item['sku'], + 'label' => $item['name'], + 'id_remote_product' => !empty($item['variation_id']) ? (!$product_variation_mode_all_to_one ? $item['product_id'] . '|' . $item['variation_id'] : $item['product_id'] . '|%') : $item['product_id'], 'product_type' => 'simple', 'price' => $price, 'total_ht' => $total_ht, 'total_tva' => $total_tva, 'total_ttc' => $total_ttc, - 'qty' => $item->quantity, + 'qty' => $item['quantity'], 'discount' => 0, 'buy_price' => null, ]; // Taxes - $taxes = $this->getTaxesInfoFromRemoteData($item->taxes, $tax_list); + $taxes = $this->getTaxesInfoFromRemoteData($item['taxes'], $tax_list); if ($taxes === false) return false; $item_data['tva_tx'] = $taxes['tva_tx']; $item_data['local_tax1_tx'] = $taxes['local_tax1_tx']; @@ -1519,10 +1424,10 @@ public function convertOrderDataIntoProcessedData($remote_data) $item_data['total_local_tax1'] = $taxes['total_local_tax1']; $item_data['total_local_tax2'] = $taxes['total_local_tax2']; - if (isset($item->cog_item_cost)) $item_data['buy_price'] = $this->site->ecommerce_price_type == 'TTC' ? 100 * $item->cog_item_cost / (100 + $item_data['tva_tx']) : $item->cog_item_cost; - if ($this->site->ecommerce_price_type == 'TTC') $item_data['price'] = (100 * $total_ttc / (100 + $item_data['tva_tx'])) / $item->quantity; + if (isset($item['cog_item_cost'])) $item_data['buy_price'] = $this->site->ecommerce_price_type == 'TTC' ? 100 * $item['cog_item_cost'] / (100 + $item_data['tva_tx']) : $item['cog_item_cost']; + if ($this->site->ecommerce_price_type == 'TTC') $item_data['price'] = (100 * $total_ttc / (100 + $item_data['tva_tx'])) / $item['quantity']; - if (!empty($item->meta_data)) { + if (!empty($item['meta_data'])) { // Synch extrafields <=> metadatas if (!empty($this->site->parameters['ef_crp']['commandedet'])) { $correspondences = array(); @@ -1531,52 +1436,52 @@ public function convertOrderDataIntoProcessedData($remote_data) $correspondences[$options_saved['correspondences']] = $key; } } - foreach ($item->meta_data as $meta) { - if (isset($correspondences[$meta->key])) { - $item_data['extrafields'][$correspondences[$meta->key]] = $meta->value; + foreach ($item['meta_data'] as $meta) { + if (isset($correspondences[$meta['key']])) { + $item_data['extrafields'][$correspondences[$meta['key']]] = $meta['value']; } } } // Add meta-data in description if ($order_metadata_product_lines_to_description_etod) { $metadata_in_description = array(); - foreach ($item->meta_data as $meta) { - if (!empty($meta->display_key) && !empty($meta->display_value) && !is_array($meta->display_value) && !is_object($meta->display_value) && ( - ($order_filter_mode_metadata_product_lines_to_description_etod == 'include' && in_array($meta->key, $order_filter_keys_metadata_product_lines_to_description_etod)) || - ($order_filter_mode_metadata_product_lines_to_description_etod == 'exclude' && !in_array($meta->key, $order_filter_keys_metadata_product_lines_to_description_etod)) + foreach ($item['meta_data'] as $meta) { + if (!empty($meta['display_key']) && !empty($meta['display_value']) && !is_array($meta['display_value']) && !is_object($meta['display_value']) && ( + ($order_filter_mode_metadata_product_lines_to_description_etod == 'include' && in_array($meta['key'], $order_filter_keys_metadata_product_lines_to_description_etod)) || + ($order_filter_mode_metadata_product_lines_to_description_etod == 'exclude' && !in_array($meta['key'], $order_filter_keys_metadata_product_lines_to_description_etod)) ) ) { - $metadata_in_description[] = $meta->display_key . ' : ' . $meta->display_value; + $metadata_in_description[] = $meta['display_key'] . ' : ' . $meta['display_value']; } } if (!empty($metadata_in_description)) $item_data['additional_description'] = implode('
', $metadata_in_description); } } - $items[$item->id] = $item_data; + $items[$item['id']] = $item_data; } } // Set shipping lines - if (!empty($remote_data->shipping_lines)) { + if (!empty($remote_data['shipping_lines'])) { $shipment_service_id = $this->site->parameters['shipping_service'] > 0 ? $this->site->parameters['shipping_service'] : 0; - foreach ($remote_data->shipping_lines as $item) { + foreach ($remote_data['shipping_lines'] as $item) { $item_data = [ - 'item_id' => $item->id, + 'item_id' => $item['id'], 'id_product' => $shipment_service_id, - 'label' => $langs->trans('ECommerceShipping') . (!empty($item->method_title) ? ' - ' . $item->method_title : ''), - 'description' => $langs->trans('ECommerceShipping') . (!empty($item->method_title) ? ' - ' . $item->method_title : ''), + 'label' => $langs->trans('ECommerceShipping') . (!empty($item['method_title']) ? ' - ' . $item['method_title'] : ''), + 'description' => $langs->trans('ECommerceShipping') . (!empty($item['method_title']) ? ' - ' . $item['method_title'] : ''), 'product_type' => 'shipment', - 'price' => $item->total, - 'total_ht' => $item->total, - 'total_tva' => $item->total_tax, - 'total_ttc' => ($item->total + $item->total_tax), + 'price' => $item['total'], + 'total_ht' => $item['total'], + 'total_tva' => $item['total_tax'], + 'total_ttc' => ($item['total'] + $item['total_tax']), 'qty' => 1, 'discount' => 0, ]; // Taxes - $taxes = $this->getTaxesInfoFromRemoteData($item->taxes, $tax_list); + $taxes = $this->getTaxesInfoFromRemoteData($item['taxes'], $tax_list); if ($taxes === false) return false; $item_data['tva_tx'] = $taxes['tva_tx']; $item_data['local_tax1_tx'] = $taxes['local_tax1_tx']; @@ -1584,20 +1489,20 @@ public function convertOrderDataIntoProcessedData($remote_data) $item_data['total_local_tax1'] = $taxes['total_local_tax1']; $item_data['total_local_tax2'] = $taxes['total_local_tax2']; - if ($this->site->ecommerce_price_type == 'TTC') $item_data['price'] = 100 * ($item->total + $item->total_tax) / (100 + $item_data['tva_tx']); + if ($this->site->ecommerce_price_type == 'TTC') $item_data['price'] = 100 * ($item['total'] + $item['total_tax']) / (100 + $item_data['tva_tx']); $item_data['buy_price'] = $item_data['price']; // Synch extrafields <=> metadatas - if (!empty($item->meta_data) && !empty($this->site->parameters['ef_crp']['commandedet'])) { + if (!empty($item['meta_data']) && !empty($this->site->parameters['ef_crp']['commandedet'])) { $correspondences = array(); foreach ($this->site->parameters['ef_crp']['commandedet'] as $key => $options_saved) { if ($options_saved['activated'] && !empty($options_saved['correspondences'])) { $correspondences[$options_saved['correspondences']] = $key; } } - foreach ($item->meta_data as $meta) { - if (isset($correspondences[$meta->key])) { - $item_data['extrafields'][$correspondences[$meta->key]] = $meta->value; + foreach ($item['meta_data'] as $meta) { + if (isset($correspondences[$meta['key']])) { + $item_data['extrafields'][$correspondences[$meta['key']]] = $meta['value']; } } } @@ -1607,18 +1512,18 @@ public function convertOrderDataIntoProcessedData($remote_data) } // Set discount code lines - if (!empty($remote_data->coupon_lines)) { + if (!empty($remote_data['coupon_lines'])) { $discount_code_service_id = $this->site->parameters['discount_code_service'] > 0 ? $this->site->parameters['discount_code_service'] : 0; // if (!($discount_code_service_id > 0)) { // $this->errors[] = $langs->trans('ECommerceWooCommerceErrorDiscountCodeServiceNotConfigured', $this->site->name); // return false; // } - foreach ($remote_data->coupon_lines as $item) { + foreach ($remote_data['coupon_lines'] as $item) { $item_data = [ - 'item_id' => $item->id, + 'item_id' => $item['id'], 'id_product' => $discount_code_service_id, - 'label' => $item->code, - 'description' => $item->code, + 'label' => $item['code'], + 'description' => $item['code'], 'product_type' => 'discount_code', 'qty' => 1, 'discount' => 0, @@ -1631,12 +1536,12 @@ public function convertOrderDataIntoProcessedData($remote_data) // Taxes $tax_rate = 0; - foreach ($remote_data->tax_lines as $data) { - if (empty($data->tax_total)) continue; - if ($data->rate_percent > $tax_rate) $tax_rate = $data->rate_percent; + foreach ($remote_data['tax_lines'] as $data) { + if (empty($data['tax_total'])) continue; + if ($data['rate_percent'] > $tax_rate) $tax_rate = $data['rate_percent']; } - $ttc = $item->discount + $item->discount_tax; + $ttc = $item['discount'] + $item['discount_tax']; $tva = $tax_rate * $ttc / ($tax_rate + 100); $ht = 100 * $ttc / ($tax_rate + 100); @@ -1647,16 +1552,16 @@ public function convertOrderDataIntoProcessedData($remote_data) $item_data['total_ttc'] = -$ttc; // Synch extrafields <=> metadatas - if (!empty($item->meta_data) && !empty($this->site->parameters['ef_crp']['commandedet'])) { + if (!empty($item['meta_data']) && !empty($this->site->parameters['ef_crp']['commandedet'])) { $correspondences = array(); foreach ($this->site->parameters['ef_crp']['commandedet'] as $key => $options_saved) { if ($options_saved['activated'] && !empty($options_saved['correspondences'])) { $correspondences[$options_saved['correspondences']] = $key; } } - foreach ($item->meta_data as $meta) { - if (isset($correspondences[$meta->key])) { - $item_data['extrafields'][$correspondences[$meta->key]] = $meta->value; + foreach ($item['meta_data'] as $meta) { + if (isset($correspondences[$meta['key']])) { + $item_data['extrafields'][$correspondences[$meta['key']]] = $meta['value']; } } } @@ -1666,22 +1571,22 @@ public function convertOrderDataIntoProcessedData($remote_data) } // Set gift card lines - if (!empty($remote_data->pw_gift_cards_redeemed)) { + if (!empty($remote_data['pw_gift_cards_redeemed'])) { $gift_cards_service_id = $this->site->parameters['pw_gift_cards_service'] > 0 ? $this->site->parameters['pw_gift_cards_service'] : 0; // if (!($gift_cards_service_id > 0)) { // $this->errors[] = $langs->trans('ECommerceWooCommerceErrorPwGiftCardsServiceNotConfigured', $this->site->name); // return false; // } - foreach ($remote_data->pw_gift_cards_redeemed as $gift_cards) { + foreach ($remote_data['pw_gift_cards_redeemed'] as $gift_cards) { $items[] = [ 'product_type' => 'pw_gift_cards', 'id_product' => $gift_cards_service_id, - 'description' => $gift_cards->number, - 'label' => $gift_cards->number, - 'price' => - $gift_cards->amount, - 'total_ht' => - $gift_cards->amount, + 'description' => $gift_cards['number'], + 'label' => $gift_cards['number'], + 'price' => - $gift_cards['amount'], + 'total_ht' => - $gift_cards['amount'], 'total_tva' => 0, - 'total_ttc' => - $gift_cards->amount, + 'total_ttc' => - $gift_cards['amount'], 'qty' => 1, 'discount' => 0, 'buy_price' => 0, @@ -1697,17 +1602,17 @@ public function convertOrderDataIntoProcessedData($remote_data) // Set fee lines $fee_lines = []; $fee_line_as_item_line = !empty($this->site->parameters['order_actions']['fee_line_as_item_line']); - if (!empty($remote_data->fee_lines)) { - foreach ($remote_data->fee_lines as $fee_line) { + if (!empty($remote_data['fee_lines'])) { + foreach ($remote_data['fee_lines'] as $fee_line) { $line = [ - 'label' => $fee_line->name, - 'total_ht' => $fee_line->total, - 'total_tva' => $fee_line->total_tax, - 'total_ttc' => ($fee_line->total + $fee_line->total_tax), + 'label' => $fee_line['name'], + 'total_ht' => $fee_line['total'], + 'total_tva' => $fee_line['total_tax'], + 'total_ttc' => ($fee_line['total'] + $fee_line['total_tax']), ]; // Taxes - $taxes = $this->getTaxesInfoFromRemoteData($fee_line->taxes, $tax_list); + $taxes = $this->getTaxesInfoFromRemoteData($fee_line['taxes'], $tax_list); if ($taxes === false) return false; $line['tva_tx'] = $taxes['tva_tx']; $line['local_tax1_tx'] = $taxes['local_tax1_tx']; @@ -1718,8 +1623,8 @@ public function convertOrderDataIntoProcessedData($remote_data) if ($fee_line_as_item_line) { $line['product_type'] = 'service'; $line['id_product'] = 0; - $line['description'] = $fee_line->name; - $line['price'] = $fee_line->total; + $line['description'] = $fee_line['name']; + $line['price'] = $fee_line['total']; $line['qty'] = 1; $line['discount'] = 0; $line['buy_price'] = 0; @@ -1731,16 +1636,16 @@ public function convertOrderDataIntoProcessedData($remote_data) } } // Manage fees in meta data (stripe payment, ...) - if (!empty($remote_data->meta_data)) { - foreach ($remote_data->meta_data as $meta) { - if ($meta->key == '_stripe_fee') { + if (!empty($remote_data['meta_data'])) { + foreach ($remote_data['meta_data'] as $meta) { + if ($meta['key'] == '_stripe_fee') { $fee_lines[] = [ 'label' => 'Stripe', 'qty' => 1, - 'price' => $meta->value, - 'total_ht' => $meta->value, + 'price' => $meta['value'], + 'total_ht' => $meta['value'], 'total_tva' => 0, - 'total_ttc' => $meta->value, + 'total_ttc' => $meta['value'], 'tva_tx' => 0, 'local_tax1_tx' => 0, 'local_tax2_tx' => 0, @@ -1752,13 +1657,13 @@ public function convertOrderDataIntoProcessedData($remote_data) } } - $create_date = $this->getDateTimeFromGMTDateTime($remote_data->date_created_gmt); - $last_update = $this->getDateTimeFromGMTDateTime(!empty($remote_data->date_modified_gmt) ? $remote_data->date_modified_gmt : $remote_data->date_created_gmt); + $create_date = $this->getDateTimeFromGMTDateTime($remote_data['date_created_gmt']); + $last_update = $this->getDateTimeFromGMTDateTime(!empty($remote_data['date_modified_gmt']) ? $remote_data['date_modified_gmt'] : $remote_data['date_created_gmt']); // Set billing's address - $bContact = $remote_data->billing; - $firstname = $bContact->first_name; - $lastname = $bContact->last_name; + $bContact = $remote_data['billing']; + $firstname = $bContact['first_name']; + $lastname = $bContact['last_name']; if (!empty($conf->global->ECOMMERCENG_UPPERCASE_LASTNAME)) { $firstname = dol_ucwords(dol_strtolower($firstname)); $lastname = dol_strtoupper($lastname); @@ -1772,15 +1677,15 @@ public function convertOrderDataIntoProcessedData($remote_data) 'remote_id' => "", 'type' => 1, //eCommerceSocpeople::CONTACT_TYPE_ORDER, 'last_update' => $last_update->format('Y-m-d H:i:s'), - 'company' => $bContact->company, + 'company' => $bContact['company'], 'firstname' => $firstname, 'lastname' => $lastname, - 'address' => $bContact->address_1 . (!empty($bContact->address_1) && !empty($bContact->address_2) ? "\n" : "") . $bContact->address_2, - 'zip' => $bContact->postcode, - 'town' => $bContact->city, - 'country_id' => getCountry($bContact->country, 3), - 'email' => $bContact->email, - 'phone' => $bContact->phone, + 'address' => $bContact['address_1'] . (!empty($bContact['address_1']) && !empty($bContact['address_2']) ? "\n" : "") . $bContact['address_2'], + 'zip' => $bContact['postcode'], + 'town' => $bContact['city'], + 'country_id' => getCountry($bContact['country'], 3), + 'email' => $bContact['email'], + 'phone' => $bContact['phone'], 'fax' => null, ]; @@ -1789,18 +1694,18 @@ public function convertOrderDataIntoProcessedData($remote_data) $contactInvoice['type'] = 1; //eCommerceSocpeople::CONTACT_TYPE_INVOICE; // Set shipping's address - $sContact = $remote_data->shipping; - if ((!empty($sContact->first_name) || !empty($sContact->last_name)) && - (!empty($sContact->address_1) || !empty($sContact->address_2)) && - !empty($sContact->postcode) && !empty($sContact->city) + $sContact = $remote_data['shipping']; + if ((!empty($sContact['first_name']) || !empty($sContact['last_name'])) && + (!empty($sContact['address_1']) || !empty($sContact['address_2'])) && + !empty($sContact['postcode']) && !empty($sContact['city']) ) { - if ($bContact->first_name != $sContact->first_name || $bContact->last_name != $sContact->last_name || - $bContact->address_1 != $sContact->address_1 || $bContact->address_2 != $sContact->address_2 || - $bContact->postcode != $sContact->postcode || $bContact->city != $sContact->city || - $bContact->country != $sContact->country + if ($bContact['first_name'] != $sContact['first_name'] || $bContact['last_name'] != $sContact['last_name'] || + $bContact['address_1'] != $sContact['address_1'] || $bContact['address_2'] != $sContact['address_2'] || + $bContact['postcode'] != $sContact['postcode'] || $bContact['city'] != $sContact['city'] || + $bContact['country'] != $sContact['country'] ) { - $firstname = $sContact->first_name; - $lastname = $sContact->last_name; + $firstname = $sContact['first_name']; + $lastname = $sContact['last_name']; if (!empty($conf->global->ECOMMERCENG_UPPERCASE_LASTNAME)) { $firstname = dol_ucwords(dol_strtolower($firstname)); $lastname = dol_strtoupper($lastname); @@ -1811,10 +1716,10 @@ public function convertOrderDataIntoProcessedData($remote_data) $lastname = $langs->transnoentitiesnoconv('ECommerceFirstNameLastNameNotInformed'); } $email = null; - if (!empty($remote_data->meta_data)) { - foreach ($remote_data->meta_data as $meta) { - if ($meta->key == '_shipping_email') { - $email = $meta->value; + if (!empty($remote_data['meta_data'])) { + foreach ($remote_data['meta_data'] as $meta) { + if ($meta['key'] == '_shipping_email') { + $email = $meta['value']; break; } } @@ -1823,19 +1728,19 @@ public function convertOrderDataIntoProcessedData($remote_data) 'remote_id' => "", 'type' => 1, //eCommerceSocpeople::CONTACT_TYPE_DELIVERY, 'last_update' => $last_update->format('Y-m-d H:i:s'), - 'company' => $sContact->company, + 'company' => $sContact['company'], 'firstname' => $firstname, 'lastname' => $lastname, - 'address' => $sContact->address_1 . (!empty($sContact->address_1) && !empty($sContact->address_2) ? "\n" : "") . $sContact->address_2, - 'zip' => $sContact->postcode, - 'town' => $sContact->city, - 'country_id' => getCountry($sContact->country, 3), + 'address' => $sContact['address_1'] . (!empty($sContact['address_1']) && !empty($sContact['address_2']) ? "\n" : "") . $sContact['address_2'], + 'zip' => $sContact['postcode'], + 'town' => $sContact['city'], + 'country_id' => getCountry($sContact['country'], 3), 'email' => $email, - 'phone' => isset($sContact->phone) ? $sContact->phone : null, + 'phone' => isset($sContact['phone']) ? $sContact['phone'] : null, 'fax' => null, ]; - if (empty($sContact->company)) { + if (empty($sContact['company'])) { if (!empty($firstname) && !empty($lastname)) { $name = dolGetFirstLastname($firstname, $lastname); } elseif (!empty($firstname)) { @@ -1845,7 +1750,7 @@ public function convertOrderDataIntoProcessedData($remote_data) } $contactShipping['company_name'] = $name; } else { - $contactShipping['company_name'] = $sContact->company; + $contactShipping['company_name'] = $sContact['company']; } } else { $contactShipping = $contactBilling; @@ -1857,27 +1762,27 @@ public function convertOrderDataIntoProcessedData($remote_data) } // Set status of order - // $remote_data->status is: 'pending', 'processing', 'on-hold', 'completed', 'cancelled', 'refunded', 'failed', 'trash' + // $remote_data['status'] is: 'pending', 'processing', 'on-hold', 'completed', 'cancelled', 'refunded', 'failed', 'trash' $status = ''; - if (isset($this->site->parameters['order_status_etod'][$remote_data->status])) - $status = substr($this->site->parameters['order_status_etod'][$remote_data->status]['selected'], 1); + if (isset($this->site->parameters['order_status_etod'][$remote_data['status']])) + $status = substr($this->site->parameters['order_status_etod'][$remote_data['status']]['selected'], 1); if ($status == '') { - dol_syslog(__METHOD__ . ": Status \"{$remote_data->status}\" was not found for remote order ID {$remote_data->id} and set in draft", LOG_ERR); + dol_syslog(__METHOD__ . ": Status \"{$remote_data['status']}\" was not found for remote order ID {$remote_data['id']} and set in draft", LOG_ERR); // $status = Commande::STATUS_DRAFT; // draft by default - $this->errors[] = $langs->trans('ECommerceWooCommerceErrorOrderStatusNotConfigured', $remote_data->status, $this->site->name); + $this->errors[] = $langs->trans('ECommerceWooCommerceErrorOrderStatusNotConfigured', $remote_data['status'], $this->site->name); return false; } // Set dolibarr billed status (payed or not) $billed = -1; // unknown - if (isset($this->site->parameters['order_status_etod'][$remote_data->status])) - $billed = $this->site->parameters['order_status_etod'][$remote_data->status]['billed']; + if (isset($this->site->parameters['order_status_etod'][$remote_data['status']])) + $billed = $this->site->parameters['order_status_etod'][$remote_data['status']]['billed']; // Note: with processing, billed can be 0 or 1, so we keep -1 // Dont synchro order $synchronize = 1; - if (isset($this->site->parameters['order_status_etod'][$remote_data->status])) - $synchronize = $this->site->parameters['order_status_etod'][$remote_data->status]['synchronize']; + if (isset($this->site->parameters['order_status_etod'][$remote_data['status']])) + $synchronize = $this->site->parameters['order_status_etod'][$remote_data['status']]['synchronize']; $orderStatus = ''; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; @@ -1891,7 +1796,7 @@ public function convertOrderDataIntoProcessedData($remote_data) if (is_array($options_list)) { foreach ($options_list as $key => $value) { $key_test = ($pos = strpos($key, '_')) > 0 ? substr($key, $pos + 1) : $key; - if ($key_test == $remote_data->status) { + if ($key_test == $remote_data['status']) { $orderStatus = $key; break; } @@ -1902,50 +1807,50 @@ public function convertOrderDataIntoProcessedData($remote_data) $order = [ 'create_date' => $create_date->getTimestamp(), 'last_update' => $last_update->format('Y-m-d H:i:s'), - 'remote_id' => $remote_data->id, - 'remote_increment_id' => $remote_data->id, - 'remote_id_societe' => $remote_data->customer_id, - 'ref_client' => $remote_data->number, - 'date_commande' => $remote_data->date_created, - 'date_payment' => $remote_data->date_paid, - 'date_livraison' => $remote_data->date_completed, - 'total_ht' => $remote_data->total - $remote_data->total_tax, - 'total_tva' => $remote_data->total_tax, - 'total_ttc' => $remote_data->total, + 'remote_id' => $remote_data['id'], + 'remote_increment_id' => $remote_data['id'], + 'remote_id_societe' => $remote_data['customer_id'], + 'ref_client' => $remote_data['number'], + 'date_commande' => $remote_data['date_created'], + 'date_payment' => $remote_data['date_paid'], + 'date_livraison' => $remote_data['date_completed'], + 'total_ht' => $remote_data['total'] - $remote_data['total_tax'], + 'total_tva' => $remote_data['total_tax'], + 'total_ttc' => $remote_data['total'], 'items' => $items, - 'note' => $this->replace4byte($remote_data->customer_note), + 'note' => $this->replace4byte($remote_data['customer_note']), 'socpeopleCommande' => $contactBilling, 'socpeopleFacture' => $contactInvoice, 'socpeopleLivraison' => $contactShipping, 'status' => $status, // dolibarr status 'billed' => $billed, 'synchronize' => !empty($synchronize), - 'remote_state' => $remote_data->status, // remote state, for information only (less accurate than status) - 'remote_status' => $remote_data->status, // remote status, for information only (more accurate than state) + 'remote_state' => $remote_data['status'], // remote state, for information only (less accurate than status) + 'remote_status' => $remote_data['status'], // remote status, for information only (more accurate than state) 'remote_order' => $remote_data, - 'payment_method' => $remote_data->payment_method_title, - 'payment_method_id' => $remote_data->payment_method, - 'payment_amount_ttc' => $remote_data->total, + 'payment_method' => $remote_data['payment_method_title'], + 'payment_method_id' => $remote_data['payment_method'], + 'payment_amount_ttc' => $remote_data['total'], 'fee_lines' => $fee_lines, 'extrafields' => [ - "ecommerceng_online_payment_{$conf->entity}" => empty($remote_data->transaction_id) ? 0 : 1, + "ecommerceng_online_payment_{$conf->entity}" => empty($remote_data['transaction_id']) ? 0 : 1, "ecommerceng_wc_status_{$this->site->id}_{$conf->entity}" => $orderStatus, - "ecommerceng_wc_link_{$this->site->id}_{$conf->entity}" => rtrim($this->site->webservice_address, '/') . '/wp-admin/post.php?action=edit&post=' . $remote_data->id, + "ecommerceng_wc_link_{$this->site->id}_{$conf->entity}" => rtrim($this->site->webservice_address, '/') . '/wp-admin/post.php?action=edit&post=' . $remote_data['id'], ], ]; // Synch extrafields <=> metadatas - if (!empty($remote_data->meta_data) && !empty($this->site->parameters['ef_crp']['commande'])) { + if (!empty($remote_data['meta_data']) && !empty($this->site->parameters['ef_crp']['commande'])) { $correspondences = array(); foreach ($this->site->parameters['ef_crp']['commande'] as $key => $options_saved) { if ($options_saved['activated'] && !empty($options_saved['correspondences'])) { $correspondences[$options_saved['correspondences']] = $key; } } - foreach ($remote_data->meta_data as $meta) { - if (isset($correspondences[$meta->key])) { - $extrafield_value = $meta->value; - $extrafield_key = $correspondences[$meta->key]; + foreach ($remote_data['meta_data'] as $meta) { + if (isset($correspondences[$meta['key']])) { + $extrafield_value = $meta['value']; + $extrafield_key = $correspondences[$meta['key']]; // Specific Altairis - Begin if (!empty($extrafield_value) && ($extrafield_key == 'rental_start' || $extrafield_key == 'rental_end')) { $extrafield_value = strtotime($extrafield_value); @@ -1957,10 +1862,10 @@ public function convertOrderDataIntoProcessedData($remote_data) } // Manage payment (stripe payment, ...) - if (!empty($remote_data->meta_data)) { - foreach ($remote_data->meta_data as $meta) { - if ($meta->key == '_payplug_metadata') { - $order['payment_amount_ttc'] = $meta->value->amount / 100; + if (!empty($remote_data['meta_data'])) { + foreach ($remote_data['meta_data'] as $meta) { + if ($meta['key'] == '_payplug_metadata') { + $order['payment_amount_ttc'] = $meta['value']['amount'] / 100; break; } } @@ -2006,36 +1911,33 @@ public function getRemoteCategoryTree() $idxPage = 1; $per_page = empty($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL) ? 100 : min($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL, 100); - while (true) { + do { $filters = [ 'page' => $idxPage++, 'per_page' => $per_page, ]; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/categories (filters: " . json_encode($filters). ")"); - try { - $results = $this->client->get('products/categories', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetRemoteCategoryTree', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetRemoteCategoryTree', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } - if (count($results) == 0) break; - - foreach ($results as $category) { - $categories[$category->id] = [ - 'category_id' => $category->id, // id category - 'parent_id' => $category->parent, - 'label' => $category->name, - 'name' => $category->name, - 'description' => $category->description, + + $page = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products/categories', [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($page) && ($idxPage == 2 || $status_code != 403)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetRemoteCategoryTree', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + if (!isset($page)) $page = array(); + + foreach ($page as $category) { + $categories[$category['id']] = [ + 'category_id' => $category['id'], // id category + 'parent_id' => $category['parent'], + 'label' => $category['name'], + 'name' => $category['name'], + 'description' => $category['description'], 'updated_at' => '', ]; } - } + } while (count($page) == $per_page); // Set tree foreach ($categories as $category) { @@ -2092,29 +1994,26 @@ public function getCategoryData($category_id) $this->errors = array(); $category = []; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/categories/{$category_id}"); - try { - $result = $this->client->get('products/categories/' . $category_id); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetCategoryData', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetCategoryData', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'products/categories/' . $category_id, [], false, $code_status); + if (!isset($result)) { + if ($code_status == 404) { + return $category; + } - if (isset($result)) { - $category = [ - 'category_id' => $result->id, // id category - 'parent_id' => $result->parent, - 'label' => $result->name, - 'name' => $result->name, - 'description' => $result->description, - 'updated_at' => '', - ]; - } + $this->errors[] = $langs->trans('ECommerceWoocommerceGetCategoryData', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + $category = [ + 'category_id' => $result['id'], // id category + 'parent_id' => $result['parent'], + 'label' => $result['name'], + 'name' => $result['name'], + 'description' => $result['description'], + 'updated_at' => '', + ]; dol_syslog(__METHOD__ . ": end", LOG_DEBUG); return $category; @@ -2266,62 +2165,32 @@ public function convertObjectIntoProductData($remote_id, $object) if (!empty($remote_product_id)) { if ($isProductVariation) { // Variations foreach ($remote_product_variation_ids as $remote_product_variation_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}/variations/{$remote_product_variation_id}"); - $results = $this->client->get("products/$remote_product_id/variations/$remote_product_variation_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - - if (!empty($results)) { - if ($isProductVariation) { - if (isset($results->image)) { - $current_images[$results->image->name] = $results->image->id; - } - } else { - if (is_array($results->images)) { - foreach ($results->images as $image) { - $current_images[$image->name] = $image->id; - } - } - } - } - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $results = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$remote_product_id}/variations/{$remote_product_variation_id}"); + if (!isset($results)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $remote_product_id . '|' . $remote_product_variation_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return array(); } + + if (isset($results['image'])) { + $current_images[$results['image']['name']] = $results['image']['id']; + } } } else { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}"); - $results = $this->client->get("products/$remote_product_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - - if (!empty($results)) { - if ($isProductVariation) { - if (isset($results->image)) { - $current_images[$results->image->name] = $results->image->id; - } - } else { - if (is_array($results->images)) { - foreach ($results->images as $image) { - $current_images[$image->name] = $image->id; - } - } - } - } - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $results = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$remote_product_id}"); + if (!isset($results)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return array(); } + + if (is_array($results['images'])) { + foreach ($results['images'] as $image) { + $current_images[$image['name']] = $image['id']; + } + } } } @@ -2569,18 +2438,41 @@ public function convertObjectIntoProductData($remote_id, $object) $object->array_options["options_ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}"] = $variationData['manage_stock'] ? 1 : 0; if ($variationData['manage_stock'] && empty($object->array_options["options_ecommerceng_wc_dont_update_stock_{$this->site->id}_{$conf->entity}"])) { - $supported_warehouses = is_array($this->site->parameters['fk_warehouse_to_ecommerce']) ? $this->site->parameters['fk_warehouse_to_ecommerce'] : array(); $object->load_stock(); - $stock = 0; - foreach ($supported_warehouses as $warehouse_id) { - $stock += isset($object->stock_warehouse[$warehouse_id]->real) ? $object->stock_warehouse[$warehouse_id]->real : 0; - } - $stock = floor($stock); + $total_stock = 0; + if (!empty($this->site->parameters['enable_warehouse_plugin_sl_support'])) { + dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php'); + $eCommerceRemoteWarehouses = new eCommerceRemoteWarehouses($this->db); + $remote_warehouses = $eCommerceRemoteWarehouses->get_all($this->site->id); + if (!is_array($remote_warehouses)) { + $this->errors[] = $eCommerceRemoteWarehouses->errorsToString(); + return array(); + } - $variationData['stock_quantity'] = $stock; - $variationData['in_stock'] = $stock > 0; - } + $stock_by_location = array(); + foreach ($remote_warehouses as $remote_code => $info) { + $stock = isset($object->stock_warehouse[$info['warehouse_id']]->real) ? $object->stock_warehouse[$info['warehouse_id']]->real : 0; + $total_stock += $stock; + $stock_by_location[] = [ + 'id' => $info['remote_id'], + 'quantity' => $stock, + ]; + } + if (!empty($stock_by_location)) { + $variationData['locations'] = $stock_by_location; + } + } else { + $supported_warehouses = is_array($this->site->parameters['fk_warehouse_to_ecommerce']) ? $this->site->parameters['fk_warehouse_to_ecommerce'] : array(); + foreach ($supported_warehouses as $warehouse_id) { + $total_stock += isset($object->stock_warehouse[$warehouse_id]->real) ? $object->stock_warehouse[$warehouse_id]->real : 0; + } + $total_stock = floor($total_stock); + } + + $variationData['stock_quantity'] = $total_stock; + $variationData['in_stock'] = $total_stock > 0; + } } // Synch extrafields <=> metadatas and attributes @@ -2810,17 +2702,40 @@ public function convertObjectIntoProductData($remote_id, $object) $object->array_options["options_ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}"] = $productData['manage_stock'] ? 1 : 0; if ($productData['manage_stock'] && empty($object->array_options["options_ecommerceng_wc_dont_update_stock_{$this->site->id}_{$conf->entity}"])) { - $supported_warehouses = is_array($this->site->parameters['fk_warehouse_to_ecommerce']) ? $this->site->parameters['fk_warehouse_to_ecommerce'] : array(); $object->load_stock(); - $stock = 0; - foreach ($supported_warehouses as $warehouse_id) { - $stock += isset($object->stock_warehouse[$warehouse_id]->real) ? $object->stock_warehouse[$warehouse_id]->real : 0; - } - $stock = floor($stock); + $total_stock = 0; + if (!empty($this->site->parameters['enable_warehouse_plugin_sl_support'])) { + dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php'); + $eCommerceRemoteWarehouses = new eCommerceRemoteWarehouses($this->db); + $remote_warehouses = $eCommerceRemoteWarehouses->get_all($this->site->id); + if (!is_array($remote_warehouses)) { + $this->errors[] = $eCommerceRemoteWarehouses->errorsToString(); + return array(); + } + + $stock_by_location = array(); + foreach ($remote_warehouses as $remote_code => $info) { + $stock = isset($object->stock_warehouse[$info['warehouse_id']]->real) ? $object->stock_warehouse[$info['warehouse_id']]->real : 0; + $total_stock += $stock; + $stock_by_location[] = [ + 'id' => $info['remote_id'], + 'quantity' => $stock, + ]; + } + if (!empty($stock_by_location)) { + $productData['locations'] = $stock_by_location; + } + } else { + $supported_warehouses = is_array($this->site->parameters['fk_warehouse_to_ecommerce']) ? $this->site->parameters['fk_warehouse_to_ecommerce'] : array(); + foreach ($supported_warehouses as $warehouse_id) { + $total_stock += isset($object->stock_warehouse[$warehouse_id]->real) ? $object->stock_warehouse[$warehouse_id]->real : 0; + } + $total_stock = floor($total_stock); + } - $productData['stock_quantity'] = $stock; - $productData['in_stock'] = $stock > 0; + $productData['stock_quantity'] = $total_stock; + $productData['in_stock'] = $total_stock > 0; } } @@ -2883,40 +2798,26 @@ public function updateRemoteProduct($remote_id, $object) $remote_id = $datas['product']['remote_id']; $remote_data = $datas['product']['data']; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$remote_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("products/$remote_id", $remote_data); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$remote_id' : Data: " . json_encode($remote_data), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProduct', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProduct', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$remote_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $remote_data]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProduct', $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } // Support for WPML (Update (others than name and descriptions) infos on translated post) if (!empty($conf->global->ECOMMERCENG_WOOCOMMERCE_WPML_SUPPORT)) { - if (isset($result->translations)) { + if (isset($result['translations'])) { if (isset($remote_data['name'])) unset($remote_data['name']); if (isset($remote_data['description'])) unset($remote_data['description']); if (isset($remote_data['short_description'])) unset($remote_data['short_description']); - foreach ((array)$result->translations as $product_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$product_id}"); - if (!self::$disable_put_post_to_api) $res = $this->client->put("products/$product_id", $remote_data); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$product_id' : Data: " . json_encode($remote_data), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteTranslatedProduct', $product_id, $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteTranslatedProduct', $product_id, $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + foreach ((array)$result['translations'] as $product_id) { + $res = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$product_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $remote_data]); + if (!isset($res)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteTranslatedProduct', $product_id, $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } @@ -2932,53 +2833,34 @@ public function updateRemoteProduct($remote_id, $object) $remote_variation_id = $variation_data['remote_id']; $remote_data = $variation_data['data']; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$remote_id}/variations/{$remote_variation_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("products/$remote_id/variations/$remote_variation_id", $remote_data); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$remote_id/variations/$remote_variation_id' : Data: " . json_encode($remote_data), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductVariation', $remote_variation_id, $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProductVariation', $remote_variation_id, $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$remote_id}/variations/{$remote_variation_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $remote_data]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductVariation', $remote_variation_id, $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } // Support for WPML (Update (others than name and descriptions) infos on translated post) if (!empty($conf->global->ECOMMERCENG_WOOCOMMERCE_WPML_SUPPORT)) { - if (isset($result->translations)) { + if (isset($result['translations'])) { if (isset($remote_data['name'])) unset($remote_data['name']); if (isset($remote_data['description'])) unset($remote_data['description']); if (isset($remote_data['short_description'])) unset($remote_data['short_description']); - foreach ((array)$result->translations as $product_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$product_id}"); - $result2 = $this->client->get("products/$product_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_variation_id, $remote_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_variation_id, $remote_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage() . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + foreach ((array)$result['translations'] as $product_id) { + $result2 = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$product_id}"); + if (!isset($result2)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_variation_id, $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$result2->parent_id}/variations/{$product_id}"); - if (!self::$disable_put_post_to_api) $res = $this->client->put("products/{$result2->parent_id}/variations/$product_id", $remote_data); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/{$result2->parent_id}/variations/$product_id' : Data: " . json_encode($remote_data), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteTranslatedProductVariation', $result2->parent_id . '|' . $product_id, $remote_variation_id, $remote_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteTranslatedProductVariation', $result2->parent_id . '|' . $product_id, $remote_variation_id, $remote_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage() . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + $res = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$result2['parent_id']}/variations/$product_id", [GuzzleHttp\RequestOptions::FORM_PARAMS => $remote_data]); + if (!isset($res)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteTranslatedProductVariation', $result2['parent_id'] . '|' . $product_id, $remote_variation_id, $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } @@ -2995,24 +2877,68 @@ public function updateRemoteProduct($remote_id, $object) * Update the remote stock of product * * @param int $remote_id Id of product on remote ecommerce - * @param MouvementStock $object MouvementStock object, enhanced with property qty_after be the trigger STOCK_MOVEMENT. * @param Product $product Product object * * @return boolean True or false */ - public function updateRemoteStockProduct($remote_id, $object, $product) + public function updateRemoteStockProduct($remote_id, $product) { - dol_syslog(__METHOD__ . ": Update stock of the remote product ID $remote_id for MouvementStock ID {$object->id}, new qty: {$object->qty_after} for site ID {$this->site->id}", LOG_DEBUG); + dol_syslog(__METHOD__ . ": Update stock of the remote product ID $remote_id for product ID {$product->id} for site ID {$this->site->id}", LOG_DEBUG); global $conf, $langs, $user; - if (empty($product->array_options["options_ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}"]) || !empty($product->array_options["options_ecommerceng_wc_dont_update_stock_{$this->site->id}_{$conf->entity}"])) { - dol_syslog(__METHOD__ . " - Ignore update stock of the remote product ID $remote_id for MouvementStock ID {$object->id}, new qty: {$object->qty_after} for site ID {$this->site->id}", LOG_INFO); - return true; + $this->errors = array(); + + $update_stock = false; + $productData = array(); + if ($this->site->stock_sync_direction == 'dolibarr2ecommerce') { + $productData['manage_stock'] = !empty($product->array_options["options_ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}"]); + $product->array_options["options_ecommerceng_wc_manage_stock_{$this->site->id}_{$conf->entity}"] = $productData['manage_stock'] ? 1 : 0; + + if ($productData['manage_stock'] && empty($product->array_options["options_ecommerceng_wc_dont_update_stock_{$this->site->id}_{$conf->entity}"])) { + $product->load_stock(); + + $total_stock = 0; + if (!empty($this->site->parameters['enable_warehouse_plugin_sl_support'])) { + dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehouses.class.php'); + $eCommerceRemoteWarehouses = new eCommerceRemoteWarehouses($this->db); + $remote_warehouses = $eCommerceRemoteWarehouses->get_all($this->site->id); + if (!is_array($remote_warehouses)) { + $this->errors[] = $eCommerceRemoteWarehouses->errorsToString(); + return false; + } + + $stock_by_location = array(); + foreach ($remote_warehouses as $remote_code => $info) { + $stock = isset($product->stock_warehouse[$info['warehouse_id']]->real) ? $product->stock_warehouse[$info['warehouse_id']]->real : 0; + $total_stock += $stock; + $stock_by_location[] = [ + 'id' => $info['remote_id'], + 'quantity' => $stock, + ]; + } + if (!empty($stock_by_location)) { + $productData['locations'] = $stock_by_location; + } + } else { + $supported_warehouses = is_array($this->site->parameters['fk_warehouse_to_ecommerce']) ? $this->site->parameters['fk_warehouse_to_ecommerce'] : array(); + foreach ($supported_warehouses as $warehouse_id) { + $total_stock += isset($product->stock_warehouse[$warehouse_id]->real) ? $product->stock_warehouse[$warehouse_id]->real : 0; + } + $total_stock = floor($total_stock); + } + +// $productData['manage_stock'] = false; // boolean Stock management at product or variation level. Default is false. + $productData['stock_quantity'] = $total_stock; // integer Stock quantity. + $productData['in_stock'] = $total_stock > 0; // boolean Controls whether or not the variation is listed as “in stock” or “out of stock” on the frontend. Default is true. +// $productData['backorders'] = 'no'; // string If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no. + $update_stock = true; + } } - $this->errors = array(); - $new_stocks = floor($object->qty_after); - $stocks_label = $object->qty_after . ' -> ' . $new_stocks; + if (!$update_stock) { + dol_syslog(__METHOD__ . " - Ignore update stock of the remote product ID $remote_id for Product ID {$product->id} for site ID {$this->site->id}", LOG_INFO); + return true; + } $isProductVariation = false; $isProductVariationHasOne = false; @@ -3035,101 +2961,56 @@ public function updateRemoteStockProduct($remote_id, $object, $product) } } - if ($isProductVariation || $isProductVariationHasOne) { - // Variations - $variationData = [ - //'manage_stock' => '', // boolean Stock management at variation level. Default is false. - 'stock_quantity' => $new_stocks, // integer Stock quantity. - 'in_stock' => $new_stocks > 0, // boolean Controls whether or not the variation is listed as “in stock” or “out of stock” on the frontend. Default is true. - //'backorders' => '', // string If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no. - ]; - + // Variation + if ($isProductVariation || $isProductVariationHasOne) { foreach ($remote_product_variation_ids as $remote_product_variation_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$remote_product_id}/variations/{$remote_product_variation_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("products/$remote_product_id/variations/$remote_product_variation_id", $variationData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$remote_product_id/variations/$remote_product_variation_id' : Data: " . json_encode($variationData), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockProductVariation', $stocks_label, $remote_product_variation_id, $remote_product_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteStockProductVariation', $stocks_label, $remote_product_variation_id, $remote_product_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse(), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$remote_product_id}/variations/{$remote_product_variation_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $productData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockProductVariation', $productData['stock_quantity'], $remote_product_variation_id, $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } } // Product if (!$isProductVariation || $isProductVariationHasOne) { - $productData = [ - //'manage_stock' => false, // boolean Stock management at product level. Default is false. - 'stock_quantity' => $new_stocks, // integer Stock quantity. - 'in_stock' => $new_stocks > 0, // boolean Controls whether or not the product is listed as “in stock” or “out of stock” on the frontend. Default is true. - //'backorders' => '', // string If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no. - ]; - - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$remote_product_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("products/$remote_product_id", $productData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$remote_product_id' : Data: " . json_encode($productData), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockProduct', $stocks_label, $remote_product_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteStockProduct', $stocks_label, $remote_product_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse(), LOG_ERR); - return false; - } + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$remote_product_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $productData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockProduct', $productData['stock_quantity'], $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } } // Support for WPML (Update stocks infos on translated post) if (!empty($conf->global->ECOMMERCENG_WOOCOMMERCE_WPML_SUPPORT)) { if ($isProductVariation || $isProductVariationHasOne) { foreach ($remote_product_variation_ids as $remote_product_variation_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_variation_id}"); - $result = $this->client->get("products/$remote_product_variation_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetProductVariation', $remote_product_variation_id, $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetProductVariation', $remote_product_variation_id, $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage() . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$remote_product_variation_id}"); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetProductVariation', $remote_product_variation_id, $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (isset($result->translations)) { - foreach ((array)$result->translations as $product_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$product_id}"); - $result2 = $this->client->get("products/$product_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_product_variation_id, $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_product_variation_id, $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage() . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + + if (isset($result['translations'])) { + foreach ((array)$result['translations'] as $product_id) { + $result2 = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$product_id}"); + if (!isset($result2)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetTranslatedProductVariation', $product_id, $remote_product_variation_id, $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$result2->parent_id}/variations/{$product_id}"); - if (!self::$disable_put_post_to_api) $res = $this->client->put("products/{$result2->parent_id}/variations/$product_id", $variationData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/{$result2->parent_id}/variations/$product_id' : Data: " . json_encode($variationData), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockTranslatedProductVariation', $stocks_label, $result2->parent_id . '|' . $product_id, $remote_product_variation_id, $remote_product_id) . ': ' . $this->site->name . ' - ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteStockTranslatedProductVariation', $stocks_label, $result2->parent_id . '|' . $product_id, $remote_product_variation_id, $remote_product_id) . ': ' . $this->site->name . ' - ' . $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse(), LOG_ERR); + + $res = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$result2['parent_id']}/variations/{$product_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $productData]); + if (!isset($res)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockTranslatedProductVariation', $productData['stock_quantity'], $result2['parent_id'] . '|' . $product_id, $remote_product_variation_id, $remote_product_id) . ': ' . $this->site->name; + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } @@ -3137,33 +3018,21 @@ public function updateRemoteStockProduct($remote_id, $object, $product) } } if (!$isProductVariation || $isProductVariationHasOne) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}"); - $result = $this->client->get("products/$remote_product_id"); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetProduct', $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetProduct', $remote_product_id, $this->site->name) . ': ' . $fault->getCode() . ': ' . $fault->getMessage() . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/{$remote_product_id}"); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetProduct', $remote_product_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } - if (isset($result->translations)) { - foreach ((array)$result->translations as $product_id) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT products/{$product_id}"); - if (!self::$disable_put_post_to_api) $res = $this->client->put("products/$product_id", $productData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send PUT to API 'products/$product_id' : Data: " . json_encode($productData), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockTranslatedProduct', $stocks_label, $product_id, $remote_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage(); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteStockTranslatedProduct', $stocks_label, $product_id, $remote_id, $this->site->name) . ' ' . $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse(), LOG_ERR); + + if (isset($result['translations'])) { + foreach ((array)$result['translations'] as $product_id) { + $res = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/{$product_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $productData]); + if (!isset($res)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteStockTranslatedProduct', $productData['stock_quantity'], $product_id, $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } @@ -3221,19 +3090,13 @@ public function updateRemoteSociete($remote_id, $object) } } - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT customers/{$remote_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("customers/$remote_id", $companyData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteSociete', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteSociete', $remote_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "customers/{$remote_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $companyData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteSociete', $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } dol_syslog(__METHOD__ . ": end", LOG_DEBUG); return true; @@ -3298,20 +3161,14 @@ public function updateRemoteSocpeople($remote_id, $object) } if (isset($contactData)) { - if (preg_match('/^(\d+)\|(\d+)$/', $remote_id, $idsCustomer) == 1) { - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT customers/{$idsCustomer[1]}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("customers/$idsCustomer[1]", $contactData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteSocpeople', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteSocpeople', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + if (preg_match('/^(\d+)\|(\d+)$/', $remote_id, $idsCustomer)) { + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "customers/{$idsCustomer[1]}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $contactData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteSocpeople', $idsCustomer[1], $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } } } @@ -3362,7 +3219,7 @@ public function updateRemoteCommande($remote_id, $object) $wc_status = $object->array_options["options_ecommerceng_wc_status_{$this->site->id}_{$conf->entity}"]; if ($order_status[$status] < $order_status[$wc_status] && - !empty($conf->global->ECOMMERCENG_WOOCOMMERCE_ORDER_STATUS_LVL_CHECK)) $status = $wc_status; + !empty($this->site->parameters['order_status_dtoe_check_lvl_status'])) $status = $wc_status; $orderData = [ 'status' => $status, // string Order status. Options: pending, processing, on-hold, completed, cancelled, refunded and failed. @@ -3389,19 +3246,13 @@ public function updateRemoteCommande($remote_id, $object) } } - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT orders/{$remote_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("orders/$remote_id", $orderData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "orders/{$remote_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $orderData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteCommande', $remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } $object->array_options["options_ecommerceng_wc_status_{$this->site->id}_{$conf->entity}"] = $order_status[$status] . '_' . $status; $object->insertExtraFields(); @@ -3455,19 +3306,14 @@ public function createRemoteProduct($object) $this->errors = array(); $filters = ['sku' => $object->ref]; - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products (filters: " . json_encode($filters). ")"); - try { - $results = $this->client->get('products', $filters); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceCheckRemoteProductExist', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceCheckRemoteProductExist', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } - $results = isset($results->products) ? $results->products : is_array($results) ? $results : []; + $results = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products", [GuzzleHttp\RequestOptions::QUERY => $filters], false, $status_code); + if (!isset($results) && $status_code != 404) { + $this->errors[] = $langs->trans('ECommerceWoocommerceCheckRemoteProductExist', $object->ref, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + $results = isset($results['products']) ? $results['products'] : is_array($results) ? $results : []; $remote_id = ''; $remote_url = ''; @@ -3490,20 +3336,11 @@ public function createRemoteProduct($object) if (!empty($datas['product'])) { $remote_data = $datas['product']['data']; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - POST products - Product ID: {$object->id} - Data: " . json_encode($remote_data)); - if (!self::$disable_put_post_to_api) $res = $this->client->post("products", $remote_data); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $remote_id = $res->id; - $remote_url = $res->permalink; - dol_syslog(__METHOD__ . " - Send POST to API 'products' : Data: " . json_encode($remote_data) . "; Remote ID: $remote_id", LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceCreateRemoteProduct', $object->id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceCreateRemoteProduct', $object->id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_POST, "products", [GuzzleHttp\RequestOptions::FORM_PARAMS => $remote_data]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceCreateRemoteProduct', $object->id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } } @@ -3585,29 +3422,20 @@ public function createRemoteCategories($batch) $requestGroups = $this->getRequestGroups($group, $nb_max_by_request); foreach ($requestGroups as $request) { - $error = 0; - - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - POST products/categories/batch"); - if (!self::$disable_put_post_to_api) $results = $this->client->post("products/categories/batch", ['create' => $request]); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - dol_syslog(__METHOD__ . " - Send POST to API 'products/categories/batch' : Data: " . json_encode(['create' => $request]), LOG_NOTICE); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceCreateRemoteBatchCategories', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceCreateRemoteBatchCategories', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $results = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "products/categories/batch", [GuzzleHttp\RequestOptions::FORM_PARAMS => ['create' => $request]]); + if (!isset($results)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceCreateRemoteBatchCategories', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } - $results = isset($results->create) ? $results->create : array(); + $results = isset($results['create']) ? $results['create'] : array(); foreach ($results as $key => $item) { - if (isset($item->error)) { - $this->errors[] = $langs->trans('ECommerceWoocommerceCreateRemoteBatchCategory', $request[$key]['slug'], $this->site->name,$item->error->code . ': ' . $item->error->message . ' (data : ' . json_encode($item->error->data) . ' )'); - dol_syslog(__METHOD__ . ': Error:' . - $langs->trans('ECommerceWoocommerceCreateRemoteBatchCategory', $request[$key]['slug'], $this->site->name, $item->error->code . ': ' . $item->error->message . ' (data : ' . json_encode($item->error->data) . ' )'), LOG_ERR); + if (isset($item['error'])) { + $error_msg = $langs->trans('ECommerceWoocommerceCreateRemoteBatchCategory', $request[$key]['slug'], $this->site->name) . $item['error']['code'] . ': ' . $item['error']['message'] . ' (data : ' . json_encode($item['error']['data']) . ' )'; + $this->errors[] = $error_msg; + dol_syslog(__METHOD__ . ' - Error: ' . $error_msg, LOG_ERR); } else { $cats_id_remote_id[$cats_slug_id[$item->slug]] = array('remote_id' => $item->id, 'remote_parent_id' => $item->parent); } @@ -3903,105 +3731,105 @@ public function batchUpdateRemoteProducts($batch) continue; } - // images - $images = []; - if ($productImageSynchDirection == 'dtoe' || $productImageSynchDirection == 'all') { - // Get current images - $current_images = []; - $stopwatch_id = -1; - try { - if ($isProductVariation) { // Variations - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}/variations/{$remote_product_variation_id}"); - $results = $this->client->get("products/$remote_product_id/variations/$remote_product_variation_id"); - } else { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}"); - $results = $this->client->get("products/$remote_product_id"); - } - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - - if (!empty($results)) { - if ($isProductVariation) { - if (isset($results->image)) { - $current_images[$results->image->name] = $results->image->id; - } - } else { - if (is_array($results->images)) { - foreach ($results->images as $image) { - $current_images[$image->name] = $image->id; - } - } - } - } - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - continue; - } - - // Product - Images properties - $entity = isset($product_static->entity) ? $product_static->entity : $conf->entity; - if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs - if ($product_static->type == Product::TYPE_PRODUCT) { - $dir = $conf->product->multidir_output[$entity] . '/' . substr(substr("000" . $product_static->id, -2), 1, 1) . '/' . substr(substr("000" . $product_static->id, -2), 0, 1) . '/' . $product_static->id . "/photos/"; - } else { - $dir = $conf->service->multidir_output[$entity] . '/' . substr(substr("000" . $product_static->id, -2), 1, 1) . '/' . substr(substr("000" . $product_static->id, -2), 0, 1) . '/' . $product_static->id . "/photos/"; - } - } else { - if (version_compare(DOL_VERSION, "13.0.0") >= 0) { - if ($product_static->type == Product::TYPE_PRODUCT) { - $dir = $conf->product->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 1, $product_static, 'product') . '/'; - } else { - $dir = $conf->service->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 1, $product_static, 'product') . '/'; - } - } else { - if ($product_static->type == Product::TYPE_PRODUCT) { - $dir = $conf->product->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 0, $product_static, 'product') . dol_sanitizeFileName($product_static->ref) . '/'; - } else { - $dir = $conf->service->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 0, $product_static, 'product') . dol_sanitizeFileName($product_static->ref) . '/'; - } - } - } - $photos = $product_static->liste_photos($dir); - foreach ($photos as $index => $photo) { - $img = []; - - $filename = ecommerceng_wordpress_sanitize_file_name($photo['photo']); - if (!isset($current_images[$filename])) { - $result = $this->worpressclient->postmedia("media", $dir . $photo['photo'], [ - 'slug' => $product_static->id . '_' . $filename, - 'ping_status' => 'closed', - 'comment_status' => 'closed', - ]); - - if ($result === null) { - $error_msg = $langs->trans($batch_infos['type'] == 'update' ? 'ECommerceWoocommerceUpdateRemoteProductSendImage' : 'ECommerceWoocommerceCreateRemoteProductSendImage', $batch_infos['type'] == 'update' ? $batch_infos['remote_id'] : $product_static->ref, $this->site->name, implode('; ', $this->worpressclient->errors)); - $this->errors[] = $error_msg; - dol_syslog(__METHOD__ . ': Error:' . $error_msg, LOG_ERR); - continue; - } elseif (!empty($result['message'])) { - $error_msg = $langs->trans($batch_infos['type'] == 'update' ? 'ECommerceWoocommerceUpdateRemoteProductSendImage' : 'ECommerceWoocommerceCreateRemoteProductSendImage', $batch_infos['type'] == 'update' ? $batch_infos['remote_id'] : $product_static->ref, $this->site->name, $result['code'] . ' - ' . $result['message']); - $this->errors[] = $error_msg; - dol_syslog(__METHOD__ . ': Error:' . $error_msg, LOG_ERR); - continue; - } - - $img['id'] = $result['id']; - } else { - $img['id'] = $current_images[$filename]; - } - - $img['name'] = $filename; - $img['position'] = $index; - $images[] = $img; - - if ($isProductVariation) { // Get only one image for variation - break; - } - } - } +// // images +// $images = []; +// if ($productImageSynchDirection == 'dtoe' || $productImageSynchDirection == 'all') { +// // Get current images +// $current_images = []; +// $stopwatch_id = -1; +// try { +// if ($isProductVariation) { // Variations +// $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}/variations/{$remote_product_variation_id}"); +// $results = $this->client->get("products/$remote_product_id/variations/$remote_product_variation_id"); +// } else { +// $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/{$remote_product_id}"); +// $results = $this->client->get("products/$remote_product_id"); +// } +// eCommerceUtils::stopAndLogStopwatch($stopwatch_id); +// +// if (!empty($results)) { +// if ($isProductVariation) { +// if (isset($results->image)) { +// $current_images[$results->image->name] = $results->image->id; +// } +// } else { +// if (is_array($results->images)) { +// foreach ($results->images as $image) { +// $current_images[$image->name] = $image->id; +// } +// } +// } +// } +// } catch (HttpClientException $fault) { +// eCommerceUtils::stopAndLogStopwatch($stopwatch_id); +// $this->errors[] = $langs->trans('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); +// dol_syslog(__METHOD__ . +// ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . +// ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); +// continue; +// } +// +// // Product - Images properties +// $entity = isset($product_static->entity) ? $product_static->entity : $conf->entity; +// if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs +// if ($product_static->type == Product::TYPE_PRODUCT) { +// $dir = $conf->product->multidir_output[$entity] . '/' . substr(substr("000" . $product_static->id, -2), 1, 1) . '/' . substr(substr("000" . $product_static->id, -2), 0, 1) . '/' . $product_static->id . "/photos/"; +// } else { +// $dir = $conf->service->multidir_output[$entity] . '/' . substr(substr("000" . $product_static->id, -2), 1, 1) . '/' . substr(substr("000" . $product_static->id, -2), 0, 1) . '/' . $product_static->id . "/photos/"; +// } +// } else { +// if (version_compare(DOL_VERSION, "13.0.0") >= 0) { +// if ($product_static->type == Product::TYPE_PRODUCT) { +// $dir = $conf->product->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 1, $product_static, 'product') . '/'; +// } else { +// $dir = $conf->service->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 1, $product_static, 'product') . '/'; +// } +// } else { +// if ($product_static->type == Product::TYPE_PRODUCT) { +// $dir = $conf->product->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 0, $product_static, 'product') . dol_sanitizeFileName($product_static->ref) . '/'; +// } else { +// $dir = $conf->service->multidir_output[$entity] . '/' . get_exdir(0, 0, 0, 0, $product_static, 'product') . dol_sanitizeFileName($product_static->ref) . '/'; +// } +// } +// } +// $photos = $product_static->liste_photos($dir); +// foreach ($photos as $index => $photo) { +// $img = []; +// +// $filename = ecommerceng_wordpress_sanitize_file_name($photo['photo']); +// if (!isset($current_images[$filename])) { +// $result = $this->worpressclient->postmedia("media", $dir . $photo['photo'], [ +// 'slug' => $product_static->id . '_' . $filename, +// 'ping_status' => 'closed', +// 'comment_status' => 'closed', +// ]); +// +// if ($result === null) { +// $error_msg = $langs->trans($batch_infos['type'] == 'update' ? 'ECommerceWoocommerceUpdateRemoteProductSendImage' : 'ECommerceWoocommerceCreateRemoteProductSendImage', $batch_infos['type'] == 'update' ? $batch_infos['remote_id'] : $product_static->ref, $this->site->name, implode('; ', $this->worpressclient->errors)); +// $this->errors[] = $error_msg; +// dol_syslog(__METHOD__ . ': Error:' . $error_msg, LOG_ERR); +// continue; +// } elseif (!empty($result['message'])) { +// $error_msg = $langs->trans($batch_infos['type'] == 'update' ? 'ECommerceWoocommerceUpdateRemoteProductSendImage' : 'ECommerceWoocommerceCreateRemoteProductSendImage', $batch_infos['type'] == 'update' ? $batch_infos['remote_id'] : $product_static->ref, $this->site->name, $result['code'] . ' - ' . $result['message']); +// $this->errors[] = $error_msg; +// dol_syslog(__METHOD__ . ': Error:' . $error_msg, LOG_ERR); +// continue; +// } +// +// $img['id'] = $result['id']; +// } else { +// $img['id'] = $current_images[$filename]; +// } +// +// $img['name'] = $filename; +// $img['position'] = $index; +// $images[] = $img; +// +// if ($isProductVariation) { // Get only one image for variation +// break; +// } +// } +// } // Product - Meta data properties $product_static->fetch_optionals(); @@ -4340,18 +4168,54 @@ public function sendFileForCommande($order_remote_id, $company_remote_id, $objec global $langs; $this->errors = array(); + + $data = [ + [ + 'name' => 'slug', + 'contents' => $order_remote_id . '_' . $object->element, + ], + [ + 'name' => 'author', + 'contents' => $company_remote_id, + ], + [ + 'name' => 'post', + 'contents' => $order_remote_id, + ], + [ + 'name' => 'ping_status', + 'contents' => 'closed', + ], + [ + 'name' => 'comment_status', + 'contents' => 'closed', + ], + ]; + + // Set File + if (file_exists($file)) { + if (function_exists('curl_file_create')) { // php 5.5+ + $cFile = curl_file_create($file); + } else { + $cFile = '@' . realpath($file); + } + $data[] = [ + 'name' => 'file', + 'filename' => basename($file), + 'contents' => $cFile, +// 'headers' => [ 'Content-Type' => $content_type ], + ]; + $data['file'] = $cFile; + } else { + $this->errors[] = array('File not found ("'.$file.'").'); + return false; + } + // Send file to WordPress - $result = $this->worpressclient->postmedia("media", $file, [ - 'slug' => $order_remote_id . '_' . $object->element, - 'author' => $company_remote_id, - 'post' => $order_remote_id, - 'ping_status' => 'closed', - 'comment_status' => 'closed', - ]); + $result = $this->worpressclient->sendToApi(eCommerceClientApi::METHOD_POST, "media", [ GuzzleHttp\RequestOptions::MULTIPART => $data ]); if ($result === null) { - $this->errors[] = $langs->trans('ECommerceWoocommerceSendFileForCommandeInWordpress', $order_remote_id, $this->site->name, implode('; ', $this->worpressclient->errors)); - dol_syslog(__METHOD__ . ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceSendFileForCommandeInWordpress', - $order_remote_id, $this->site->name, implode('; ', $this->worpressclient->errors)), LOG_ERR); + $this->errors[] = $langs->trans('ECommerceWoocommerceSendFileForCommandeInWordpress', $order_remote_id, $this->site->name, $this->worpressclient->errorsToString('; ')); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } @@ -4372,19 +4236,13 @@ public function sendFileForCommande($order_remote_id, $company_remote_id, $objec ], ] ]; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - PUT orders/{$order_remote_id}"); - if (!self::$disable_put_post_to_api) $result = $this->client->put("orders/$order_remote_id", $commandeData); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceSendFileForCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceSendFileForCommande', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $result = $this->client->sendToApi(eCommerceClientApi::METHOD_PUT, "orders/{$order_remote_id}", [GuzzleHttp\RequestOptions::FORM_PARAMS => $commandeData]); + if (!isset($result)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceSendFileForCommande', $order_remote_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } dol_syslog(__METHOD__ . ": end", LOG_DEBUG); return true; @@ -4407,11 +4265,11 @@ private function getTaxesInfoFromRemoteData($taxes_data, $tax_list = array()) if (!empty(self::$taxes_rates_cached) || !empty($tax_list)) { foreach ($taxes_data as $data) { - if (empty($data->total)) continue; + if (empty($data['total'])) continue; $count++; if ($count > 1) break; - $tax_id = $data->id; + $tax_id = $data['id']; if (isset($tax_list[$tax_id])) { $tva_tx = $tax_list[$tax_id]; } else { @@ -4562,32 +4420,25 @@ public function getAllWoocommerceAttributes() $nb_max_by_request = empty($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL) ? 100 : min($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL, 100); $attributes_list = []; - $idxPage = 0; + $idxPage = 1; do { - $idxPage++; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/attributes"); - $attributes = $this->client->get('products/attributes', - [ - 'page' => $idxPage, - 'per_page' => $nb_max_by_request, - ] - ); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceAttributes', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetAllWoocommerceAttributes', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $filters = [ + 'page' => $idxPage++, + 'per_page' => $nb_max_by_request, + ]; + + $attributes = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/attributes", [GuzzleHttp\RequestOptions::QUERY => $filters]); + if (!isset($attributes)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceAttributes', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } foreach ($attributes as $attribute) { - $attributes_list[$attribute->id] = $attribute; + $attributes_list[$attribute['id']] = $attribute; } - } while (!empty($attibutes)); + } while (count($attributes) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, return: ".json_encode($attributes_list), LOG_DEBUG); return $attributes_list; @@ -4607,32 +4458,25 @@ public function getAllWoocommerceAttributeTerms($attribute_id) $nb_max_by_request = empty($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL) ? 100 : min($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL, 100); $terms_list = []; - $idxPage = 0; + $idxPage = 1; do { - $idxPage++; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET products/attributes/$attribute_id/terms"); - $terms = $this->client->get('products/attributes/' . $attribute_id . '/terms', - [ - 'page' => $idxPage, - 'per_page' => $nb_max_by_request, - ] - ); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceAttributeTerms', $attribute_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetAllWoocommerceAttributeTerms', $attribute_id, $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $filters = [ + 'page' => $idxPage++, + 'per_page' => $nb_max_by_request, + ]; + + $terms = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "products/attributes/{$attribute_id}/terms", [GuzzleHttp\RequestOptions::QUERY => $filters]); + if (!isset($terms)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceAttributeTerms', $attribute_id, $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } foreach ($terms as $term) { - $terms_list[$term->id] = $term; + $terms_list[$term['id']] = $term; } - } while (!empty($terms)); + } while (count($terms) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, return: ".json_encode($terms_list), LOG_DEBUG); return $terms_list; @@ -4648,24 +4492,18 @@ public function getAllWoocommerceTaxClass() dol_syslog(__METHOD__ . ": Retrieve all Woocommerce tax classes", LOG_DEBUG); global $langs; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET taxes/classes"); - $tax_classes = $this->client->get('taxes/classes'); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceTaxClass', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetAllWoocommerceTaxClass', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $tax_classes = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, "taxes/classes"); + if (!isset($tax_classes)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceTaxClass', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } $taxClassesTable = []; foreach ($tax_classes as $tax_class) { - unset($tax_class->_links); - $taxClassesTable[$tax_class->slug] = $tax_class; + unset($tax_class['_links']); + $taxClassesTable[$tax_class['slug']] = $tax_class; } dol_syslog(__METHOD__ . ": end, return: ".json_encode($taxClassesTable), LOG_DEBUG); @@ -4685,33 +4523,26 @@ public function getAllWoocommerceTaxRate() $nb_max_by_request = empty($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL) ? 100 : min($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL, 100); $taxClassesTable = []; - $idxPage = 0; + $idxPage = 1; do { - $idxPage++; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET taxes"); - $taxes = $this->client->get('taxes', - [ - 'page' => $idxPage, - 'per_page' => $nb_max_by_request, - ] - ); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetWoocommerceTaxes', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetWoocommerceTaxes', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $filters = [ + 'page' => $idxPage++, + 'per_page' => $nb_max_by_request, + ]; + + $taxes = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'taxes', [GuzzleHttp\RequestOptions::QUERY => $filters]); + if (!isset($taxes)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetWoocommerceTaxes', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } foreach ($taxes as $tax) { - unset($tax->_links); - $taxClassesTable[$tax->id] = $tax; + unset($tax['_links']); + $taxClassesTable[$tax['id']] = $tax; } - } while (!empty($taxes)); + } while (count($taxes) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, return: ".json_encode($taxClassesTable), LOG_DEBUG); return $taxClassesTable; @@ -4725,33 +4556,71 @@ public function getAllWoocommerceTaxRate() public function getAllPaymentGateways() { dol_syslog(__METHOD__ . ": Retrieve all Woocommerce payment gateways", LOG_DEBUG); - global $langs; + global $conf, $langs; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET payment_gateways"); - $payment_gateways = $this->client->get('payment_gateways'); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommercePaymentGateways', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceGetAllWoocommercePaymentGateways', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); - return false; - } + $nb_max_by_request = empty($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL) ? 100 : min($conf->global->ECOMMERCENG_MAXSIZE_MULTICALL, 100); - $paymentGatewaysTable = []; - foreach ($payment_gateways as $infos) { - if ($infos->enabled) { - $paymentGatewaysTable[$infos->id] = $infos->method_title . (!empty($infos->title) ? ' - ' . $infos->title : ''); - } - } + $paymentGatewaysTable = []; + $idxPage = 1; + do { + $filters = [ + 'page' => $idxPage++, + 'per_page' => $nb_max_by_request, + ]; + + $payment_gateways = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'payment_gateways', [GuzzleHttp\RequestOptions::QUERY => $filters]); + if (!isset($payment_gateways)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommercePaymentGateways', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + foreach ($payment_gateways as $infos) { + if ($infos['enabled']) { + $paymentGatewaysTable[$infos['id']] = $infos['method_title'] . (!empty($infos['title']) ? ' - ' . $infos['title'] : ''); + } + } + } while (count($payment_gateways) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, return: ".json_encode($paymentGatewaysTable), LOG_DEBUG); return $paymentGatewaysTable; } + /** + * Get all remote warehouses + * + * @return array|false List of remote warehouses or false if error + */ + public function getAllRemoteWarehouses() + { + dol_syslog(__METHOD__ . ": Retrieve all Woocommerce remote warehouses", LOG_DEBUG); + global $langs; + $remoteWarehousesTable = []; + + // plugin SL support + if (!empty($this->site->parameters['enable_warehouse_plugin_sl_support'])) { + $remote_warehouses = $this->worpressclient->sendToApi(eCommerceClientApi::METHOD_GET, 'location'); + if (!isset($remote_warehouses)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceGetAllWoocommerceRemoteWarehouses', $this->site->name); + $this->errors[] = $this->worpressclient->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); + return false; + } + + foreach ($remote_warehouses as $infos) { + $remoteWarehousesTable[$infos["slug"]] = [ + 'remote_id' => $infos["id"], + 'name' => $infos["name"], + 'parent' => $infos["parent"], + ]; + } + } + + dol_syslog(__METHOD__ . ": end, return: ".json_encode($remoteWarehousesTable), LOG_DEBUG); + return $remoteWarehousesTable; + } + /** * Get all webhooks * @@ -4770,43 +4639,36 @@ public function getAllWebHooks() $eCommerceSiteWebHooksUrl = $currentUri->getAbsoluteUri(); $webhooks_list = []; - $idxPage = 0; + $idxPage = 1; do { - $idxPage++; - $stopwatch_id = -1; - try { - $stopwatch_id = eCommerceUtils::startStopwatch(__METHOD__ . " - GET webhooks"); - $webhooks = $this->client->get('webhooks', - [ - 'page' => $idxPage, - 'per_page' => $nb_max_by_request, - ] - ); - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - } catch (HttpClientException $fault) { - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - $this->errors[] = $langs->trans('ECommerceWoocommerceErrorGetWoocommerceWebHooks', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()); - dol_syslog(__METHOD__ . - ': Error:' . $langs->transnoentitiesnoconv('ECommerceWoocommerceErrorGetWoocommerceWebHooks', $this->site->name, $fault->getCode() . ': ' . $fault->getMessage()) . - ' - Request:' . json_encode($fault->getRequest()) . ' - Response:' . json_encode($fault->getResponse()), LOG_ERR); + $filters = [ + 'page' => $idxPage++, + 'per_page' => $nb_max_by_request, + ]; + + $webhooks = $this->client->sendToApi(eCommerceClientApi::METHOD_GET, 'webhooks', [GuzzleHttp\RequestOptions::QUERY => $filters]); + if (!isset($webhooks)) { + $this->errors[] = $langs->trans('ECommerceWoocommerceErrorGetWoocommerceWebHooks', $this->site->name); + $this->errors[] = $this->client->errorsToString(); + dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR); return false; } foreach ($webhooks as $webhook) { - if ($webhook->delivery_url == $eCommerceSiteWebHooksUrl) { - $webhooks_list[$webhook->id] = array( - 'remote_id' => $webhook->id, - 'name' => $webhook->name, - 'status' => $webhook->status == 'active', + if ($webhook['delivery_url'] == $eCommerceSiteWebHooksUrl) { + $webhooks_list[$webhook['id']] = array( + 'remote_id' => $webhook['id'], + 'name' => $webhook['name'], + 'status' => $webhook['status'] == 'active', 'infos' => json_encode(array( - 'topic' => $webhook->topic, - 'resource' => $webhook->resource, - 'event' => $webhook->event, + 'topic' => $webhook['topic'], + 'resource' => $webhook['resource'], + 'event' => $webhook['event'], )), ); } } - } while (!empty($webhooks)); + } while (count($webhooks) == $nb_max_by_request); dol_syslog(__METHOD__ . ": end, return: ".json_encode($webhooks_list), LOG_DEBUG); return $webhooks_list; @@ -4903,4 +4765,15 @@ public function __destruct() { ini_set("memory_limit", "528M"); } + + /** + * Method to output saved errors + * + * @param string $separator Separator between each error + * @return string String with errors + */ + public function errorsToString($separator = ', ') + { + return $this->error . (is_array($this->errors) ? (!empty($this->error) ? $separator : '') . join($separator, $this->errors) : ''); + } } diff --git a/composer.json b/composer.json index 965d1eb..4291ee2 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,6 @@ { "name": "open-dsi/ecommerceng_woosync", - "require": {} + "require": { + "guzzlehttp/guzzle": "^6.3" + } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..8a5015d --- /dev/null +++ b/composer.lock @@ -0,0 +1,803 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "279d851d37775893df3c17d22e75f485", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "6.5.8", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "a52f0440530b54fa079ce76e8c5d196a42cad981" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a52f0440530b54fa079ce76e8c5d196a42cad981", + "reference": "a52f0440530b54fa079ce76e8c5d196a42cad981", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.9", + "php": ">=5.5", + "symfony/polyfill-intl-idn": "^1.17" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "psr/log": "^1.1" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.5-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/6.5.8" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2022-06-20T22:16:07+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.5.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "b94b2807d85443f9719887892882d0329d1e2598" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598", + "reference": "b94b2807d85443f9719887892882d0329d1e2598", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.5.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2022-08-28T14:55:35+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.9.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", + "reference": "e98e3e6d4f86621a9b75f623996e6bbdeb4b9318", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/1.9.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2022-06-20T21:43:03+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v9.99.100", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "shasum": "" + }, + "require": { + "php": ">= 7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/random_compat/issues", + "source": "https://github.com/paragonie/random_compat" + }, + "time": "2020-10-15T08:29:30+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "4ad5115c0f5d5172a9fe8147675ec6de266d8826" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/4ad5115c0f5d5172a9fe8147675ec6de266d8826", + "reference": "4ad5115c0f5d5172a9fe8147675ec6de266d8826", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php70": "^1.10", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.19-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.19.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-21T09:57:48+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8db0ae7936b42feb370840cf24de1a144fb0ef27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8db0ae7936b42feb370840cf24de1a144fb0ef27", + "reference": "8db0ae7936b42feb370840cf24de1a144fb0ef27", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.19-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.19.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-23T09:01:57+00:00" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "3fe414077251a81a1b15b1c709faf5c2fbae3d4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/3fe414077251a81a1b15b1c709faf5c2fbae3d4e", + "reference": "3fe414077251a81a1b15b1c709faf5c2fbae3d4e", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0|~9.99", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.19-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php70/tree/v1.19.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-23T09:01:57+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "beecef6b463b06954638f02378f52496cb84bacc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/beecef6b463b06954638f02378f52496cb84bacc", + "reference": "beecef6b463b06954638f02378f52496cb84bacc", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.19-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.19.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-23T09:01:57+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.1.0" +} diff --git a/core/modules/modECommerceNg.class.php b/core/modules/modECommerceNg.class.php index dd6409b..6b63428 100644 --- a/core/modules/modECommerceNg.class.php +++ b/core/modules/modECommerceNg.class.php @@ -61,7 +61,7 @@ function __construct($db) $this->editor_url = 'http://www.open-dsi.fr'; // Possible values for version are: 'development', 'experimental', 'dolibarr' or version - $this->version = '4.1.34'; + $this->version = '4.1.35'; // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name); // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific) @@ -100,7 +100,7 @@ function __construct($db) $this->style_sheet = ''; // Config pages. Put here list of php page names stored in admmin directory used to setup module. - $this->config_page_url = array('eCommerceSetup.php@ecommerceng'); + $this->config_page_url = array('setup.php@ecommerceng'); // Dependencies $this->depends = array("modSociete", "modProduct", "modCategorie", "modWebServices"); // List of modules id that must be enabled if this module is enabled @@ -227,6 +227,7 @@ function __construct($db) 1 => array('label' => 'ECommerceProcessPendingWebHooks', 'jobtype' => 'method', 'class' => '/ecommerceng/class/business/eCommercePendingWebHook.class.php', 'objectname' => 'eCommercePendingWebHook', 'method' => 'cronProcessPendingWebHooks', 'parameters' => '', 'comment' => 'Process all pending WebHooks.', 'frequency' => 15, 'unitfrequency' => 60, 'priority' => 90, 'status' => 1, 'test' => '$conf->ecommerceng->enabled'), 2 => array('label' => 'ECommerceCheckWebHooksStatus', 'jobtype' => 'method', 'class' => '/ecommerceng/class/business/eCommercePendingWebHook.class.php', 'objectname' => 'eCommercePendingWebHook', 'method' => 'cronCheckWebHooksStatus', 'parameters' => '', 'comment' => 'Check WebHooks status.', 'frequency' => 15, 'unitfrequency' => 60, 'priority' => 80, 'status' => 1, 'test' => '$conf->ecommerceng->enabled'), 3 => array('label' => 'ECommerceCheckWebHooksVolumetry', 'jobtype' => 'method', 'class' => '/ecommerceng/class/business/eCommercePendingWebHook.class.php', 'objectname' => 'eCommercePendingWebHook', 'method' => 'cronCheckWebHooksVolumetry', 'parameters' => '', 'comment' => 'Check WebHooks volumetry.', 'frequency' => 15, 'unitfrequency' => 60, 'priority' => 70, 'status' => 0, 'test' => '$conf->ecommerceng->enabled'), + 4 => array('label' => 'ECommerceSynchronizeStocksToSite', 'jobtype' => 'method', 'class' => '/ecommerceng/class/business/eCommerceUtils.class.php', 'objectname' => 'eCommerceUtils', 'method' => 'cronSynchronizeStocksToSite', 'parameters' => '', 'comment' => 'Synchronize stock to site.', 'frequency' => 15, 'unitfrequency' => 60, 'priority' => 100, 'status' => 1, 'test' => '$conf->ecommerceng->enabled'), ); // Permissions @@ -306,7 +307,7 @@ function __construct($db) 'type' => 'left', 'titre' => 'ECommerceMenuSetup', 'leftmenu' => 'ecommerceng_setup', - 'url' => '/ecommerceng/admin/eCommerceSetup.php', + 'url' => '/ecommerceng/admin/setup.php', 'langs' => 'ecommerce@ecommerceng', 'position' => 120, 'enabled' => '$conf->ecommerceng->enabled', @@ -458,7 +459,6 @@ function init($options = '') $result=$this->load_tables($options); $this->addSettlementTerms(); $this->addAnonymousCompany(); - $this->addFiles(); return $this->_init($sql, $options); } @@ -571,18 +571,5 @@ private function AddSettlementTerms() } } } - - /** - * Add files need for dolibarr - */ - private function addFiles() - { - $srcFile = dol_buildpath('/ecommerceng/patchs/dolibarr/includes/OAuth/OAuth2/Service/WordPress.php'); - $destFile = DOL_DOCUMENT_ROOT . '/includes/OAuth/OAuth2/Service/WordPress.php'; - - if (!file_exists($destFile) && dol_copy($srcFile, $destFile) < 0) { - setEventMessages("Error copy file '$srcFile' to '$destFile'", null, 'errors'); - } - } } diff --git a/core/modules/oauth/wordpress_oauthcallback.php b/core/modules/oauth/wordpress_oauthcallback.php deleted file mode 100644 index 11a4d99..0000000 --- a/core/modules/oauth/wordpress_oauthcallback.php +++ /dev/null @@ -1,195 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/core/modules/oauth/wordpress_oauthcallback.php - * \ingroup oauth - * \brief Page to get oauth callback - */ - -$res=0; -if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"); -if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php"); -if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php"); -if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php"); -if (! $res && file_exists("../../../../main.inc.php")) $res=@include("../../../../main.inc.php"); -if (! $res && file_exists("../../../../../main.inc.php")) $res=@include("../../../../../main.inc.php"); -if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include("../../../dolibarr".$reg[1]."/htdocs/main.inc.php"); // Used on dev env only -if (! $res && preg_match('/\/teclib([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include("../../../dolibarr".$reg[1]."/htdocs/main.inc.php"); // Used on dev env only -if (! $res) die("Include of main fails"); -require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; -dol_include_once('/ecommerceng/includes/CurlClientEx.php'); -dol_include_once('/ecommerceng/class/data/eCommerceSite.class.php'); -use OAuth\Common\Storage\DoliStorage; -use OAuth\Common\Consumer\Credentials; -use OAuth\Common\Http\Uri\Uri; -use OAuth\Common\Http\Client\CurlClient; -use OAuth\OAuth2\Service\WordPress; - -// Define $urlwithroot -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file -//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current - - - -$action = GETPOST('action', 'alpha'); -$backtourl = GETPOST('backtourl', 'alpha'); -$siteId = GETPOST('ecommerce_id', 'int'); - -//LOAD SELECTED SITE -$siteDb = new eCommerceSite($db); -$res = $siteDb->fetch($siteId); -if ($res < 0) { - setEventMessage("Error: site ecommerce not found", 'errors'); - header('Location: ' . $backtourl); - exit(); -} - -/** - * Create a new instance of the URI class with the current URI, stripping the query string - */ -$uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); -//$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); -//$currentUri->setQuery(''); -//$currentUri = $uriFactory->createFromAbsolute($urlwithroot.'/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php?ecommerce_id='.$siteId); -$currentUri = $uriFactory->createFromAbsolute(dol_buildpath('/ecommerceng/core/modules/oauth/wordpress_oauthcallback.php', 2).'?ecommerce_id='.$siteId); - - -/** - * Load the credential for the service - */ - -/** @var $serviceFactory \OAuth\ServiceFactory An OAuth service factory. */ -$serviceFactory = new \OAuth\ServiceFactory(); -$httpClient = new CurlClient(); -// TODO Set options for proxy and timeout -// $params=array('CURLXXX'=>value, ...) -//$httpClient->setCurlParameters($params); -$serviceFactory->setHttpClient($httpClient); - -// Dolibarr storage -$storage = new DoliStorage($db, $conf); - -// Setup the credentials for the requests -$credentials = new Credentials( - $siteDb->oauth_id, - $siteDb->oauth_secret, - $currentUri->getAbsoluteUri() -); - -$requestedpermissionsarray=array(); -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back -/*if ($action != 'delete' && empty($requestedpermissionsarray)) -{ - print 'Error, parameter state is not defined'; - exit; -}*/ -//var_dump($requestedpermissionsarray);exit; - -// Instantiate the Api service using the credentials, http client and storage mechanism for the token -/** @var $apiService Service */ -$apiService = $serviceFactory->createService('WordPress', $credentials, $storage, array(), new Uri($siteDb->webservice_address)); - -// access type needed to have oauth provider refreshing token -// alos note that a refresh token is sent only after a prompt -//$apiService->setAccessType('offline'); - -//$apiService->setApprouvalPrompt('force'); - -$langs->load("oauth"); - - -/* - * Actions - */ - - -if ($action == 'delete') -{ - $storage->clearToken('ECommerce_'.$siteId); - - setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); - - header('Location: ' . $backtourl); - exit(); -} - -if (! empty($_GET['code'])) // We are coming from oauth provider page -{ - $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; - unset($_SESSION["backtourlsavedbeforeoauthjump"]); - - //llxHeader('',$langs->trans("OAuthSetup")); - - //$linkback=''.$langs->trans("BackToModuleList").''; - //print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup'); - - //dol_fiche_head(); - // retrieve the CSRF state parameter - $state = isset($_GET['state']) ? $_GET['state'] : null; - //print ''; - - // This was a callback request from service, get the token - try { - //var_dump($_GET['code']); - //var_dump($state); - //var_dump($apiService); // OAuth\OAuth2\Service\WordPress - - $token = $apiService->requestAccessToken($_GET['code'], $state); - $storage->storeAccessToken('ECommerce_'.$siteId, $token); - -// $token = $apiService->refreshAccessToken($token); - - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token - } catch (Exception $e) { - setEventMessage($e->getMessage(), 'errors'); - } - - header('Location: ' . $backtourl); - exit(); -} -else // If entry on page with no parameter, we arrive here -{ - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; - - // This may create record into oauth_state before the header redirect. - // Creation of record with state in this tables depend on the Provider used (see its constructor). - if (GETPOST('state')) - { - $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); - } - else - { - $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated - } - - // we go on oauth provider authorization page - header('Location: ' . $url); - exit(); -} - - -/* - * View - */ - -// No view at all, just actions - -$db->close(); - diff --git a/core/triggers/interface_90_modECommerceng_ECommerceng.class.php b/core/triggers/interface_90_modECommerceng_ECommerceng.class.php index ee937c1..2a5aee3 100644 --- a/core/triggers/interface_90_modECommerceng_ECommerceng.class.php +++ b/core/triggers/interface_90_modECommerceng_ECommerceng.class.php @@ -437,6 +437,7 @@ function runTrigger($action,$object,$user,$langs,$conf) if (!$error) { //eCommerce update link $eCommerceProduct->last_update = dol_print_date($now, '%Y-%m-%d %H:%M:%S'); + if ($site->stock_sync_direction == 'dolibarr2ecommerce') $eCommerceProduct->last_update_stock = $eCommerceProduct->last_update; if ($eCommerceProduct->update($user) < 0) { $error++; $error_msg = $langs->trans('ECommerceUpdateRemoteProductLink', $object->id, $site->name, $eCommerceProduct->error); @@ -485,6 +486,7 @@ function runTrigger($action,$object,$user,$langs,$conf) if (!$error) { // Create remote link $eCommerceProduct->last_update = dol_print_date($now, '%Y-%m-%d %H:%M:%S'); + if ($site->stock_sync_direction == 'dolibarr2ecommerce') $eCommerceProduct->last_update_stock = $eCommerceProduct->last_update; $eCommerceProduct->fk_product = $object->id; $eCommerceProduct->fk_site = $site->id; $eCommerceProduct->remote_id = $remote_id; @@ -1012,114 +1014,6 @@ function runTrigger($action,$object,$user,$langs,$conf) } } - - // Stock Movement - if ($action == 'STOCK_MOVEMENT') { - if ($object->element != 'stockmouvement') { - $error_msg = "Trigger : Object element (" . $object->element . ") is not a stockmouvement for the action " . $action; - dol_syslog($error_msg, LOG_ERR); - $this->errors[] = $error_msg; - return -1; - } - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); - - $this->db->begin(); - - $save_entity = $conf->entity; - $stopwatch_id = eCommerceUtils::startAndLogStopwatch(__METHOD__ . " - Action {$action} (ID: {$object->id})"); - - $eCommerceSite = new eCommerceSite($this->db); - $sites = $eCommerceSite->listSites('object'); - $entities = explode(',', getEntity('stock')); - - foreach ($sites as $site) { - if ($object->context['fromsyncofecommerceid'] && $object->context['fromsyncofecommerceid'] == $site->id) { - dol_syslog("Triggers was ran from a create/update to sync from ecommerce to dolibarr, so we won't run code to sync from dolibarr to ecommerce"); - continue; - } - - if (!in_array($site->entity, $entities)) { - dol_syslog("Site '{$site->name}' not in the shared entities"); - continue; - } - - try { - $supported_warehouses = is_array($site->parameters['fk_warehouse_to_ecommerce']) ? $site->parameters['fk_warehouse_to_ecommerce'] : array(); - - // Do we sync the stock ? - if (!$error && $site->stock_sync_direction == 'dolibarr2ecommerce' && in_array($object->entrepot_id, $supported_warehouses)) { - $site->setEntityValues($site->entity); - - $eCommerceProduct = new eCommerceProduct($this->db); - $eCommerceProduct->fetchByProductId($object->product_id, $site->id); - - // Get new qty. We read stock_reel of product. Trigger is called after creating movement and updating table product, so we get total after move. - $dbProduct = new Product($this->db); - $dbProduct->fetch($object->product_id); - $dbProduct->load_stock(); - - $object->qty_after = 0; - foreach ($supported_warehouses as $warehouse_id) { - $object->qty_after += isset($dbProduct->stock_warehouse[$warehouse_id]->real) ? $dbProduct->stock_warehouse[$warehouse_id]->real : 0; - } - - if ($eCommerceProduct->remote_id > 0) { - // Connect to magento - $eCommerceSynchro = new eCommerceSynchro($this->db, $site); - dol_syslog("Trigger " . $action . " try to connect to eCommerce site " . $site->name); - $eCommerceSynchro->connect(); - if (count($eCommerceSynchro->errors)) { - $error++; - $object->errors[] = $eCommerceSynchro->errorsToString(); - setEventMessages($eCommerceSynchro->error, $eCommerceSynchro->errors, 'errors'); - } - - if (!$error) { - $result = $eCommerceSynchro->eCommerceRemoteAccess->updateRemoteStockProduct($eCommerceProduct->remote_id, $object, $dbProduct); - $now = dol_now(); - if (!$result) { - $error++; - $this->errors[] = $eCommerceSynchro->eCommerceRemoteAccess->error; - $object->errors = array_merge($this->errors, $eCommerceSynchro->eCommerceRemoteAccess->errors); - } - } - - if (!$error) { - //eCommerce update link - $eCommerceProduct->last_update = dol_print_date($now, '%Y-%m-%d %H:%M:%S'); - if ($eCommerceProduct->update($user) < 0) { - $error++; - $error_msg = $langs->trans('ECommerceUpdateRemoteProductLink', $object->id, $site->name, $eCommerceProduct->error); - $this->errors[] = $error_msg; - $object->errors = array_merge($this->errors, $eCommerceProduct->errors); - dol_syslog(__METHOD__ . ': Error:' . $error_msg, LOG_WARNING); - } - } - } else { - dol_syslog("Product with id " . $object->id . " is not linked to an ecommerce record and does not has category flag to push on eCommerce."); - } - } - } catch (Exception $e) { - $error++; - $object->errors[] = 'Trigger exception : ' . $e->getMessage(); - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id . " " . 'Trigger exception : ' . $e->getMessage()); - break; - } - } - - eCommerceUtils::stopAndLogStopwatch($stopwatch_id); - if (isset($site)) $site->setEntityValues($save_entity); - - if ($error) { - $this->errors[] = 'Product ID: ' . $object->product_id; - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } - } - return 0; } } diff --git a/includes/CurlClientEx.php b/includes/CurlClientEx.php deleted file mode 100644 index a216fc7..0000000 --- a/includes/CurlClientEx.php +++ /dev/null @@ -1,157 +0,0 @@ - value` pairs) to be passed to `curl_setopt` - * - * @var array - */ - private $parameters = array(); - - /** - * Additional `curl_setopt` parameters - * - * @param array $parameters - */ - public function setCurlParameters(array $parameters) - { - $this->parameters = $parameters; - } - - /** - * @param bool $buildHttpQuery - */ - public function setHttpPostBuildQuery($buildHttpQuery) - { - $this->httpPostBuildQuery = $buildHttpQuery; - } - - /** - * @param bool $force - * - * @return CurlClientEx - */ - public function setForceSSL3($force) - { - $this->forceSSL3 = $force; - - return $this; - } - - /** - * Any implementing HTTP providers should send a request to the provided endpoint with the parameters. - * They should return, in string form, the response body and throw an exception on error. - * - * @param UriInterface $endpoint - * @param mixed $requestBody - * @param array $extraHeaders - * @param string $method - * - * @return string - * - * @throws TokenResponseException - * @throws \InvalidArgumentException - */ - public function retrieveResponse( - UriInterface $endpoint, - $requestBody, - array $extraHeaders = array(), - $method = 'POST' - ) { - // Normalize method name - $method = strtoupper($method); - - $this->normalizeHeaders($extraHeaders); - - if ($method === 'GET' && !empty($requestBody)) { - throw new \InvalidArgumentException('No body expected for "GET" request.'); - } - - if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) { - $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded'; - } - - $extraHeaders['Host'] = 'Host: '.$endpoint->getHost(); - $extraHeaders['Connection'] = 'Connection: close'; - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $endpoint->getAbsoluteUri()); - - if ($method === 'POST' || $method === 'PUT') { - if ($requestBody && is_array($requestBody) && $this->httpPostBuildQuery) { - $requestBody = http_build_query($requestBody, '', '&'); - } - - if ($method === 'PUT') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - } else { - curl_setopt($ch, CURLOPT_POST, true); - } - - curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); - } else { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); - } - - if ($this->maxRedirects > 0) { - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_MAXREDIRS, $this->maxRedirects); - } - - curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_HTTPHEADER, $extraHeaders); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - - foreach ($this->parameters as $key => $value) { - curl_setopt($ch, $key, $value); - } - - if ($this->forceSSL3) { - curl_setopt($ch, CURLOPT_SSLVERSION, 3); - } - - $response = curl_exec($ch); - $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - if (false === $response) { - $errNo = curl_errno($ch); - $errStr = curl_error($ch); - curl_close($ch); - if (empty($errStr)) { - throw new TokenResponseException('Failed to request resource.', $responseCode); - } - throw new TokenResponseException('cURL Error # '.$errNo.': '.$errStr, $responseCode); - } - - curl_close($ch); - - return $response; - } -} diff --git a/includes/WooCommerce/Client.php b/includes/WooCommerce/Client.php deleted file mode 100644 index cc5a249..0000000 --- a/includes/WooCommerce/Client.php +++ /dev/null @@ -1,109 +0,0 @@ -http = new HttpClient($url, $consumerKey, $consumerSecret, $options); - } - - /** - * POST method. - * - * @param string $endpoint API endpoint. - * @param array $data Request data. - * - * @return array - */ - public function post($endpoint, $data) - { - return $this->http->request($endpoint, 'POST', $data); - } - - /** - * PUT method. - * - * @param string $endpoint API endpoint. - * @param array $data Request data. - * - * @return array - */ - public function put($endpoint, $data) - { - return $this->http->request($endpoint, 'PUT', $data); - } - - /** - * GET method. - * - * @param string $endpoint API endpoint. - * @param array $parameters Request parameters. - * - * @return array - */ - public function get($endpoint, $parameters = []) - { - return $this->http->request($endpoint, 'GET', [], $parameters); - } - - /** - * DELETE method. - * - * @param string $endpoint API endpoint. - * @param array $parameters Request parameters. - * - * @return array - */ - public function delete($endpoint, $parameters = []) - { - return $this->http->request($endpoint, 'DELETE', [], $parameters); - } - - /** - * OPTIONS method. - * - * @param string $endpoint API endpoint. - * - * @return array - */ - public function options($endpoint) - { - return $this->http->request($endpoint, 'OPTIONS', [], []); - } -} diff --git a/includes/WooCommerce/HttpClient/BasicAuth.php b/includes/WooCommerce/HttpClient/BasicAuth.php deleted file mode 100644 index f831cd6..0000000 --- a/includes/WooCommerce/HttpClient/BasicAuth.php +++ /dev/null @@ -1,95 +0,0 @@ -ch = $ch; - $this->consumerKey = $consumerKey; - $this->consumerSecret = $consumerSecret; - $this->doQueryString = $doQueryString; - $this->parameters = $parameters; - - $this->processAuth(); - } - - /** - * Process auth. - */ - protected function processAuth() - { - if ($this->doQueryString) { - $this->parameters['consumer_key'] = $this->consumerKey; - $this->parameters['consumer_secret'] = $this->consumerSecret; - } else { - \curl_setopt($this->ch, CURLOPT_USERPWD, $this->consumerKey . ':' . $this->consumerSecret); - } - } - - /** - * Get parameters. - * - * @return array - */ - public function getParameters() - { - return $this->parameters; - } -} diff --git a/includes/WooCommerce/HttpClient/HttpClient.php b/includes/WooCommerce/HttpClient/HttpClient.php deleted file mode 100644 index c1f90ad..0000000 --- a/includes/WooCommerce/HttpClient/HttpClient.php +++ /dev/null @@ -1,444 +0,0 @@ -options = new Options($options); - $this->url = $this->buildApiUrl($url); - $this->consumerKey = $consumerKey; - $this->consumerSecret = $consumerSecret; - } - - /** - * Check if is under SSL. - * - * @return bool - */ - protected function isSsl() - { - return 'https://' === \substr($this->url, 0, 8); - } - - /** - * Build API URL. - * - * @param string $url Store URL. - * - * @return string - */ - protected function buildApiUrl($url) - { - $api = $this->options->isWPAPI() ? $this->options->apiPrefix() : '/wc-api/'; - - return \rtrim($url, '/') . $api . $this->options->getVersion() . '/'; - } - - /** - * Build URL. - * - * @param string $url URL. - * @param array $parameters Query string parameters. - * - * @return string - */ - protected function buildUrlQuery($url, $parameters = []) - { - if (!empty($parameters)) { - $url .= '?' . \http_build_query($parameters); - } - - return $url; - } - - /** - * Authenticate. - * - * @param string $url Request URL. - * @param string $method Request method. - * @param array $parameters Request parameters. - * - * @return array - */ - protected function authenticate($url, $method, $parameters = []) - { - // Setup authentication. - if ($this->isSsl()) { - $basicAuth = new BasicAuth( - $this->ch, - $this->consumerKey, - $this->consumerSecret, - $this->options->isQueryStringAuth(), - $parameters - ); - $parameters = $basicAuth->getParameters(); - } else { - $oAuth = new OAuth( - $url, - $this->consumerKey, - $this->consumerSecret, - $this->options->getVersion(), - $method, - $parameters, - $this->options->oauthTimestamp() - ); - $parameters = $oAuth->getParameters(); - } - - return $parameters; - } - - /** - * Setup method. - * - * @param string $method Request method. - */ - protected function setupMethod($method) - { - if ('POST' == $method) { - \curl_setopt($this->ch, CURLOPT_POST, true); - } elseif (\in_array($method, ['PUT', 'DELETE', 'OPTIONS'])) { - \curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method); - } - } - - /** - * Get request headers. - * - * @param bool $sendData If request send data or not. - * - * @return array - */ - protected function getRequestHeaders($sendData = false) - { - $headers = [ - 'Accept' => 'application/json', - 'User-Agent' => $this->options->userAgent() . '/' . Client::VERSION, - ]; - - if ($sendData) { - $headers['Content-Type'] = 'application/json;charset=utf-8'; - } - - return $headers; - } - - /** - * Create request. - * - * @param string $endpoint Request endpoint. - * @param string $method Request method. - * @param array $data Request data. - * @param array $parameters Request parameters. - * - * @return Request - */ - protected function createRequest($endpoint, $method, $data = [], $parameters = []) - { - $body = ''; - $url = $this->url . $endpoint; - $hasData = !empty($data); - - // Setup authentication. - $parameters = $this->authenticate($url, $method, $parameters); - - // Setup method. - $this->setupMethod($method); - - // Include post fields. - if ($hasData) { - $body = \json_encode($data); - \curl_setopt($this->ch, CURLOPT_POSTFIELDS, $body); - } - - $this->request = new Request( - $this->buildUrlQuery($url, $parameters), - $method, - $parameters, - $this->getRequestHeaders($hasData), - $body - ); - - return $this->getRequest(); - } - - /** - * Get response headers. - * - * @return array - */ - protected function getResponseHeaders() - { - $headers = []; - $lines = \explode("\n", $this->responseHeaders); - $lines = \array_filter($lines, 'trim'); - - foreach ($lines as $index => $line) { - // Remove HTTP/xxx params. - if (strpos($line, ': ') === false) { - continue; - } - - list($key, $value) = \explode(': ', $line); - - $headers[$key] = isset($headers[$key]) ? $headers[$key] . ', ' . trim($value) : trim($value); - } - - return $headers; - } - - /** - * Create response. - * - * @return Response - */ - protected function createResponse() - { - - // Set response headers. - $this->responseHeaders = ''; - \curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, function ($_, $headers) { - $this->responseHeaders .= $headers; - return \strlen($headers); - }); - - // Get response data. - $body = \curl_exec($this->ch); - $code = \curl_getinfo($this->ch, CURLINFO_HTTP_CODE); - $headers = $this->getResponseHeaders(); - - // Register response. - $this->response = new Response($code, $headers, $body); - - return $this->getResponse(); - } - - /** - * Set default cURL settings. - */ - protected function setDefaultCurlSettings() - { - $verifySsl = $this->options->verifySsl(); - $timeout = $this->options->getTimeout(); - $followRedirects = $this->options->getFollowRedirects(); - - \curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, $verifySsl); - if (!$verifySsl) { - \curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, $verifySsl); - } - if ($followRedirects) { - \curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); - } - \curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $timeout); - \curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); - \curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); - \curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->request->getRawHeaders()); - \curl_setopt($this->ch, CURLOPT_URL, $this->request->getUrl()); - } - - /** - * Look for errors in the request. - * - * @param array $parsedResponse Parsed body response. - */ - protected function lookForErrors($parsedResponse) - { - // Any non-200/201/202 response code indicates an error. - if (!\in_array($this->response->getCode(), ['200', '201', '202'])) { - $errors = isset($parsedResponse->errors) ? $parsedResponse->errors : $parsedResponse; - $errorMessage = ''; - $errorCode = ''; - - if (is_array($errors)) { - $errorMessage = $errors[0]->message; - $errorCode = $errors[0]->code; - } elseif (isset($errors->message, $errors->code)) { - $errorMessage = $errors->message; - $errorCode = $errors->code; - } - - throw new HttpClientException( - \sprintf('Error: %s [%s]', $errorMessage, $errorCode), - $this->response->getCode(), - $this->request, - $this->response - ); - } - } - - /** - * Process response. - * - * @return array - */ - protected function processResponse() - { - $body = $this->response->getBody(); - - // Look for UTF-8 BOM and remove. - if (0 === strpos(bin2hex(substr($body, 0, 4)), 'efbbbf')) { - $body = substr($body, 3); - } - - $parsedResponse = \json_decode($body); - - // Test if return a valid JSON. - if (JSON_ERROR_NONE !== json_last_error()) { - $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Invalid JSON returned'; - throw new HttpClientException( - sprintf('JSON ERROR: %s', $message), - $this->response->getCode(), - $this->request, - $this->response - ); - } - - $this->lookForErrors($parsedResponse); - - return $parsedResponse; - } - - /** - * Make requests. - * - * @param string $endpoint Request endpoint. - * @param string $method Request method. - * @param array $data Request data. - * @param array $parameters Request parameters. - * - * @return array - */ - public function request($endpoint, $method, $data = [], $parameters = []) - { - // Initialize cURL. - $this->ch = \curl_init(); - - // Set request args. - $request = $this->createRequest($endpoint, $method, $data, $parameters); - - // Default cURL settings. - $this->setDefaultCurlSettings(); - - // Get response. - $response = $this->createResponse(); - - // Check for cURL errors. - if (\curl_errno($this->ch)) { - throw new HttpClientException('cURL Error: ' . \curl_error($this->ch), 0, $request, $response); - } - - \curl_close($this->ch); - - return $this->processResponse(); - } - - /** - * Get request data. - * - * @return Request - */ - public function getRequest() - { - return $this->request; - } - - /** - * Get response data. - * - * @return Response - */ - public function getResponse() - { - return $this->response; - } -} diff --git a/includes/WooCommerce/HttpClient/HttpClientException.php b/includes/WooCommerce/HttpClient/HttpClientException.php deleted file mode 100644 index ef11a6b..0000000 --- a/includes/WooCommerce/HttpClient/HttpClientException.php +++ /dev/null @@ -1,70 +0,0 @@ -request = $request; - $this->response = $response; - } - - /** - * Get request data. - * - * @return Request - */ - public function getRequest() - { - return $this->request; - } - - /** - * Get response data. - * - * @return Response - */ - public function getResponse() - { - return $this->response; - } -} diff --git a/includes/WooCommerce/HttpClient/OAuth.php b/includes/WooCommerce/HttpClient/OAuth.php deleted file mode 100644 index b3c67a9..0000000 --- a/includes/WooCommerce/HttpClient/OAuth.php +++ /dev/null @@ -1,268 +0,0 @@ -url = $url; - $this->consumerKey = $consumerKey; - $this->consumerSecret = $consumerSecret; - $this->apiVersion = $apiVersion; - $this->method = $method; - $this->parameters = $parameters; - $this->timestamp = $timestamp; - } - - /** - * Encode according to RFC 3986. - * - * @param string|array $value Value to be normalized. - * - * @return string - */ - protected function encode($value) - { - if (is_array($value)) { - return array_map([$this, 'encode'], $value); - } else { - return str_replace(['+', '%7E'], [' ', '~'], rawurlencode($value)); - } - } - - /** - * Normalize parameters. - * - * @param array $parameters Parameters to normalize. - * - * @return array - */ - protected function normalizeParameters($parameters) - { - $normalized = []; - - foreach ($parameters as $key => $value) { - // Percent symbols (%) must be double-encoded. - $key = $this->encode($key); - $value = $this->encode($value); - - $normalized[$key] = $value; - } - - return $normalized; - } - - /** - * Process filters. - * - * @param array $parameters Request parameters. - * - * @return array - */ - protected function processFilters($parameters) - { - if (isset($parameters['filter'])) { - $filters = $parameters['filter']; - unset($parameters['filter']); - foreach ($filters as $filter => $value) { - $parameters['filter[' . $filter . ']'] = $value; - } - } - - return $parameters; - } - - /** - * Get secret. - * - * @return string - */ - protected function getSecret() - { - $secret = $this->consumerSecret; - - // Fix secret for v3 or later. - if (!\in_array($this->apiVersion, ['v1', 'v2'])) { - $secret .= '&'; - } - - return $secret; - } - - /** - * Generate oAuth1.0 signature. - * - * @param array $parameters Request parameters including oauth. - * - * @return string - */ - protected function generateOauthSignature($parameters) - { - $baseRequestUri = \rawurlencode($this->url); - - // Extract filters. - $parameters = $this->processFilters($parameters); - - // Normalize parameter key/values and sort them. - $parameters = $this->normalizeParameters($parameters); - \uksort($parameters, 'strcmp'); - - // Set query string. - $queryString = \implode('%26', $this->joinWithEqualsSign($parameters)); // Join with ampersand. - $stringToSign = $this->method . '&' . $baseRequestUri . '&' . $queryString; - $secret = $this->getSecret(); - - return \base64_encode(\hash_hmac(self::HASH_ALGORITHM, $stringToSign, $secret, true)); - } - - /** - * Creates an array of urlencoded strings out of each array key/value pairs. - * - * @param array $params Array of parameters to convert. - * @param array $queryParams Array to extend. - * @param string $key Optional Array key to append - * @return string Array of urlencoded strings - */ - protected function joinWithEqualsSign($params, $queryParams = [], $key = '') - { - foreach ($params as $paramKey => $paramValue) { - if ($key) { - $paramKey = $key . '%5B' . $paramKey . '%5D'; // Handle multi-dimensional array. - } - - if (is_array($paramValue)) { - $queryParams = $this->joinWithEqualsSign($paramValue, $queryParams, $paramKey); - } else { - $string = $paramKey . '=' . $paramValue; // Join with equals sign. - $queryParams[] = $this->encode($string); - } - } - - return $queryParams; - } - - /** - * Sort parameters. - * - * @param array $parameters Parameters to sort in byte-order. - * - * @return array - */ - protected function getSortedParameters($parameters) - { - \uksort($parameters, 'strcmp'); - - foreach ($parameters as $key => $value) { - if (\is_array($value)) { - \uksort($parameters[$key], 'strcmp'); - } - } - - return $parameters; - } - - /** - * Get oAuth1.0 parameters. - * - * @return string - */ - public function getParameters() - { - $parameters = \array_merge($this->parameters, [ - 'oauth_consumer_key' => $this->consumerKey, - 'oauth_timestamp' => $this->timestamp, - 'oauth_nonce' => \sha1(\microtime()), - 'oauth_signature_method' => 'HMAC-' . self::HASH_ALGORITHM, - ]); - - // The parameters above must be included in the signature generation. - $parameters['oauth_signature'] = $this->generateOauthSignature($parameters); - - return $this->getSortedParameters($parameters); - } -} diff --git a/includes/WooCommerce/HttpClient/Options.php b/includes/WooCommerce/HttpClient/Options.php deleted file mode 100644 index faf86dd..0000000 --- a/includes/WooCommerce/HttpClient/Options.php +++ /dev/null @@ -1,148 +0,0 @@ -options = $options; - } - - /** - * Get API version. - * - * @return string - */ - public function getVersion() - { - return isset($this->options['version']) ? $this->options['version'] : self::VERSION; - } - - /** - * Check if need to verify SSL. - * - * @return bool - */ - public function verifySsl() - { - return isset($this->options['verify_ssl']) ? (bool) $this->options['verify_ssl'] : true; - } - - /** - * Get timeout. - * - * @return int - */ - public function getTimeout() - { - return isset($this->options['timeout']) ? (int) $this->options['timeout'] : self::TIMEOUT; - } - - /** - * Basic Authentication as query string. - * Some old servers are not able to use CURLOPT_USERPWD. - * - * @return bool - */ - public function isQueryStringAuth() - { - return isset($this->options['query_string_auth']) ? (bool) $this->options['query_string_auth'] : false; - } - - /** - * Check if is WP REST API. - * - * @return bool - */ - public function isWPAPI() - { - return isset($this->options['wp_api']) ? (bool) $this->options['wp_api'] : true; - } - - /** - * Custom API Prefix for WP API. - * - * @return string - */ - public function apiPrefix() - { - return isset($this->options['wp_api_prefix']) ? $this->options['wp_api_prefix'] : self::WP_API_PREFIX; - } - - /** - * oAuth timestamp. - * - * @return string - */ - public function oauthTimestamp() - { - return isset($this->options['oauth_timestamp']) ? $this->options['oauth_timestamp'] : \time(); - } - - /** - * Custom user agent. - * - * @return string - */ - public function userAgent() - { - return isset($this->options['user_agent']) ? $this->options['user_agent'] : self::USER_AGENT; - } - - /** - * Get follow redirects - * - * @return bool - */ - public function getFollowRedirects() - { - return isset($this->options['follow_redirects']) ? (bool) $this->options['follow_redirects'] : false; - } -} diff --git a/includes/WooCommerce/HttpClient/Request.php b/includes/WooCommerce/HttpClient/Request.php deleted file mode 100644 index 9c22fc5..0000000 --- a/includes/WooCommerce/HttpClient/Request.php +++ /dev/null @@ -1,187 +0,0 @@ -url = $url; - $this->method = $method; - $this->parameters = $parameters; - $this->headers = $headers; - $this->body = $body; - } - - /** - * Set url. - * - * @param string $url Request url. - */ - public function setUrl($url) - { - $this->url = $url; - } - - /** - * Set method. - * - * @param string $method Request method. - */ - public function setMethod($method) - { - $this->method = $method; - } - - /** - * Set parameters. - * - * @param array $parameters Request paramenters. - */ - public function setParameters($parameters) - { - $this->parameters = $parameters; - } - - /** - * Set headers. - * - * @param array $headers Request headers. - */ - public function setHeaders($headers) - { - $this->headers = $headers; - } - - /** - * Set body. - * - * @param string $body Request body. - */ - public function setBody($body) - { - $this->body = $body; - } - - /** - * Get url. - * - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * Get method. - * - * @return string - */ - public function getMethod() - { - return $this->method; - } - - /** - * Get parameters. - * - * @return array - */ - public function getParameters() - { - return $this->parameters; - } - - /** - * Get headers. - * - * @return array - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Get raw headers. - * - * @return array - */ - public function getRawHeaders() - { - $headers = []; - - foreach ($this->headers as $key => $value) { - $headers[] = $key . ': ' . $value; - } - - return $headers; - } - - /** - * Get body. - * - * @return string - */ - public function getBody() - { - return $this->body; - } -} diff --git a/includes/WooCommerce/HttpClient/Response.php b/includes/WooCommerce/HttpClient/Response.php deleted file mode 100644 index 15f7f41..0000000 --- a/includes/WooCommerce/HttpClient/Response.php +++ /dev/null @@ -1,113 +0,0 @@ -code = $code; - $this->headers = $headers; - $this->body = $body; - } - - /** - * Set code. - * - * @param int $code Response code. - */ - public function setCode($code) - { - $this->code = (int) $code; - } - - /** - * Set headers. - * - * @param array $headers Response headers. - */ - public function setHeaders($headers) - { - $this->headers = $headers; - } - - /** - * Set body. - * - * @param string $body Response body. - */ - public function setBody($body) - { - $this->body = $body; - } - - /** - * Get code. - * - * @return int - */ - public function getCode() - { - return $this->code; - } - - /** - * Get headers. - * - * @return array $headers Response headers. - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Get body. - * - * @return string $body Response body. - */ - public function getBody() - { - return $this->body; - } -} diff --git a/includes/WordPressClient.php b/includes/WordPressClient.php deleted file mode 100644 index 212a703..0000000 --- a/includes/WordPressClient.php +++ /dev/null @@ -1,251 +0,0 @@ -errors = array(); - - // Token storage - $this->storage = new DoliStorage($db, $conf); - - // Setup the credentials for the requests - $this->credentials = new Credentials( - $oauth_id, - $oauth_secret, - $callbackUrl - ); - - // Setup the api service - $this->baseApiUri = $baseApiUri.(substr($baseApiUri, -1, 1)!='/'?'/':'').'wp-json/wp/v2'; - $serviceFactory = new \OAuth\ServiceFactory(); - $this->httpClient = new CurlClientEx(); - $serviceFactory->setHttpClient($this->httpClient); - $this->apiService = $serviceFactory->createService(self::OAUTH_SERVICENAME_WORDPRESS, $this->credentials, $this->storage, array(), new Uri($baseApiUri)); - } - - /** - * POST method. - * - * @param string $endpoint API endpoint. - * @param array $data Request data. - * - * @return array - */ - public function post($endpoint, $data) - { - $this->errors = array(); - return $this->request($endpoint, 'POST', $data); - } - - /** - * POST media method. - * - * @param string $endpoint API endpoint. - * @param string $filepath File path. - * @param array $data Request data. - * - * @return array - */ - public function postmedia($endpoint, $filepath, $data) - { - $responseData = null; - $this->errors = array(); - - // Set File - if (file_exists($filepath)) { - if (function_exists('curl_file_create')) { // php 5.5+ - $cFile = curl_file_create($filepath); - } else { - $cFile = '@' . realpath($filepath); - } - $data['file'] = $cFile; - } else { - $this->errors[] = array('File not found ("'.$filepath.'").'); - return $responseData; - } - - $extraHeaders = array("Content-Type" => "multipart/form-data"); - - return $this->request($endpoint, 'POST', $data, $extraHeaders); - } - - /** - * PUT method. - * - * @param string $endpoint API endpoint. - * @param array $data Request data. - * - * @return array - */ - public function put($endpoint, $data) - { - $this->errors = array(); - return $this->request($endpoint, 'PUT', $data); - } - - /** - * GET method. - * - * @param string $endpoint API endpoint. - * @param array $parameters Request parameters. - * - * @return array - */ - public function get($endpoint, $parameters = []) - { - $this->errors = array(); - return $this->request($endpoint, 'GET', $parameters); - } - - /** - * DELETE method. - * - * @param string $endpoint API endpoint. - * @param array $parameters Request parameters. - * - * @return array - */ - public function delete($endpoint, $parameters = []) - { - $this->errors = array(); - return $this->request($endpoint, 'DELETE', $parameters); - } - - /** - * OPTIONS method. - * - * @param string $endpoint API endpoint. - * - * @return array - */ - public function options($endpoint) - { - $this->errors = array(); - return $this->request($endpoint, 'OPTIONS'); - } - - /** - * Request. - * - * @param string $endpoint API endpoint. - * @param string $method HTTP method - * @param array $body Request body if applicable (an associative array will - * automatically be converted into a urlencoded body) - * @param array $extraHeaders Extra headers if applicable. These will override service-specific - * any defaults. - * @return array - */ - public function request($endpoint, $method, $body = [], $extraHeaders = []) - { - $responseData = null; - - // Check if we have auth token - try { - $token = $this->storage->retrieveAccessToken(self::OAUTH_SERVICENAME_WORDPRESS); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - return $responseData; - } - - // Is token expired or will token expire in the next 30 seconds - $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); - - // Token expired so we refresh it - if ($expire) { - try { - $this->httpClient->setHttpPostBuildQuery(true); - $token = $this->apiService->refreshAccessToken($token); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - return $responseData; - } - } - - // Send a request with api - try { - $this->httpClient->setHttpPostBuildQuery(false); - $response = $this->apiService->request($this->baseApiUri.(substr($this->baseApiUri, -1, 1)!='/'?'/':'').$endpoint, $method, $body, $extraHeaders); - $responseData = json_decode($response, true); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - } - - return $responseData; - } -} diff --git a/includes/oauth-subscriber-woocommerce b/includes/oauth-subscriber-woocommerce new file mode 160000 index 0000000..fd04b27 --- /dev/null +++ b/includes/oauth-subscriber-woocommerce @@ -0,0 +1 @@ +Subproject commit fd04b277ad9ab6a9cc4d937d6b479bab5a95a8bf diff --git a/js/form.js b/js/form.js index 3d8c613..6b75f80 100644 --- a/js/form.js +++ b/js/form.js @@ -1,57 +1,34 @@ -function eCommerceSubmitForm(id_form) -{ - document.getElementById(id_form).submit(); -} - -function eCommerceConfirmDelete(id_form, confirmation) -{ - if (confirm(confirmation)) - { - document.getElementById(id_form+'_action').value = 'delete'; - eCommerceSubmitForm(id_form); - } -} - -function eCommerceConfirmWoocommerceUpdateAttributes(id_form, confirmation) -{ - if (confirm(confirmation)) - { - document.getElementById(id_form+'_action').value = 'update_woocommerce_attribute'; - eCommerceSubmitForm(id_form); - } -} - -function eCommerceConfirmWoocommerceUpdateDictTaxClass(id_form, confirmation) -{ - if (confirm(confirmation)) - { - document.getElementById(id_form+'_action').value = 'update_woocommerce_tax_class'; - eCommerceSubmitForm(id_form); - } -} - -function eCommerceConfirmUpdatePaymentGateways(id_form, confirmation) -{ - if (confirm(confirmation)) - { - document.getElementById(id_form+'_action').value = 'update_payment_gateways'; - eCommerceSubmitForm(id_form); - } -} +jQuery(document).ready(function (){ + var ef_crp_all = $('.ef_crp_all'); -function eCommerceConfirmUpdatePriceLevel(id_form, confirmation, price_level) -{ - jQuery('#'+id_form).on('submit', function(e) { - var current_price_level = jQuery('#'+id_form+' select[name="ecommerce_price_level"]').val(); + $.map(ef_crp_all, function (item) { + var table = $(item).closest('table'); - if (current_price_level != price_level && !confirm(confirmation)) { - e.preventDefault(); - } + act_ef_crp_update_all_checkbox(table); }); -} -jQuery(document).ready(function (){ - jQuery('#form_reset_data').submit(function() { - return confirm(jQuery('#confirm').val()); + $('.ef_crp_state').click(function () { + var _this = $(this); + var state = _this.is(':checked'); + var table = _this.closest('table'); + var tr_line = _this.closest('tr'); + + tr_line.find('.ef_crp_value').prop('disabled', !state); + act_ef_crp_update_all_checkbox(table); }); + + ef_crp_all.click(function () { + var _this = $(this); + var table = _this.closest('table'); + var state = _this.is(':checked'); + + table.find('.ef_crp_state').prop('checked', state); + table.find('.ef_crp_value').prop('disabled', !state); + }); + + function act_ef_crp_update_all_checkbox(table) { + var all_checkbox_checked = table.find('.ef_crp_state').length == table.find('.ef_crp_state:checked').length; + + table.find('.ef_crp_all').prop('checked', all_checkbox_checked); + } }); \ No newline at end of file diff --git a/langs/en_US/ecommerce.lang b/langs/en_US/ecommerce.lang index a8c46c7..4bac38f 100755 --- a/langs/en_US/ecommerce.lang +++ b/langs/en_US/ecommerce.lang @@ -17,6 +17,7 @@ ECommerceMenuSites=ECommerce Sync ECommerceMenuSetup=Setup ECommerce sites ##SETUP## +ECommerceNgSelectSite=Selection du site ECommercePriceType=Imported prices' types ECommercePriceTypeHT=Tax excluded ECommercePriceTypeTTC=Tax included @@ -35,6 +36,11 @@ ECommerceFilterLabel=Filter label ECommerceFilterValue=Filter value ECommerceSiteType=Ecommerce type ECommerceSiteAddress=URL for Magento SOAP services +ECommercAuthenticationType =Type d'authentification +ECommercAuthenticationTypeDescription =Choissiez le type de connexion à WooCommerce +ECommercAuthenticationTypeOauth =Oauth 1 (Les informations de connection sont passées dans l'entête de la requête) +ECommercAuthenticationTypeBasic =Basic (Les informations de connection sont passées dans l'entête de la requête) +ECommercAuthenticationTypeQuery =Url (Les informations de connection sont passées en clair dans l'url de la requête) ECommerceUserName=Username (for SOAP services) ECommerceUserPassword=API key (for SOAP services) ECommerceUserPasswordRetype=Retype API key @@ -157,8 +163,12 @@ SoapCacheIsOff=Your PHP WSDL cache is off. SetupOfWarehouseNotDefinedForThisSite=A new or modified product were found on eCommerce shop with a different stock level than into Dolibarr. To be able to create/update them in Dolibarr, you must setup the warehouse to initialize. ECommerceStockSyncDirection=Stock synchronisation direction ECommerceStockSyncDirectionDescription=Define if you want to see stock decrease in Dolibarr when stock decrease on Magento (rare), or overwrite Magento stock when stock in Dolibarr is modified (common choice) -ECommerceValidOrderWarehouse =Validation d'une commande/facture -ECommerceValidOrderWarehouseDescription =Entrepot utilisé lors de la validation d'une commande ou facture pendant une synchronisation du Site vers Dolibarr +ECommerceValidOrderWarehouse =Validation d'une commande +ECommerceValidOrderWarehouseDescription =Entrepot utilisé lors de la validation d'une commande pendant une synchronisation de E-Commerce vers Dolibarr +ECommerceValidInvoiceWarehouse =Validation d'une facture +ECommerceValidInvoiceWarehouseDescription =Entrepot utilisé lors de la validation d'une facture pendant une synchronisation de E-Commerce vers Dolibarr +ECommerceValidSupplierInvoiceWarehouse =Validation d'une facture fournisseur +ECommerceValidSupplierInvoiceWarehouseDescription =Entrepot utilisé lors de la validation d'une facture fournisseur pendant une synchronisation de E-Commerce vers Dolibarr MainSyncSetup=Main synchronization setup StockSyncSetup=Stock synchronization setup ErrorModuleSoapRequired=Error: PHP module SOAP is required to have this module working. @@ -173,6 +183,7 @@ ShowDebugTools=Show init/purge/debug tools ECommerceShipping=Shipping ECommercePriceLevel=Price level ECommercePriceLevelDescription=Only this price level are synchronized between Dolibarr and eCommerce +ECommerceUpdateLevelPrice =Mise à jour du niveau de prix ECommerceConfirmUpdatePriceLevel=You have changed the price level and the products on the eCommerce will be updated.\nThis may take a long time, please confirm. SeeECommerceConfFileIfKo=See content of file %s, on your eCommerce server, if this URL does not work. RestrictNbInSync=Restrict number of record of same object to synchronize in same request @@ -182,14 +193,15 @@ ECommerceDontUpdateDolibarrCompany ECommerceDontUpdateDolibarrCompanyDescription =Ne pas mettre à jour le tiers sur Dolibarr lorsqu'il existe déja dans dolibarr ## OAuth Setup ## -ECommerceOAuthWordpressSetup=OAuth2 connection on WordPress ( Go to this page , then "Add a new customer" to create the OAuth2 credentials) -ECommerceSiteOAuthRedirectUri=Redirection Url -ECommerceSiteOAuthRedirectUriDescription=Use the following redirection URL as redirection URI (Callback) when you create a new application (or a new customer) -ECommerceSiteOAuthId=OAuth ID -ECommerceSiteOAuthIdDescription=OAuth service connection ID -ECommerceSiteOAuthSecret=OAuth secret -ECommerceSiteOAuthSecretDescription=OAuth service connection secret -ECommerceOAuthCheckToken=Go to this page to verify/delete the authorizations saved by the OAuth2 provider. +ECommerceWordpressAuthenticationSetup =Connexion sur WordPress (Allez sur cette page , puis configurer la connexion) +ECommerceWordpressAuthenticationType =Type d'authentification +ECommerceWordpressAuthenticationTypeDescription =Choissiez entre la connexion interne Wordpress avec un mot de passe d'application situé sur un utilisateur
Ou une authentification JWT grâçe à l'extension "WordPress REST API Authentication" de miniOrange +ECommerceWordpressAuthenticationTypeWordpressApplication =Mot de passe d'application (Wordpress) +ECommerceWordpressAuthenticationTypeJWTAuthentication =Authentification JWT +ECommerceWordpressAuthenticationLogin =Identifiant +ECommerceWordpressAuthenticationLoginDescription =Identifiant de connexion +ECommerceWordpressAuthenticationPassword =Mot de passe +ECommerceWordpressAuthenticationPasswordDescription =Mot de passe de connexion ECommerceOrderStatusSetup=Order status synchronization ECommerceOrderStatusSetupDescription=Choose the corresponding status when synchronizing. @@ -235,12 +247,14 @@ ECommerceCreateRemoteProductLink=Error updating the product link 'id:%s' on the ECommerceUpdateRemoteOrderLink=Error updating the order link 'id:%s' on the site '%s': %s ECommerceUpdateRemoteInvoiceLink=Error updating the bill link 'id:%s' on the site '%s': %s -ECommerceRealTimeSynchroDolibarrToECommerceSetup = Real time synchronization from Dolibarr to Ecommerce -ECommerceThirdParty = Third parties -ECommerceContact = Contacts -ECommerceProduct = Products -ECommerceOrder = Orders -ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription = Synchronization of the element in the ECommerce site at the modification of the one linked in Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceThirdParty =Synchronisation du tiers en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceThirdPartyDescription =Synchronisation du tiers dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceContact =Synchronisation du contact en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceContactDescription =Synchronisation du contact dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceProduct =Synchronisation du produit en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceProductDescription =Synchronisation du produit dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceOrder =Synchronisation de la commande en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceOrderDescription =Synchronisation de la commande dans le site E-Commerce à la modification de celui lié dans Dolibarr ECommercePaymentCondition = Payment conditions ECommercePaymentConditionDescription = Default payment conditions when retrieving the order from the ECommerce site @@ -295,14 +309,21 @@ ECommerceOnlyNew = Only the new ones ECommerceUpdateRemoteCompanyLinkWhenMergeCompany = Error updating tje links of the company 'id:%s' during the merger with the company 'id:%s': %s ECommerceSynchronizeStockToECommerce=Synchronization of the product stock on the site %s. -ECommerceCreateOrderInvoiceWhenSyncOrder = Actions when retrieving WooCommerce orders ECommerceCreateOrder = Create the order +ECommerceCreateOrderDescription = Activer la création de la commande a la synchronisation de la commande ECommerceCreateInvoice = Create the bill +ECommerceCreateInvoiceDescription =Activer la création de la facture a la synchronisation de la commande +ECommerceCreateInvoiceType =Type la facture +ECommerceCreateInvoiceTypeDescription =Type la facture créée a la synchronisation de la commande ECommerceCreateSupplierInvoiceFromFee = Create the supplier bill from the charges +ECommerceCreateSupplierInvoiceFromFeeDescription =Créer la facture fournisseur à partir des frais lors de la creation de la facture ECommerceFeeLineAsItemLine = The fee line is as the service line +ECommerceFeeLineAsItemLineDescription =Considérer les lignes de frais comme des lignes de services lors de la création de la commande/facture ECommerceSendInvoiceByMail = Send the bill by email +ECommerceSendInvoiceByMailDescription =Envoyer la facture par courriel après la création avec succes de la facture ECommerceCreateOrderDescription = Related actions when retrieving WooCommerce orders (Enter the payment methods associated with WooCommerce) ECommerceCreateInvoiceIfAmount0 =Créer la facture même si le montant est égale à 0 +ECommerceCreateInvoiceIfAmount0Description =Créer la facture même si le montant est nul lors de la synchronisation de la commande ECommercePaymentGatewaysCorrespondence = Correspondence of the payment methods with the site ECommercePaymentGatewayLabel = Payment method on the site diff --git a/langs/en_US/woocommerce.lang b/langs/en_US/woocommerce.lang index 9cb1da2..582954f 100644 --- a/langs/en_US/woocommerce.lang +++ b/langs/en_US/woocommerce.lang @@ -2,39 +2,40 @@ CHARSET=UTF-8 ECommerceWoocommerceConnect=Error connecting to site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande=Error retrieving orders on the site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct=Error retrieving products on the site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations=Error retrieving variations of remote product 'id:%s' on the site '%s': %s -ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete=Erreor retrieving companies on the site '%s': %s +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande=Error retrieving orders on the site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct=Error retrieving products on the site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations=Error retrieving variations of remote product 'id:%s' on the site '%s': +ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete=Erreor retrieving companies on the site '%s': ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSocpeople=Error retrieving companies (for contact/adresses) on the site '%s': %s -ECommerceWoocommerceCreateRemoteProduct=Error creating the product 'id:%s' on the site '%s': %s +ECommerceWoocommerceCreateRemoteProduct=Error creating the product 'id:%s' on the site '%s': ECommerceWoocommerceCreateRemoteProductLink=Error creating the link for the product 'id:%s' on the site '%s': %s -ECommerceWoocommerceGetCategoryData=Error retrieving data from the remote category 'id:%s' on the site '%s': %s -ECommerceWoocommerceGetCommandeToUpdate=Error retrieving the list of orders to be updated on the site '%s': %s -ECommerceWoocommerceGetProductToUpdate=Error retrieving the list of products to be updated on the site '%s': %s -ECommerceWoocommerceGetRemoteCategoryTree=Error retrieving the list of categories to be updated on the site '%s': %s -ECommerceWoocommerceGetSocieteToUpdate=Error retrieving the list of companies to be updated on the site '%s': %s -ECommerceWoocommerceSendFileForCommande=Error linking the file with the remote order 'id:%s' on the site '%s': %s +ECommerceWoocommerceGetCategoryData=Error retrieving data from the remote category 'id:%s' on the site '%s': +ECommerceWoocommerceGetCommandeToUpdate=Error retrieving the list of orders to be updated on the site '%s': +ECommerceWoocommerceGetProductToUpdate=Error retrieving the list of products to be updated on the site '%s': +ECommerceWoocommerceGetRemoteCategoryTree=Error retrieving the list of categories to be updated on the site '%s': +ECommerceWoocommerceGetSocieteToUpdate=Error retrieving the list of companies to be updated on the site '%s': +ECommerceWoocommerceSendFileForCommande=Error linking the file with the remote order 'id:%s' on the site '%s': ECommerceWoocommerceSendFileForCommandeInWordpress=Error sending the file for the remote order 'id:%s' in the Wordpress media on the site '%s': %s -ECommerceWoocommerceUpdateRemoteCommande=Error updating the remote order 'id:%s' on the site '%s': %s -ECommerceWoocommerceUpdateRemoteProduct=Error updating the remote product 'id:%s' on the site '%s': %s -ECommerceWoocommerceUpdateRemoteTranslatedProduct=Error updating the translation 'id:%s' of the remote product 'id:%s' on the site '%s': %s -ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct=Error retrieving the remote product 'id:%s' on the site '%s': %s +ECommerceWoocommerceUpdateRemoteCommande=Error updating the remote order 'id:%s' on the site '%s': +ECommerceWoocommerceUpdateRemoteProduct=Error updating the remote product 'id:%s' on the site '%s': +ECommerceWoocommerceUpdateRemoteTranslatedProduct=Error updating the translation 'id:%s' of the remote product 'id:%s' on the site '%s': +ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct=Error retrieving the remote product 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteProductSendImage=Error sending an image for the product 'id:%s' in the Wordpress media on the site '%s': %s -ECommerceWoocommerceUpdateRemoteProductVariation=Error updating the variant 'id:%s' of the remote product 'id:%s' on the site '%s': %s +ECommerceWoocommerceUpdateRemoteProductVariation=Error updating the variant 'id:%s' of the remote product 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteTranslatedProductVariation=Error updating the translation 'id:%s' of the variant 'id:%s' of the remote product 'id:%s' on the site '%s' -ECommerceWoocommerceUpdateRemoteSociete=Error updating the remote company 'id:%s' on the site '%s': %s -ECommerceWoocommerceUpdateRemoteSocpeople=Error updating contacts/adresses of the remote company 'id:%s' on the site '%s': %s +ECommerceWoocommerceUpdateRemoteSociete=Error updating the remote company 'id:%s' on the site '%s': +ECommerceWoocommerceUpdateRemoteSocpeople=Error updating contacts/adresses of the remote company 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteStockProduct=Error updating inventory (%s) of the remote product 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteStockTranslatedProduct=Error updating inventory (%s) of the translation 'id:%s' of the remote product 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteStockProductVariation=Error updating inventory (%s) of the variant 'id:%s' of the remote product 'id:%s' on the site '%s': ECommerceWoocommerceUpdateRemoteStockTranslatedProductVariation=Error updating inventory (%s) of the translation 'id:%s' of the variant 'id:%s' of the remote product 'id:%s' on the site -ECommerceWoocommerceGetAllWoocommerceAttributes =Erreur de récupération des données des attributs sur le site '%s': %s -ECommerceWoocommerceGetAllWoocommerceTaxClass=Error retrieving tax class data from the site '%s': %s -ECommerceWoocommerceGetWoocommerceTaxes=Erreur retrieving tax data from the site '%s': %s +ECommerceWoocommerceGetAllWoocommerceAttributes =Erreur de récupération des données des attributs sur le site '%s': +ECommerceWoocommerceGetAllWoocommerceAttributeTerms =Erreur de récupération des données de l'attribut '%s' sur le site '%s': +ECommerceWoocommerceGetAllWoocommerceTaxClass=Error retrieving tax class data from the site '%s': +ECommerceWoocommerceGetWoocommerceTaxes=Erreur retrieving tax data from the site '%s': ECommerceWoocommerceCreateRemoteProductSendImage=Error sending an image for the prodcut 'ref:%s' in the Wordpress media on the site '%s': %s -ECommerceWoocommerceGetAllWoocommercePaymentGateways=Error retrieving tax class data from the site '%s': %s +ECommerceWoocommerceGetAllWoocommercePaymentGateways=Error retrieving payment gateways data from the site '%s': ECommerceWoocommerceGetTranslatedProductVariation=Error retrieving the translation 'id:%s' of the variant 'id:%s' of the remote product 'id:%s' on the site '%s': ECommercengWoocommerceStatus=Site status [%s] @@ -95,13 +96,14 @@ ECommercengWoocommerceProductExtrafieldsCorrespondenceAttributeSetupDescription ECommerceWoocommerceCreateRemoteCategoryParentNotCreated = Erreur pour le site '%s' lors de la recherche de l'ID parent da la catégorie '%s' (slug: '%s') ECommercengWoocommerceExtrafieldsCorrespondence = Match of additional attributes with Woocommerce metadata +ECommercengWoocommerceExtrafieldsCorrespondenceOf = Correspondance des attributs supplémentaires des "%s" avec les méta-données de Woocommerce ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription = Enter the name of the metadata corresponding to this additional attribute: %s ECommerceWoocommerceCreateRemoteCategoryParentNotCreated = Error for the site '%s' when searching for the parent ID of the category '%s' (slug: '%s') -ECommerceWoocommerceCreateRemoteBatchCategories = Error creating categories by batch on the site '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategories = Error creating categories by batch on the site '%s': ECommerceWoocommerceCreateRemoteBatchProducts = Error creating products by batch on the site '%s': %s -ECommerceWoocommerceCreateRemoteBatchCategory = Error crating the category (slug : %s) on the site '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategory = Error crating the category (slug : %s) on the site '%s': ECommerceWoocommerceCreateRemoteBatchProduct = Error creating the product (sku : %s) on the site '%s': %s ECommerceWoocommerceUpdateRemoteBatchProduct = Error updating the product (sku : %s) on the site '%s': %s @@ -149,5 +151,5 @@ ECommerceWoocommerceErrorUpdateDictTaxRate = Erreur updating the tax ra ECommerceWoocommerceErrorAddDictTaxRate = Erreur adding the tax rate line (ID: %s): %s ECommerceWooCommerceErrorTaxNotFound = Error the tax was not found in the synchronized one (ID: %s) ECommerceWooCommerceErrorDontSupportMultiTaxes = The module does not currently support multi-taxation. -ECommerceWoocommerceErrorGetWoocommerceWebHooks = Error retrieving webhooks from the site '%s': %s +ECommerceWoocommerceErrorGetWoocommerceWebHooks = Error retrieving webhooks from the site '%s': ECommerceWoocommerceErrorTaxClassNotFoundFromTaxRate = La taxe '%s' n'est pas trouver dans le dictionnaire de taxe du module WooSync pour le site '%s' pour le produit '%s' diff --git a/langs/fr_FR/ecommerce.lang b/langs/fr_FR/ecommerce.lang index ded8ddc..557401b 100644 --- a/langs/fr_FR/ecommerce.lang +++ b/langs/fr_FR/ecommerce.lang @@ -18,6 +18,7 @@ ECommerceMenuSites ECommerceMenuSetup =Configuration des sites ##SETUP## +ECommerceNgSelectSite =Selection du site magento =Magento woocommerce =WooCommerce ECommerceToDolibarr =De E-Commerce vers Dolibarr @@ -41,9 +42,19 @@ ECommerceFilterLabel ECommerceFilterValue =Valeur du filtre ECommerceSiteType =Type de site ECommerceSiteAddress =Adresse du site +ECommerceAuthenticationType =Type d'authentification +ECommerceAuthenticationTypeDescription =Choissiez le type de connexion à WooCommerce
- Oauth 1 (Entête) (Les informations de connection sont passées dans l'entête de la requête)
- Oauth 1 (Url) (Les informations de connection sont passées en clair dans l'url de la requête)
- Basic (Les informations de connection sont passées dans l'entête de la requête)
- Url (Les informations de connection sont passées en clair dans l'url de la requête) +ECommerceAuthenticationTypeOauth1Header =Oauth 1 (Entête) +ECommerceAuthenticationTypeOauth1Query =Oauth 1 (Url) +ECommerceAuthenticationTypeBasic =Basic +ECommerceAuthenticationTypeQuery =Url ECommerceUserName =Clé client API WooCommerce ECommerceUserPassword =Clé secret API WooCommerce ECommerceUserPasswordRetype =Clé secret API WooCommerce - confirmation +ECommerceTimeout =Timeout des accès à l'API de WooCommerce +ECommerceTimeoutDescription =Timeout des accès à l'API de WooCommerce, en secondes (30 secondes si vide) +ECommerceDebug =Debug +ECommerceDebugDescription =Activer le debug détaillé lors d'une connection à l'API de WooCommerce ECommerceConfirmDelete =Êtes vous sûre de vouloir supprimer ce site ? ECommerceConfirmReset =Êtes vous sûre de vouloir purger les données synchronisées liées à ce site ? (Attention : cette action est irréversible, toute les données synchronisées seront perdues) ECommerceSetupSaved =La configuration a bien été enregistrée. @@ -123,11 +134,7 @@ ECommerceSynchCommandeSuccess ECommerceSynchFactureSuccess =factures ont bien été synchronisées. ECommerceSynchSocieteFailed =%s erreurs se sont produites lors de la synchronisation. ECommerceSynchECommerceSocpeopleCreateError =Une erreur est survenue lors de l'enregistrement du contact (Tiers ID : %s; prénom: %s; nom: %s). -ECommerceTimeout =Timeout des accès aux APIs ECommerceClickUrlToTestUrl =Cliquez ici pour tester l'URL (un fichier XML ou JSON doit s'afficher) -ECommerceTimeoutDescription =Timeout des accès aux APIs, en secondes -ECommerceSetupTimeoutEmpty =Durée de connexion vide -ECommerceSetupTimeoutMustBeInt =La durée de connexion doit-être un entier ECommerceCategoriesProducts =Catégories de produits SyncCategFirst =Synchroniser d'abord les catégories ECommerceSynchCommandeError =Erreur durant la synchronisation des commandes @@ -156,8 +163,12 @@ SoapCacheIsOff SetupOfWarehouseNotDefinedForThisSite =Un nouveau produit ou un produit modifié a été trouvé sur la boutique E-Commerce avec un niveau de stock différent de celui de Dolibarr. Afin de pouvoir les créer/mettre à jour dans Dolibarr, vous devez mettre en place l'entrepôt à initialiser. ECommerceStockSyncDirection =Synchronisation des stocks ECommerceStockSyncDirectionDescription =Ce paramètre détermine :
- Si le stock doit être décrémenté dans Dolibarr suite à une décrémentation du stock E-Commerce (rare) ou
- Si le stock E-Commerce doit être remplacé par le stock Dolibarr suite à sa modification (choix commun) -ECommerceValidOrderWarehouse =Validation d'une commande/facture -ECommerceValidOrderWarehouseDescription =Entrepot utilisé lors de la validation d'une commande ou facture pendant une synchronisation de E-Commerce vers Dolibarr +ECommerceValidOrderWarehouse =Validation d'une commande +ECommerceValidOrderWarehouseDescription =Entrepot utilisé lors de la validation d'une commande pendant une synchronisation de E-Commerce vers Dolibarr +ECommerceValidInvoiceWarehouse =Validation d'une facture +ECommerceValidInvoiceWarehouseDescription =Entrepot utilisé lors de la validation d'une facture pendant une synchronisation de E-Commerce vers Dolibarr +ECommerceValidSupplierInvoiceWarehouse =Validation d'une facture fournisseur +ECommerceValidSupplierInvoiceWarehouseDescription =Entrepot utilisé lors de la validation d'une facture fournisseur pendant une synchronisation de E-Commerce vers Dolibarr MainSyncSetup =Synchronisation générale StockSyncSetup =Synchronisation des stocks ErrorModuleSoapRequired =Erreur: le module PHP SOAP est requis pour le bon fonctionnement du module. @@ -167,21 +178,28 @@ ShowDebugTools ECommerceShipping =Frais de port ECommercePriceLevel =Niveau de prix ECommercePriceLevelDescription =Seul ce niveau de prix sera synchronisé entre Dolibarr et E-Commerce +ECommerceUpdateLevelPrice =Mise à jour du niveau de prix ECommerceConfirmUpdatePriceLevel =Vous avez modifié le niveau de prix. Les produits sur le site E-Commerce vont être mis à jour.\nCette opération peut être longue, merci de confirmer. ThirdPartyForNonLoggedUsers =Tiers générique de recueil des clients sans compte créé SynchUnkownCustomersOnThirdParty =Tiers générique auquel seront rattachées les commandes de clients sans compte ECommerceDontUpdateDolibarrCompany =Mise à jour du tiers ECommerceDontUpdateDolibarrCompanyDescription =Ne pas mettre à jour le tiers de Dolibarr lorsqu'il existe déja dans dolibarr -## OAuth Setup ## -ECommerceOAuthWordpressSetup =Connexion OAuth2 sur WordPress (Allez sur cette page , puis "Ajouter un nouveau client" pour créer les informations d'identification OAuth2) -ECommerceSiteOAuthRedirectUri =URL de redirection -ECommerceSiteOAuthRedirectUriDescription =Utilisez l'URL suivante comme URI de redirection (Callback) quand vous créez une nouvelle application (ou un nouveau client) -ECommerceSiteOAuthId =OAuth ID -ECommerceSiteOAuthIdDescription =Id de connexion au service OAuth -ECommerceSiteOAuthSecret =OAuth secret -ECommerceSiteOAuthSecretDescription =Secret de connexion au service OAuth -ECommerceOAuthCheckToken =Allez sur cette page pour vérifier/effacer les autorisations sauvées par le fournisseur OAuth2. +## Wordpress Setup ## +ECommerceWordpressAuthenticationOptions =Paramètres de connexion à WordPress +ECommerceWordpressAuthenticationSetup =(Allez sur cette page , puis configurer la connexion) +ECommerceWordpressAuthenticationType =Type d'authentification +ECommerceWordpressAuthenticationTypeDescription =Choissiez entre la connexion interne Wordpress avec un mot de passe d'application situé sur un utilisateur
Ou une authentification JWT grâçe à l'extension "WordPress REST API Authentication" de miniOrange +ECommerceWordpressAuthenticationTypeWordpressApplication =Mot de passe d'application (Wordpress) +ECommerceWordpressAuthenticationTypeJWTAuthentication =Authentification JWT +ECommerceWordpressAuthenticationLogin =Identifiant +ECommerceWordpressAuthenticationLoginDescription =Identifiant de connexion +ECommerceWordpressAuthenticationPassword =Mot de passe +ECommerceWordpressAuthenticationPasswordDescription =Mot de passe de connexion +ECommerceWordpressTimeout =Timeout des accès à l'API de Wordpress +ECommerceWordpressTimeoutDescription =Timeout des accès à l'API de Wordpress, en secondes (30 secondes si vide) +ECommerceWordpressDebug =Debug +ECommerceWordpressDebugDescription =Activer le debug détaillé lors d'une connection à l'API de Wordpress ECommerceOrderStatusSetup =Synchronisation des statuts des commandes ECommerceOrderStatusSetupDescription =Choisissez le statut correspondant lors de la synchronisation. @@ -227,12 +245,14 @@ ECommerceCreateRemoteProductLink ECommerceUpdateRemoteOrderLink =Erreur de mise à jour du lien de la commande 'id:%s' sur le site '%s': %s ECommerceUpdateRemoteInvoiceLink =Erreur de mise à jour du lien de la facture 'id:%s' sur le site '%s': %s -ECommerceRealTimeSynchroDolibarrToECommerceSetup =Synchronisation en temps réel de Dolibarr vers E-Commerce -ECommerceThirdParty =Tiers -ECommerceContact =Contacts -ECommerceProduct =Produits -ECommerceOrder =Commandes -ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription =Synchronisation de l'élément dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceThirdParty =Synchronisation du tiers en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceThirdPartyDescription =Synchronisation du tiers dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceContact =Synchronisation du contact en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceContactDescription =Synchronisation du contact dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceProduct =Synchronisation du produit en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceProductDescription =Synchronisation du produit dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceOrder =Synchronisation de la commande en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceOrderDescription =Synchronisation de la commande dans le site E-Commerce à la modification de celui lié dans Dolibarr ECommercePaymentCondition =Conditions de règlement ECommercePaymentConditionDescription =Conditions de règlement par défaut lors de la récupération de la commande depuis le site E-Commerce @@ -287,14 +307,29 @@ ECommerceOnlyNew ECommerceUpdateRemoteCompanyLinkWhenMergeCompany =Erreur de mise à jour des lien de la société 'id:%s' lors de la fusion avec la société 'id:%s': %s ECommerceSynchronizeStockToECommerce =Synchronisation du stock du produit sur le site %s. -ECommerceCreateOrderInvoiceWhenSyncOrder =Actions lors de la récupération des commandes WooCommerce ECommerceCreateOrder =Créer la commande +ECommerceCreateOrderDescription =Activer la création de la commande a la synchronisation de la commande ECommerceCreateInvoice =Créer la facture +ECommerceCreateInvoiceDescription =Activer la création de la facture a la synchronisation de la commande +ECommerceCreateInvoiceType =Type la facture +ECommerceCreateInvoiceTypeDescription =Type la facture créée a la synchronisation de la commande ECommerceCreateSupplierInvoiceFromFee =Créer la facture fournisseur à partir des frais +ECommerceCreateSupplierInvoiceFromFeeDescription =Créer la facture fournisseur à partir des frais lors de la creation de la facture ECommerceFeeLineAsItemLine =Considérer les lignes de frais comme des lignes de services +ECommerceFeeLineAsItemLineDescription =Considérer les lignes de frais comme des lignes de services lors de la création de la commande/facture ECommerceSendInvoiceByMail =Envoyer la facture par courriel +ECommerceSendInvoiceByMailDescription =Envoyer la facture par courriel après la création avec succes de la facture ECommerceCreateOrderDescription =Actions associées lors de la récupération des commandes WooCommerce (renseigner les modes de paiements associés à WooCommerce) ECommerceCreateInvoiceIfAmount0 =Créer la facture même si le montant est nul +ECommerceCreateInvoiceIfAmount0Description =Créer la facture même si le montant est nul lors de la synchronisation de la commande + +ECommerceRemoteWarehousesCorrespondence =Correspondance des entrpôts avec le site +ECommerceWarehouseSetToZeroEvenIfEmptyStock =Definie le stock même si la quantité est à zero +ECommerceWarehouseOldEntry =Ancien entrepôt +ECommerceUpdateRemoteWarehouses =Mise à jour des entrepôts distants +ECommerceConfirmUpdateRemoteWarehouses =Confirmer la mise à jour des entrepôts distants pour ce site ? +ECommerceRemoteWarehousesUpdated =Les entrepôts distants depuis le site ont été mise à jour. +ECommerceRemoteID =ID distant ECommercePaymentGatewaysCorrespondence =Correspondance des modes de paiements avec le site ECommercePaymentGatewayLabel =Mode de paiement sur le site @@ -425,6 +460,24 @@ ECommerceSendEmailErrorCheckWebHooksVolumetry ECommerceSendEmailErrorCheckWebHooksVolumetryErrorSubject =[WooSync] Erreur lors de la vérification de la volumétrie des crochets Web (WebHooks) ECommerceCheckWebHooksVolumetrySuccess =La vérification de la volumétrie des crochets Web (WebHooks) s'est terminée avec succès +####################################################################### +# API +####################################################################### +ECommerceRequestData = Données de la requête +ECommerceRequestProtocolVersion = Version du protocole +ECommerceRequestUri = Url +ECommerceRequestMethod = Méthode +ECommerceRequestTarget = Cible +ECommerceRequestHeaders = En-têtes +ECommerceRequestBody = Corps +ECommerceResponseData = Données de la réponse +ECommerceResponseProtocolVersion = Version du protocole +ECommerceResponseCode = Code +ECommerceResponseReasonPhrase = Raison +ECommerceResponseHeaders = En-têtes +ECommerceResponseBody = Corps +ECommerceErrorBadConvertResult = Mauvais format de la réponse d'une requête sur l'API + ############################################################################################ # Errors ############################################################################################ @@ -555,6 +608,7 @@ ECommerceErrorUpdateProductComponent ECommerceErrorDelProductComponent =Erreur lors de la suppression du composant (ID: %s) constituant le produit (ID: %s) ECommerceErrorSetOrderCorrectAmount =Erreur lors du forçage du prix TTC de la commande ECommerceErrorSetInvoiceCorrectAmount =Erreur lors du forçage du prix TTC de la facture +ECommerceErrorConnectAPI =Erreur de connexion au site '%s' ############################################################################################ # Warnings diff --git a/langs/fr_FR/woocommerce.lang b/langs/fr_FR/woocommerce.lang index 676f703..7575c2f 100644 --- a/langs/fr_FR/woocommerce.lang +++ b/langs/fr_FR/woocommerce.lang @@ -2,39 +2,41 @@ CHARSET=UTF-8 ECommerceWoocommerceConnect =Erreur de connexion au site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande =Erreur de récupération des commandes sur le site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct =Erreur de récupération des produits sur le site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations =Erreur de récupération des variations du produit distant 'id:%s' sur le site '%s': %s -ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete =Erreur de récupération des sociétés sur le site '%s': %s +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande =Erreur de récupération des commandes sur le site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct =Erreur de récupération des produits sur le site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations =Erreur de récupération des variations du produit distant 'id:%s' sur le site '%s': +ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete =Erreur de récupération des sociétés sur le site '%s': ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSocpeople =Erreur de récupération des sociétés (pour les contacts/adresses) sur le site '%s': %s -ECommerceWoocommerceCreateRemoteProduct =Erreur de création du produit 'id:%s' sur le site '%s': %s +ECommerceWoocommerceCreateRemoteProduct =Erreur de création du produit 'id:%s' sur le site '%s': ECommerceWoocommerceCreateRemoteProductLink =Erreur de création du lien pour le produit 'id:%s' pour le site '%s': %s -ECommerceWoocommerceGetCategoryData =Erreur de récupération des données de la catégorie distante 'id:%s' sur le site '%s': %s -ECommerceWoocommerceGetCommandeToUpdate =Erreur de récupération de la liste des commandes à mettre à jour sur le site '%s': %s -ECommerceWoocommerceGetProductToUpdate =Erreur de récupération de la liste des produits à mettre à jour sur le site '%s': %s -ECommerceWoocommerceGetRemoteCategoryTree =Erreur de récupération de la liste des catégories à mettre à jour sur le site '%s': %s -ECommerceWoocommerceGetSocieteToUpdate =Erreur de récupération de la liste des sociétés à mettre à jour sur le site '%s': %s -ECommerceWoocommerceSendFileForCommande =Erreur pour lier le fichier avec la commande distante 'id:%s' sur le site '%s': %s +ECommerceWoocommerceGetCategoryData =Erreur de récupération des données de la catégorie distante 'id:%s' sur le site '%s': +ECommerceWoocommerceGetCommandeToUpdate =Erreur de récupération de la liste des commandes à mettre à jour sur le site '%s': +ECommerceWoocommerceGetProductToUpdate =Erreur de récupération de la liste des produits à mettre à jour sur le site '%s': +ECommerceWoocommerceGetRemoteCategoryTree =Erreur de récupération de la liste des catégories à mettre à jour sur le site '%s': +ECommerceWoocommerceGetSocieteToUpdate =Erreur de récupération de la liste des sociétés à mettre à jour sur le site '%s': +ECommerceWoocommerceSendFileForCommande =Erreur pour lier le fichier avec la commande distante 'id:%s' sur le site '%s': ECommerceWoocommerceSendFileForCommandeInWordpress =Erreur de l'envoi du fichier pour la commande distante 'id:%s' dans les médias de Wordpress sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteCommande =Erreur de mise à jour de la commande distante 'id:%s' sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteProduct =Erreur de mise à jour du produit distant 'id:%s' sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteTranslatedProduct =Erreur de mise à jour de la traduction 'id:%s' du produit distant 'id:%s' sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct =Erreur de récupération du produit distant 'id:%s' sur le site '%s': %s +ECommerceWoocommerceUpdateRemoteCommande =Erreur de mise à jour de la commande distante 'id:%s' sur le site '%s': +ECommerceWoocommerceUpdateRemoteProduct =Erreur de mise à jour du produit distant 'id:%s' sur le site '%s': +ECommerceWoocommerceUpdateRemoteTranslatedProduct =Erreur de mise à jour de la traduction 'id:%s' du produit distant 'id:%s' sur le site '%s': +ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct =Erreur de récupération du produit distant 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteProductSendImage =Erreur de l'envoi d'une image pour le produit distante 'id:%s' dans les médias de Wordpress sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteProductVariation =Erreur de mise à jour de la variation 'id:%s' du produit distant 'id:%s' sur le site '%s': %s +ECommerceWoocommerceUpdateRemoteProductVariation =Erreur de mise à jour de la variation 'id:%s' du produit distant 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteTranslatedProductVariation =Erreur de mise à jour de la traduction 'id:%s' de la variation 'id:%s' du produit distant 'id:%s' sur le site '%s' -ECommerceWoocommerceUpdateRemoteSociete =Erreur de mise à jour de la société distante 'id:%s' sur le site '%s': %s -ECommerceWoocommerceUpdateRemoteSocpeople =Erreur de mise à jour des contacts/adresses de la société distante 'id:%s' sur le site '%s': %s +ECommerceWoocommerceUpdateRemoteSociete =Erreur de mise à jour de la société distante 'id:%s' sur le site '%s': +ECommerceWoocommerceUpdateRemoteSocpeople =Erreur de mise à jour des contacts/adresses de la société distante 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteStockProduct =Erreur de mise à jour des stocks (%s) du produit distant 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteStockTranslatedProduct =Erreur de mise à jour des stocks (%s) de la traduction 'id:%s' du produit distant 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteStockProductVariation =Erreur de mise à jour des stocks (%s) de la variation 'id:%s' du produit distant 'id:%s' sur le site '%s': ECommerceWoocommerceUpdateRemoteStockTranslatedProductVariation =Erreur de mise à jour des stocks (%s) de la traduction 'id:%s' de la variation 'id:%s' du produit distant 'id:%s' sur le site -ECommerceWoocommerceGetAllWoocommerceAttributes =Erreur de récupération des données des attributs sur le site '%s': %s -ECommerceWoocommerceGetAllWoocommerceTaxClass =Erreur de récupération des données des classes de taxes sur le site '%s': %s -ECommerceWoocommerceGetWoocommerceTaxes =Erreur de récupération des données des taxes sur le site '%s': %s +ECommerceWoocommerceGetAllWoocommerceAttributes =Erreur de récupération des données des attributs sur le site '%s': +ECommerceWoocommerceGetAllWoocommerceAttributeTerms =Erreur de récupération des données de l'attribut '%s' sur le site '%s': +ECommerceWoocommerceGetAllWoocommerceTaxClass =Erreur de récupération des données des classes de taxes sur le site '%s': +ECommerceWoocommerceGetWoocommerceTaxes =Erreur de récupération des données des taxes sur le site '%s': ECommerceWoocommerceCreateRemoteProductSendImage =Erreur de l'envoi d'une image pour le produit 'ref:%s' dans les médias de Wordpress sur le site '%s': %s -ECommerceWoocommerceGetAllWoocommercePaymentGateways =Erreur de récupération des données des classes de taxes sur le site '%s': %s +ECommerceWoocommerceGetAllWoocommercePaymentGateways =Erreur de récupération des données des modes de paiement sur le site '%s': +ECommerceWoocommerceGetAllWoocommerceRemoteWarehouses =Erreur de récupération des données des entrepots distants sur le site '%s': ECommerceWoocommerceGetTranslatedProductVariation =Erreur de récupération de la traduction 'id:%s' de la variation 'id:%s' du produit distant 'id:%s' sur le site '%s': ECommercengWoocommerceStatus =Statut pour le site [%s] @@ -66,6 +68,9 @@ ECommerceWoocommerceErrorDisableDictAttribute =Erreur de ECommerceWoocommerceErrorAddDictAttribute =Erreur d'ajout d'un attribut, slug:"%s", nom:"%s", erreur:"%s" ECommerceWoocommerceErrorUpdateDictAttribute =Erreur de mise à jour d'un attribut, slug:"%s", erreur:"%s" +ECommerceWoocommerceEnableWarehouseSlPluginSupport = Stock Locations +ECommerceWoocommerceEnableWarehousePluginSlSupportDescription = Active le support de l'extension "Stock Locations" installée sur WooCommerce + ECommercengWoocommerceStatusDraft =Brouillon ECommercengWoocommerceStatusPending =En attente de relecture ECommercengWoocommerceStatusPrivate =Privé @@ -91,13 +96,14 @@ ECommercengWoocommerceProductAttribute ECommercengWoocommerceProductExtrafieldsCorrespondenceAttributeSetupDescription = Code champ dolibarr : %s. Les valeurs du champ complémentaire Dolibarr doit être sous la forme "Nom,Nom" exemple: "Jaune,Jaune" ECommercengWoocommerceExtrafieldsCorrespondence = Correspondance des attributs supplémentaires avec les méta-données de Woocommerce +ECommercengWoocommerceExtrafieldsCorrespondenceOf = Correspondance des attributs supplémentaires des "%s" avec les méta-données de Woocommerce ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription = Renseigner le nom de la méta-donnée correspondant à cet attribut supplémentaire : %s ECommerceWoocommerceCreateRemoteCategoryParentNotCreated = Erreur pour le site '%s' lors de la recherche de l'ID parent da la catégorie '%s' (slug: '%s') -ECommerceWoocommerceCreateRemoteBatchCategories = Erreur lors de la création des catégories par lot sur le site '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategories = Erreur lors de la création des catégories par lot sur le site '%s': ECommerceWoocommerceCreateRemoteBatchProducts = Erreur lors de la création des produits par lot sur le site '%s': %s -ECommerceWoocommerceCreateRemoteBatchCategory = Erreur lors de la création de la catégorie (slug : %s) sur le site '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategory = Erreur lors de la création de la catégorie (slug : %s) sur le site '%s': ECommerceWoocommerceCreateRemoteBatchProduct = Erreur lors de la création du produit (UGS : %s) sur le site '%s': %s ECommerceWoocommerceUpdateRemoteBatchProduct = Erreur lors de la mise à jour du produit (UGS : %s) sur le site '%s': %s @@ -145,5 +151,5 @@ ECommerceWoocommerceErrorUpdateDictTaxRate = Erreur lo ECommerceWoocommerceErrorAddDictTaxRate = Erreur lors de l'ajout de la ligne du taux de la taxe (ID: %s): %s ECommerceWooCommerceErrorTaxNotFound = Erreur la taxe n'a pas été trouvée dans celles synchronisées (ID: %s) ECommerceWooCommerceErrorDontSupportMultiTaxes = Le module ne supporte pas actuellement le multi-taxe. -ECommerceWoocommerceErrorGetWoocommerceWebHooks = Erreur de récupération des crochets web sur le site '%s': %s +ECommerceWoocommerceErrorGetWoocommerceWebHooks = Erreur de récupération des crochets web sur le site '%s': ECommerceWoocommerceErrorTaxClassNotFoundFromTaxRate = La taxe '%s' n'est pas trouvée dans le dictionnaire de taxe du module WooSync pour le site '%s' pour le produit '%s' diff --git a/langs/it_IT/ecommerce.lang b/langs/it_IT/ecommerce.lang index 2026fab..959e5b4 100644 --- a/langs/it_IT/ecommerce.lang +++ b/langs/it_IT/ecommerce.lang @@ -162,6 +162,7 @@ ShowDebugTools=Mostra gli strumenti init / purge / debug ECommerceShipping=Spese di spedizione ECommercePriceLevel=Livello dei prezzi ECommercePriceLevelDescription=Solo questo livello di prezzo sarà sincronizzato tra Dolibarr ed E-commerce +ECommerceUpdateLevelPrice =Mise à jour du niveau de prix ECommerceConfirmUpdatePriceLevel=Hai modificato il livello dei prezzi. I prodotti sul sito di e-commerce verranno aggiornati. Potrebbe essere necessario molto tempo, confermare. SeeECommerceConfFileIfKo=See content of file %s, on your eCommerce server, if this URL does not work. RestrictNbInSync=Restrict number of record of same object to synchronize in same request @@ -171,14 +172,15 @@ ECommerceDontUpdateDolibarrCompany ECommerceDontUpdateDolibarrCompanyDescription =Ne pas mettre à jour le tiers sur Dolibarr lorsqu'il existe déja dans dolibarr ## OAuth Setup ## -ECommerceOAuthWordpressSetup=Connessione OAuth2 su WordPress (continua su questa pagina, quindi "Aggiungi un nuovo client" per creare le credenziali OAuth2) -ECommerceSiteOAuthRedirectUri=URL di reindirizzamento -ECommerceSiteOAuthRedirectUriDescription=Utilizzare il seguente URL come URI di richiamata quando si crea una nuova applicazione (o un nuovo client) -ECommerceSiteOAuthId=OAuth ID -ECommerceSiteOAuthIdDescription=ID connessione servizio OAuth -ECommerceSiteOAuthSecret=OAuth secret -ECommerceSiteOAuthSecretDescription=Client Secret della connessione al servizio OAuth -ECommerceOAuthCheckToken=continua questa pagina per controllare / cancellare le autorizzazioni salvate dal provider OAuth2. +ECommerceWordpressAuthenticationSetup =Connexion sur WordPress (Allez sur cette page , puis configurer la connexion) +ECommerceWordpressAuthenticationType =Type d'authentification +ECommerceWordpressAuthenticationTypeDescription =Choissiez entre la connexion interne Wordpress avec un mot de passe d'application situé sur un utilisateur
Ou une authentification JWT grâçe à l'extension "WordPress REST API Authentication" de miniOrange +ECommerceWordpressAuthenticationTypeWordpressApplication =Mot de passe d'application (Wordpress) +ECommerceWordpressAuthenticationTypeJWTAuthentication =Authentification JWT +ECommerceWordpressAuthenticationLogin =Identifiant +ECommerceWordpressAuthenticationLoginDescription =Identifiant de connexion +ECommerceWordpressAuthenticationPassword =Mot de passe +ECommerceWordpressAuthenticationPasswordDescription =Mot de passe de connexion ECommerceOrderStatusSetup=Sincronizzazione degli stati degli ordini ECommerceOrderStatusSetupDescription=Scegli lo stato corrispondente durante la sincronizzazione. @@ -224,12 +226,14 @@ ECommerceCreateRemoteProductLink=Errore durante la creazione del collegamento al ECommerceUpdateRemoteOrderLink=Errore durante l'aggiornamento del collegamento dell'ordine cliente 'id:%s' per lo shop '%s': %s ECommerceUpdateRemoteInvoiceLink=Errore durante l'aggiornamento del collegamento alla fattura 'id:%s' per lo shop '%s': %s -ECommerceRealTimeSynchroDolibarrToECommerceSetup = Sincronizzazione in tempo reale da Dolibarr allo Shop -ECommerceThirdParty = Soggetti terzi -ECommerceContact = Contatti -ECommerceProduct = Prodotti -ECommerceOrder = Ordini clienti -ECommerceRealTimeSynchroDolibarrToECommerceSetupDescription = Sincronizza l'articolo nello shop dopo la modifica dell'articolo collegato in Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceThirdParty =Synchronisation du tiers en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceThirdPartyDescription =Synchronisation du tiers dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceContact =Synchronisation du contact en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceContactDescription =Synchronisation du contact dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceProduct =Synchronisation du produit en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceProductDescription =Synchronisation du produit dans le site E-Commerce à la modification de celui lié dans Dolibarr +ECommerceRealTimeSynchroDolibarrToECommerceOrder =Synchronisation de la commande en temps réel de Dolibarr vers E-Commerce +ECommerceRealTimeSynchroDolibarrToECommerceOrderDescription =Synchronisation de la commande dans le site E-Commerce à la modification de celui lié dans Dolibarr ECommerceSyncheCommerceMotherCategoryCreateError=Erreur de création du lien de la catégorie racine pour la catégorie distante '%s' 'id:%s' sur le site '%s'. ECommerceNGUpdateElementDateMoreRecent=Inclus aussi les éléments dont la date de mise à jour est plus récente que celle de synchronisation @@ -312,14 +316,21 @@ ECommerceOnlyNew = Only the new ones ECommerceUpdateRemoteCompanyLinkWhenMergeCompany = Errore durante l'aggiornamento del collegamento della società "id: %s" durante l'unione con la società 'id:%s': %s ECommerceSynchronizeStockToECommerce=Synchronization of the product stock on the site %s. -ECommerceCreateOrderInvoiceWhenSyncOrder = Actions when retrieving WooCommerce orders ECommerceCreateOrder = Create the order +ECommerceCreateOrderDescription = Activer la création de la commande a la synchronisation de la commande ECommerceCreateInvoice = Create the bill +ECommerceCreateInvoiceDescription =Activer la création de la facture a la synchronisation de la commande +ECommerceCreateInvoiceType =Type la facture +ECommerceCreateInvoiceTypeDescription =Type la facture créée a la synchronisation de la commande ECommerceCreateSupplierInvoiceFromFee = Create the supplier bill from the charges +ECommerceCreateSupplierInvoiceFromFeeDescription =Créer la facture fournisseur à partir des frais lors de la creation de la facture ECommerceFeeLineAsItemLine = The fee line is as the service line +ECommerceFeeLineAsItemLineDescription =Considérer les lignes de frais comme des lignes de services lors de la création de la commande/facture ECommerceSendInvoiceByMail = Send the bill by email +ECommerceSendInvoiceByMailDescription =Envoyer la facture par courriel après la création avec succes de la facture ECommerceCreateOrderDescription = Related actions when retrieving WooCommerce orders (Enter the payment methods associated with WooCommerce) ECommerceCreateInvoiceIfAmount0 =Créer la facture même si le montant est égale à 0 +ECommerceCreateInvoiceIfAmount0Description =Créer la facture même si le montant est nul lors de la synchronisation de la commande ECommercePaymentGatewaysCorrespondence = Correspondence of the payment methods with the site ECommercePaymentGatewayLabel = Payment method on the site diff --git a/langs/it_IT/woocommerce.lang b/langs/it_IT/woocommerce.lang index dbe678d..2c1b40c 100644 --- a/langs/it_IT/woocommerce.lang +++ b/langs/it_IT/woocommerce.lang @@ -2,32 +2,32 @@ CHARSET=UTF-8 ECommerceWoocommerceConnect=Errore di connessione allo shop '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande=Errore durante il recupero degli ordini dallo shop '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct=Errore durante il recupero dei prodotti dallo shop '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations=Errore durante il recupero delle varianti del prodotto remoto 'id:%s' dallo shop '%s': %s -ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': %s -ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete=Errore durante il recupero dei soggetti terzi dallo shop '%s': %s +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrCommande=Errore durante il recupero degli ordini dallo shop '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProduct=Errore durante il recupero dei prodotti dallo shop '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrProductVariations=Errore durante il recupero delle varianti del prodotto remoto 'id:%s' dallo shop '%s': +ECommerceWoocommerceCheckRemoteProductExist =Erreur lors de la verification de l'existance du produit %s sur le site '%s': +ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSociete=Errore durante il recupero dei soggetti terzi dallo shop '%s': ECommerceWoocommerceConvertRemoteObjectIntoDolibarrSocpeople=Errore durante il recupero dei soggetti terzi (per i contatti / indirizzi) dallo shop '%s': %s -ECommerceWoocommerceCreateRemoteProduct=Errore durante la creazione del prodotto 'id:%s' dallo shop '%s': %s +ECommerceWoocommerceCreateRemoteProduct=Errore durante la creazione del prodotto 'id:%s' dallo shop '%s': ECommerceWoocommerceCreateRemoteProductLink=Errore di creazione del collegamento per il prodotto 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceGetCategoryData=Errore durante il recupero dei dati dalla categoria remota 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceGetCommandeToUpdate=Errore durante il recupero dell'elenco degli ordini da aggiornare sullo shop '%s': %s -ECommerceWoocommerceGetProductToUpdate=Errore durante il recupero dell'elenco dei prodotti da aggiornare sullo shop '%s': %s -ECommerceWoocommerceGetRemoteCategoryTree=Errore durante il recupero dell'elenco delle categorie da aggiornare sullo shop '%s': %s -ECommerceWoocommerceGetSocieteToUpdate=Errore durante il recupero dell'elenco dei soggetti terzi da aggiornare sullo shop '%s': %s -ECommerceWoocommerceSendFileForCommande=Errore durante il collegamento del file con l'ordine cliente remoto'id:%s' per lo shop '%s': %s +ECommerceWoocommerceGetCategoryData=Errore durante il recupero dei dati dalla categoria remota 'id:%s' per lo shop '%s': +ECommerceWoocommerceGetCommandeToUpdate=Errore durante il recupero dell'elenco degli ordini da aggiornare sullo shop '%s': +ECommerceWoocommerceGetProductToUpdate=Errore durante il recupero dell'elenco dei prodotti da aggiornare sullo shop '%s': +ECommerceWoocommerceGetRemoteCategoryTree=Errore durante il recupero dell'elenco delle categorie da aggiornare sullo shop '%s': +ECommerceWoocommerceGetSocieteToUpdate=Errore durante il recupero dell'elenco dei soggetti terzi da aggiornare sullo shop '%s': +ECommerceWoocommerceSendFileForCommande=Errore durante il collegamento del file con l'ordine cliente remoto'id:%s' per lo shop '%s': ECommerceWoocommerceSendFileForCommandeInWordpress=Errore durante l'invio del file per il comando remoto 'id:%s' nei media di Wordpress per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteCommande=Errore durante l'aggiornamento dell'ordine cliente remoto 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteProduct=Errore durante l'aggiornamento del prodotto remoto 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct=Errore durante il recupero del prodotto remoto 'id:%s' per lo shop '%s': %s +ECommerceWoocommerceUpdateRemoteCommande=Errore durante l'aggiornamento dell'ordine cliente remoto 'id:%s' per lo shop '%s': +ECommerceWoocommerceUpdateRemoteProduct=Errore durante l'aggiornamento del prodotto remoto 'id:%s' per lo shop '%s': +ECommerceWoocommerceUpdateRemoteProductGetRemoteProduct=Errore durante il recupero del prodotto remoto 'id:%s' per lo shop '%s': ECommerceWoocommerceUpdateRemoteProductSendImage=Errore durante l'invio di un'immagine per il prodotto remoto 'id:%s' nei media di Wordpress per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteProductVariation=Errore durante l'aggiornamento della variazione 'id:%s' del prodotto remoto 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteSociete=Errore durante l'aggiornamento dell'azienda remota 'id:%s' per lo shop '%s': %s -ECommerceWoocommerceUpdateRemoteSocpeople=Errore durante l'aggiornamento dei contatti / indirizzi dell'azienda remota 'id:%s' per lo shop '%s': %s +ECommerceWoocommerceUpdateRemoteProductVariation=Errore durante l'aggiornamento della variazione 'id:%s' del prodotto remoto 'id:%s' per lo shop '%s': +ECommerceWoocommerceUpdateRemoteSociete=Errore durante l'aggiornamento dell'azienda remota 'id:%s' per lo shop '%s': +ECommerceWoocommerceUpdateRemoteSocpeople=Errore durante l'aggiornamento dei contatti / indirizzi dell'azienda remota 'id:%s' per lo shop '%s': ECommerceWoocommerceUpdateRemoteStockProduct=Errore di aggiornamento delle scorte di magazzino (%s) del prodotto remoto 'id:%s' per lo shop '%s': ECommerceWoocommerceUpdateRemoteStockProductVariation=Errore di aggiornamento dello stock (%s) della variante 'id:%s' del prodotto remoto 'id:%s' per lo shop '%s': -ECommerceWoocommerceGetAllWoocommerceTaxClass=Errore durante la raccolta dei dati sull'aliquota fiscale per lo shop '%s': %s -ECommerceWoocommerceGetWoocommerceTaxes=Errore durante il recupero delle aliquote fiscali per lo shop '%s': %s +ECommerceWoocommerceGetAllWoocommerceTaxClass=Errore durante la raccolta dei dati sull'aliquota fiscale per lo shop '%s': +ECommerceWoocommerceGetWoocommerceTaxes=Errore durante il recupero delle aliquote fiscali per lo shop '%s': ECommerceWoocommerceCreateRemoteProductSendImage=Errore durante l'invio di un'immagine per il prodotto 'ref:%s' nei media di Wordpress per lo shop '%s': %s ECommercengWoocommerceStatus=Stato per lo shop [%s] @@ -61,13 +61,14 @@ ECommercengWoocommerceOrderStatusRefunded=Rimborsato ECommercengWoocommerceOrderStatusFailed=Fallito ECommercengWoocommerceExtrafieldsCorrespondence = Abbina attributi aggiuntivi ai metadati di Woocommerce +ECommercengWoocommerceExtrafieldsCorrespondenceOf = Correspondance des attributs supplémentaires des "%s" avec les méta-données de Woocommerce ECommercengWoocommerceExtrafieldsCorrespondenceSetupDescription = Inserisci il nome dei metadati corrispondenti a questo attributo aggiuntivo: %s ECommerceWoocommerceCreateRemoteCategoryParentNotCreated = Errore per lo shop '%s' durante la ricerca dell'ID principale della categoria '%s' (slug: '%s') -ECommerceWoocommerceCreateRemoteBatchCategories = Errore durante la creazione delle categorie lotto sullo shop '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategories = Errore durante la creazione delle categorie lotto sullo shop '%s': ECommerceWoocommerceCreateRemoteBatchProducts = Errore durante la creazione di lotti di prodotto sullo shop '%s': %s -ECommerceWoocommerceCreateRemoteBatchCategory = Errore durante la creazione della categoria (slug : %s) per lo shop '%s': %s +ECommerceWoocommerceCreateRemoteBatchCategory = Errore durante la creazione della categoria (slug : %s) per lo shop '%s': ECommerceWoocommerceCreateRemoteBatchProduct = Errore durante la creazione del prodotto (sku : %s) per lo shop'%s': %s ECommerceWoocommerceUpdateRemoteBatchProduct = Errore durante l'aggiornamento del prodotto (sku : %s) per lo shop'%s': %s diff --git a/lib/eCommerce.lib.php b/lib/eCommerce.lib.php index 8480d3d..c6edb4c 100644 --- a/lib/eCommerce.lib.php +++ b/lib/eCommerce.lib.php @@ -22,6 +22,71 @@ dol_include_once('/ecommerceng/class/business/eCommerceSynchro.class.php'); dol_include_once('/ecommerceng/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php'); +/** + * Prepare array with list of tabs for configuration of sites + * + * @param eCommerceSite $object Site handler + * @return array Array of tabs to show + */ +function ecommercengConfigSitePrepareHead($object) +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath("/ecommerceng/admin/setup.php", 1) . ($object->id > 0 ? '?id=' . $object->id : ''); + $head[$h][1] = $langs->trans("Parameters"); + $head[$h][2] = 'settings'; + $h++; + + if ($object->id > 0) { + if (!empty($conf->societe->enabled)) { + $langs->load('companies'); + $head[$h][0] = dol_buildpath("/ecommerceng/admin/thirdparty.php", 1) . '?id=' . $object->id; + $head[$h][1] = $langs->trans("ThirdParty"); + $head[$h][2] = 'thirdparty'; + $h++; + } + + if (!empty($conf->product->enabled)) { + $langs->load('products'); + $head[$h][0] = dol_buildpath("/ecommerceng/admin/product.php", 1) . '?id=' . $object->id; + $head[$h][1] = $langs->trans("Product"); + $head[$h][2] = 'product'; + $h++; + } + + if (!empty($conf->stock->enabled)) { + $langs->load('products'); + $head[$h][0] = dol_buildpath("/ecommerceng/admin/stock.php", 1) . '?id=' . $object->id; + $head[$h][1] = $langs->trans("Stock"); + $head[$h][2] = 'stock'; + $h++; + } + + if (!empty($conf->commande->enabled) || !empty($conf->facture->enabled)) { + $langs->loadLangs(array('orders','bills')); + $labels = array(); + if (!empty($conf->commande->enabled)) $labels[] = $langs->trans("Order"); + if (!empty($conf->facture->enabled)) $labels[] = $langs->trans("Invoice"); + $head[$h][0] = dol_buildpath("/ecommerceng/admin/order.php", 1) . '?id=' . $object->id; + $head[$h][1] = implode(' / ', $labels); + $head[$h][2] = 'order_invoice'; + $h++; + } + } + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf, $langs, null, $head, $h, 'ecommerceng_config_site'); + + complete_head_from_modules($conf, $langs, null, $head, $h, 'ecommerceng_config_site', 'remove'); + + return $head; +} + /** * Update the price for all product in the ecommerce product category for this site price level * @param eCommerceSite $siteDb Object eCommerceSite @@ -494,35 +559,35 @@ function ecommerceng_update_woocommerce_attribute($db, $site) } else { $attribute = $attributes[$line['attribute_id']]; $result = $eCommerceDict->update([ - 'attribute_name' => ['value'=>$attribute->name,'type'=>'string'], - 'attribute_slug' => ['value'=>$attribute->slug,'type'=>'string'], - 'attribute_type' => ['value'=>$attribute->type,'type'=>'string'], - 'attribute_order_by' => ['value'=>$attribute->order_by,'type'=>'string'], - 'attribute_has_archives' => ['value'=>$attribute->has_archives?1:0], + 'attribute_name' => ['value'=>$attribute['name'],'type'=>'string'], + 'attribute_slug' => ['value'=>$attribute['slug'],'type'=>'string'], + 'attribute_type' => ['value'=>$attribute['type'],'type'=>'string'], + 'attribute_order_by' => ['value'=>$attribute['order_by'],'type'=>'string'], + 'attribute_has_archives' => ['value'=>$attribute['has_archives']?1:0], ], ['rowid' => ['value' => $line['rowid']]]); if ($result == false) { setEventMessage($langs->trans('ECommerceWoocommerceErrorUpdateDictAttribute', $line['attribute_slug'], $db->error()), 'errors'); $db->rollback(); return false; } - $attributes[$line['attribute_id']]->founded = true; + $attributes[$line['attribute_id']]['founded'] = true; } } // Add new attribute from woocommerce foreach ($attributes as $attribute) { - if (!isset($attribute->founded)) { + if (!isset($attribute['founded'])) { // Add new attribute $result = $eCommerceDict->insert(['site_id','attribute_id','attribute_name','attribute_slug','attribute_type','attribute_order_by','attribute_has_archives','entity','active'], ['site_id'=>['value'=>$site->id], - 'attribute_id'=>['value'=>$attribute->id], - 'attribute_name'=>['value'=>$attribute->name,'type'=>'string'], - 'attribute_slug'=>['value'=>$attribute->slug,'type'=>'string'], - 'attribute_type'=>['value'=>$attribute->type,'type'=>'string'], - 'attribute_order_by'=>['value'=>$attribute->order_by,'type'=>'string'], - 'attribute_has_archives'=>['value'=>$attribute->has_archives?1:0], + 'attribute_id'=>['value'=>$attribute['id']], + 'attribute_name'=>['value'=>$attribute['name'],'type'=>'string'], + 'attribute_slug'=>['value'=>$attribute['slug'],'type'=>'string'], + 'attribute_type'=>['value'=>$attribute['type'],'type'=>'string'], + 'attribute_order_by'=>['value'=>$attribute['order_by'],'type'=>'string'], + 'attribute_has_archives'=>['value'=>$attribute['has_archives']?1:0], 'entity'=>['value'=>$conf->entity],'active'=>['value'=>1]]); if ($result == false) { - setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictAttribute', $attribute->slug, $attribute->name, $db->error()), 'errors'); + setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictAttribute', $attribute['slug'], $attribute['name'], $db->error()), 'errors'); $db->rollback(); return false; } @@ -571,23 +636,23 @@ function ecommerceng_update_woocommerce_dict_tax($db, $site) return false; } } else { - $result = $eCommerceDict->update(['label' => ['value'=>$taxClasses[$line['code']]->name,'type'=>'string']], ['rowid' => ['value' => $line['rowid']]]); + $result = $eCommerceDict->update(['label' => ['value'=>$taxClasses[$line['code']]['name'],'type'=>'string']], ['rowid' => ['value' => $line['rowid']]]); if ($result == false) { setEventMessage($langs->trans('ECommerceWoocommerceErrorUpdateDictTaxClass', $line['code'], $db->error()), 'errors'); $db->rollback(); return false; } - $taxClasses[$line['code']]->founded = true; + $taxClasses[$line['code']]['founded'] = true; } } // Add new code from woocommerce foreach ($taxClasses as $taxClass) { - if (!isset($taxClass->founded)) { + if (!isset($taxClass['founded'])) { // Add new tax class code - $result = $eCommerceDict->insert(['site_id','code','label','entity','active'], ['site_id'=>['value'=>$site->id],'code'=>['value'=>$taxClass->slug,'type'=>'string'],'label'=>['value'=>$taxClass->name,'type'=>'string'],'entity'=>['value'=>$conf->entity],'active'=>['value'=>1]]); + $result = $eCommerceDict->insert(['site_id','code','label','entity','active'], ['site_id'=>['value'=>$site->id],'code'=>['value'=>$taxClass['slug'],'type'=>'string'],'label'=>['value'=>$taxClass['name'],'type'=>'string'],'entity'=>['value'=>$conf->entity],'active'=>['value'=>1]]); if ($result == false) { - setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictTaxClass', $taxClass->slug, $taxClass->name, $db->error()), 'errors'); + setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictTaxClass', $taxClass['slug'], $taxClass['name']) . ' ' . $db->error(), 'errors'); $db->rollback(); return false; } @@ -618,35 +683,35 @@ function ecommerceng_update_woocommerce_dict_tax($db, $site) } } else { $taxRate = $taxRates[$line['tax_id']]; - $rate = price2num($taxRate->rate); + $rate = price2num($taxRate['rate']); if (strpos((string)$rate, '.') === false) $rate = $rate . '.0'; - $result = $eCommerceDict->update(['tax_country'=>['value'=>$taxRate->country,'type'=>'string'],'tax_state'=>['value'=>$taxRate->state,'type'=>'string'], - 'tax_postcode'=>['value'=>$taxRate->postcode,'type'=>'string'],'tax_city'=>['value'=>$taxRate->city,'type'=>'string'],'tax_rate'=>['value'=>$rate,'type'=>'string'], - 'tax_name'=>['value'=>$taxRate->name,'type'=>'string'],'tax_priority'=>['value'=>$taxRate->priority],'tax_compound'=>['value'=>$taxRate->compound?1:0], - 'tax_shipping'=>['value'=>$taxRate->shipping?1:0],'tax_order'=>['value'=>$taxRate->order],'tax_class'=>['value'=>$taxRate->class,'type'=>'string']], ['rowid' => ['value' => $line['rowid']]]); + $result = $eCommerceDict->update(['tax_country'=>['value'=>$taxRate['country'],'type'=>'string'],'tax_state'=>['value'=>$taxRate['state'],'type'=>'string'], + 'tax_postcode'=>['value'=>$taxRate['postcode'],'type'=>'string'],'tax_city'=>['value'=>$taxRate['city'],'type'=>'string'],'tax_rate'=>['value'=>$rate,'type'=>'string'], + 'tax_name'=>['value'=>$taxRate['name'],'type'=>'string'],'tax_priority'=>['value'=>$taxRate['priority']],'tax_compound'=>['value'=>$taxRate['compound']?1:0], + 'tax_shipping'=>['value'=>$taxRate['shipping']?1:0],'tax_order'=>['value'=>$taxRate['order']],'tax_class'=>['value'=>$taxRate['class'],'type'=>'string']], ['rowid' => ['value' => $line['rowid']]]); if ($result == false) { setEventMessage($langs->trans('ECommerceWoocommerceErrorUpdateDictTaxRate', $line['tax_id'], $db->error()), 'errors'); $db->rollback(); return false; } - $taxRates[$line['tax_id']]->founded = true; + $taxRates[$line['tax_id']]['founded'] = true; } } // Add new tax rate from woocommerce foreach ($taxRates as $taxRate) { - if (!isset($taxRate->founded)) { - $rate = price2num($taxRate->rate); + if (!isset($taxRate['founded'])) { + $rate = price2num($taxRate['rate']); if (strpos((string)$rate, '.') === false) $rate = $rate . '.0'; // Add new tax rate $result = $eCommerceDict->insert(['site_id','tax_id','tax_country','tax_state','tax_postcode','tax_city','tax_rate','tax_name','tax_priority','tax_compound','tax_shipping','tax_order','tax_class','entity','active'], - ['site_id'=>['value'=>$site->id],'tax_id'=>['value'=>$taxRate->id],'tax_country'=>['value'=>$taxRate->country,'type'=>'string'],'tax_state'=>['value'=>$taxRate->state,'type'=>'string'], - 'tax_postcode'=>['value'=>$taxRate->postcode,'type'=>'string'],'tax_city'=>['value'=>$taxRate->city,'type'=>'string'],'tax_rate'=>['value'=>$rate,'type'=>'string'], - 'tax_name'=>['value'=>$taxRate->name,'type'=>'string'],'tax_priority'=>['value'=>$taxRate->priority],'tax_compound'=>['value'=>$taxRate->compound?1:0], - 'tax_shipping'=>['value'=>$taxRate->shipping?1:0],'tax_order'=>['value'=>$taxRate->order],'tax_class'=>['value'=>$taxRate->class,'type'=>'string'] + ['site_id'=>['value'=>$site->id],'tax_id'=>['value'=>$taxRate['id']],'tax_country'=>['value'=>$taxRate['country'],'type'=>'string'],'tax_state'=>['value'=>$taxRate['state'],'type'=>'string'], + 'tax_postcode'=>['value'=>$taxRate['postcode'],'type'=>'string'],'tax_city'=>['value'=>$taxRate['city'],'type'=>'string'],'tax_rate'=>['value'=>$rate,'type'=>'string'], + 'tax_name'=>['value'=>$taxRate['name'],'type'=>'string'],'tax_priority'=>['value'=>$taxRate['priority']],'tax_compound'=>['value'=>$taxRate['compound']?1:0], + 'tax_shipping'=>['value'=>$taxRate['shipping']?1:0],'tax_order'=>['value'=>$taxRate['order']],'tax_class'=>['value'=>$taxRate['class'],'type'=>'string'] ,'entity'=>['value'=>$conf->entity],'active'=>['value'=>1]]); if ($result == false) { - setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictTaxRate', $taxRate->slug, $db->error()), 'errors'); + setEventMessage($langs->trans('ECommerceWoocommerceErrorAddDictTaxRate', $taxRate['slug'], $db->error()), 'errors'); $db->rollback(); return false; } @@ -707,6 +772,71 @@ function ecommerceng_update_payment_gateways($db, $site) return true; } +function ecommerceng_update_remote_warehouses($db, $site) +{ + global $conf, $langs; + $langs->load('woocommerce@ecommerceng'); + + dol_include_once('/ecommerceng/class/business/eCommerceSynchro.class.php'); + $synchro = new eCommerceSynchro($db, $site, 0, 0); + + dol_syslog("site.php Try to connect to eCommerce site " . $site->name); + $result = $synchro->connect(); + if (!$result) { + setEventMessages($synchro->error, $synchro->errors, 'errors'); + return false; + } + + $remote_warehouses_list = $synchro->getAllRemoteWarehouses(); + if ($remote_warehouses_list === false) { + setEventMessages($synchro->error, $synchro->errors, 'errors'); + return false; + } + + // Get all payment gateways + dol_include_once('/ecommerceng/class/data/eCommerceRemoteWarehousesPluginSlSupport.class.php'); + $remote_warehouses = new eCommerceRemoteWarehouses($db); + $currentRemoteWarehouses = $remote_warehouses->get_all($site->id); + if (!is_array($currentRemoteWarehouses) && $currentRemoteWarehouses < 0) { + setEventMessages($remote_warehouses->error, $remote_warehouses->errors, 'errors'); + return false; + } + + $finalRemoteWarehouses = array(); + + // Add remotes warehouses + foreach ($remote_warehouses_list as $remote_code => $infos) { + $finalRemoteWarehouses[$remote_code] = array( + 'remote_id' => $infos['remote_id'], + 'remote_name' => $infos['name'], + 'warehouse_id' => $currentRemoteWarehouses[$remote_code]['warehouse_id'] > 0 ? $currentRemoteWarehouses[$remote_code]['warehouse_id'] : 0, + 'set_even_if_empty_stock' => $currentRemoteWarehouses[$remote_code]['set_even_if_empty_stock'] > 0 ? $currentRemoteWarehouses[$remote_code]['set_even_if_empty_stock'] : 0, + 'old_entry' => 0, + ); + } + + // Add current warehouses who has been deleted + foreach ($currentRemoteWarehouses as $remote_code => $infos) { + if (!isset($finalRemoteWarehouses[$remote_code])) { + $finalRemoteWarehouses[$remote_code] = array( + 'remote_id' => $infos['remote_id'], + 'remote_name' => $infos['name'], + 'warehouse_id' => $infos['warehouse_id'], + 'set_even_if_empty_stock' => $infos['set_even_if_empty_stock'], + 'old_entry' => 1, + ); + } + } + + $result = $remote_warehouses->set($site->id, $finalRemoteWarehouses); + if ($result < 0) { + setEventMessages($remote_warehouses->error, $remote_warehouses->errors, 'errors'); + return false; + } + + return true; +} + function get_company_by_email($db, $email, $site=0) { $email = $db->escape($email); diff --git a/patchs/dolibarr/includes/OAuth/OAuth2/Service/WordPress.php b/patchs/dolibarr/includes/OAuth/OAuth2/Service/WordPress.php deleted file mode 100755 index c59e90c..0000000 --- a/patchs/dolibarr/includes/OAuth/OAuth2/Service/WordPress.php +++ /dev/null @@ -1,97 +0,0 @@ -baseApiUri = new Uri('https://addresse_de_votre_site_wordpress'); - } - } -/* - // LDR CHANGE Add approval_prompt to force the prompt if value is set to 'force' so it force return of a "refresh token" in addition to "standard token" - public $approvalPrompt='auto'; - public function setApprouvalPrompt($prompt) - { - if (!in_array($prompt, array('auto', 'force'), true)) { - // @todo Maybe could we rename this exception - throw new InvalidAccessTypeException('Invalid approuvalPrompt, expected either auto or force.'); - } - $this->approvalPrompt = $prompt; - }*/ - - /** - * {@inheritdoc} - */ - public function getAuthorizationEndpoint() - { - return new Uri(sprintf('%s/oauth/authorize', $this->baseApiUri)); - } - - /** - * {@inheritdoc} - */ - public function getAccessTokenEndpoint() - { - return new Uri(sprintf('%s/oauth/token', $this->baseApiUri)); - } - - /** - * {@inheritdoc} - */ - protected function getAuthorizationMethod() - { - global $conf; - return empty($conf->global->OAUTH_WORDPRESS_AUTHORIZATION_METHOD_QUERY_STRING) ? static::AUTHORIZATION_METHOD_HEADER_BEARER : static::AUTHORIZATION_METHOD_QUERY_STRING; - } - - /** - * {@inheritdoc} - */ - protected function parseAccessTokenResponse($responseBody) - { - $data = json_decode($responseBody, true); - - if (null === $data || !is_array($data)) { - throw new TokenResponseException('Unable to parse response: "'.(isset($responseBody)?$responseBody:'NULL').'"'); - } elseif (isset($data['error'])) { - throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '" : "'.$data['error_description'].'"'); - } - - $token = new StdOAuth2Token(); - $token->setAccessToken($data['access_token']); - $token->setLifetime($data['expires_in']); - - if (isset($data['refresh_token'])) { - $token->setRefreshToken($data['refresh_token']); - unset($data['refresh_token']); - } - - unset($data['access_token']); - unset($data['expires_in']); - - $token->setExtraParams($data); - - return $token; - } -} diff --git a/scripts/syncronize_all_stocks_to_ecommerce.php b/scripts/syncronize_all_stocks_to_ecommerce.php deleted file mode 100755 index 5dd02a9..0000000 --- a/scripts/syncronize_all_stocks_to_ecommerce.php +++ /dev/null @@ -1,264 +0,0 @@ -#!/usr/bin/env php - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file scripts/osv_companies_categories.php - * \ingroup cron - * \brief Execute pendings jobs - */ -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); -if (! defined('NOLOGIN')) define('NOLOGIN','1'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); - - -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit(-1); -} - -// Check parameters -if (! isset($argv[1]) || ! $argv[1]) { - print 'Usage: ' . $script_file . ' user_login_in_dolibarr'; - exit(-1); -} -$userlogin=$argv[1]; - -// Change this following line to use the correct relative path (../, ../../, etc) -$res=0; -if (! $res && file_exists("../../master.inc.php")) $res=@include '../../master.inc.php'; // to work if your module directory is into a subdir of root htdocs directory -if (! $res && file_exists("../../../master.inc.php")) $res=@include '../../../master.inc.php'; // to work if your module directory is into a subdir of root htdocs directory -if (! $res) die("Include of main fails"); -require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; -require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; -dol_include_once('/ecommerceng/class/data/eCommerceSite.class.php'); -dol_include_once('/ecommerceng/class/business/eCommerceSynchro.class.php'); -dol_include_once('/ecommerceng/class/data/eCommerceProduct.class.php'); -dol_include_once('/ecommerceng/lib/eCommerce.lib.php'); - -// Global variables -$version=DOL_VERSION; -$product_cached = array(); - -/* - * Main - */ - -// current date -$now=dol_now(); - -@set_time_limit(0); -print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." ***** userlogin=" . $userlogin . " ***** " . $now . " *****\n"; -print "\n"; - -$user = new User($db); -$res = $user->fetch('', $userlogin); -if ($res == 0) { - print "Error user (Login: $userlogin) not found\n"; - $db->close(); - exit(0); -} elseif ($res < 0) { - print "Error fetch user (Login: $userlogin) : " . $user->errorsToString() . "\n"; - $db->close(); - exit(0); -} - -$movement_stock_static = new MouvementStock($db); -$categories = new Categorie($db); -$siteDb = new eCommerceSite($db); - -$all_cat_full_arbo = $categories->get_full_arbo('product'); -$sites = $siteDb->listSites('object'); - -$max_sites = count($sites); -$num_sites = 0; - -if ($max_sites > 0) { - $startTime = microtime(true); - - foreach ($sites as $site) { - print "Processing the site '{$site->name}'.\n"; - $num_sites++; - $max_jobs = 0; - $num_jobs = 0; - - $result = $site->setEntityValues($site->entity); - if ($result < 0) { - print "Error set entity to {$site->entity} : " . $db->lasterror() . "\n"; - continue; - } - $user->getrights(); - - print "Connect to the site.\n"; - $eCommerceSynchro = new eCommerceSynchro($db, $site); - $eCommerceSynchro->connect(); - if (count($eCommerceSynchro->errors)) { - print "Warning: Connect to site fails: {$eCommerceSynchro->errorsToString()}.\n"; - continue; - } - - print "Get all WooCommerce product categories.\n"; - $woocommerce_product_categories = array(); - if ($site->fk_cat_product > 0) { - $woocommerce_product_categories[$site->fk_cat_product] = $site->fk_cat_product; - foreach ($all_cat_full_arbo as $cat_infos) { - if (preg_match("/^{$site->fk_cat_product}$/", $cat_infos['fullpath']) || preg_match("/^{$site->fk_cat_product}_/", $cat_infos['fullpath']) || - preg_match("/_{$site->fk_cat_product}_/", $cat_infos['fullpath']) || preg_match("/_{$site->fk_cat_product}$/", $cat_infos['fullpath'])) { - $woocommerce_product_categories[$cat_infos['id']] = $cat_infos['id']; - } - } - } - if (empty($woocommerce_product_categories)) { - print "Warning: WooCommerce product categories not found.\n"; - continue; - } - - $supported_warehouses = is_array($site->parameters['fk_warehouse_to_ecommerce']) ? $site->parameters['fk_warehouse_to_ecommerce'] : array(); - if (empty($supported_warehouses)) { - print "Warning: Warehouses not configured.\n"; - continue; - } - - $sql = "SELECT DISTINCT cp.fk_product AS product_id"; - $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp"; - $sql .= " WHERE cp.fk_categorie IN (" . implode(',', $woocommerce_product_categories) . ")"; - - $resql = $db->query($sql); - if ($resql) { - $max_jobs = $db->num_rows($resql); - while ($obj = $db->fetch_object($resql)) { - $error = 0; - - // Get product link - $eCommerceProduct = new eCommerceProduct($db); - $result = $eCommerceProduct->fetchByProductId($obj->product_id, $site->id); - if ($result < 0) { - print "\nError: Get product link (ID: {$obj->product_id}): " . errorsToString($eCommerceProduct) . ".\n"; - $error++; - } elseif (empty($eCommerceProduct->remote_id)) { - print "\nError: Get product remote ID (ID: {$obj->product_id}).\n"; - $error++; - } - - // Get product - if (!$error) { - $dbProduct = getProduct($obj->product_id); - if (!($dbProduct->id > 0)) { - print "\nError: Get product (ID: {$obj->product_id}): " . errorsToString($dbProduct) . ".\n"; - $error++; - } else { - $movement_stock_static->qty_after = 0; - foreach ($supported_warehouses as $warehouse_id) { - $movement_stock_static->qty_after += isset($dbProduct->stock_warehouse[$warehouse_id]->real) ? $dbProduct->stock_warehouse[$warehouse_id]->real : 0; - } - } - } - - if (!$error) { - $db->begin(); - - // Update remote product stock - $result = $eCommerceSynchro->eCommerceRemoteAccess->updateRemoteStockProduct($eCommerceProduct->remote_id, $movement_stock_static, $dbProduct); - if (!$result) { - print "\nError: Update product stock (ID: {$obj->product_id}, remote ID: {$eCommerceProduct->remote_id}): " . errorsToString($eCommerceSynchro->eCommerceRemoteAccess) . ".\n"; - $error++; - } - - // Update product link - if (!$error) { - $eCommerceProduct->last_update = dol_print_date(dol_now(), '%Y-%m-%d %H:%M:%S'); - $result = $eCommerceProduct->update($user); - if ($result < 0) { - print "\nError: Update product link (ID: {$obj->product_id}): " . errorsToString($eCommerceProduct) . ".\n"; - $error++; - } - } - - if ($error) { - $db->rollback(); - $db->close(); - exit(0); - } else { - $db->commit(); - } - } - - $num_jobs++; - printStatus($num_sites, $max_sites, $num_jobs, $max_jobs); - } - - $db->free($resql); - } else { - print "\nError: SQL : $sql; Error: " . $db->lasterror() . "\n"; - continue; - } - } -} - -print "\nEnd.\n"; - -$db->close(); - -exit(0); - -function getProduct($product_id) -{ - global $db, $product_cached; - - if (!isset($product_cached[$product_id])) { - $dbProduct = new Product($db); - $dbProduct->fetch($product_id); - $dbProduct->load_stock(); - - $product_cached[$product_id] = $dbProduct; - } - - return $product_cached[$product_id]; -} - -function errorsToString($object, $separator = ', ') -{ - return $object->error . (is_array($object->errors) ? (!empty($object->error) ? $separator : '') . join($separator, $object->errors) : ''); -} - -function printStatus($num_sites, $max_sites, $num_jobs, $max_jobs) -{ - global $startTime; - - $sub_percent = $num_sites * 100 / $max_sites; - $percent = $num_jobs * $sub_percent / $max_jobs; - $elapsedTime = microtime(true) - $startTime; - $remainingTime = $percent > 0 ? $elapsedTime * (100 - $percent) / $percent : 0; - print sprintf("\rStatus: Site: %2d / %2d - Product: %6d / %6d - %3d%% - Elapsed: " . microTimeToTime($elapsedTime) . " - Remaining: " . microTimeToTime($remainingTime), $num_sites, $max_sites, $num_jobs, $max_jobs, $percent); -} - -function microTimeToTime($microtime) -{ - $hours = (int)($microtime / 60 / 60); - $minutes = (int)($microtime / 60) - $hours * 60; - $seconds = (int)$microtime - $hours * 60 * 60 - $minutes * 60; - return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); -} \ No newline at end of file diff --git a/scripts/syncronize_products_to_ecommerce.php b/scripts/syncronize_products_to_ecommerce.php index 4b5a7fc..4431eb3 100755 --- a/scripts/syncronize_products_to_ecommerce.php +++ b/scripts/syncronize_products_to_ecommerce.php @@ -196,6 +196,7 @@ $eCommerceProduct->fk_site = $site->id; $eCommerceProduct->fk_product = $dbProduct->id; $eCommerceProduct->last_update = dol_print_date(dol_now(), '%Y-%m-%d %H:%M:%S'); + if ($site->stock_sync_direction == 'dolibarr2ecommerce') $eCommerceProduct->last_update_stock = $eCommerceProduct->last_update; $result = $eCommerceProduct->create($user); if ($result < 0) { print "\nError: Create product link (ID: {$obj->product_id}): " . errorsToString($eCommerceProduct) . ".\n"; @@ -206,6 +207,7 @@ $result = $eCommerceProduct->fetch($obj->link_id); if ($result > 0) { $eCommerceProduct->last_update = dol_print_date(dol_now(), '%Y-%m-%d %H:%M:%S'); + if ($site->stock_sync_direction == 'dolibarr2ecommerce') $eCommerceProduct->last_update_stock = $eCommerceProduct->last_update; $result = $eCommerceProduct->update($user); } if ($result < 0) { diff --git a/sql/llx_ecommerce_product.sql b/sql/llx_ecommerce_product.sql index f795ae0..2846d24 100644 --- a/sql/llx_ecommerce_product.sql +++ b/sql/llx_ecommerce_product.sql @@ -21,5 +21,6 @@ CREATE TABLE llx_ecommerce_product ( fk_product integer NOT NULL, fk_site integer NOT NULL, remote_id varchar(255) NOT NULL, - last_update datetime default NULL + last_update datetime default NULL, + last_update_stock datetime default NULL ) ENGINE=InnoDB COMMENT='Table transition remote site - Dolibarr'; diff --git a/sql/llx_ecommerce_site.sql b/sql/llx_ecommerce_site.sql index cddacd5..afeb6b5 100644 --- a/sql/llx_ecommerce_site.sql +++ b/sql/llx_ecommerce_site.sql @@ -21,18 +21,27 @@ CREATE TABLE llx_ecommerce_site ( name varchar(255) NOT NULL, type integer NOT NULL DEFAULT 1, webservice_address varchar(255) NOT NULL, + authentication_type varchar(255) NULL, user_name varchar(255) DEFAULT NULL, user_password varchar(255) DEFAULT NULL, + wordpress_authentication_type varchar(255) NULL, + wordpress_authentication_login varchar(255) NULL, + wordpress_authentication_password varchar(255) NULL, + wordpress_timeout integer NOT NULL DEFAULT 30, + wordpress_debug integer(1) NULL, price_level integer NULL DEFAULT 1, filter_label varchar(255) DEFAULT NULL, filter_value varchar(255) DEFAULT NULL, fk_cat_societe integer NOT NULL, fk_cat_product integer NOT NULL, fk_warehouse integer NULL, + fk_anonymous_thirdparty integer NULL, stock_sync_direction varchar(24) DEFAULT 'none', last_update datetime DEFAULT NULL, - timeout integer NOT NULL DEFAULT 300, + timeout integer NOT NULL DEFAULT 30, + debug integer(1) NULL, magento_use_special_price INTEGER NOT NULL DEFAULT 0, - magento_price_type VARCHAR(3) NOT NULL DEFAULT 'HT', + ecommerce_price_type VARCHAR(3) NOT NULL DEFAULT 'HT', + parameters TEXT NULL, entity integer DEFAULT 1 ) ENGINE=InnoDB; diff --git a/sql/llx_ecommerceng_remote_warehouses.key.sql b/sql/llx_ecommerceng_remote_warehouses.key.sql new file mode 100644 index 0000000..0f2644a --- /dev/null +++ b/sql/llx_ecommerceng_remote_warehouses.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2011 Auguria +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- =================================================================== + +ALTER TABLE llx_ecommerceng_remote_warehouses ADD UNIQUE INDEX uk_ecommerceng_remote_warehouses(site_id,remote_code,entity); +--ALTER TABLE llx_ecommerceng_remote_warehouses ADD CONSTRAINT fk_ecommerceng_remote_warehouses_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES llx_entrepot(rowid); \ No newline at end of file diff --git a/sql/llx_ecommerceng_remote_warehouses.sql b/sql/llx_ecommerceng_remote_warehouses.sql new file mode 100644 index 0000000..3504b7c --- /dev/null +++ b/sql/llx_ecommerceng_remote_warehouses.sql @@ -0,0 +1,30 @@ +-- =================================================================== +-- Copyright (C) 2011 Auguria +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- =================================================================== + +create table llx_ecommerceng_remote_warehouses +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + site_id integer NOT NULL, + remote_code varchar(255) NOT NULL, --Remote warehouse code + remote_id varchar(255) NOT NULL, --Remote warehouse ID + remote_name varchar(255) NOT NULL, --Remote warehouse name + warehouse_id integer, -- Dolibarr warehouse ID + set_even_if_empty_stock tinyint(1), -- Flag for set the stock of the warehouse even if the stock is empty + old_entry tinyint(1), -- Flag for set if this warehouse has been delete on WooCommerce + entity integer DEFAULT 1 +) ENGINE=InnoDB; \ No newline at end of file diff --git a/sql/update.sql b/sql/update.sql index 964b77b..5500471 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -18,8 +18,8 @@ -- v4.0.18 ALTER TABLE llx_ecommerce_site ADD COLUMN fk_anonymous_thirdparty integer NULL; -ALTER TABLE llx_ecommerce_site ADD COLUMN oauth_id varchar(255) NULL after user_password; -ALTER TABLE llx_ecommerce_site ADD COLUMN oauth_secret varchar(255) NULL after oauth_id; +-- ALTER TABLE llx_ecommerce_site ADD COLUMN oauth_id varchar(255) NULL after user_password; +-- ALTER TABLE llx_ecommerce_site ADD COLUMN oauth_secret varchar(255) NULL after oauth_id; ALTER TABLE llx_ecommerce_site ADD COLUMN price_level integer NULL DEFAULT 1; ALTER TABLE llx_ecommerce_site CHANGE COLUMN magento_price_type ecommerce_price_type VARCHAR(3) NOT NULL DEFAULT 'HT'; @@ -36,3 +36,15 @@ ALTER TABLE llx_ecommerce_pending_webhooks CHANGE COLUMN webhook_data webhook_da -- v4.0.92 ALTER TABLE llx_ecommerce_site ADD COLUMN entity integer NULL DEFAULT 1; + +-- v4.1.35 +ALTER TABLE llx_ecommerce_site ADD COLUMN authentication_type varchar(255) NULL after webservice_address; +ALTER TABLE llx_ecommerce_site ADD COLUMN debug integer(1) NULL after timeout; +ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_authentication_type varchar(255) NULL after user_password; +ALTER TABLE llx_ecommerce_site CHANGE COLUMN oauth_id wordpress_authentication_login varchar(255) NULL; +ALTER TABLE llx_ecommerce_site CHANGE COLUMN oauth_secret wordpress_authentication_password varchar(255) NULL; +ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_authentication_login varchar(255) NULL after wordpress_authentication_type; +ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_authentication_password varchar(255) NULL after wordpress_authentication_login; +ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_timeout integer NOT NULL DEFAULT 30 after wordpress_authentication_password; +ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_debug integer(1) NULL after wordpress_timeout; +ALTER TABLE llx_ecommerce_product ADD COLUMN last_update_stock datetime default NULL after last_update;