Skip to content

Commit

Permalink
fix(client): removing cart item correctly (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored Sep 18, 2020
1 parent b315782 commit 1e7d907
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ describe("CartService - removeCartItem", () => {
const result = await removeCartItem(lineItemId);
expect(mockedDelete).toBeCalledTimes(1);
expect(mockedDelete).toBeCalledWith(
"/store-api/v3/checkout/cart/line-item",
{ data: { ids: ["geawq90a5dab4206843d0vc3sa8wefdf"] } }
"/store-api/v3/checkout/cart/line-item?ids[]=geawq90a5dab4206843d0vc3sa8wefdf"
);
expect(result.lineItems).toBeUndefined();
});
Expand All @@ -50,8 +49,7 @@ describe("CartService - removeCartItem", () => {
);
expect(mockedDelete).toBeCalledTimes(1);
expect(mockedDelete).toBeCalledWith(
"/store-api/v3/checkout/cart/line-item",
{ data: { ids: ["someNonExistingLineItemId"] } }
"/store-api/v3/checkout/cart/line-item?ids[]=someNonExistingLineItemId"
);
});
});
10 changes: 5 additions & 5 deletions packages/shopware-6-client/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getCustomerAddressEndpoint = (addressId?: string) =>
: "/sales-channel-api/v3/customer/address"; // replace with `/store-api/v4/account/list-address`

const getCustomerDefaultAddressEndpoint = (type: string, addressId: string) =>
`/sales-channel-api/v3/customer/address/${addressId}/default-${type}`; // replace with `/store-api/v4/context` { includes: { customer: defaultBillingAddress|defaultShipingAddress } }
`/sales-channel-api/v3/customer/address/${addressId}/default-${type}`; // replace with `/store-api/v4/context` { includes: { customer: defaultBillingAddress|defaultShipingAddress } }

export const getCustomerDefaultBillingAddressEndpoint = (addressId: string) =>
getCustomerDefaultAddressEndpoint("billing", addressId);
Expand All @@ -43,7 +43,7 @@ export const getCustomerDefaultShippingAddressEndpoint = (addressId: string) =>
getCustomerDefaultAddressEndpoint("shipping", addressId);

export const getCustomerAddressDetailsEndpoint = (addressId: string) =>
`/sales-channel-api/v3/customer/address/${addressId}`; // replace with `/store-api/v4/account/list-address` { ids: [ addressId }
`/sales-channel-api/v3/customer/address/${addressId}`; // replace with `/store-api/v4/account/list-address` { ids: [ addressId }

export const getCustomerAddressSetDefaultShippingEndpoint = (
addressId: string
Expand All @@ -68,7 +68,7 @@ export const getCustomerLogoutEndpoint = () => `/store-api/v3/account/logout`;
export const getCustomerOrderEndpoint = () => `/store-api/v3/order`;

export const getCustomerOrderDetailsEndpoint = (orderId: string) =>
`/sales-channel-api/v3/checkout/guest-order/${orderId}`;
`/sales-channel-api/v3/checkout/guest-order/${orderId}`;

export const getCustomerUpdateEmailEndpoint = () =>
`/store-api/v3/account/change-email`;
Expand Down Expand Up @@ -96,7 +96,7 @@ export const getCheckoutOrderPayEndpoint = (orderId: string) =>
`/sales-channel-api/v3/checkout/order/${orderId}/pay`; // replace with `/store-api/v4/handle-payment` { orderId: orderId }

export const getCheckoutGuestOrderDetailsEndpoint = (orderId: string) =>
`/sales-channel-api/v3/checkout/guest-order/${orderId}`; // replace with `/store-api/v3/account/order` { ids: [ orderId ] }
`/sales-channel-api/v3/checkout/guest-order/${orderId}`; // replace with `/store-api/v3/account/order` { ids: [ orderId ] }

export const getCheckoutPromotionCodeEndpoint = (code: string) =>
`/sales-channel-api/v3/checkout/cart/code/${code}`; // replace with `/store-api/v3/checkout/cart/line-item` - see https://docs.shopware.com/en/shopware-platform-dev-en/store-api-guide/cart?category=shopware-platform-dev-en/store-api-guide#promotion
Expand All @@ -112,7 +112,7 @@ export const getContextLanguageEndpoint = () => `/store-api/v3/language`;
export const getContextCountryEndpoint = () => `/sales-channel-api/v3/country`; // replace with `/store-api/v4/country`

export const getContextCountryItemEndpoint = (countryId: string): string =>
`/sales-channel-api/v3/country/${countryId}`; // replace with `/store-api/v4/country` { ids: [ countryId ] }
`/sales-channel-api/v3/country/${countryId}`; // replace with `/store-api/v4/country` { ids: [ countryId ] }

export const getContextPaymentMethodEndpoint = () =>
`/store-api/v3/payment-method`;
Expand Down
7 changes: 1 addition & 6 deletions packages/shopware-6-client/src/services/cartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ export async function removeCartItem(
contextInstance: ShopwareApiInstance = defaultInstance
): Promise<Cart> {
const resp = await contextInstance.invoke.delete(
getCheckoutCartLineItemEndpoint(),
{
data: {
ids: [itemId],
},
}
`${getCheckoutCartLineItemEndpoint()}?ids[]=${itemId}`
);

return resp.data;
Expand Down

1 comment on commit 1e7d907

@vercel
Copy link

@vercel vercel bot commented on 1e7d907 Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.