2014-05-08 83 views
0

我正在嘗試爲Magento 1.8.x運行安裝程序腳本,但我不確定如何執行它。任何人都可以確認是否有任何問題與我的文件下面,也如何讓Magento實際執行此腳本並添加此自定義客戶屬性?無法在Magento中運行安裝程序腳本(1.8.x)

這裏是我的文件夾結構(包括剛纔那些我覺得適用於此):

\app\code\local\SS\Rapt\ 
\app\code\local\SS\Rapt\etc\config.xml 
\app\code\local\SS\Rapt\sql\mysql4-install-0.0.1.php 

我的安裝文件如下:

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$entityTypeId  = $setup->getEntityTypeId('customer'); 
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); 
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); 

$setup->addAttribute('customer', 'organisation_id', array(
    'input'   => 'select', //or select or whatever you like 
    'type'   => 'int', //or varchar or anything you want it 
    'label'   => 'Organisation ID', 
    'visible'  => 1, 
    'required'  => 0, //mandatory? then 1 
    'user_defined' => 1, 
)); 

$setup->addAttributeToGroup(
    $entityTypeId, 
    $attributeSetId, 
    $attributeGroupId, 
    'organisation_id', 
    '100' 
); 

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'organisation_id'); 
$oAttribute->setData('used_in_forms', array('adminhtml_customer')); 
$oAttribute->save(); 

$setup->endSetup(); 

我config.xml中如下:

<config> 
<modules> 
    <SS_Rapt> 
     <version>0.0.1</version> 
    </SS_Rapt> 
</modules> 
/** more here but left out as not applicable to this installer feature **/ 

回答

2

MySQL4不再使用。您應該使用資源設置模型。首先,你應該在config.xml中定義資源

<config> 
    <modules> 
     <SS_Rapt> 
     <version>0.0.1</version> 
    </SS_Rapt> 
    </modules> 

    <global> 
     <resources> 
      <rapt_setup> 
       <setup> 
        <module>SS_Rapt</module> 
        <class>SS_Rapt_Model_Resource_Setup</class> 
       </setup> 
       <connection> 
        <use>core_setup</use> 
       </connection> 
      </rapt_setup> 
     </resources> 
    </global> 

</config> 

然後,你需要創建在以下位置SS_Rapt_Model_Resource_Setup文件:

SS/Rapt/Model/Resource/Setup.php 

這個類應該只包含這樣的:

<?php 
class SS_Rapt_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup{ 

} 

在最後,您需要在此位置創建安裝腳本:SS/Rapt/sql/rapt_setup/install-0.0.1.php

您不需要將mysql4放在安裝腳本名稱的開頭。就是這樣:)

+0

感謝JS - 會給它一個鏡頭:) 我需要做什麼特別的「執行」這一次代碼已添加? – Zabs

+1

只需重新加載您的Magento商店的任何頁面。 –

+0

我已經這樣做了 - 沒有錯誤(或者我可以看到) - 我怎麼能確定這確實已經執行?例如,這個新的自定義屬性'organisation_id'位於數據庫結構中? – Zabs

0

我終於搞定了 - sql目錄需要有一個名爲'rapt_setup'的文件夾,裏面的sql!衛生署!

但由於JS提供這麼多的幫助我還是希望他能收到答案要點:)

相關問題