【问题标题】:Create Discount Code using Shopify API?使用 Shopify API 创建折扣代码?
【发布时间】:2013-11-09 08:30:24
【问题描述】:

我目前正在尝试确定是否可以通过 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 功能现在可用吗?它仍在开发中还是完全被放弃了?

【问题讨论】:

标签: shopify


【解决方案1】:
$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')
                ]
            ]
        );

    }

【讨论】:

    【解决方案2】:

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

    Price Rule

    Discount Code

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-07
        • 1970-01-01
        • 1970-01-01
        • 2013-06-26
        • 1970-01-01
        相关资源
        最近更新 更多