Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-client): removing cart item correctly #1107

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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