• Resolved MeatRo

    (@meatro)


    I have a Windows application that I enter my inventory into, it then posts the inventory to eBay and my WooCommerce site.

    I have added support for attributes and now my only issue is preserving new lines in the attribute value. I can do it in the administrative panel manually… Edit attribute value (br is stripped), Enter key’s new line will save and display on front end.

    However, I cannot pass any of these via the API, br is still stripped as well as environment.newline vbCrLf is also removed.

    This is what I am trying to enter:

    Fitment
    GENESIS 09-12 (electric windows), Sdn, L., laminated glass (opt 8243A2)
    GENESIS 13-14 (electric windows), Sdn, L.

    This is what is showing:

    Fitment
    GENESIS 09-12 (electric windows), Sdn, L., laminated glass (opt 8243A2) GENESIS 13-14 (electric windows), Sdn, L.

    For items with longer attribute values (some have several lines) it is a clustered, hard to read, impossible to understand mess.. Like this:

    Available with chrome or painted lower moulding., B, fits, A, ; difference is glass type. HY 760043M000 door $856 HY 824113M000 glass $429 HY 824013M050 reg, ’11- $125 HY 824013M000 reg, ’09-10 $125 HY 824503M000 motor $376 KI 760043M000 door Ident: 760043M000 W/tempered glass. HY 824113M021 glass $485 KI 760043M000 door shell W/laminated glass. Hyundai option code 8243A2 – Acoustic Laminated Glass, Front Door.

    Which should read…

    Available with chrome or painted lower moulding., B, fits, A, ; difference is glass type.
    HY 760043M000 door $856
    HY 824113M000 glass $429
    HY 824013M050 reg, ’11- $125
    HY 824013M000 reg, ’09-10 $125
    HY 824503M000 motor $376
    KI 760043M000 door Ident: 760043M000 W/tempered glass.
    HY 824113M021 glass $485
    KI 760043M000 door shell W/laminated glass. Hyundai option code 8243A2 – Acoustic Laminated Glass, Front Door.

    I read somewhere that I should not assign new lines to non-variable product attributes, but I figure it should not hurt anything (doesn’t seem to be) as I have no variable products. ??

    Thank you!

    PS., WooCommerce is great an V3 API is very nice to work with.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter MeatRo

    (@meatro)

    Resolved.

    In /includes/api/class-wc-api-products.php

    } elseif ( isset( $attribute['options'] ) ) {
    					// Array based
    					if ( is_array( $attribute['options'] ) ) {
    						$values = implode( ' ' . WC_DELIMITER . ' ', array_map( 'wc_clean', $attribute['options'] ) );
    
    					// Text based, separate by pipe
    					} else {
    						$values = implode( ' ' . WC_DELIMITER . ' ', array_map( 'wc_clean', explode( WC_DELIMITER, $attribute['options'] ) ) );
    					}

    Changed to

    } elseif ( isset( $attribute['options'] ) ) {
    					// Array based
    					if ( is_array( $attribute['options'] ) ) {
    						$values = $attribute['options'];
    
    					// Text based, separate by pipe
    					} else {
    						$values = $attribute['options'];
    					}

    Can you tell it in some more detail. Actually i am not having the same problem and the above fix does not work for me.

    Thread Starter MeatRo

    (@meatro)

    I don’t know in too much detail how it works.. I just know that the WooCommerce API strips out any delimiters such as a line break. The top code is the original and it’s stripping out delimiters.

    The bottom code is what I changed it to, which basically passes the attributes to the API and keeps them in their original format.

    Then here is the VB code that pulls the multiline attributes from my Access Database and passes them to the API:

    If Not IsDBNull(dr("ptFitment")) Then
                Dim objatt2 = New ProductAttribute()
                objatt2.name = "Fitment"
                objatt2.options = Regex.Replace(dr("ptFitment"), Environment.NewLine, "<br>")
                objatt2.visible = True
                objattribute1.Add(objatt2)
            End If
            If Not IsDBNull(dr("ptNotes")) Then
                Dim objatt3 = New ProductAttribute()
                objatt3.name = "Fitment Notes"
                objatt3.options = Regex.Replace(dr("ptNotes"), Environment.NewLine, "<br>")
                objatt3.visible = True
                objattribute1.Add(objatt3)
            End If

    It’s finding any new lines (Environment.NewLine) and replacing it with the HTML tag. So when it is passed to the API, it looks like this:

    Example1
    Example2

    Gets passed as:

    Example1Example2

    … Then in the API code itsel, above.. I pulled out the part that strips delimiters. Because any NewLine, BR, etc was being removed and everything was getting passed like this:

    Example1Example2

    I hope this helps, but it was a looong time ago. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Preserving New Lines via API’ is closed to new replies.