includes/admin/create-products.php
##This function is used to update the articles stock by article ID.
This function is used to update the articles stock by article ID.
This function is used to update the articles stock by article ID .
public function update_article_stock_by_id($options,$article_id){
		$url = $options['arcavis_link'].'/api/articlestocks/'.$article_id;
		$request_args = array(
		  'headers' => array(
			'Authorization' => 'Basic ' . base64_encode( $options['arcavis_username'] . ':' . $options['arcavis_password'] )
		  )
		);
		$stock_data = wp_remote_get($url,$request_args);
		if(is_wp_error($stock_data)){
			$wc_arcavis_shop->logError('wp_remote_get failed '.$stock_data->geterrormessage());
			exit;
		}
		$stocks = json_decode(wp_remote_retrieve_body($stock_data));
		if(!empty($stocks->Result)){
			$total_stock = 0;
			foreach ($stocks->Result as $stock) {
				$total_stock += $stock->Stock;
			}
			$args = array(
			'post_type'		=>	array('product','product_variation'),
			'meta_query' => array(
					array(
						'key' => 'article_id',
						'value'     => $article_id,
						'compare'   => '='
					),
				)
			);
			$products = get_posts($args);
			if(!empty($products)){
				$stockstatus='instock';
				if($total_stock<=0){
					$stockstatus='outofstock';
				}
				update_post_meta($products[0]->ID, '_stock_status', $stockstatus );
				update_post_meta($products[0]->ID,'_stock',$total_stock);
			}
		}
	}
public function update_article_stock_by_id ( $ options , $ article_id ) { $ url = $ options [ 'arcavis_link' ] . '/api/articlestocks/' . $ article_id ; $ request_args = array ( 'headers' => array ( 'Authorization' => 'Basic ' . base64_encode ( $ options [ 'arcavis_username' ] . ':' . $ options [ 'arcavis_password' ] ) ) ) ; $ stock_data = wp_remote_get ( $ url , $ request_args ) ; if ( is_wp_error ( $ stock_data ) ) { $ wc_arcavis_shop -> logError ( 'wp_remote_get failed ' . $ stock_data -> geterrormessage ( ) ) ; exit ; } $ stocks = json_decode ( wp_remote_retrieve_body ( $ stock_data ) ) ; if ( ! empty ( $ stocks -> Result ) ) { $ total_stock = 0 ; foreach ( $ stocks -> Result as $ stock ) { $ total_stock += $ stock -> Stock ; } $ args = array ( 'post_type' => array ( 'product' , 'product_variation' ) , 'meta_query' => array ( array ( 'key' => 'article_id' , 'value' => $ article_id , 'compare' => '=' ) , ) ) ; $ products = get_posts ( $ args ) ; if ( ! empty ( $ products ) ) { $ stockstatus = 'instock' ; if ( $ total_stock <= 0 ) { $ stockstatus = 'outofstock' ; } update_post_meta ( $ products [ 0 ] -> ID , '_stock_status' , $ stockstatus ) ; update_post_meta ( $ products [ 0 ] -> ID , '_stock' , $ total_stock ) ; } } }
This function is used to update the articles stock by article ID.
This function is used to update the articles stock by article ID .