Shopify API - 无法将产品图像存储起来

时间:2016-06-28 14:51:04

标签: php shopify

我已经调整了phpish / shopify API客户端(https://github.com/phpish/shopify)来创建一个简单的网络表单,客户可以在其中添加产品并将产品图片上传到我的Shopify商店。

我可以添加产品,没问题,但图片只是上传了。我正在使用API​​创建具有默认变体和base64编码图像的新产品,例如下面的示例。

任何人都可以发现我做错了吗?

try
{
    $product = $shopify('POST /admin/products.json', array(), array
    (
        'product' => array
        (
            "title" => "Test Product 2" ,
            "body_html" => "test description" ,
            "vendor" => "URG Trial",
            "variants" => array
            (
                array
                (
                    "price" => "2.50",
                    "sku" => "25",
                                                "weight" => "2",
                                                "weight_unit" => "lb"
                )
            ),
            "images" => array
            (
                                    "attachment" => "/9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA5ADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVY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Mon1IsbmS4aF0GVCAxkgYPAHA4/Unk+mV5X/wA1k/7e/wD2jXqld2EulJN31Z4mawUZU5LrFP8AMKKKK6zyz//Z==\n"
            ),
        )
    ));

}

2 个答案:

答案 0 :(得分:0)

你忘记了图像是一个数组数组,请尝试使用图像:

"images" => array(
    array(
        "attachment" => "your_image_base_64"
    )
)

答案 1 :(得分:0)

谢谢!图像不能是本地文件,我也忘记了数组,但它有效!

    $image="https://previews.123rf.com/images/victoroancea/victoroancea1201/victoroancea120100059/12055848-tv-color-test-pattern-test-card-for-pal-and-ntsc.jpg";

    $products_array = array
    (
        'product' => array
        (
            'title' => $_POST['title'],
            'body_html' => $_POST['body_html'],
            'vendor' => $_POST['vendor'],
            'product_type' => $_POST['type'],
            'images' => array(
                            array(
                            'src' => $image
                            )
                        )
        )
    );