Reputation: 1
I am using rebuy smart cart for shopify e-commerce, in the smart cart and in the body i've used a custom code and i added gift notes input field...also i have the default order notes input, now the problem is that when i test ... the order notes are being sent to the admin dashboard but the gift notes no. also i checked the cart.js the order notes attrs are in the request but the gift notes not.
Here is my logic
export default {
data() {
return {
giftMessage: {
value: "", // Stores the user's gift message
},
};
},
methods: {
// Check if cart contains a gift bag or gift card
cartContainsGiftProduct() {
return this.cart.items.some((item) =>
["gift-bag-id", "gift-card-id"].includes(item.id)
);
},
// Handle changes to the gift message
giftMessageChange(event) {
this.giftMessage.value = event.target.value;
this.updateGiftMessageInCart();
},
// Update the gift message in the cart attributes
updateGiftMessageInCart() {
console.log("Updating gift message", this.giftMessage.value)
Rebuy.Cart.update({
attributes: {
gift_message: this.giftMessage.value,
},
})
.then(() => console.log("Gift message updated"))
.catch((err) => console.error("Error updating gift message:", err));
},
// Display remaining characters for the gift message
giftMessageRemainingCharacters() {
const remaining = 100 - (this.giftMessage.value?.length || 0);
return `${remaining} characters remaining`;
},
},
computed: {
// Access cart items (ensure this is connected to your Rebuy data)
cart() {
return Rebuy.Cart.get() || { items: [] };
},
},
};
/* Custom logic to show or hide the gift message input based on cart contents */
function manageGiftNoteDisplay() {
setTimeout(() => {
const giftNoteElement = document.querySelector(".rebuy-cart__gift-message");
const giftBagAndCardProductId = 6677605122166; // Replace with your actual product ID for "Gift bag + Gift card"
// Hide the gift note input by default
if (giftNoteElement) {
giftNoteElement.style.display = "none";
}
// Fetch the cart product IDs using Rebuy's API
const cartProductIds = Rebuy.Cart.getCartProductIDs();
// Check if the specific product is in the cart
const isGiftBagAndCardInCart = cartProductIds.includes(giftBagAndCardProductId);
// Show the gift note input if the product is in the cart
if (isGiftBagAndCardInCart && giftNoteElement) {
giftNoteElement.style.display = "block";
}
}, 300); // Delay to ensure cart data is loaded
}
// Run on page load
manageGiftNoteDisplay();
// Run again whenever the cart changes
document.addEventListener("rebuy:cart.change", () => {
manageGiftNoteDisplay();
});
Upvotes: 0
Views: 13