1
0
mirror of synced 2025-01-18 17:01:41 +03:00

Add check for add new items

This commit is contained in:
Dima Uryvskiy 2021-11-17 11:51:03 +03:00 committed by GitHub
parent 6a716cc14e
commit 6d95580155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -394,6 +394,18 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$arItemsOld[$orderItemId] = $orderItemId; $arItemsOld[$orderItemId] = $orderItemId;
} }
if (isset($item['externalIds'])) {
foreach ($item['externalIds'] as $externalId) {
if ($externalId['code'] == 'woocomerce') {
$itemExternalId = explode('_', $externalId['value']);
}
}
if (array_key_exists($itemExternalId[1], $arItemsOld)) {
continue;
}
}
$wcOrder->add_product($product, $item['quantity']); $wcOrder->add_product($product, $item['quantity']);
foreach ($wcOrder->get_items() as $orderItemId => $orderItem) { foreach ($wcOrder->get_items() as $orderItemId => $orderItem) {
@ -405,13 +417,13 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$order['items'][$key]['woocomerceId'] = $result; $order['items'][$key]['woocomerceId'] = $result;
} else { } else {
foreach ($wcOrder->get_items() as $orderItemId => $orderItem) { foreach ($wcOrder->get_items() as $orderItem) {
if ( if (
isset($this->retailcrmSettings['bind_by_sku']) isset($this->retailcrmSettings['bind_by_sku'])
&& $this->retailcrmSettings['bind_by_sku'] == WC_Retailcrm_Base::YES && $this->retailcrmSettings['bind_by_sku'] == WC_Retailcrm_Base::YES
) { ) {
$offerId = $item['offer']['xmlId']; $offerId = $item['offer']['xmlId'];
} elseif ($orderItem['variation_id'] != 0 ) { } elseif ($orderItem['variation_id'] != 0) {
$offerId = $orderItem['variation_id']; $offerId = $orderItem['variation_id'];
} else { } else {
$offerId = $orderItem['product_id']; $offerId = $orderItem['product_id'];
@ -426,6 +438,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
} else { } else {
$itemExternalId = explode('_', $item['externalId']); $itemExternalId = explode('_', $item['externalId']);
} }
if ( if (
$offerId == $item['offer'][$this->bindField] $offerId == $item['offer'][$this->bindField]
&& (isset($itemExternalId) && $itemExternalId[1] == $orderItem->get_id()) && (isset($itemExternalId) && $itemExternalId[1] == $orderItem->get_id())
@ -773,7 +786,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
} }
$order['items'][$key]['woocomerceId'] = $result; $order['items'][$key]['woocomerceId'] = $result;
} }
} }