#anubis_code

1 messages ¡ Page 1 of 1 (latest)

vital reefBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1324636056577904694

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

woeful moss
#

I can send you the product creation and backend code for myAddToCartFunction as well if its asked

#

backend,
import { Permissions, webMethod } from "wix-web-module";
import { cart } from "wix-ecom-backend";

export const myAddToCartFunction = webMethod(
Permissions.Anyone,
async (_id, options) => {
try {
const updatedCart = await cart.addToCart(_id, options);
console.log("Success! Updated cart:", updatedCart);
return updatedCart;
} catch (error) {
console.error(error);
throw new Error("Error adding to cart.");
}
}
);

#

fronetend

#

const myProduct = {
name: productName,
description: rankDescription,
price: totalPrice,
visible: false,
productOptions: { Weight: { choices: [{ value: "Digital", description: "Digital Product" }] } },
manageVariants: true,
productType: "physical",
weight: 0,
ribbon: boostType,
brand: "EloArcane",
seoData: {
tags: [
{ type: "title", children: "Rank Boosting Service" },
{ type: "meta", props: { name: "description", content: Boost from ${startingRank} to ${desiredRank}. } }
]
},
};

    try {
        const product = await createProduct(myProduct);
        const productId = product._id;
        console.log(`Product created with ID: ${productId}`);

        const cart = await wixStores.cart.getCurrentCart();  // Get the current cart
        const cartId = cart._id;  // Get cart ID
        console.log("Cart ID:", cartId);
        const options = {
            lineItems: [{
                catalogReference: {
                    appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
                    catalogItemId: productId,
                },
                quantity: 1,
            }],
        };

        myAddToCartFunction(cartId, options)
            .then((updatedCart) => {
                console.log("Success! Updated cart:", updatedCart);
                return updatedCart;
            })
            .catch((error) => {
                console.error("Error updating cart:", error);
            });

        console.log('Product added to cart successfully');
    } catch (error) {
        console.error('Error creating product or adding to cart:', error);
    }
}