@orderingstack/front-hooks 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -6952,5 +6952,37 @@ const useDisplayPrice = ({
6952
6952
  displayPrice = parseFloat(product.minPrice);
6953
6953
  return { displayPrice, showAsMinPrice, calculatedPriceDefaultProductState };
6954
6954
  };
6955
- export { useAvailability, useDisplayPrice, useInterval };
6955
+ function useGroupOrderLines(array) {
6956
+ const result = [];
6957
+ array.reduce((res, value) => {
6958
+ if (!res[value.hash]) {
6959
+ res[value.hash] = {
6960
+ ...value,
6961
+ quantity: 0,
6962
+ discounted: 0,
6963
+ discounts: [],
6964
+ firstProductQuantity: value.quantity,
6965
+ itemsToRemove: []
6966
+ };
6967
+ result.push(res[value.hash]);
6968
+ }
6969
+ res[value.hash].quantity += value.quantity;
6970
+ res[value.hash].itemsToRemove.push(value.id);
6971
+ if (value.discounts) {
6972
+ if (!res[value.hash].discounts) {
6973
+ res[value.hash].discounts = [];
6974
+ }
6975
+ res[value.hash].discounts = res[value.hash].discounts.concat(value.discounts);
6976
+ res[value.hash].discounted = 0;
6977
+ for (let i = 0; i < res[value.hash].discounts.length; i += 1) {
6978
+ if (res[value.hash].discounts[i]) {
6979
+ res[value.hash].discounted += parseFloat(res[value.hash].discounts[i].discountPrice);
6980
+ }
6981
+ }
6982
+ }
6983
+ return res;
6984
+ }, {});
6985
+ return result;
6986
+ }
6987
+ export { useAvailability, useDisplayPrice, useGroupOrderLines, useInterval };
6956
6988
  //# sourceMappingURL=index.es.js.map