扩展Shopware模型

fnl*_*s10 2 shopware

我需要扩展Shopware变体模型,以便添加一些自定义属性,例如金属的类型,宝石的类型,这是基础文章.这些属性将在后端和前端中使用.

我怎样才能做到这一点?谢谢

bar*_*rew 7

根本不可能扩展Shopware核心模型本身.根据您尝试扩展的具体型号,某些解决方法有两种不同的方式:

  1. 如果您要扩展的文章本身可以使用此处所述的自定义属性字段:http://community.shopware.com/Anlegen,-Anpassen-und-Ausgabe-von-Artikel-Attributen_detail_1208.html

  2. 另一种方法是编写一个插件,您可以通过插件install()上的代码创建属性字段.这仅适用于具有属于实体本身的属性表的实体.例如s_order和s_order_attributes

对于第二种方法,在插件的Bootstrap.php中创建一个方法,如下所示,并在插件的install()方法中调用该方法:

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'));
}
Run Code Online (Sandbox Code Playgroud)

/engine/Shopware/Components/Model/ModelManager.php中的addAttribute()函数具有以下签名:

/**
 * 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);
Run Code Online (Sandbox Code Playgroud)

希望这会有所帮助.

亲切的问候!