我需要扩展Shopware变体模型,以便添加一些自定义属性,例如金属的类型,宝石的类型,这是本文的基础。这些属性将同时用于后端和前端。
我怎么能这么做?谢谢
发布于 2016-04-14 13:58:19
扩展Shopware核心模型本身是不可能的。根据您要扩展的特定模型,有两种不同的解决方法:
对于第二种方法,在插件的Bootstrap.php中创建一个方法,如下所示,并在plugin的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'));
}/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);希望这能帮上忙。
亲切的问候!
https://stackoverflow.com/questions/36400874
复制相似问题