【问题标题】:How to update Products inventory from 3rd party POS system in Magento2?如何从 Magento2 中的 3rd 方 POS 系统更新产品库存?
【发布时间】:2019-12-15 19:54:14
【问题描述】:

如何从 Magento2 中的 3rd 方 POS 系统更新产品库存? 当我点击该按钮时,我需要在 POS 系统中创建一个按钮,产品库存应该从 POS 更新到 Magento2 系统。

【问题讨论】:

    标签: api magento pos


    【解决方案1】:

    这是从 Rest API 更新数量的工作代码

    <?php $adminUrl = 'http://localhost/magento2/rest/V1/integration/admin/token/';
    $ch = curl_init(); 
    $data = array("username" => "admin", "password" => "admin"); //Admin Login details
    $data_string = json_encode($data);
    $ch = curl_init($adminUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_string)));
    $token = curl_exec($ch);
    $token= json_decode($token);
    $headers = array("Authorization: Bearer $token","Content-Type: application/json");
    $skus = array('100001' => 66,'100002' => 99); //Here 100001 and 100002 are SKU and 66 and 99 are Qty
    foreach ($skus as $sku => $stock) {
    $requestUrl='http://localhost/magento2/rest/V1/products/' . $sku . '/stockItems/1';
    $sampleProductData = array("qty" => $stock);
    $productData = json_encode(array('stockItem' => $sampleProductData));
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $requestUrl);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    var_dump($response);
    unset($productData);
    unset($sampleProductData);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 2015-03-08
      • 2019-12-19
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      相关资源
      最近更新 更多