Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda