Shopware 5.4 ExtJs模型关联显示

时间:2018-09-21 15:09:20

标签: extjs associations shopware

我在后端extjs模型中有一个字段,该字段具有与实体中的ManyToOne关联相匹配的称为“商店”的字段。我正在从控制器传递相关数据,但是该字段没有被数据填充,也没有被关联选项的下拉列表取代。

这是目前的样子: Grid Display Detail Display

这是模型:

Ext.define('Shopware.apps.MyModule.model.PrimaryDateExemption', {
    extend: 'Shopware.data.Model',

    configure: function() {
        return {
            controller: 'MyModule',
            detail: 'Shopware.apps.MyModule.view.detail.PrimaryDateExemption'
        };
    },

    associations: [
        {
            relation: 'ManyToOne',
            field: 'storeId',
            type: 'hasMany',
            name: 'getName',
            associationKey: 'store',
            model: 'Shopware.apps.StoreLocator.model.Main'
        }
    ],

    fields: [
        { name : 'id', type: 'int', useNull: true },
        { name : 'primaryDate', type: 'date', dateFormat: 'd.m.Y' },
        { name : 'storeId', type: 'int', useNull: true }
    ]
});

ID和日期在网格和详细信息视图中显示良好,但是我得到的只是商店的一个整数字段。从文档https://developers.shopware.com/developers-guide/backend-components/associations/可以看出,我不需要添加任何其他内容。引用该文件:

  

因为关联可能以相同的方式显示,所以Shopware.data.Model已经预先配置了一些视图。例如,ManyToOne关联(例如,产品和税收)始终显示组合框   和   要将这些信息合并到一个字段中,请提供选项字段:“ taxId”,它告诉应用程序将默认输入字段替换为之前配置的适当组件。

这是实体:

<?php

namespace MyModule\Models;

use Doctrine\ORM\Mapping as ORM;
use Shopware\Components\Model\ModelEntity;

/**
 * @ORM\Entity
 * @ORM\Table(name="s_primary_date_exemption")
 */
class PrimaryDateExemption extends ModelEntity
{
    /**
     * @var int $id
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="date")
     */
    private $primaryDate;

    /**
     * @ORM\ManyToOne(targetEntity="NetiStoreLocator\Models\Store")
     * @ORM\JoinColumn(name="store_id", referencedColumnName="id")
     */
    private $store = null;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    public function getPrimaryDate()
    {
        return $this->primaryDate;
    }

    public function setPrimaryDate($primaryDate)
    {
        $this->primaryDate = $primaryDate;
    }

    /**
     * @return null|mixed
     */
    public function getStore()
    {
        return $this->store;
    }

    /**
     * Get ID of pick up store or null if none set
     *
     * @return null|int
     */
    public function getStoreId()
    {
        return ($this->store !== null) ? $this->store->getId() : null;
    }

    /**
     * @param mixed $store
     */
    public function setStore($store)
    {
        $this->store = $store;
    }
}

这是返回数据的控制器:

<?php

use MyModule\Models\PrimaryDateExemption;

class Shopware_Controllers_Backend_MyModule extends Shopware_Controllers_Backend_Application
{
    protected $model = PrimaryDateExemption::class;
    protected $alias = 'primary_date';

    protected function getListQuery()
    {
        $builder = parent::getListQuery();

        $builder->leftJoin('primary_date.store', 'store');
        $builder->addSelect(array('store'));

        return $builder;
    }

    protected function getDetailQuery($id)
    {
        $builder = parent::getDetailQuery($id);

        $builder->leftJoin('primary_date.store', 'store');
        $builder->addSelect(array('store'));

        return $builder;
    }
}

正如我所说的,我可以看到网格的数据返回了有意义的数据(格式化以便于查看):

    {
    "success": true,
    "data" :
    [{
        "id": 14,
        "primaryDate": new Date(1566860400000),
        "store": {
            "id": 1,
            "subshopIDs": "0",
            "name": "George Street, London"
        }
    }, {
        "id": 1,
        "primaryDate": new Date(1545696000000),
        "store": null
    }, {
        "id": 3,
        "primaryDate": new Date(1535410800000),
        "store": null
    }, {
        "id": 4,
        "primaryDate": new Date(1545264000000),
        "store": null
    }, {
        "id": 5,
        "primaryDate": new Date(1545350400000),
        "store": null
    }, {
        "id": 6,
        "primaryDate": new Date(1545782400000),
        "store": null
    }, {
        "id": 7,
        "primaryDate": new Date(1545868800000),
        "store": null
    }, {
        "id": 8,
        "primaryDate": new Date(1546300800000),
        "store": null
    }, {
        "id": 9,
        "primaryDate": new Date(1546387200000),
        "store": null
    }, {
        "id": 10,
        "primaryDate": new Date(1555628400000),
        "store": null
    }, {
        "id": 11,
        "primaryDate": new Date(1555974000000),
        "store": null
    }, {
        "id": 12,
        "primaryDate": new Date(1557183600000),
        "store": null
    }, {
        "id": 13,
        "primaryDate": new Date(1558998000000),
        "store": null
    }], 
"total":13
}

如果这里没有明显的错误,谁能指出我有关extJs关联魔术的一些文档?该区域的Shopware文档不多。

0 个答案:

没有答案