2016-08-13 85 views
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()); 
} 
?> 

请让我知道如何整合?

+0

$ product-> setData('attributeName','Value'); –

+0

谢谢你Vishnu, 我检查了$ product-> setData('diamond_shape','Radiant'),但它不工作。 Radiant已经在Manage选项中,但是当我尝试执行上面的代码时没有设置。 –

+0

你有没有尝试过addData –

回答

0

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

- > setdiamond_shape(134)

这里134是辐射的值。

相关问题