2017-07-01 7 views
0

私はMagentoの初心者で、Magento1.9 CEを使用しました。 プログラムでカタログ/製品に属性を追加したいと思います。私は私がmagento1.9の製品にプログラムで属性を追加する方法は?

Magentoの/アプリ/コード/コア/メイジ/カタログの/ etc/config.xmlファイルのバージョンを変更

This Image

上で強調表示オレンジ色のボックスでそれを見たいという 私が意味します、

`<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

Step1:最初にPHPファイルを作成します。

ステップ2:以下のコードをファイルに書き込みます。

<?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で作成する必要があるだけで、プロダクト属性をプログラムで追加することができます。属性を追加する適切な方法です。新しいモジュールを作成について認識していない場合は、製品を作るためにあなたを助けるかもしれない

このリンクは、Magentoの中でこのURL

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

に指す意味

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

属性

さらに援助が必要な場合は、私に尋ねてください。

関連する問題