forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next-8818/admin-order-store-api' into 'master'
NEXT-8818 - Migrate admin order to store-api See merge request shopware/6/product/platform!2627
- Loading branch information
Showing
15 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
...istration/Resources/app/administration/src/core/service/api/cart-store-api.api.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import { deepCopyObject } from 'src/core/service/utils/object.utils'; | ||
import utils from 'src/core/service/util.service'; | ||
import ApiService from '../api.service'; | ||
|
||
const lineItemConstants = Object.freeze({ | ||
types: Object.freeze({ | ||
PRODUCT: 'product', | ||
CREDIT: 'credit', | ||
CUSTOM: 'custom', | ||
PROMOTION: 'promotion' | ||
}), | ||
|
||
priceTypes: Object.freeze({ | ||
ABSOLUTE: 'absolute', | ||
QUANTITY: 'quantity' | ||
}) | ||
}); | ||
|
||
/** | ||
* Gateway for the API end point "cart" | ||
* Uses the _proxy endpoint of the admin api to connect to the store-api endpoint cart | ||
* @class | ||
* @extends ApiService | ||
*/ | ||
class CartStoreService extends ApiService { | ||
constructor(httpClient, loginService, apiEndpoint = 'cart') { | ||
super(httpClient, loginService, apiEndpoint); | ||
this.name = 'cartStoreService'; | ||
} | ||
|
||
getLineItemTypes() { | ||
return lineItemConstants.types; | ||
} | ||
|
||
getLineItemPriceTypes() { | ||
return lineItemConstants.priceTypes; | ||
} | ||
|
||
mapLineItemTypeToPriceType(itemType) { | ||
const lineItemTypes = this.getLineItemTypes(); | ||
const priceTypes = this.getLineItemPriceTypes(); | ||
|
||
const mapTypes = { | ||
[lineItemTypes.PRODUCT]: priceTypes.QUANTITY, | ||
[lineItemTypes.CUSTOM]: priceTypes.QUANTITY, | ||
[lineItemTypes.CREDIT]: priceTypes.ABSOLUTE | ||
}; | ||
|
||
return mapTypes[itemType]; | ||
} | ||
|
||
createCart(salesChannelId, additionalParams = {}, additionalHeaders = {}) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/cart`; | ||
const headers = this.getBasicHeaders(additionalHeaders); | ||
|
||
return this.httpClient.get(route, { additionalParams, headers }); | ||
} | ||
|
||
getCart(salesChannelId, contextToken, additionalParams = {}, additionalHeaders = {}) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/cart`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.get(route, { additionalParams, headers }); | ||
} | ||
|
||
cancelCart(salesChannelId, contextToken, additionalParams = {}, additionalHeaders = {}) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/cart`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.delete(route, { additionalParams, headers }); | ||
} | ||
|
||
removeLineItems( | ||
salesChannelId, | ||
contextToken, | ||
lineItemKeys, | ||
additionalParams = {}, | ||
additionalHeaders = {} | ||
) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/cart/line-item`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.delete(route, { additionalParams, headers, data: { ids: lineItemKeys } }); | ||
} | ||
|
||
getRouteForItem(id, salesChannelId) { | ||
return `_proxy/store-api/${salesChannelId}/v1/checkout/cart/line-item`; | ||
} | ||
|
||
getPayloadForItem(item, salesChannelId, isNewProductItem, id) { | ||
const 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 | ||
} | ||
] | ||
}; | ||
} | ||
|
||
saveLineItem( | ||
salesChannelId, | ||
contextToken, | ||
item, | ||
additionalParams = {}, | ||
additionalHeaders = {} | ||
) { | ||
const isNewProductItem = item._isNew && item.type === this.getLineItemTypes().PRODUCT; | ||
const id = item.identifier || item.id || utils.createId(); | ||
const route = this.getRouteForItem(id, salesChannelId, isNewProductItem); | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
const payload = this.getPayloadForItem(item, salesChannelId, isNewProductItem, id); | ||
|
||
if (item._isNew) { | ||
return this.httpClient.post(route, payload, { additionalParams, headers }); | ||
} | ||
|
||
return this.httpClient.patch(route, payload, { additionalParams, headers }); | ||
} | ||
|
||
addPromotionCode( | ||
salesChannelId, | ||
contextToken, | ||
code, | ||
additionalParams = {}, | ||
additionalHeaders = {} | ||
) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/cart/line-item`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
const payload = { | ||
items: [ | ||
{ | ||
type: 'promotion', | ||
referencedId: code | ||
} | ||
] | ||
}; | ||
|
||
return this.httpClient.post(route, payload, { additionalParams, headers }); | ||
} | ||
|
||
modifyShippingCosts(salesChannelId, contextToken, shippingCosts, additionalHeaders, additionalParams = {},) { | ||
const route = '_proxy/modify-shipping-costs'; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.patch(route, { salesChannelId, shippingCosts }, { additionalParams, headers }); | ||
} | ||
|
||
|
||
disableAutomaticPromotions(contextToken, additionalParams = {}, additionalHeaders = {}) { | ||
const route = '_proxy/disable-automatic-promotions'; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.patch(route, {}, { additionalParams, headers }); | ||
} | ||
|
||
enableAutomaticPromotions(contextToken, additionalParams = {}, additionalHeaders = {}) { | ||
const route = '_proxy/enable-automatic-promotions'; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient.patch(route, {}, { additionalParams, headers }); | ||
} | ||
} | ||
|
||
export default CartStoreService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...istration/Resources/app/administration/src/core/service/api/checkout-store.api.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ApiService from '../api.service'; | ||
|
||
/** | ||
* Gateway for the API end point "order" | ||
* Uses the _proxy endpoint of the admin api to connect to the store-api endpoint cart | ||
* @class | ||
* @extends ApiService | ||
*/ | ||
class CheckoutStoreService extends ApiService { | ||
constructor(httpClient, loginService, apiEndpoint = 'checkout') { | ||
super(httpClient, loginService, apiEndpoint); | ||
this.name = 'checkoutStoreService'; | ||
} | ||
|
||
checkout(salesChannelId, contextToken, additionalParams = {}, additionalHeaders = {}) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/checkout/order`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
return this.httpClient | ||
.post(route, {}, { additionalParams, headers }); | ||
} | ||
} | ||
|
||
export default CheckoutStoreService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...nistration/Resources/app/administration/src/core/service/api/store-context.api.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ApiService from '../api.service'; | ||
|
||
/** | ||
* Gateway for the API end point "sales-channel-context" | ||
* Uses the _proxy endpoint of the admin api to connect to the store-api endpoint cart | ||
* @class | ||
* @extends ApiService | ||
*/ | ||
class StoreContextService extends ApiService { | ||
constructor(httpClient, loginService, apiEndpoint = 'sales-channel-context') { | ||
super(httpClient, loginService, apiEndpoint); | ||
this.name = 'contextStoreService'; | ||
} | ||
|
||
updateCustomerContext( | ||
customerId, | ||
salesChannelId, | ||
contextToken, | ||
additionalParams = {}, | ||
additionalHeaders = {} | ||
) { | ||
const route = '_proxy/switch-customer'; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient | ||
.patch( | ||
route, | ||
{ customerId: customerId, salesChannelId: salesChannelId }, | ||
{ additionalParams, headers } | ||
); | ||
} | ||
|
||
updateContext( | ||
context, | ||
salesChannelId, | ||
contextToken, | ||
additionalParams = {}, | ||
additionalHeaders = {} | ||
) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/context`; | ||
const headers = { | ||
...this.getBasicHeaders(additionalHeaders), | ||
'sw-context-token': contextToken | ||
}; | ||
|
||
return this.httpClient | ||
.patch( | ||
route, | ||
context, | ||
{ additionalParams, headers } | ||
); | ||
} | ||
|
||
getContext(salesChannelId, source, additionalParams = {}, additionalHeaders = {}) { | ||
const route = `_proxy/store-api/${salesChannelId}/v1/${source}`; | ||
const headers = this.getBasicHeaders(additionalHeaders); | ||
|
||
return this.httpClient.post(route, {}, { additionalParams, headers }); | ||
} | ||
} | ||
|
||
export default StoreContextService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.