1
0
mirror of synced 2025-01-19 01:11:42 +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) { if (isset($item['create']) && $item['create'] == true) {
$arItemsNew = array(); $arItemsNew = [];
$arItemsOld = array(); $arItemsOld = [];
$product = retailcrm_get_wc_product( $product = retailcrm_get_wc_product(
$item['offer'][$this->bindField], $item['offer'][$this->bindField],
$this->retailcrmSettings $this->retailcrmSettings
@ -562,15 +562,21 @@ if (!class_exists('WC_Retailcrm_History')) :
} else { } else {
if (isset($item['quantity']) && $item['quantity']) { if (isset($item['quantity']) && $item['quantity']) {
$orderItem->set_quantity($item['quantity']); $orderItem->set_quantity($item['quantity']);
$product = retailcrm_get_wc_product($item['offer'][$this->bindField], $this->retailcrmSettings); $product = retailcrm_get_wc_product($item['offer'][$this->bindField], $this->retailcrmSettings);
$orderItem->set_subtotal($product->get_price()); $orderItem->set_subtotal($product->get_price());
$dataStore = $orderItem->get_data_store(); $dataStore = $orderItem->get_data_store();
$dataStore->update($orderItem); $dataStore->update($orderItem);
} }
if (isset($item['summ']) && $item['summ']) { if (isset($item['summ']) && $item['summ']) {
$orderItem->set_total($item['summ']); $orderItem->set_total($item['summ']);
$dataStore = $orderItem->get_data_store(); $dataStore = $orderItem->get_data_store();
$dataStore->update($orderItem); $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) private function set_offer(WC_Order_Item_Product $item)
{ {
$uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $uid = $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'] ;
$offer = array('externalId' => $uid); $offer = ['externalId' => $uid];
$product = $item->get_product(); $product = $item->get_product();
if (!empty($product) && if (
isset($this->settings['bind_by_sku']) && !empty($product)
$this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES && isset($this->settings['bind_by_sku'])
&& $this->settings['bind_by_sku'] == WC_Retailcrm_Base::YES
) { ) {
$offer['xmlId'] = $product->get_sku(); $offer['xmlId'] = $product->get_sku();
unset($offer['externalId']);
} }
$this->set_data_field('offer', $offer); $this->set_data_field('offer', $offer);