Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. function get_malab_api_and_inport()
  2. {
  3. global $feed;
  4. $data = json_decode($feed, TRUE);
  5. $woocommerce = getWoocommerceConfig();
  6.  
  7. $newProducts = array();
  8. $item_no = array_column($data['results'], 'item_no');
  9. $cost = array_column($data['results'], 'price');
  10. $upc = array_column($data['results'], 'upc_code');
  11. $manufacturer_no = array_column($data['results'], 'manufacturer_no');
  12. $manufacturer = array_column($data['results'], 'manufacturer');
  13. $category = array_column($data['results'], 'category');
  14. $product_name = array_column($data['results'], 'product_name');
  15. $manufacturer = array_column($data['results'], 'manufacturer');
  16. $instant_rebate = array_column($data['results'], 'instant_rebate');
  17. $in_stock = array_column($data['results'], 'in_stock');
  18. $weight = array_column($data['results'], 'weight');
  19. $package = array_column($data['results'], 'package');
  20. $image_path = array_column($data['results'], 'image_path');
  21. $product_spec = array_column($data['results'], 'product_spec');
  22. $inventory = array_column($data['results'], 'inventory');
  23.  
  24. $price= array_map(function($num){return number_format($num,2);}, $cost);
  25.  
  26. $newProduct = [
  27. 'name' => $product_name,
  28. 'type' => 'simple',
  29. 'regular_price' => $price,
  30. 'description' => $product_spec,
  31. 'short_description' => $manufacturer,
  32. 'categories' => [
  33. [
  34. 'id' => 15
  35. ]
  36. ],
  37. 'images' => [
  38. [
  39. 'src' => $image_path
  40. ]
  41. ]
  42. ];
  43.  
  44. array_push($newProducts, $newProduct);
  45.  
  46. foreach ($newProducts as $nproduct) {
  47. try {
  48.  
  49. $woocommerce->post('products', $nproduct);
  50.  
  51. } catch (HttpClientException $e) {
  52.  
  53. print_r($e);
  54. print_r($e->getMessage() . PHP_EOL);
  55. print_r('Code: ' . $e->getResponse()->getCode() . PHP_EOL);
  56. print_r('Body: ' . $e->getResponse()->getBody() . PHP_EOL);
  57. }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement