我想每次从XML数据中发布1个“列表”标签。 我不能。 翻白页。 如果您能帮助我,我会很高兴。
api.xml
<listings>
<listing>
<Sku>HBV00000H74DE</Sku>
<MerchantSku>Encok-D02</MerchantSku>
<ProductName>Baseus D02 Kablosuz Bluetooth 5.0 Kulaklık renk beyaz</ProductName>
<Price>294,10</Price>
<AvailableStock>0</AvailableStock>
<DispatchTime>1</DispatchTime>
<MaximumPurchasableQuantity>0</MaximumPurchasableQuantity>
</listing>
<listing>
<Sku>HBV00000H74DD</Sku>
<MerchantSku>Encok-S09</MerchantSku>
<ProductName>Baseus S09 Encok Manyetik Kablosuz Bluetooth Mikrofonlu Kulaklık renk silver</ProductName>
<Price>136,08</Price>
<AvailableStock>1</AvailableStock>
<DispatchTime>1</DispatchTime>
<MaximumPurchasableQuantity>0</MaximumPurchasableQuantity>
</listing>
xml继续这样。
我可以发送1个产品的数据。
<?php
$xmldata = simplexml_load_file('api.xml');
$output = "<listings>";
foreach($xmldata->children() as $listing) {
$output .= "<listing>";
$output .= "<Sku>" . $listing->Sku ."</Sku>";
$output .= "<MerchantSku>". $listing->MerchantSku ."</MerchantSku>";
$output .= "<ProductName>". $listing->ProductName ."</ProductName>";
$output .= "<Price>". $listing->Price ."</Price>";
$output .= "<AvailableStock>". $listing->AvailableStock ."</AvailableStock>";
$output .= "<DispatchTime>". $listing->DispatchTime ."</DispatchTime>";
$output .= "<MaximumPurchasableQuantity>". $listing->MaximumPurchasableQuantity ."</MaximumPurchasableQuantity>";
$output .= "</listing>";
}
$output = "</listings>";
$service_url = 'https://.../inventory-uploads';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $output);
$header = array(
'Authorization: Basic '. base64_encode('user:passw'),
'Content-Type: application/xml'
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$result .= $curl_response = curl_exec($curl);
?>
我想通过此交易更新产品价格和库存。