I'm working with BigCommerce and I have a product banner with dynamic pricing based on user input for width (w) and height (h). However, BigCommerce doesn't seem to provide any built-in functionality for dynamic pricing based on custom inputs.
Does anyone have suggestions on how I can implement this functionality using the BigCommerce API or perhaps through a plugin or custom development? Any insights or guidance would be greatly appreciated. Thank you!
Here is my code :
const cartId = 'xxxxxx';
const newCartAmount = 245.0;
const apiUrl = `https://api.bigcommerce.com/stores/storeHash/v3/carts/${cartId}`;
const accessToken = 'xxxxxxx';
const headers = {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
};
const requestData = {
cartAmount: newCartAmount
};
fetch(apiUrl, {
method: 'PUT',
headers: headers,
body: JSON.stringify(requestData)
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to update cart amount');
}
return response.json();
})
.then(data => {
console.log('Cart amount updated successfully:', data);
})
.catch(error => {
console.error('Error updating cart amount:', error);
});