Search code examples
vue.jsshopware6shopware6-api

Empty API Response When Deleting Payment Method ID In Shopware 6 Administration


When I try deleting the paymentMethodId from sales_channel_payment_method table I get an empty response from the API and the payload object DELETE http://localhost/api/sales-channel-payment-method/[object Object] seems empty too.

Below is my Vue js method



const { Component} = Shopware;

import template from './pau-settings-page.html.twig';

Component.register('pau-settings-page', {

   template,

   inject: [
    'repositoryFactory'
    ],

   metaInfo() {
      return {
          title: this.$createTitle()
      };
    },

 

   computed: {

    salesChannelPaymentMethodRepository() {
        return this.repositoryFactory.create('sales_channel_payment_method');
    },



    
   },


   methods: {



    deletePaymentMethodIdHeadless(){

       const identity = { 
                            fieldCount: 2, 
                            fieldsString: "05cde2abfe744bffaf47ad71f8a49270, f6dd50230aa145adb6b73801d4bcf31b",
                            fields: ['salesChannelId', 'paymentMethodId'] 
                        };


        this.salesChannelPaymentMethodRepository.delete(
            identity, Shopware.Context.api
        );

       

    },

    

   }

    
  
});

Image of The Response


Solution

  • You're trying to remove a many-to-many mapping. These feature two distinct primary keys, both foreign keys of the related tables. You already have the right idea. The regular delete endpoint only works with single primary keys, hence why you get the malformed url.

    To delete the mappings you may use the syncService instead.

    const { Component} = Shopware;
    
    import template from './pau-settings-page.html.twig';
    
    Component.register('pau-settings-page', {
        template,
        inject: [
            'repositoryFactory',
            'syncService',
        ],
        metaInfo() {
            return {
                title: this.$createTitle()
            };
        },
        computed: {
            salesChannelPaymentMethodRepository() {
                return this.repositoryFactory.create('sales_channel_payment_method');
            },
        },
        methods: {
            deletePaymentMethodIdHeadless() {
                const payload = [{
                    action: 'delete',
                    entity: 'sales_channel_payment_method',
                    payload: [
                        {
                            salesChannelId: '05cde2abfe744bffaf47ad71f8a49270',
                            paymentMethodId: 'f6dd50230aa145adb6b73801d4bcf31b'
                        },
                    ],
                }];
    
                this.syncService.sync(payload, {}, { 'single-operation': 1 });
            },
        },
    });