0

I am using magento2.2 version. I have an API of products coming from another system, for a specific purpose i want to print specific quantity from API.

Here is the sample JSON data of API coming when i use vardump :

string(526) " [{"PRODUCTID":"47-0001-000247","PRODUCTNAME":"Black Pepper Powder 100gm","BARCODE":"GC00093","RETAILPRICE":"110","QUANTITY":"853","DISCOUNTPRICE":"0","COSTPRICE":"58","UOM":"0001.UM","TYPE":"Pieces","LTEAM":"Food","DEPARTMENT":"Edible Grocery (Food) N (Grocery)","MAINCATEGORY":"Basic Commodities","SUBCATOEGORY":"Spices","BRAND_NAME":"Own Brand EG","VENDOR_NAME":"Ar Brothers (Spices & Dry Fruit) (205443)","VENDORCODE":"V-0658"}]" 

Here is the original data coming from API on print function :

[
{
"PRODUCTID":"47-0001-000247",
"PRODUCTNAME":"Black Pepper Powder 100gm",
"BARCODE":"GC00093",
"RETAILPRICE":"110",
"QUANTITY":"853","DISCOUNTPRICE":"0","COSTPRICE":"58","UOM":"0001.UM","TYPE":"Pieces","LTEAM":"Food","DEPARTMENT":"Edible Grocery (Food) N (Grocery)","MAINCATEGORY":"Basic Commodities","SUBCATOEGORY":"Spices","BRAND_NAME":"Own Brand EG","VENDOR_NAME":"Ar Brothers (Spices & Dry Fruit) (205443)","VENDORCODE":"V-0658"}
]

here's my code to print quantity of specific barcode i wanna use :

<?php
$url = 'http://test.com/GetItemsByBarcode';


    $params = "GC00093";

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url.'?barcd='.$params ); //Url together with parameters
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Return data instead printing directly in Browser
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 7); //Timeout after 7 seconds
    curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_HEADER, 0);

        $result = curl_exec($ch);
    curl_close($ch);

if(curl_errno($ch))  //catch if curl error exists and show it
  echo 'Curl error: ' . curl_error($ch);
else
  var_dump($result) ;



?>

Please guide me how can i pass multiple barcodes in URL and print their attribut quantities i have in stock.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.