1
0
mirror of synced 2025-02-21 01:13:13 +03:00

ref #90237 Optimizing unloading of stock

This commit is contained in:
Uryvskiy Dima 2023-06-05 10:31:59 +03:00 committed by GitHub
commit 8525db0d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 26 deletions

View File

@ -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

View File

@ -1 +1 @@
4.6.3
4.6.4

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.6.3
* @version 4.6.4
*
* @package RetailCRM
*/

View File

@ -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());
}
}