使用Shopify API创建折扣代码?

时间:2013-10-29 23:10:16

标签: shopify

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

我从去年发现了这个问题,通过API无法实现,但可以使用自定义脚本实现(我希望尽可能避免这种黑客攻击): Shopify API: Create a Promotion?

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

此API功能现在是否可用,是否仍在使用中或是否已完全放弃?

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

Price Rule

Discount Code

答案 2 :(得分:0)

$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')
                ]
            ]
        );

    }