Extending the sw-entity-multi-id-select does not work

68 Views Asked by At

I am currently trying to extend an entity-multi-id-select field via JavaScript. The code should only reduce the results to the order statuses My code is this:

const { Component } = Shopware;
const { Criteria } = Shopware.Data;

Component.extend('testField', 'sw-entity-multi-id-select', {
    props: {
        criteria: {
            type: Object,
            required: false,
            default() {
                const criteria = new Criteria(1, this.resultLimit);
                criteria.addFilter(Criteria.equals('stateMachine.technicalName', 'order.state'));
                return criteria;
            }
        },
    }
});

This works without errors when I expand a sw-entity-single-select. However, as soon as I enter the name of the multi select, this error message appears:

An error was captured in current module: TypeError: Cannot read properties of null (reading 'entity')

Does anyone here have a suggested solution? Many thanks in advance!

Edit: I have found the solution. Shopware apparently handles the requests for single-select and multi-id-select differently. It worked with this code:

const { Component } = Shopware;
const { Criteria } = Shopware.Data;

Component.extend('testField', 'sw-entity-multi-id-select', {
    inject: ['repositoryFactory'],

    computed: {
        repository() {
            return this.repositoryFactory.create('state_machine_state');
        },

        criteria() {
            const criteria = new Criteria();
            criteria.addFilter(Criteria.equals('stateMachine.technicalName', 'order.state'));
            return criteria;
        }
    },

    created() {
        this.createdComponent();
    },

    methods: {
        createdComponent() {
            this.$super('createdComponent');
        },

        updateIds(collection) {
            this.$super('updateIds', collection);
        },
    },
});
0

There are 0 best solutions below