简体   繁体   中英

Etsy API PHP, how to create custom property_values

Im using Etsy API (PHP) from : https://github.com/gentor/etsy-php-laravel . Im having problems trying to create a listing which contains these custom attributes : "color","height". There is an example code but i don't know how to get the "property_id" field from my custom attributes, also i have no clue how to add these custom attributes to my list. I did read their developer document but still can't figure out anything myself, been 2 days and they keep locking my accounts from here means i can't test my code much. Thanks in advance, here is example code i tried:

dd($conn->updateInventory(
            [
                'params' => [
                    'listing_id' => '710642930'
                ],
                'data' => [
                    'products' => [
                        'json' => json_encode([
                            [
                                'sku' => 'sku-1',
                                'property_values' => [
                                    [
                                        'property_id' => 2000,
                                        'property_name' => 'color',
                                        'values' => 'red'
                                    ],
                                    [
                                        'property_name' => 'height',
                                        'property_id' => 5000,
                                        'value' => '57 cm'
                                    ]
                                ],
                                'offerings' => [
                                    [
                                        'price' => 10,
                                        'quantity' => 3
                                    ]
                                ]
                            ],
                            [
                                'sku' => 'sku-2',
                                'property_values' => [
                                    [
                                        'property_name' => 'color',
                                        'property_id' => 2000,
                                        'value' => 'red'
                                    ],
                                    [
                                        'property_name' => 'height',
                                        'property_id' => 5000,
                                        'value' => '68 cm'
                                    ]
                                ],
                                'offerings' => [
                                    [
                                        'price' => 11,
                                        'quantity' => 4
                                    ]
                                ]
                            ],
                            [
                                'sku' => 'sku-3',
                                'property_values' => [
                                    [
                                        'property_name' => 'color',
                                        'property_id' => 2000,
                                        'value' => 'blue'
                                    ],
                                    [
                                        'property_name' => 'height',
                                        'property_id' => 5000,
                                        'value' => '57 cm'
                                    ]
                                ],
                                'offerings' => [
                                    [
                                        'price' => 12,
                                        'quantity' => 5
                                    ]
                                ]
                            ],
                            [
                                'sku' => 'sku-4',
                                'property_values' => [
                                    [
                                        'property_name' => 'color',
                                        'property_id' => 2000,
                                        'value' => 'blue'
                                    ],
                                    [
                                        'property_name' => 'height',
                                        'property_id' => 5000,
                                        'value' => '68 cm'
                                    ]
                                ],
                                'offerings' => [
                                    [
                                        'price' => 14,
                                        'quantity' => 6
                                    ]
                                ]
                            ],
                        ])
                    ],
                    'price_on_property' => [2000, 5000],
                    'quantity_on_property' => [2000, 5000],
                    'sku_on_property' => [2000, 5000],
                ],
            ]));

The property ids that you are looking for are what Etsy considers their "Structured Data". You will want to make an API call using the getTaxonomyNodeProperties method. This method takes a taxonomy id representing the taxonomy of the product you are trying to list and will return a list of available TaxonomyNodeProperty objects that describe the options that are available to set up your listings variations.

If I recall correctly, height is in there (with its ID) and color is in there as 'Primary color' with its own ID. Keep in mind however that some of these structured node properties have a list of 'possible values' where you will be limited in the values you can supply. I remember that primary color has a specific list of possible values that you are limited to.

If you find that your colors are not in the list, then the list of pre-defined taxonomy node properties usually does include two 'custom' properties that can be used to make variations of any type at all. If you use any of the custom options, then you just use the pre-defined IDs of the custom properties.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM