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.
Related
I'm trying to utilise the Yii2 Flot extension with more or less success. However, I'm having trouble altering the labels of a pie-chart using a labelFormatter function.
This is the extension I'm using: bburim/flot
Here is the code I have so far, it generates a nice chart, but I cannot alter the labels.
Any help is appreciated.
echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);
That is a pretty broad term to say customize, I will assume it means providing custom label text, its pretty simple and straight forward you just need to use the new JsExpression() for the callback function to work correctly
echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'labelFormatter' => new JsExpression("function(label, series) {
// series is the series object for the label
return 'Custom Label for '+series.label+'';
}"),
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);
On a side note I wont use that repo as the owner seems to be unresponsive since 2015 not a single reply on the issues, you might have to maintain or fix the bugs your self so better fork the repo and use your own customized version
Right now I'm using the $project aggregation for filtering out unnecessary fields. Also I'm using the $lookup aggregation to link two collections togethe and I know how to use both of them in the main collection.
Now my question is; how can I put this $project aggregation inside of a lookup?
What I have now is looks like this:
[
'$lookup' => [
'from' => Media::collectionName(),
'localField' => '_id',
'foreignField' => 'project_id',
'as' => 'mediaList'
]
],
[
'$project' => [
'title' => 1,
'owner_id' => 1,
'owner_name' => 1,
'created_at' => 1,
'updated_at' => 1,
'status' => 1,
'discount' => 1,
'company' => 1,
'media' => [
'$filter' => [
'input' => '$mediaList',
'as' => 'media',
'cond' => $mediaFilter
]
]
]
],
So I can filtering out the unnecessary fields in the main collection. How can I do this in the sub-collection?
If I understood your question correctly, you want to apply a $filter operation on your $mediaList field.
To avoid a redundant $project stage (where you have to declare every single field you want to keep), use $addFields stage instead, like this :
[
'$lookup' => [
'from' => Media::collectionName(),
'localField' => '_id',
'foreignField' => 'project_id',
'as' => 'media' // Note that I use the same name for the field
]
],
[
'$addFields' => [
'media' => [
'$filter' => [
'input' => '$media',
'as' => 'media',
'cond' => $mediaFilter
]
]
]
],
I want to make a chart, I have database province and I want to make this be xAxis on Highcharts.
My Database
<?= \dosamigos\highcharts\HighCharts::widget([
'clientOptions' => [
'chart' => [
'type' => 'spline'
],
'title' => [
'text' => 'Fruit Consumption'
],
'xAxis' => [
'categories' => [
'Jabodetabek',
'Banten',
'Jawa Tengah',
'Jawa Timur',
'Medan',
'Riau',
'Bangka Belitung',
'Lampung',
'Kalimantan Selatan',
'Kalimantan Barat',
'Kalimantan Timur',
'Kalimantan Tengah',
'NTB',
'NTT',
'Papua']
],
'yAxis' => [
'title' => [
'text' => 'Fruit eaten'
]
],
'plotOptions' => [
'line' => [
'dataLabels' => [
'enabled'=> true
]
]
],
'series' => [
['data' => [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
],
'responsive' => [
'rules' => [[
'condition' => [
'maxWidth' => 500
],
'charOptions' => [
'legend' => [
'align' => 'center',
'verticalAlign' => 'bottom',
'layout' => 'horizontal'
],
'yAxis' => [
'labels' => [
'align' => 'left',
'x' => 0,
'y' => 0
],
'title' => [
'text' => null
]
]
]
]]
]
]
]);
How can I make the contents of the province table be an array? I want data count all group by provinces.
Please help me
The yii2-friendly method is to use gii to generate models for each of your tables. Then you can get an array like
$provinces = \app\models\Province::find()->select('name')->asArray();
You can use a similar technique to get the count; I'd post an example except I'm not sure what the correct sql would be for your case.
I have a CollectionSet<UDT> where UDT contains a CollectionMap<int,boolean>. I have not been able to find any documentation or example of how to define this when creating a new Cassandra\Type\CollectionSet for inserting into the table. There is a great example with a CollectionList (found here) which is like this:
// CollectionSet<UDT>, where UDT contains: Int, Text, Boolean,
// CollectionList<Text>, CollectionList<UDT>
new Cassandra\Type\CollectionSet([
[
'id' => 1,
'name' => 'string',
'active' => true,
'friends' => ['string1', 'string2', 'string3'],
'drinks' => [['qty' => 5, 'brand' => 'Pepsi'], ['qty' => 3, 'brand' => 'Coke']]
],[
'id' => 2,
'name' => 'string',
'active' => false,
'friends' => ['string4', 'string5', 'string6'],
'drinks' => []
]
], [
[
'type' => Cassandra\Type\Base::UDT,
'definition' => [
'id' => Cassandra\Type\Base::INT,
'name' => Cassandra\Type\Base::VARCHAR,
'active' => Cassandra\Type\Base::BOOLEAN,
'friends' => [
'type' => Cassandra\Type\Base::COLLECTION_LIST,
'value' => Cassandra\Type\Base::VARCHAR
],
'drinks' => [
'type' => Cassandra\Type\Base::COLLECTION_LIST,
'value' => [
'type' => Cassandra\Type\Base::UDT,
'typeMap' => [
'qty' => Cassandra\Type\Base::INT,
'brand' => Cassandra\Type\Base::VARCHAR
]
]
]
]
]
]);
I've tried using the above example with several variations to accommodate the CollectionMap but nothing is working. My last attempt was this
new Cassandra\Type\CollectionSet($udt_array, [[
'type'=>Cassandra\Type\Base::UDT,
'definition' => [
'map_name' => [
'type' => Cassandra\Type\Base::COLLECTION_MAP,
'value' => [
Cassandra\Type\Base::INT,
Cassandra\Type\Base::BOOLEAN
]
]
]
]])
which gives the error Caught exception: Since v0.7, collection types should have \"definition\" directive. I've also tried using 'definition' instead of 'value'. I'm running out of ideas, any help would be greatly appreciated.
Use "definition" instead of "value". I tried this before but apparently I was doing something else wrong because this worked.
new Cassandra\Type\CollectionSet($udt_array, [[
'type'=>Cassandra\Type\Base::UDT,
'definition' => [
'map_name' => [
'type' => Cassandra\Type\Base::COLLECTION_MAP,
'definition' => [
Cassandra\Type\Base::INT,
Cassandra\Type\Base::BOOLEAN
]
]
]
]])
I'm using high-chart extension, but I don't know how to give ID to the container, now getting random id's like yw11,yw12 etc., How to give my own ids to the container like graph1, graph2 etc.,
You have two options:
Change widget id container as states in this line.
Set directly id of container:
$this->Widget('ext.highcharts.HighchartsWidget',array(
'options' =>array(
'chart' => array('renderTo' => $id),
'title' => array('text' => 'title'),
'yAxis' => array(
'title' => array('text' => 'y-values'),
)
)
));
set id to highcharts in yii2 :
echo Highcharts::widget([
'id' => 'YOUR-CUSTOM-ID',
'options' => [
'chart' => [
'type' => 'column',
'margin' => [60, 10, 40, 40],
],
'title' => [
'text' => 'Symmetrical Distribution',
'x' => 25
],
'subtitle' => [
'text' => 'Fisher\'s Iris Data: Sepal Width',
'x' => 25,
],
'legend' => [
'enabled' => false,
],
'credits' => [
'enabled' => false,
],
'tooltip' => [
],
'scripts' => [
'highcharts-more', // enables supplementary chart types (gauge, arearange, columnrange, etc.)
'modules/exporting', // adds Exporting button/menu to chart
'themes/grid' // applies global 'grid' theme to all charts
],
'plotOptions' => [
'series' => [
'pointPadding' => 0,
'groupPadding' => 0.5,
'borderColor' => 'rgba(255,255,255,0.5)',
'color' => '#434348',
]
],
'xAxis' => [
'title' => [
'text' => 'Sepal Width (cm)'
]
],
'yAxis' => [
'title' => [
'text' => ''
]
],
'series' => [
[
'name' => 'Distribution',
'data' => [[2.1, 4], [2.3000000000000003, 7], [2.5, 13], [2.7, 23], [2.9000000000000004, 36], [3.1, 24], [3.3000000000000003, 18], [3.5000000000000004, 10], [3.7000000000000006, 9], [3.9000000000000004, 3], [4.1, 2], [4.300000000000001, 1]]
]
]
]
]);