• Resolved k0b32010

    (@k0b32010)


    Hello there,

    I want to ask you i have an XML that has the attributes as below and i don’t know how to import them. Can you please help me?

    Thank you in advance.

    <attributes>
    διάμετρος:44mm,αδιάβροχο:10 ΑΤΜ,μηχανισμός:Only Solar Time,κάσα:Ανοξείδωτο Ατσάλι,xroma-kasas:Χρυσό,xroma-kantran:Μαύρο,μπρασελέ:Ανοξείδωτο Ατσάλι,xroma-mprasele:Χρυσό,κούμπωμα:Ασφαλείας,φύλο:Ανδρικό
    </attributes>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @k0b32010

    The standard way to call this value would be typing {attributes[1]} into the appropriate field. This would put ALL of the attributes into that field.

    If you can provide more specific information, I can assist further.

    I noticed that “attributes” seems to have multiple key/value pairs.
    If you’re trying to parse those out individually (ex: “διάμετρος:44mm” mapped to a field, “αδιάβροχο:10 ATM” mapped to another field, etc.) it would be be best if the XML file had them as nodes like this:

    <attributes>
      <διάμετρος>44mm<διάμετρος>
      <αδιάβροχο>10 ΑΤΜ<αδιάβροχο>
      <μηχανισμός>Only Solar Time<μηχανισμός>
    <attributes>

    otherwise you’ll need a custom PHP function to handle this. I’ll see if I can whip something up.

    Hope this helped point you in the right direction.

    • This reply was modified 4 years, 1 month ago by Aakash.

    Hi @k0b32010

    I’ve found a solution to parse the attributes. It’s not pretty, but it works!

    Paste this code into the function editor.

    <?php
    function get_value_for($string, $key){
      $string = "{" . $string . "}";
      preg_match('/\K[^{]*(?=})/', $string, $matches);
    
    $matchedResult = $matches[0];
    $exploded = explode(",",$matchedResult); // explode with ,
    
    $yourData = array();
    foreach ($exploded as $value) {
        $result = explode(':',$value); // explode with :
        $yourData[$result[0]] = $result[1];
    }
    
    return($yourData[$key]);
    }
    ?>

    You can then call the attributes like this – https://i.imgur.com/ldiLAZT.png

    [get_value_for({attributes[1]},"διάμετρος")]
    I hope this helped!

    Thread Starter k0b32010

    (@k0b32010)

    Thank you @aakash8 very much for your help!! God bless you!!
    I have one last question to ask you, some attributes on some products have 2 or even 3 values. Is that possible?

    Glad to help @k0b32010

    If you can provide an XML example of cases with multiple values, I can try to assist further.

    Another good place to get advice on a custom PHP function for this would be StackOverflow forums. Show them the current code/function and the XML you’re trying to parse to get additional advice.

    Thread Starter k0b32010

    (@k0b32010)

    They are separated with comma, the example below is with 2 values:

    <attributes>διάμετρος:44mm,αδιάβροχο:10 ΑΤΜ,μηχανισμός:QUARTZ Χρονογράφος Ακριβείας,κάσα:Ανοξείδωτο Ατσάλι,xroma-kasas:Ασημί, Ροζ Χρυσό,xroma-kantran:Γκρι,μπρασελέ:Ανοξείδωτο Ατσάλι,xroma-mprasele:Ασημί, Ροζ Χρυσό,κούμπωμα:Ασφαλείας,φύλο:Ανδρικό</attributes>

    And the one below with 3 values:
    <attributes>είδος:Βραχιόλι,χρώμα:Ασημί, Μαύρο, Ροζ Χρυσό,φύλο:Γυναικείο</attributes>

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Attributes All in One’ is closed to new replies.