• Resolved ilyapokrov

    (@ilyapokrov)


    For many days I have been racking my brains over how to solve one problem, but nothing happens =)
    Can you tell me the code I need to use?
    There are goods that are divided into 3 values: “Adults”, “Children”, “Babies”.
    In turn, these products have gender, but the file is not specified correctly, like this:

    <param name=”Age”> – “Adults”, “Children”, “Babies”
    <param name=”gender”> – “male”, “female”, “None”

    “Adults” – “male”, “female”
    “Children” – “male”
    “Babies” – “None”

    How to write code like this so that:
    If the product is “Adults”, then write down what is indicated in the file, if the product is “children” or the product “Babies”, then write down this value – “For girls | For boys”

    I understand that I am not going too far when I ask you to help me, nevertheless I really hope that you can tell =)

    My code is half working. Products for children still have the meaning “for male”:

    [my_map_data({param[@name="gender"]})]

    ///////////* Gender Attribute*/
    function my_map_data( $data ) {
        $map = array(
    		'male' => 'for male',
    		'female' => 'for female',
    		'None' => 'for girls|for boys',
        );
        return ( array_key_exists( $data, $map ) ) ? $map[ $data ] : $data;
    }
    • This topic was modified 3 years, 9 months ago by ilyapokrov.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    You’d need to pass both the gender and the age to your function like this:

    [my_parse_data({param[@name="Age"]},{param[@name="gender"]})]

    Then, process the data in the function. Here is an untested example that you can modify as needed:

    function my_parse_data( $age, $gender ) {
        $age    = strtolower( $age );
        $gender = strtolower( $gender );
    
        if ( $age == 'adults' ) {
            return 'for ' . $gender;
        } elseif ( $age == 'babies' || $age == 'children' ) {
            return 'For girls | For boys';
        } else {
            if ( $gender == 'none' ) {
                return 'for girls|for boys';
            }
        }   
    
        return 'for ' . $gender;
    }
    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,
    That’s what I need! Many thanks! Thank you very much!

    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,
    But what to do when you need to use the previously obtained value using a formula?
    For example, I rewritten using the “Category” function, and in order to determine the “size” attribute I need to use the resulting category.
    I have already written the code, checked it – it works. But I cannot display it in the attribute. Tried it like this:
    Get a category
    [my_map_data_Category({typePrefix[1]})]

    Get the attribute
    [my_map_data_Size({param[@name="Size"]},[my_map_data_Category({typePrefix[1]})])]

    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,

    After several attempts, I still managed to achieve the result =)
    I wrote down the formula as follows:
    [my_map_data_Size({param[@name="Size"]},my_map_data_Category({typePrefix[1]}))]

    There is also a drawback of this method – a very long catalog update. Apparently such formulas slow down the update process very much.

    • This reply was modified 3 years, 9 months ago by ilyapokrov.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Overwrite values’ is closed to new replies.