首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展Shopware模型

扩展Shopware模型
EN

Stack Overflow用户
提问于 2016-04-04 11:03:55
回答 1查看 3.8K关注 0票数 2

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

我怎么能这么做?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-14 13:58:19

扩展Shopware核心模型本身是不可能的。根据您要扩展的特定模型,有两种不同的解决方法:

  1. 如果它是您想要扩展的文章本身,您可以使用自定义属性字段,如下所述:1208.html
  2. 另一种方法是编写一个插件,通过plugin ()上的代码创建属性字段。这只有在具有属于实体本身的属性表的实体上才有可能。例如,s_order和s_order_attributes

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

代码语言:javascript
复制
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'));
}

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

代码语言:javascript
复制
/**
 * 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);

希望这能帮上忙。

亲切的问候!

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36400874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档