如何使用Volusion API在Volusion中添加和更新类别

时间:2016-11-07 13:35:52

标签: php xml api volusion

实际上我有一个商店我将产品导入我的商店所有产品数据都是插入和更新,但唯一的类别ID不是插入和更新。

  1. 这是我的名为dataPro.txt的XML代码。
  2. <Products_Joined>
      <productcode>3710_012T</productcode> 
      <vendor_partno>EAH5450SILENT/DI/1GD3(LP)</vendor_partno> 
      <productname>Test Product TA</productname> 
      <hideproduct>N</hideproduct> 
      <stockstatus>20</stockstatus> 
      <lastmodified>1/5/2016 10:25:00 AM</lastmodified>  
      <lastmodby>2</lastmodby> 
      <productweight>0.9</productweight> 
      <productprice>100</productprice> 
      <productmanufacturer>ASUS TeK</productmanufacturer> 
      <vendor_price>32.69</vendor_price> 
      <numproductssharingstock>0</numproductssharingstock> 
      <categoryids>107</categoryids> 
      <producturl>http://tebkq.mvlce.servertrust.com/ProductDetails.asp?ProductCode=3710_012T</producturl> 
      <photourl>http://tebkq.mvlce.servertrust.com/v/vspfiles/templates/tlztech/images/3710_012T.gif</photourl> 
      <categorytree>New: Parts and Accessories</categorytree> 
    </Products_Joined>

    1. 这是我的PHP脚本。
    2. <?php
       $file = file_get_contents('dataPro.txt', true);
      
      //  Create the Xml to POST to the Webservice
      
          $Xml_to_Send = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
          $Xml_to_Send .= "<Volusion_API>";
      //  $Xml_to_Send .= "<!--";
          $Xml_to_Send .= $file;
      //  $Xml_to_Send .= "\"\"";
      //  $Xml_to_Send .= "-->";
          $Xml_to_Send .= "</Volusion_API>";
      
      
      $url = "http://mysitedomian/net/WebService.aspx?Login=xxxxxxxxxxx&EncryptedPassword=xxxxxxxxx&Import=Insert-Update";
      
      
      //  Create the Header   
      
          //  Post and Return Xml
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $Xml_to_Send); 
          curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/x-www-form-urlencoded; charset=utf-8", "Content-Action:Volusion_API"));
          $data = curl_exec($ch);
      
          //  Check for Errors
          if (curl_errno($ch)){
            
              print curl_error($ch);
          } else {
            
             curl_close($ch);
          }
      
         //  Display the Xml Returned on the Browser
          
         echo $data;
        
      ?>

1 个答案:

答案 0 :(得分:1)

一旦您的产品和类别已经在您的Volusion数据库中,请调用API并按照以下方式传递XML:

<xmldata>
  <Categories_Products_Link>
    <CategoryID>10</CategoryID>
    <ProductID>20</ProductID>
  </Categories_Products_Link>
</xmldata>