0

提前感谢您帮助解决我的问题。
在产品中保存在 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");
}

谁能帮我解决这个问题?

4

3 回答 3

1

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

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

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

HTH,
法学博士

于 2011-04-26T01:40:30.400 回答
1

如果您可以使用脚本更快地完成它并$product->save像您一样使用但不要将它混合在一起,那么您为什么要使用 API!

代替

$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();
于 2012-05-06T22:39:34.890 回答
0

为什么不使用 Magento 的后端?无需使用代码...

于 2011-04-26T02:23:01.057 回答