首页 > 解决方案 > 是否可以使用 shopify-buy sdk 店面 api 覆盖定价计算?

问题描述

我正在使用 shopify-buy sdk 使用店面 api 创建一个反应应用程序作为我的 shopify 商店的网络应用程序。在我的商店中,我有一个包含自定义属性的订单项:高度和宽度。我想使用高度和宽度来计算该订单项的价格。

这是我添加订单项的代码:

const addItemToCheckout = async (variantId: string, quantity: string, height: string, width: string) => {
    const lineItemsToAdd = [
      {
        variantId,
        quantity: parseInt(quantity, 10),
        customAttributes: [{ height, width }]
      }
    ];

    try {
      const newCheckout = await client.checkout.addLineItems(
        checkout.id,
        lineItemsToAdd
      );
      setCheckout(newCheckout);

      openCart();
    }
    catch (err) {
      console.error(`Failed to add item with id '${variantId}' to cart`);
      console.error(err);

      setError(err);
    }
  };

问题是,默认情况下,lineitem 的价格是通过简单地将 line item 数量乘以产品价格来计算的,是否可以覆盖价格的计算方式,使其高度乘以宽度乘以数量乘以按产品价格?

标签: javascripttypescriptshopifyshopify-api

解决方案


推荐阅读