• 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 2 years, 11 months 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.