厕所 REST API |未上传属性 [英] WC REST API | Attributes not uploading

查看:22
本文介绍了厕所 REST API |未上传属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为颜色"的属性,它有两个属性红色"和绿色".
当我使用 WC REST API 运行它时

I have a Attribute called "Color" and it has two attributes "Red" and "Green".
When i run this using WC REST API

一切都在下面的代码中工作,我被这些属性困住了.

Everything is working from the below code, i am stuck with the attributes.

print_r( $client->products->create( array( 
    'title' => 'Nile - Over Counter Basin',
    'sku' => '91081_Nile', 
    'type' => 'simple', 
    'regular_price' => '7260',
    'sale_price' => '5445',
    'description' => 'Nile - Over Counter BasinOver Counter BasinHindware Italian CollectionContemporary design with smooth flowing line Space for toiletries', 
    'dimensions'=>array( 'length' =>'67.5' ,'width' =>'39.5','height'=>'12.5'), 
    'categories'=>array( ' SANITARYWARE' =>'592',' WASHBASIN' =>'650',' Table Top Wash Basin' =>'508'),
    'images' =>Array ('91081_Nile'=>Array('src'=>'http://www.somethingsomething.com/images/products/91081/2.jpg','title'=>'91081_Nile','position'=>'0') ),
    'short_description'=>'Contemporary design with smooth flowing line Space for toiletries <table id="ProductDescriptiontable"><tr><td>Brand</td><td>:</td><td class="thirdcolumn">Hindware</td></tr><tr><td>Product Name</td><td>:</td><td class="thirdcolumn">Nile - Over Counter Basin</td></tr><tr><td>Product Description</td><td>:</td><td class="thirdcolumn">Table Top Wash Basin</td></tr></tr><tr><td>Product Color</td><td>:</td><td class="thirdcolumn">StarwhiteIvory</td></tr></table>',
'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),
    'enable_html_short_description' => true,  // This is the line you need to add 
)  ) ) ;

Anand:在多个数组中添加属性后,属性显示在正确的部分,但它们不被视为属性,..请看图片,它们被视为纯文本而不是作为属性.
我的代码是:

Anand: After adding the attributes in multiple array, the attributes are displayed in correct section, but they are not considered as attributes, .. please see the image, they are seen as a plain text and not as an attributes.
My Code is:

'attributes'=>array(array('name'=>'Color','Slug'=>'color','position'=>'0','visible'=>true,'options'=>'Starwhite'),array('name'=>'Model',
'Slug'=>'model','position'=>'0','visible'=>true,'options'=>'Pedestal Wash Basin'),array('name'=>'Brands','Slug'=>'brands','position'=>'0','visible'=>true,'options'=>'Hindware'),array('name'=>'Washbasin Size','Slug'=>'washbasin-size','position'=>'0','visible'=>true,'options'=>'56 x 46 x 38.5 cm'),array('name'=>'Washbasin Type','Slug'=>'washbasin-type','position'=>'0','visible'=>true,'options'=>'Washbasin With Pedestal'))

推荐答案

需要将属性作为数组传递,更改

You need to pass attributes as an array of arrays, change

'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),

'attributes' => array( array( 'name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red' ) ),

P.S:我假设分类法和术语已经存在,并且分类法的类型设置为文本.

P.S: I am presuming there that the taxonomy and term already exist, and that the taxonomy's type is set to text.

编辑

当分类法的类型设置为文本"时,将 options 作为纯文本传递

When the taxonomy's type is set to "text" pass options as plain text

'options' => 'term'

当分类的类型设置为选择"时,将options作为数组传递

When the taxonomy's type is set to "select" pass options as an array

'options' => array( 'red', 'white' )

要传递多个属性,请将它们作为数组的数组发送,例如:

To pass multiple attributes, send them as an array of arrays, for eg:

'attributes'=>array(
    array( 'name'=>'Color', 'slug'=>'color', 'position'=>'0', 'visib‌​le'=>true, 'options'=> array('Starwhite') ),
    array( 'name'=>'Washbasin Type', 'slug'=>'washbasin-type', 'position'=>'0', 'visible'=>true, 'options'=> array(‌​'Washbasin With Pedestal') ),
);

这篇关于厕所 REST API |未上传属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆