2016-04-04 32 views
2

我需要擴展Shopware變體模型以添加一些自定義屬性,例如金屬類型,寶石類型,這是基礎文章。 這些屬性將用於後端和前端。擴展Shopware Models

我該怎麼做?謝謝

回答

7

擴展Shopware核心模型本身是不可能的。根據你想擴展會有一些解決方法兩種不同的方式是什麼具體型號:

  1. 如果你想擴展您可以使用自定義物品本身屬性字段說明如下:http://community.shopware.com/Anlegen,-Anpassen-und-Ausgabe-von-Artikel-Attributen_detail_1208.html

  2. 另一種方法是編寫一個插件,通過plugin install()上的代碼創建屬性字段。這僅適用於具有屬於實體本身的屬性表的實體。例如s_order和s_order_attributes

對於第二種方式在你的插件的bootstrap.php中的插件的安裝()方法創建一個方法類似下面,並調用方法:

public function installOrderAttributes() 
{ 
    Shopware()->Models()->addAttribute(
     's_order_attributes', 
     'ordermod', 
     'Random1', 
     'DECIMAL(12,4)', 
     false, 
     0.0000); 
    Shopware()->Models()->addAttribute(
     's_order_attributes', 
     'ordermod', 
     'Random2', 
     'DECIMAL(12,4)', 
     false, 
     0.0000); 

    $metaDataCacheDoctrine = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl(); 
    $metaDataCacheDoctrine->deleteAll(); 

    Shopware()->Models()->generateAttributeModels(array('s_order_attributes')); 
} 

中的addAttribute(在/engine/Shopware/Components/Model/ModelManager.php)函數具有以下特徵:

/** 
* Shopware helper function to extend an attribute table. 
* 
* @param string $table Full table name. Example: "s_user_attributes" 
* @param string $prefix Column prefix. The prefix and column parameter will be the column name. Example: "swag". 
* @param string $column The column name 
* @param string $type Full type declaration. Example: "VARCHAR(5)"/"DECIMAL(10, 2)" 
* @param bool $nullable Allow null property 
* @param null $default Default value of the column 
* @throws \InvalidArgumentException 
*/ 
public function addAttribute($table, $prefix, $column, $type, $nullable = true, $default = null); 

希望這會有所幫助。

親切的問候!