diff --git a/class/business/eCommerceSynchro.class.php b/class/business/eCommerceSynchro.class.php index 7bb660d..00979ee 100755 --- a/class/business/eCommerceSynchro.class.php +++ b/class/business/eCommerceSynchro.class.php @@ -4471,11 +4471,34 @@ public function synchronizeOrder($order_data, $dont_synchronize_products = false if (empty($conf->global->ECOMMERCENG_DISABLED_PRODUCT_SYNCHRO_STOD)) { $this->initECommerceProduct(); $result = $this->eCommerceProduct->fetchByRemoteId($item['id_remote_product'], $this->eCommerceSite->id); // load info of table ecommerce_product - if ($result < 0 && !empty($this->eCommerceProduct->error)) { - $this->errors[] = $this->langs->trans('ECommerceErrorFetchProductLinkByRemoteId', $item['id_remote_product'], $this->eCommerceSite->id); - $this->errors[] = $this->eCommerceProduct->error; - $error++; - break; // break on items + if ($result < 0) { + if (!empty($this->eCommerceProduct->error)) { + $this->errors[] = $this->langs->trans('ECommerceErrorFetchProductLinkByRemoteId', $item['id_remote_product'], $this->eCommerceSite->id); + $this->errors[] = $this->eCommerceProduct->error; + $error++; + break; // break on items + } else { // if no product is found on the matching table, use ref instead, permits WPML products identification + $product_ref = trim($item['ref']); + if (!empty($product_ref)) { + $product = new Product($this->db); + $result = $product->fetch(0, $product_ref); + if ($result < 0) { + $this->errors[] = $this->langs->trans('ECommerceErrorFetchProductByRef', $product_ref); + $this->errors[] = $product->errorsToString(); + $error++; + break; // break on items + } elseif ($result == 0) { + $this->errors[] = $this->langs->trans('ECommerceErrorProductNotFoundByRef', $product_ref); + $error++; + break; // break on items + } + $fk_product = $product->id; + } elseif (!empty($conf->global->ECOMMERCENG_PRODUCT_REF_MANDATORY)) { + $this->errors[] = $this->langs->trans('ECommerceErrorProductRefMandatory2', $item['label']); + $error++; + break; // break on items + } + } } elseif ($result > 0) { $fk_product = $this->eCommerceProduct->fk_product; } diff --git a/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php b/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php index 930d398..7de375f 100755 --- a/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php +++ b/class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php @@ -920,12 +920,19 @@ public function convertRemoteObjectIntoDolibarrProduct($from_date = null, $to_da foreach ($page as $product) { // Don't synchronize the variation parent 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); - return false; + $res = 0; + if (!empty($product->sku)) { + $is_product = new Product($this->db); + $res = $is_product->fetch('', $product->sku); + } + if ($res <= 0){ + $data = $this->convertProductDataIntoProcessedData($product); + if (!is_array($data)) { + $this->errors = array_merge(array($langs->trans('ECommerceErrorWhenConvertProductData', $product->id)), $this->errors); + return false; + } + $products[] = $data; } - $products[] = $data; } // Synchronize all the variations of the product if only the parent is provided