FROM CACHE - zh-cn_header

use rest api to create Automatic discount

use rest api to create Automatic discount

crowdserve-tech
访客
1 0 0

1. 手动在后台管理页面添加完一个automatic的discount,用price rule的api获取不到这个discount的信息

await instance.rest.PriceRule.find({ session: this.getSession(), id: priceRuleId })
2. 如何创建一个price rule,设置这个discount是automatic的呢
    const instance = this.getInstance();
    const priceRule = new instance.rest.PriceRule({ session: this.getSession() });
    if (data.id) {
      priceRule.id = data.id;
    } else {
      priceRule.value_type = "percentage";
      priceRule.value = "-100.0";
      priceRule.customer_selection = "all";
      priceRule.target_type = "line_item";
      priceRule.target_selection = "entitled";
      priceRule.allocation_method = "each";
      priceRule.starts_at = "2023-07-21T00:00:00-00:00";
    }
    priceRule.title = data.title;
    priceRule.prerequisite_product_ids = [data.buyProductId];
    priceRule.entitled_product_ids = [data.getProductId];
    priceRule.prerequisite_to_entitlement_quantity_ratio = {
      "prerequisite_quantity": data.buyNumber,
      "entitled_quantity": data.getNumber,
    };
    await priceRule.save({
      update: true,
    });
0 条回复0