1
我使用的是magento 1.9,我想在下面的代碼中設置我的自定義屬性「diamond_clarity」值。 自定義屬性「diamond_clarity」是下拉菜單。如何使用我的自定義屬性在Magento 1.9中以編程方式創建簡單產品?
以下是我的代碼。
<?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());
}
?>
請讓我知道如何整合?
$ product-> setData('attributeName','Value'); –
謝謝你Vishnu, 我檢查了$ product-> setData('diamond_shape','Radiant'),但它不工作。 Radiant已經在Manage選項中,但是當我嘗試執行上面的代碼時沒有設置。 –
你有沒有嘗試過addData –