4

我目前正在尝试确定是否可以通过 shopify API 添加折扣代码。

我从去年发现了这个问题,无法通过 API 但可以通过自定义脚本实现(如果可能,我想避免这种黑客攻击): Shopify API:创建促销?

根据这篇文章,它应该是一个即将推出的功能:http: //ecommerce.shopify.com/c/shopify-apps/t/is-there-an-api-for-coupon-codes-47500

这个 API 功能现在可用吗?它仍在工作中还是完全被放弃了?

4

3 回答 3

2
$shop = ShopifyApp::shop();

    if( $shopSettings->discount_id == '' || $shopSettings->discount_id == null || $shopSettings->discount_id == undefined ) {

        $price_rule = $shop->api()->rest(
            'POST',
            '/admin/price_rules.json',
            [
                "price_rule" => [
                    "title" => "SUMMERSALE10OFF",
                    "target_type" => "line_item",
                    "target_selection" => "all",
                    "allocation_method" => "across",
                    "value_type" => "percentage",
                    "value" => "-"+request('discount_percentage'),
                    "customer_selection" => "all",
                    "starts_at" => "2017-01-19T17:59:10Z"
                ]
            ]
        );

        $shopSettings->price_rule_id = $price_rule->body->price_rule->id;

        $discount_code = $shop->api()->rest(
            'POST',
            '/admin/price_rules/'.$price_rule->body->price_rule->id.'/discount_codes.json',
            [
                "discount_code" => [
                    "code" => $price_rule->body->price_rule->title
                ]
            ]
        );

        $shopSettings->discount_id = $discount_code->body->discount_code->id;

    } else if( request('discount_percentage') && request('discount_type') == "percentage" ) {

        $price_rule = $shop->api()->rest(
            'POST',
            '/admin/price_rules/'.$shopSettings->price_rule_id.'.json',
            [
                "price_rule" => [
                    "value" => "-"+request('discount_percentage')
                ]
            ]
        );

    }
于 2019-09-10T06:01:07.490 回答
2

对于所有来到这里的人,Shopify 最近开发了一个端点来创建折扣代码和价格规则。

价格规则

优惠码

于 2018-01-09T22:11:49.750 回答
-2

Shopify 提供免费的应用程序来制作和管理折扣代码。安装并使用它,因为它与使用脚本编写代码一样好。

于 2013-10-30T13:15:04.843 回答