开发者

Magento product insert method

Thanks in advance for helping solve my issue.

in product save in magento this code not save the products. please find the solution of this problem:

<?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");
}

Can any one help me to resolve this issue?


Should this line have a properly formatted URL? You seem to be missing characters between the colon and the www.

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

I also think that $product->setWebsiteIDs(array('1')); should have a lowercase "D". Since the website ID is a required field, a misspelling here might cause problems.

HTH,
JD


why are you using the API if you can do it much faster with a script and use $product->save like you did but don't mix it together!

replace

$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);

-- with

Mage::init();


Why don't use the backend of Magento? No need to use code...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜