Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
extending cartStoreService in shopware 6

I have quite a technical question regarding the extension possibilities of existing services:

Particularly, I need to change the functionality of one method in the cart-store-api.api.service.js service. The API call should transmit the item.payload field as well to enable passing custom payload when creating lineItems in the admin:

getPayloadForItem(item, salesChannelId, isNewProductItem, id) {
    let dummyPrice = null;
    if (this.shouldPriceUpdated(item, isNewProductItem)) {
        dummyPrice = deepCopyObject(item.priceDefinition);
        dummyPrice.taxRules = item.priceDefinition.taxRules;
        dummyPrice.quantity = item.quantity;
        dummyPrice.type = this.mapLineItemTypeToPriceType(item.type);
    }

    return {
        items: [
            {
                id: id,
                referencedId: id,
                label: item.label,
                quantity: item.quantity,
                type: item.type,
                description: item.description,
                priceDefinition: dummyPrice,
                stackable: true,
                removable: true,
                salesChannelId,
                // this is what I want to add
                payload: item.payload
            },
        ],
    };
}

I found this guide explaining how services can be decorated, HOWEVER I did not manage to extend the cartStoreApi service because it does not seem to have a 'technical name' (I found these globals.types.ts where many services are assigned a key - like 'acl' for the aclService). So my problem is that I cannot decorate the cartStoreService because I dont know its reference identifier.

Two questions arise from this:

  1. Are my observations correct? Or is there a way to decorate the cartStoreApi?
  2. If this is indeed not possible, what is the suggested way to solve my issue?

many thanks!

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

There is quite a difference between extending and decorating a service. If it suites your needs, you can use the service simply by extending it, like CartStoreService extends ApiService. Then you can use it as your custom service in your plugin. If you really want to decorate it, which means you will modify every call to the service from anywhere, maybe just try to access it in the service container like indicated in the docs, I'm not sure the globals.types.ts is complete.

about 4 years ago · Santiago Gelvez Relatório

0

Ok, I managed to solve my issue. This is what the solution looks like:

Shopware.Application.addServiceProviderDecorator(
    "cartStoreService",
    (service) => {
      const decoratedMethod = service.getPayloadForItem;
  
      service.getPayloadForItem = function (item, salesChannelId, isNewProductItem, id) {
        const returnValue = decoratedMethod.call(service, item, salesChannelId, isNewProductItem, id)
        returnValue.items[0]['payload'] = item.payload // <-- reason for this whole decoration: pass custom payload to API 
        
        return returnValue
      };
  
      return service;
    }
  );
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda