1
0
mirror of synced 2025-01-31 07:11:42 +03:00

Fix check api version (#9)

This commit is contained in:
Akolzin Dmitry 2017-08-16 14:17:35 +02:00 committed by Alex Lushpai
parent 754c41d49e
commit 7201d9fe08
2 changed files with 9 additions and 18 deletions

View File

@ -284,7 +284,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
$response = $api->statisticUpdate();
if (!$response->isSuccessful()) {
if ($response['errorMsg'] == 'API method not found') {
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-demo' ) );
}

View File

@ -40,26 +40,17 @@ if ( ! class_exists( 'WC_Retailcrm_Inventories' ) ) :
foreach ($result['offers'] as $offer) {
if (isset($offer['externalId'])) {
$post = get_post($offer['externalId']);
if ($post->post_type == 'product') {
$product = new WC_Product_Simple($offer['externalId']);
update_post_meta($offer['externalId'], '_manage_stock', 'yes');
$product->set_stock($offer['quantity']);
} elseif ($post->post_type == 'product_variation') {
$args = array();
if ($post->post_parent) {
$args['parent_id'] = $post->post_parent;
$args['parent'] = new WC_Product_Simple($post->post_parent);
}
$product = new WC_Product_Variation($offer['externalId'], $args);
update_post_meta($offer['externalId'], '_manage_stock', 'yes');
$product->set_stock($offer['quantity']);
}
$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();
}
}
} while ($page < $totalPageCount);
} while ($page <= $totalPageCount);
}
public function updateQuantity()