簡體   English   中英

Magento:在安裝腳本中為分組產品添加新屬性

[英]Magento: Adding new attribute to grouped products in setup script

我正在為分組產品開發一個小的Magento擴展。 這個擴展需要另一個屬性,所以我想我可以編寫一個設置腳本,為分組產品添加一個新屬性。 但就像我在Magento嘗試做的幾乎所有事情一樣,事實證明這比我預期的要復雜得多。 官方Magento論壇沒有真正的幫助,所以我希望在這里得到一些支持:)

新屬性應僅出現在分組產品的“常規”選項卡中; 簡單的產品,可配置的產品,捆綁產品等應該保持不變。 該屬性應該獨立於所選屬性集,就像它是一個系統屬性一樣。

為此,我想我可以將屬性添加到分組產品的實體中,但正如我所知,對於分組產品沒有特殊實體,一般只有產品“catalog_product”。 因此我的下一個想法是,我需要將屬性添加到“catalog_product”實體,然后將其分配給正確的屬性組,以便它僅適用於分組產品。

問題是我還沒有那么深入Magento而且我完全不知道我應該如何找到相應的屬性組,或者我的想法是否會起作用,也許我完全走錯了軌道:/

只是為了讓你知道到目前為止我得到了什么:我在擴展程序的配置文件中注冊了我的安裝腳本並且它正在執行,唯一的問題是安裝腳本本身,它看起來像下面的atm,因為 - 正如我所說 - 我有還沒有任何線索:

$installer = $this;
$installer->startSetup();
$installer->addAttribute("catalog_product", "my_attrib_name", array( /* just a placeholder */ ));
$installer->endSetup();

非常基本......

我現在想出了如何自己做。 我的方法是正確的,我只需要找到相應的參數。

addAttribute() - 調用現在看起來如下:

// ...
$installer->addAttribute(
    "catalog_product", // Entity the new attribute is supposed to be added to
    "my_attrib_code", // attribute code
     array( // Array containing all settings:
        "type" => "varchar",
        "label" => "My attribute",
        "note" => "Insert additional information about the attribute here",
        "input" => "text",
        "global" => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        // Dont know if this is really necessary, but it makes sure 
        // the attribute is created as a system attribute:
        "user_defined" => false,
        // This makes sure the attribute only applies to grouped products
        "apply_to" => Mage_Catalog_Model_Product_Type::TYPE_GROUPED
    )
);
// ...

現在,安裝程序添加的屬性是系統屬性,它會自動添加到每個屬性集的“常規”組中,並且無法更改/移動。 正如我所預期的那樣,它也僅適用於分組產品。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM