Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_malab_api_and_inport()
- {
- global $feed;
- $data = json_decode($feed, TRUE);
- $woocommerce = getWoocommerceConfig();
- $newProducts = array();
- $item_no = array_column($data['results'], 'item_no');
- $cost = array_column($data['results'], 'price');
- $upc = array_column($data['results'], 'upc_code');
- $manufacturer_no = array_column($data['results'], 'manufacturer_no');
- $manufacturer = array_column($data['results'], 'manufacturer');
- $category = array_column($data['results'], 'category');
- $product_name = array_column($data['results'], 'product_name');
- $manufacturer = array_column($data['results'], 'manufacturer');
- $instant_rebate = array_column($data['results'], 'instant_rebate');
- $in_stock = array_column($data['results'], 'in_stock');
- $weight = array_column($data['results'], 'weight');
- $package = array_column($data['results'], 'package');
- $image_path = array_column($data['results'], 'image_path');
- $product_spec = array_column($data['results'], 'product_spec');
- $inventory = array_column($data['results'], 'inventory');
- $price= array_map(function($num){return number_format($num,2);}, $cost);
- $newProduct = [
- 'name' => $product_name,
- 'type' => 'simple',
- 'regular_price' => $price,
- 'description' => $product_spec,
- 'short_description' => $manufacturer,
- 'categories' => [
- [
- 'id' => 15
- ]
- ],
- 'images' => [
- [
- 'src' => $image_path
- ]
- ]
- ];
- array_push($newProducts, $newProduct);
- foreach ($newProducts as $nproduct) {
- try {
- $woocommerce->post('products', $nproduct);
- } catch (HttpClientException $e) {
- print_r($e);
- print_r($e->getMessage() . PHP_EOL);
- print_r('Code: ' . $e->getResponse()->getCode() . PHP_EOL);
- print_r('Body: ' . $e->getResponse()->getBody() . PHP_EOL);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement