2014-08-30 31 views
1
$result = $client->call($session, 'catalog_product.update', array('123', array(
                  'name' => 'Product333222' 
                 ) 
                ) 
                ); 

這裏'123'是產品的Sku。 Sku在更新Api中不在這裏工作。Sku不能在magento產品更新中使用API​​

如果我給產品ID代替Sku,它工作正常。

那麼背後的問題是什麼。

如果有人知道,請讓我知道。

謝謝。

回答

2

Magento在這裏有點沉悶。

長話短說:

如果您使用的是數值而不指定識別輸入其假設你是在一個產品ID做你的作品。如果你在哪裏插入「abc」作爲值(不是數字),它將作爲SKU受到威脅。

解決此問題的最佳方法是在您的api調用中使用標識類型(在您的情況下爲「SKU」)。

有關使用識別碼類型的更多信息: http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.update.html

或者看到:Magento 1.5, numeric SKUs and productIdentifierType

短篇小說長:

下面的函數被調用低谷API 應用程序/代碼/核心/法師/目錄/型號/原料藥/ Resource.php

protected function _getProduct($productId, $store = null, $identifierType = null) 
{ 
    $product = Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType); 
    if (is_null($product->getId())) { 
     $this->_fault('product_not_exists'); 
    } 
    return $product; 
} 

正如你可以看到該函數在產品hel上調用以下函數每:

public function getProduct($productId, $store, $identifierType = null) { 
     $loadByIdOnFalse = false; 
     if ($identifierType == null) { 
      if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) { 
       $identifierType = 'sku'; 
       $loadByIdOnFalse = true; 
      } else { 
       $identifierType = 'id'; 
      } 
     } 

     /** @var $product Mage_Catalog_Model_Product */ 
     $product = Mage::getModel('catalog/product'); 
     if ($store !== null) { 
      $product->setStoreId($store); 
     } 
     if ($identifierType == 'sku') { 
      $idBySku = $product->getIdBySku($productId); 
      if ($idBySku) { 
       $productId = $idBySku; 
      } 
      if ($loadByIdOnFalse) { 
       $identifierType = 'id'; 
      } 
     } 

     if ($identifierType == 'id' && is_numeric($productId)) { 
      $productId = !is_float($productId) ? (int) $productId : 0; 
      $product->load($productId); 
     } 

     return $product; 
    } 

沒有在這裏指定$ identifierType和使用SKU像「123」的THRID線要做一個預浸匹配會導致如此。因此使用其他函數將其作爲ID來代替sku。

到底:

所以,做你的電話一樣:

$result = $client->call($session, 'catalog_product.update', array('123', array(
                  'name' => 'Product333222' 
                 ), null, 'sku'));