How to Update Specific Product Quantities using SOAP API?

 <?php

use Magento\Framework\App\Bootstrap;


try {

require './app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);


$objectManager = $bootstrap->getObjectManager();

$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');

$connection = $resource->getConnection();

$state = $objectManager->get('Magento\Framework\App\State');

$state->setAreaCode('frontend');


$request = new SoapClient("https://your_domain/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2));

// changes your store url.

$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin", "password"=>"admin@123"));


$request = new SoapClient(

    'https://your_domain/soap/default?wsdl&services=catalogInventoryStockRegistryV1',

    array(

'soap_version' => SOAP_1_2,

'stream_context' => stream_context_create(array(

    'http'=> array('header' => 'Authorization: Bearer '.$token->result)

))

    )

);

$qtyData = [

    'qty' => 1000,

    'isInStock' => 1,

    'isQtyDecimal' => 0,

    'showDefaultNotificationMessage' => 0,

    'useConfigMinQty' => 0,

    'minQty' => 2,

    'useConfigMinSaleQty' => 1,

    'minSaleQty' => 1,

    'useConfigMaxSaleQty' => 0,

    'maxSaleQty' => 10,

    'useConfigBackorders'  => 0,

    'backorders' => 1,

    'useConfigNotifyStockQty' => 0,

    'notifyStockQty' => 10,

    'useConfigQtyIncrements' => 1,

    'qtyIncrements' => 1,

    'useConfigEnableQtyInc' => 1,

    'enableQtyIncrements' => 1,

    'useConfigManageStock' => 1,

    'manageStock' => 1,

    'lowStockDate' => 1,

    'isDecimalDivided' => 1,

    'stockStatusChangedAuto' => 1

];


$response = $request->catalogInventoryStockRegistryV1UpdateStockItemBySku(['productSku'=> 'Simple Product', 'stockItem' => $qtyData]);

echo "<pre>";

print_r($response);

echo "</pre>";


}catch (\Exception $e){

    echo $e->getMessage() . " \n";

}

Comments

Popular posts from this blog

Add Admin User name and Action name in Order Comment Section through Action Performed from Sales Order Grid in Magento 2

How to Update Product Stock Programmatically in Magento 2

How to Set and Get Cookie in Magento 2