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