dongzhong7299
2013-10-14 08:19
浏览 17
已采纳

Magento - 在php中创建产品并设置尺寸

I'm already creating Magento products in php. Now I want to add the product's weight and dimensions (length, width, height), so that it can be used by a shipping plugin.

For settings the weight, I found this method: $product->setWeight(1.0); But I can't find any similar method for the dimensions.

Now my questions is: How can I set the product dimensions?

This is the code I'm using for adding a product:

umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name'=>'adminhtml'));

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

$product->setSku("SKU");
$product->setName("name");
$product->setDescription("description");
$product->setShortDescription("short description");
$product->setPrice(9.99);

$product->setTypeId('simple');
$product->setAttributeSetId(9);
$product->setCategoryIds("0");

$product->setWeight(1.0);

[...] // setting stock and tax information

$product->save();

Thanks in advance

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudao2954 2013-10-14 08:39
    已采纳

    You can set any attribute in the same way as you set the weight. Let's say the attribute code is some_attribute you can do this:

    $product->setData('some_attribute', 'value_here');
    //or
    $product->setSomeAttribute('value_here');
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题