如何使用我的自定义属性在Magento 1.9中以编程方式创建简单产品?

时间:2016-08-13 09:48:35

标签: php magento

我正在使用magento 1.9,我想在下面的代码中设置我的自定义属性“diamond_clarity”值。 自定义属性“diamond_clarity”是下拉列表。

以下是我的代码。

<?php
require_once '../app/Mage.php';
umask(0) ;  
Mage::app();

try {
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product');
$product
    ->setWebsiteIds(array(1)) //website ID the product is assigned to, as an array
    ->setAttributeSetId(67) //ID of a attribute set named 'default'
    ->setTypeId('simple') //product type
    ->setCreatedAt(strtotime('now')) //product creation time
    ->setSku('Round Diamonds') //SKU
    ->setName('round diamonds') //product name
    ->setWeight(8.00)
    ->setStatus(1) //product status (1 - enabled, 2 - disabled)
    ->setTaxClassId(4) //tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
    ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) //catalog and search visibility
    ->setManufacturer(28) //manufacturer id
    ->setColor(24)
    ->setNewsFromDate(strtotime('now')) //product set as new from
    ->setNewsToDate('06/30/2015') //product set as new to
    ->setCountryOfManufacture('AF') //country of manufacture (2-letter country code)
    ->setPrice(11.22) //price in form 11.22
    ->setCost(11.11) //price in form 11.22    
    ->setStockData(array(
                       'use_config_manage_stock' => 0, //'Use config settings' checkbox
                       'manage_stock'=>1, //manage stock
                       'min_sale_qty'=>1, //Minimum Qty Allowed in Shopping Cart
                       'max_sale_qty'=>1, //Maximum Qty Allowed in Shopping Cart
                       'is_in_stock' => 1, //Stock Availability
                       'qty' => 1 //qty
                   )
    )
    ->setCategoryIds(array(3, 10)); //assign product to categories
$product->save();
}catch(Exception $e){
Mage::log($e->getMessage());
}
?> 

请告诉我如何整合?

1 个答案:

答案 0 :(得分:1)

最后,我找到了解决这个问题的方法。

- &GT; setdiamond_shape(134)

这里134是Radiant的值。