2013-10-24 65 views
0

我已經使用自定義模塊的安裝腳本創建了一個屬性。一個屬性是一個下拉菜單,它只有兩個選項,分別是'是','否'。另一個屬性是文本字段。我需要通過此腳本設置默認值。我捆綁了以下內容。但沒有奏效。如何通過安裝腳本爲屬性設置默認值?

$th = new Mage_Catalog_Model_Resource_Setup(); 
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
      'group' => 'Prices', 
      'type' => 'text', 
      'backend' => '', 
      'frontend' => '', 
      'label' => 'Credit rewards', 
      'input' => 'text', 
      'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
      'visible' => true, 
      'required' => false, 
      'user_defined' => true, 
      'default' => 'kkkkkkkk', // this is default value. but is's not setting 
      'searchable' => false, 
      'filterable' => true, 
      'comparable' => false, 
      'visible_on_front' => true, 
      'visible_in_advanced_search' => true, 
      'used_in_product_listing' => true, 
      'unique' => false, 
      'apply_to' => 'simple', 
     )); 

任何建議將不勝感激。先謝謝了。

回答

1

請檢查以下代碼,我已在我的一個magento安裝中使用。

$installer = $this; 
$installer->startSetup(); 

$installer->addAttribute('catalog_product', 'offer_type', array(
     'backend'  => '', 
     'frontend'  => '', 
     'class' => '', 
     'default'  => 'Wedding Planning', 
     'label' => 'Offer type', 
     'input' => 'text', 
     'type' => 'int', 
     'source'  => '', 
     'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
     'visible'  => 1, 
     'required'  => 1, 
     'searchable' => 0, 
     'filterable' => 1, 
     'unique'  => 0, 
     'comparable' => 0, 
     'visible_on_front' => 1, 
     'is_html_allowed_on_front' => 1, 
     'user_defined' => 1, 
)); 

如下你也可以添加此屬性設置屬性:

$installer->addAttributeToSet('catalog_product', $sSetId, $groupName, 'offer_type'); 
+0

我可以使用$安裝=新Mage_Catalog_Model_Resource_Setup(); – Sukeshini

+0

你可以使用上面的答案作爲更新,如果不工作,你可以從這篇文章也參考:http://stackoverflow.com/questions/9599262/magento-add-new-attribute-to-all-products –

+0

謝謝許多。它是當我添加一個新產品時。 – Sukeshini