Advertisement
Guest User

tokped_parser

a guest
Jan 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. function parse_tokped($keyword)
  2. {
  3. $this -> url_tokped = "https://ace.tokopedia.com/search/product/v3?scheme=https&device=desktop&related=true&catalog_rows=5&source=universe&ob=23&st=product&rows=60&q=";
  4.  
  5. $url = $this->url_tokped.urlencode($keyword);
  6. $hasil = json_decode($this -> http_request($url));
  7.  
  8. // $data['vendor'] = 'tokopedia';
  9. // parsing hasil
  10. // cek apakah response ok;
  11.  
  12. if(count($hasil->data->products)<1):
  13. $data['status'] = 'ok';
  14. $data['msg'] = 'produk tidak ditemukan';
  15. else:
  16. $data['produk'] = array();
  17. foreach($hasil->data->products as $prdk):
  18. $data['produk'][] = array( 'p_name' => $prdk->name,
  19. 'p_price' => $prdk->price_int,
  20. 'p_sold' => 'gk ada info barang yg udh terjual di API ini ',
  21. 'p_link' => $prdk->url,
  22. 'p_img' => $prdk->image_url,
  23. 'p_vendor' => 'tokopedia'
  24. );
  25. endforeach;
  26. endif;
  27. return json_encode($data);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement