Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

use ref if no match in ecommerce_product #80

Open
wants to merge 2 commits into
base: 2022.5.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions class/business/eCommerceSynchro.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 12 additions & 5 deletions class/data/woocommerce/eCommerceRemoteAccessWoocommerce.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down