【问题标题】:How to create customers/products with HTTP API and guzzle in shopify如何在 shopify 中使用 HTTP API 和 guzzle 创建客户/产品
【发布时间】:2017-07-07 07:43:05
【问题描述】:

我是 Shopify 应用程序和 Guzzle 的新手,并已关注 https://www.sitepoint.com/shopify-app-development-made-simple/ 开始使用 shopify 应用程序。但现在无法创建产品/客户。我使用过的代码:

                <?php
            require 'vendor/autoload.php';

            use GuzzleHttp\Client;

            $dotenv = new Dotenv\Dotenv(__DIR__);
            $dotenv->load();

            $db = new Mysqli(getenv('MYSQL_HOST'), getenv('MYSQL_USER'), getenv('MYSQL_PASS'), getenv('MYSQL_DB')); 

            $store = 'customboxes1.myshopify.com'; 
            $select = $db->query("SELECT access_token FROM installs WHERE store = '$store'");
            $user = $select->fetch_object();
            $access_token = $user->access_token;
            $customerData = array
                    (
                        "customer" => array(
                            "first_name"    =>  "Steve",
                            "last_name"     =>  "Lastnameson",
                            "email"         =>  "steve.lastnameson10@test.com",
                            "verified_email"=>  true,
                        )
                    );
            $client = new Client();

            $response = $client->request(
                'POST', 
                "https://{$store}/admin/customers.json",
                [
                    'query' => [
                        'fields' => $customerData,
                        'access_token' => $access_token
                    ]
                ]
            );

            $result = json_decode($response->getBody()->getContents(), true);
            echo $result;

【问题讨论】:

    标签: php guzzle shopify-app


    【解决方案1】:
    POST /admin/products.json
    {
      "product": {
        "title": "Burton Custom Freestyle 151",
        "body_html": "<strong>Good snowboard!<\/strong>",
        "vendor": "Burton",
        "product_type": "Snowboard",
        "tags": "Barnes & Noble, John's Fav, \"Big Air\""
      }
    }
    

    在这段代码中使用它

    $client = new Client();

    $response = $client->request(
        'POST', 
        "https://{$store}/admin/products.json/access_token",
        [
            'form_params' => [
                'client_id' => $api_key,
                'client_secret' => $secret_key,
                'code' => $query['code']
            ]
        ]
    );
    

    【讨论】:

    • 这看起来很有帮助,但我不赞成因为格式需要修复。请花时间处理帖子格式,并在提交前使用预览窗口。谢谢!
    • 我使用的编码是一样的,只是这里使用了form_params
    猜你喜欢
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    相关资源
    最近更新 更多