orderDetailTools.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type { AddressListInOrderDetails,OrderAddressType,ProductItemAdditional } from "@/types/customer/type";
  2. import type { CartAddress } from "@/types/cart/type";
  3. export function getAddressFromOrderDetailAddressList(addressList: AddressListInOrderDetails, addressType: OrderAddressType) {
  4. const address = addressList.edges.find((x) => x.node.addressType === addressType);
  5. if (!address) {
  6. throw new Error(
  7. "Order shipping address missing"
  8. );
  9. }
  10. const res: CartAddress = {
  11. id: String(address.node._id),
  12. firstName: address.node.firstName,
  13. lastName: address.node.lastName,
  14. email: address.node.email,
  15. address: address.node.address,
  16. city: address.node.city,
  17. state: address.node.state,
  18. country: address.node.country,
  19. postcode: address.node.postcode,
  20. phone: address.node.phone,
  21. }
  22. return res;
  23. }
  24. export function getProductAdditionalInfo(productItem: ProductItemAdditional) {
  25. const attributeKeys = Object.keys(productItem.attributes);
  26. let res = '';
  27. attributeKeys.forEach(key => {
  28. const attribute = productItem.attributes[key];
  29. if (attribute) {
  30. // option_label value_label
  31. if(res) {
  32. res = res + ', ' + attribute.option_label + ': ' + attribute.value_label;
  33. } else {
  34. res = attribute.option_label + ': ' + attribute.value_label;
  35. }
  36. }
  37. });
  38. return res;
  39. }
  40. export function getProductFinalPriceInOrder() {}
  41. // export function getProductAdditinalInOrder(itemAdditional: string) {
  42. // const additinal = JSON.parse(itemAdditional);
  43. // let optionsTxt = '';
  44. // Object.keys(additinal.attributes).forEach((key) => {
  45. // const att = additinal.attributes[key];
  46. // optionsTxt = optionsTxt
  47. // });
  48. // return {}
  49. // }