以编程方式将字段添加到system.xml

时间:2014-03-26 11:28:10

标签: magento

我为Magento创建了一个插件。 我需要改进基于语言添加一些功能。所以我必须为每种语言添加一个文本字段。

        <lc_global translate="label" module="lc_e">
    [...]
            <groups>
                <lc_preferences translate="label">
                    <label></label>
    [...]
                    <fields>

to be cycled

                        *<it_code>
                            <label>Code</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                            <validate>validate-number</validate>
                        </it_code>*
end
                    </fields>

1 个答案:

答案 0 :(得分:0)

你好@ClaudioƜǝısMulas

Magento:如何以编程方式添加自定义选项

如何以编程方式创建产品自定义选项?

[php]
$option = array(
  'title' => 'Your custom option title',
  'type' => 'radio', // could be drop_down ,checkbox , multiple
  'is_require' => 1,
  'sort_order' => 0,
  'values' => getOptions()
);

function getOptions(){
  return array(
    array(
      'title' => 'Option Value 1',
      'price' =>100,
      'price_type' => 'fixed',
      'sku' => 'any sku for 1',
      'sort_order' => '1'
    ),
    array(
      'title' => 'Option Value 2',
      'price' =>100,
      'price_type' => 'fixed',
      'sku' => 'any sku for 2',
      'sort_order' => '1'
    ),
    array(
      'title' => 'Option Value 3',
      'price' =>100,
      'price_type' => 'fixed',
      'sku' => 'any sku for 3',
      'sort_order' => '1'
    )
  );
}

//Suppose we are creating a new product.
$product = Mage::getModel('catalog/product');
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);

//Or if we are adding the options to a already created product.
$product = Mage::getModel('catalog/product')->load($id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);

//Do not forget to save the product
$product->save();

[/php]

参考:http://magegurus.blogspot.com/2013/07/magento-how-to-add-custom- options.html