Recently ive started working on shopify apps rights now i am developing a checkout ui extension which lets the merchant to upsell products in checkout page. Last time ive checked everything was working fine but today iam facing some issues while i add up sell products to the cart line items when i add a product it was supposed to update the cart with updated line items but it works as expected when i click on add product 1st time the second time when i click it was supposed to check whether the product is already added in cart if yes it should only update the quantity + 1 this was working fine last week but today its not working and also if i add a new product its not appended to the line items instead it just simply replaces the product which was previously added.
documentation: https://shopify.dev/apps/checkout/product-offers/add-product-offer
App.jsx
import {useEffect, useState} from 'react';
import {
BlockStack,
useShop,
useCartLines,
useApplyCartLinesChange,
} from '@shopify/checkout-ui-extensions-react';
import {getRecommendations} from './services/recommendations.service.js';
import Loader from './components/Loader.jsx';
import {Divider, Heading} from '@shopify/checkout-ui-extensions';
import ProductCard from './components/ProductCard.jsx';
function App() {
const storeUrl = useShop().myshopifyDomain;
const [products, setProducts] = useState([]);
const [loading, setLoading] = useState(false);
const lineItems = useCartLines();
const applyCartLinesChange = useApplyCartLinesChange();
const recommendationLimit = 2;
console.log(lineItems, 'line items');
const lineItemsId = lineItems.map((l) =>
l.merchandise.product.id.substring(
l.merchandise.product.id.lastIndexOf('/') + 1
)
);
useEffect(async () => {
try {
setLoading(true);
let resp = await getRecommendations(
lineItemsId.toString(),
recommendationLimit,
storeUrl
);
setProducts(resp.data);
setLoading(false);
console.log(products, 'api response');
} catch (error) {
console.error(error);
}
}, []);
if (loading) return