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条)

报告相同问题?