2010-10-01 73 views
0

预先感谢您帮助解决我的问题。
产品保存在magento此代码不保存产品。请找到这个问题的解决办法:Magento产品插入方法

<?php 
define('MAGENTO_MAGE_LOCATION','/home/admin/domains/public_html/importcsv1/app/Mage.php'); 
error_reporting(E_ALL); 
require_once MAGENTO_MAGE_LOCATION; 
$client = new Zend_XmlRpc_Client('http:www.examole.com/importcsv1/index.php/api/xmlrpc/'); 
$session = $client->call('login', array('aazi', 'asdfjsdf')); 

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

$product = Mage::getModel('catalog/product'); 

$product->setSku("12"); 
$product->setName("test name of the product"); 
$product->setWebsiteIDs(array('1')); 
$product->setTypeId('simple'); 
$product->setPrice("111"); 
$product->setInprice("222"); 
$product->setDescription("test description of the product"); 
$product->setShort_description("test short description of the product"); 
$product->setQty("11"); 
$product->setWeight("1.1"); 
$product->setCategoryIds(array(4)); 

try { 
    $product->save(); 
    echo "<br>yes save new product insert into magento"; 
} catch (Exception $e) { 
    var_dump("NO new insert product save"); 
} 

任何人都可以帮我解决这个问题吗?

+1

你们是不是要更新现有产品,或创建一个新的? –

+1

此外,当所有错误日志记录打开时,您会在错误日志中看到哪些错误? (或至少$ e-> getMessage()) –

回答

1

此行是否有格式正确的网址?您似乎缺少冒号和www之间的字符。

$client = new Zend_XmlRpc_Client('http:www.examole.com/importcsv1/index.php/api/xmlrpc/'); 

我也认为$product->setWebsiteIDs(array('1'));应该有一个小写字母“D”。由于网站ID是必填字段,因此这里拼写错误可能会导致问题。

HTH,
JD

0

为什么不使用的Magento的后台?不需要使用代码...

+1

看着他的代码,似乎他想绑定到一个XmlRpc服务来导入产品... –

1

为什么你使用API​​,如果你可以用脚本快速完成并使用$product->save像你一样,但不要混合在一起!

更换

$client = new Zend_XmlRpc_Client('http:www.examole.com/importcsv1/index.php/api/xmlrpc/'); 
$session = $client->call('login', array('aazi', 'asdfjsdf')); 

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

- 与

Mage::init();