2016-08-13 2 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はすでに管理オプションにありますが、上記のコードを実行しようとすると設定されません。 –

+0

あなたもaddDataを試しましたか? –

答えて

0

最後に、この問題の解決策を見つけました。

- > setdiamond_shape(134)

ここで134放射の値です。

関連する問題