diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7a51d..6f2673d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2022-05-26 4.6.4 +* Optimizing unloading of stock + ## 2022-05-29 4.6.3 * Types of deliveries and payments are displayed only for available stores diff --git a/VERSION b/VERSION index 7962f0f..101d404 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.6.3 \ No newline at end of file +4.6.4 \ No newline at end of file diff --git a/src/include/class-wc-retailcrm-inventories.php b/src/include/class-wc-retailcrm-inventories.php index d526d96..5d0fa77 100644 --- a/src/include/class-wc-retailcrm-inventories.php +++ b/src/include/class-wc-retailcrm-inventories.php @@ -42,7 +42,7 @@ if (!class_exists('WC_Retailcrm_Inventories')) : /** * Load stock from RetailCRM * - * @return mixed + * @return void */ protected function load_stocks() { @@ -71,6 +71,10 @@ if (!class_exists('WC_Retailcrm_Inventories')) : $product = retailcrm_get_wc_product($offer[$this->bind_field], $this->retailcrm_settings); if ($product instanceof WC_Product) { + if ($product->get_type() == 'external') { + continue; + } + if ($product->get_type() == 'variation' || $product->get_type() == 'variable') { $parentId = $product->get_parent_id(); @@ -85,39 +89,44 @@ if (!class_exists('WC_Retailcrm_Inventories')) : $product->set_manage_stock(true); $product->set_stock_quantity($offer['quantity']); - $success[] = $product->save(); + $product->save(); } } } - if (!empty($variationProducts)) { - foreach ($variationProducts as $id => $quantity) { + // Clearing the object cache after calling the function wc_get_products + wp_cache_flush(); + } while ($page <= $totalPageCount); + + if (!empty($variationProducts)) { + $chunks = array_chunk($variationProducts, 100, true); + + foreach ($chunks as $chunk) { + foreach ($chunk as $id => $quantity) { $variationProduct = wc_get_product($id); if (is_object($variationProduct)) { $variationProduct->set_manage_stock(true); $variationProduct->set_stock_quantity($quantity); - $success[] = $variationProduct->save(); + $variationProduct->save(); } } - } - } while ($page <= $totalPageCount); - return $success; + wp_cache_flush(); + } + } } /** * Update stock quantity in WooCommerce * - * @return mixed + * @return void */ public function updateQuantity() { if ($this->retailcrm_settings['sync'] == WC_Retailcrm_Base::YES) { - return $this->load_stocks(); + $this->load_stocks(); } - - return false; } } endif; diff --git a/src/readme.txt b/src/readme.txt index d4feff6..822ac84 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.6.4 = +* Optimizing unloading of stock + = 4.6.3 = * Types of deliveries and payments are displayed only for available stores diff --git a/src/retailcrm.php b/src/retailcrm.php index 2ca8f23..e586d95 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.6.3 + * Version: 4.6.4 * Tested up to: 6.0 * WC requires at least: 5.4 * WC tested up to: 6.9 diff --git a/src/uninstall.php b/src/uninstall.php index 30aae38..5c601aa 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.6.3 + * @version 4.6.4 * * @package RetailCRM */ diff --git a/tests/test-wc-retailcrm-inventories.php b/tests/test-wc-retailcrm-inventories.php index 79a5360..4cdda9f 100644 --- a/tests/test-wc-retailcrm-inventories.php +++ b/tests/test-wc-retailcrm-inventories.php @@ -57,9 +57,9 @@ class WC_Retailcrm_Inventories_Test extends WC_Retailcrm_Test_Case_Helper } $retailcrm_inventories = new WC_Retailcrm_Inventories($retailcrm); - $result = $retailcrm_inventories->updateQuantity(); + $retailcrm_inventories->updateQuantity(); - $this->checkProductData($retailcrm, $response, $result, 'simple'); + $this->checkProductData($retailcrm, $response, $offer->get_id(), 'simple'); } /** @@ -86,9 +86,9 @@ class WC_Retailcrm_Inventories_Test extends WC_Retailcrm_Test_Case_Helper } $retailcrm_inventories = new WC_Retailcrm_Inventories($retailcrm); - $result = $retailcrm_inventories->updateQuantity(); + $retailcrm_inventories->updateQuantity(); - $this->checkProductData($retailcrm, $response, $result, 'variation'); + $this->checkProductData($retailcrm, $response, $childrens[0], 'variation'); } public function test_sync_off() @@ -104,19 +104,16 @@ class WC_Retailcrm_Inventories_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEquals(false, $result); } - private function checkProductData($retailcrm, $response, $result, $entity) + private function checkProductData($retailcrm, $response, $offerId, $entity) { + $product = wc_get_product($offerId); + if ($retailcrm && null !== $response) { - $product = wc_get_product($result[0]); $this->assertInstanceOf('WC_Product', $product); $this->assertEquals($entity, $product->get_type()); $this->assertEquals(10, $product->get_stock_quantity()); - $this->assertEquals($result[0], $product->get_id()); - $this->assertInternalType('array', $result); - } elseif (null === $response) { - $this->assertEquals(false, $result); } else { - $this->assertEquals(null, $result); + $this->assertNotEquals(10, $product->get_stock_quantity()); } }