• Resolved abusquets

    (@abusquets)


    Woocomerce REST API fails
    When I create a product with the REST API with the default language, ej: BOTIN AY1701 in the response I get [:fr]BOTIN AY1701[:]. This also fails if I send [:es]BOTIN AY1701[:], the name value is empty.
    Below there is a example url, a post data example and the response
    URL
    url = ‘products?lang=es’
    resposta = wcapi.post(url, data)
    POST data
    {‘type’: ‘variable’, ‘name’: ‘BOTIN AY1701’, ‘attributes’: [{‘variation’: True, ‘visible’: True, ‘id’: 3, ‘options’: [‘OCRE01’]}, {‘variation’: True, ‘visible’: True, ‘id’: 4, ‘options’: [’52’, ’40’]}], ‘categories’: [{‘id’: 304}], ‘sku’: ‘AY1701’}
    Response
    {‘_links’: {‘collection’: [{‘href’: ‘https://devel-lxc.local:81/botiga/wp-json/wc/v2/products’}],
    ‘self’: [{‘href’: ‘https://devel-lxc.local:81/botiga/wp-json/wc/v2/products/2242’}]},
    ‘attributes’: [{‘id’: 3,
    ‘name’: ‘Color’,
    ‘options’: [‘OCRE01’],
    ‘position’: 0,
    ‘variation’: True,
    ‘visible’: True},
    {‘id’: 4,
    ‘name’: ‘Talla’,
    ‘options’: [’40’, ’52’],
    ‘position’: 0,
    ‘variation’: True,
    ‘visible’: True}],
    ‘average_rating’: ‘0’,
    ‘backordered’: False,
    ‘backorders’: ‘no’,
    ‘backorders_allowed’: False,
    ‘button_text’: ”,
    ‘catalog_visibility’: ‘visible’,
    ‘categories’: [{‘id’: 304,
    ‘name’: ‘BOTIN ESPECIAL’,
    ‘slug’: ‘botin-especial’}],
    ‘cross_sell_ids’: [],
    ‘date_created’: ‘2018-01-20T19:21:39’,
    ‘date_created_gmt’: ‘2018-01-20T18:21:39’,
    ‘date_modified’: ‘2018-01-20T19:21:39’,
    ‘date_modified_gmt’: ‘2018-01-20T18:21:39’,
    ‘date_on_sale_from’: None,
    ‘date_on_sale_from_gmt’: None,
    ‘date_on_sale_to’: None,
    ‘date_on_sale_to_gmt’: None,
    ‘default_attributes’: [],
    ‘description’: ”,
    ‘dimensions’: {‘height’: ”, ‘length’: ”, ‘width’: ”},
    ‘download_expiry’: -1,
    ‘download_limit’: -1,
    ‘downloadable’: False,
    ‘downloads’: [],
    ‘external_url’: ”,
    ‘featured’: False,
    ‘grouped_products’: [],
    ‘id’: 2242,
    ‘images’: [{‘alt’: ‘Marcador’,
    ‘date_created’: ‘2018-01-20T19:21:40’,
    ‘date_created_gmt’: ‘2018-01-20T18:21:40’,
    ‘date_modified’: ‘2018-01-20T19:21:40’,
    ‘date_modified_gmt’: ‘2018-01-20T18:21:40’,
    ‘id’: 0,
    ‘name’: ‘Marcador’,
    ‘position’: 0,
    ‘src’: ‘https://devel-lxc.local:81/botiga/wp-content/plugins/woocommerce/assets/images/placeholder.png’}],
    ‘in_stock’: False,
    ‘manage_stock’: False,
    ‘menu_order’: 0,
    ‘meta_data’: [],
    ‘name’: ‘[:fr]BOTIN AY1701[:]’,
    ‘on_sale’: False,
    ‘parent_id’: 0,
    ‘permalink’: ‘https://devel-lxc.local:81/botiga/producto/botin-ay1701/’,
    ‘price’: ”,
    ‘price_html’: ”,
    ‘purchasable’: False,
    ‘purchase_note’: ”,
    ‘rating_count’: 0,
    ‘regular_price’: ”,
    ‘related_ids’: [],
    ‘reviews_allowed’: True,
    ‘sale_price’: ”,
    ‘shipping_class’: ”,
    ‘shipping_class_id’: 0,
    ‘shipping_required’: True,
    ‘shipping_taxable’: True,
    ‘short_description’: ”,
    ‘sku’: ‘AY1701’,
    ‘slug’: ‘botin-ay1701’,
    ‘sold_individually’: False,
    ‘status’: ‘publish’,
    ‘stock_quantity’: None,
    ‘tags’: [],
    ‘tax_class’: ”,
    ‘tax_status’: ‘taxable’,
    ‘total_sales’: 0,
    ‘type’: ‘variable’,
    ‘upsell_ids’: [],
    ‘variations’: [],
    ‘virtual’: False,
    ‘weight’: ”}

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @abusquets
    Send request for creating or editing product with lang paran in body of the request. Not in url.

    Thread Starter abusquets

    (@abusquets)

    In the body of request. Do you mean add lang attribute like this? It fails too.

    
    {
        'lang': 'es,
        
        'type': 'variable', 'name': 'BOTIN AY1701', 
        'attributes': [
        {'variation': True, 'visible': True, 'id': 3, 'options': ['OCRE01']}, 
        {'variation': True, 'visible': True, 'id': 4, 'options': ['52', '40']}], 
        'categories': [{'id': 304}], 
        'sku': 'AY1701'
    }
    
    
    • This reply was modified 6 years, 10 months ago by abusquets.
    Thread Starter abusquets

    (@abusquets)

    When I create a product, in wpm_translate_object function $lang is empty.
    The file is includes/wpm-translation-functions.php

    
    function wpm_translate_object( $object, $lang = '' ) {
    
    	foreach ( get_object_vars( $object ) as $key => $content ) {
    		switch ( $key ) {
    			case 'attr_title':
    			case 'post_title':
    			case 'name':
    			case 'title':
    				print( 'content:' . $content ."\n");
    				print( 'lang:' .$lang ."\n");
    				print( 'wpm_translate_string:' . wpm_translate_string( $content, $lang ) ."\n");
    				die();
    				$object->$key = wpm_translate_string( $content, $lang );
    				break;
    
    

    Hi @abusquets
    Add ‘edit_lang’ to url param for editing products.

    Thread Starter abusquets

    (@abusquets)

    For new products too?

    Yes.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WooComerce REST API’ is closed to new replies.