Liferay.Loader.define("commerce-frontend-js@4.0.75/components/add_to_cart/data",["module","exports","require","../../ServiceProvider/index","../../utilities/eventsDefinitions"],(function(t,e,r){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.addToCart=async function addToCart(e,r,i,n){if(!r){const r=await t.createCartByChannelId(i.id,{accountId:n,cartItems:e.map(formatCartItem),currencyCode:i.currencyCode});return Liferay.fire(a.CURRENT_ORDER_UPDATED,{order:r}),r}if(1===e.length){await t.createItemByCartId(r,formatCartItem(e[0]));const i=await t.getCartByIdWithItems(r);return Liferay.fire(a.CURRENT_ORDER_UPDATED,{order:i}),i}const o=(await t.getCartByIdWithItems(r)).cartItems;e.forEach((t=>{const e=o.find((e=>e.skuId===t.skuId&&e.options===JSON.stringify(t.skuOptions)));e?e.quantity+=t.quantity:o.push(formatCartItem(t))}));const d=await t.updateCartById(r,{cartItems:o});return Liferay.fire(a.CURRENT_ORDER_UPDATED,{order:d}),d};var i=function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}(r("../../ServiceProvider/index")),a=r("../../utilities/eventsDefinitions");const t=i.default.DeliveryCartAPI("v1");function formatCartItem(t){return{options:JSON.stringify(t.skuOptions||[]),quantity:t.quantity,skuId:t.skuId}}}}));
//# sourceMappingURL=data.js.map