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

Fix the error of using xmlId field to link products in orders

This commit is contained in:
Dima Uryvskiy 2022-02-24 18:45:17 +03:00 committed by GitHub
parent e07cfbd1f5
commit fa32395161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -405,8 +405,8 @@ if (!class_exists('WC_Retailcrm_History')) :
}
if (isset($item['create']) && $item['create'] == true) {
$arItemsNew = array();
$arItemsOld = array();
$arItemsNew = [];
$arItemsOld = [];
$product = retailcrm_get_wc_product(
$item['offer'][$this->bindField],
$this->retailcrmSettings
@ -562,15 +562,21 @@ if (!class_exists('WC_Retailcrm_History')) :
} else {
if (isset($item['quantity']) && $item['quantity']) {
$orderItem->set_quantity($item['quantity']);
$product = retailcrm_get_wc_product($item['offer'][$this->bindField], $this->retailcrmSettings);
$orderItem->set_subtotal($product->get_price());
$dataStore = $orderItem->get_data_store();
$dataStore->update($orderItem);
}
if (isset($item['summ']) && $item['summ']) {
$orderItem->set_total($item['summ']);
$dataStore = $orderItem->get_data_store();
$dataStore->update($orderItem);
}
}

View File

@ -73,16 +73,19 @@ class WC_Retailcrm_Order_Item extends WC_Retailcrm_Abstracts_Data
*/
private function set_offer(WC_Order_Item_Product $item)
{
$uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ;
$offer = array('externalId' => $uid);
$uid = $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'] ;
$offer = ['externalId' => $uid];
$product = $item->get_product();
if (!empty($product) &&
isset($this->settings['bind_by_sku']) &&
$this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES
if (
!empty($product)
&& isset($this->settings['bind_by_sku'])
&& $this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES
) {
$offer['xmlId'] = $product->get_sku();
unset($offer['externalId']);
}
$this->set_data_field('offer', $offer);