[Vuejs]-How Do I Update The Shopware 6 Sales Channel Table When It Refuses To Update Via The Admin API

0👍

paymentMethodIds is a ManyToManyIdField of the SalesChannelDefinition. These fields represent a special case. The content for these fields is computed server-side by the corresponding EntityIndexer instance. So when you assign a payment method to the sales channel, the column of the paymentMethodIds should automatically be updated.

If you want to add payment methods programmatically, you should use the actual association field instead:

// create a new payment method entity
const paymentMethod = this.repositoryFactory.create('payment_method')
    .create(Shopware.Context.api, this.paymentMethodId);
// or fetch an existing one
// const paymentMethod = await this.repositoryFactory.create('payment_method')
//     .get(this.paymentMethodId, Shopware.Context.api);

const criteria = new Criteria(1, 1);
criteria.addAssociation('paymentMethods');

this.salesChannelRepository
    .get(this.salesChannelId, Shopware.Context.api, criteria)
    .then((update) => {
        update.paymentMethods.add(paymentMethod);
        this.salesChannelRepository.save(update, Shopware.Context.api);
    });

Leave a comment