diff --git a/README.md b/README.md index ecacefe..98d9905 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# woocommerce-module \ No newline at end of file +woocommerce-module +================== + +Module allows integrate Woocommerce with [retailCRM](http://retailcrm.pro) \ No newline at end of file diff --git a/retailcrm/include/class-wc-retailcrm-history.php b/retailcrm/include/class-wc-retailcrm-history.php index 06d7392..16faa6c 100644 --- a/retailcrm/include/class-wc-retailcrm-history.php +++ b/retailcrm/include/class-wc-retailcrm-history.php @@ -229,12 +229,12 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : elseif ($record['field'] == 'delivery_address.street') { $order = new WC_Order($record['order']['externalId']); - $order->set_shipping_address1($record['newValue']); + $order->set_shipping_address_1($record['newValue']); } elseif ($record['field'] == 'delivery_address.building') { $order = new WC_Order($record['order']['externalId']); - $order->set_shipping_address2($record['newValue']); + $order->set_shipping_address_2($record['newValue']); } elseif ($record['field'] == 'payment_type') { @@ -366,8 +366,20 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : } } - $shipping_rate = new WC_Shipping_Rate($shipping_method_id, isset($shipping_method_title) ? $shipping_method_title : '', isset($shipping_total) ? floatval($shipping_total) : 0, array(), $shipping_method_id); - $order->add_shipping($shipping_rate); + if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) { + $shipping_rate = new WC_Shipping_Rate($shipping_method_id, isset($shipping_method_title) ? $shipping_method_title : '', isset($shipping_total) ? floatval($shipping_total) : 0, array(), $shipping_method_id); + $order->add_shipping($shipping_rate); + } else { + $shipping = new WC_Order_Item_Shipping(); + $shipping->set_props( array( + 'method_title' => $shipping_method_title, + 'method_id' => $shipping_method_id, + 'total' => wc_format_decimal($shipping_total), + 'order_id' => $order->id + ) ); + $shipping->save(); + $order->add_item( $shipping ); + } $this->update_total($order); @@ -378,7 +390,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : $this->retailcrm->ordersFixExternalIds($ids); } - $this->addFuncsHook(); } @@ -441,7 +452,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : protected function getShippingItemId($items) { if ($items) { - foreach ($items as $key => $value) { $item_id[] = $key; } diff --git a/retailcrm/include/class-wc-retailcrm-icml.php b/retailcrm/include/class-wc-retailcrm-icml.php index 5931cd4..9c1f954 100644 --- a/retailcrm/include/class-wc-retailcrm-icml.php +++ b/retailcrm/include/class-wc-retailcrm-icml.php @@ -404,13 +404,18 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) : $product_data['params'] = $params; } - $full_product_list[] = $product_data; + if (isset($product_data)) { + $full_product_list[] = $product_data; + } + unset($product_data); } endwhile; - $this->writeOffers($full_product_list); - unset($full_product_list); + if (isset($full_product_list) && $full_product_list) { + $this->writeOffers($full_product_list); + unset($full_product_list); + } $offset += $limit; diff --git a/retailcrm/include/class-wc-retailcrm-inventories.php b/retailcrm/include/class-wc-retailcrm-inventories.php index beaea6a..d5dc4ef 100644 --- a/retailcrm/include/class-wc-retailcrm-inventories.php +++ b/retailcrm/include/class-wc-retailcrm-inventories.php @@ -42,11 +42,14 @@ if ( ! class_exists( 'WC_Retailcrm_Inventories' ) ) : if (isset($offer['externalId'])) { $product = wc_get_product($offer['externalId']); - if ($product == false || $product->get_type() == 'variable') continue; - - update_post_meta($offer['externalId'], '_manage_stock', 'yes'); - $product->set_stock_quantity($offer['quantity']); - $product->save(); + if ($product != false) { + if ($product->get_type() == 'variable') { + continue; + } + update_post_meta($offer['externalId'], '_manage_stock', 'yes'); + $product->set_stock_quantity($offer['quantity']); + $product->save(); + } } }