2017-07-01 166 views
0

我是Magento的初学者,我使用Magento1.9 CE, 我想在目录/产品中以编程方式添加属性。 我的意思是,我想看看它在橙色盒子,我就如何以编程方式将属性添加到magento1.9中的产品?

This Image

我在Magento更改版本/应用程序/代码/核心/法师/目录的/ etc/config.xml文件中强调

`<modules> 
    <Mage_Catalog> 
     <version>1.6.0.0.19.1.15</version> 
    </Mage_Catalog> 
</modules>` 

,我添加此文件/magento/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.6.0.0.19.1.15.php

$installer = $this; 
$installer->startSetup(); 
$installer->addAttribute('catalog_product', 'promotion', array(
    'group'    => 'promotion', 
    'type'    => 'text', 
    'backend'   => 
    'catalog/product_attribute_backend_promotion', 
    'frontend'   => '', 
    'label'    => 'promotion', 
    'input'    => 'text', 
    'class'    => '', 
    'source'   => '', 
    'global'   => Mage_Eav_Model_Entity_Setup::SCOPE_GLOBAL, 
    'visible'   => true, 
    'required'   => false, 
    'user_defined'  => false, 
    'default'   => '', 
    'searchable'  => false, 
    'filterable'  => false, 
    'comparable'  => false, 
    'visible_on_front' => false, 
    'unique'   => false, 
    'apply_to'   => 'simple,virtual', 
    'is_configurable' => false 
)); 

时一世刷新添加产品页面,在数据库core_resource表中,catalog_setup版本更改为1.6.0.0.19.1.15,但没有任何事件发生到eav_attribute

我应该怎么做才能在eav_attribute表中添加'promotion'?

回答

0

第一步:先创建一个php文件。

第二步:在文件中写下如下代码。

<?php 
require_once('app/Mage.php'); 
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); 
$installer = new Mage_Eav_Model_Entity_Setup('core_setup'); 
$installer->startSetup(); 
$installer->addAttribute('catalog_product', 'custom_att', array(
      'group'   => 'General', 
      'label'   => 'Custom att', 
      'input'   => 'text', 
      'type'   => 'varchar', 
      'required'  => 0, 
      'visible_on_front'=> 1, 
      'filterable'  => 0, 
      'searchable'  => 0, 
      'comparable'  => 0, 
      'user_defined' => 1, 
      'is_configurable' => 0, 
      'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
      'note'   => '', 
)); 
$installer->endSetup(); 
?> 

第3步:把这个文件放在根目录下,并通过url运行这个文件。然后创建产品属性。

0

你不应该改变核心模块的任何东西。 首先您需要在magento中创建一个本地模块,然后您只能以编程方式添加产品属性。这是添加属性的正确方法。

这个链接可以帮助你创建产品属性

http://inchoo.net/magento/programatically-create-attribute-in-magento-useful-for-the-on-the-fly-import-system/

https://magento.stackexchange.com/questions/162595/programmatically-add-custom-product-attribute-to-attribute-set

如果你不知道有关创建新的模块,在Magento是指是指这个网址

http://inchoo.net/magento/programming-magento/magento-hello-world-module-extension/

如果您需要进一步的帮助,请问我。

相关问题