【问题标题】:Magento product insert methodMagento产品插入方法
【发布时间】:2010-10-01 06:46:05
【问题描述】:

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

谁能帮我解决这个问题?

【问题讨论】:

  • 您是要更新现有产品,还是要创建新产品?
  • 另外,当所有错误日志都打开时,您的错误日志中会出现什么错误? (或至少 $e->getMessage())

标签: php magento product


【解决方案1】:

这行应该有一个格式正确的 URL 吗?您似乎缺少冒号和 www 之间的字符。

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

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

HTH,
京东

【讨论】:

    【解决方案2】:

    如果您可以使用脚本更快地完成它并像您一样使用$product-&gt;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();
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 看他的代码,好像是想绑定一个XmlRpc服务来导入产品……
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多