• Resolved ilyapokrov

    (@ilyapokrov)


    I very much ask you to give me a tip with the formula, since I am not very strong in this.

    As a varied example, let’s say I have parameters like this:

    <param name=”gender”>Male</param>
    <param name=”gender”>Women</param>
    <param name=”gender”>Naughty children</param>
    <param name=”gender”>dogs and cats</param>

    I use this formula to write attributes:

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

    function my_map_data_Probnik( $data ) {
        $map = array(
    		'Male' => 'For Male',
    		'Women' => 'For women',
        );
        return ( array_key_exists( $data, $map ) ) ? $map[ $data ] : $data;
    }

    And here’s my question:

    How to rewrite this formula to do the following:
    If parameter = ‘Male’, then write as ‘For Male’.
    If parameter = ‘Women’, then write as ‘For women’.
    If the parameter contains the word ‘Children’, then write it as ‘For children’.
    If the parameter is different, then do not write anything.

    I looked at your instructions but couldn’t find a similar example.
    I very much ask you to help me, as I cannot write the code on my own.

    Thank you in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    How to rewrite this formula to do the following:
    If parameter = ‘Male’, then write as ‘For Male’.
    If parameter = ‘Women’, then write as ‘For women’.
    If the parameter contains the word ‘Children’, then write it as ‘For children’.
    If the parameter is different, then do not write anything.

    You’d have to use if statements to do that: https://www.php.net/manual/en/control-structures.if.php.

    Unfortunately, I do not have an example snippet that does exactly what you describe, but we have a lot of code examples here that might help: https://www.wpallimport.com/documentation/developers/code-snippets/.

    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,
    I coped with the task with code like this:

    function my_map_data_Probnik( $data ) {
        $map = array(
    		'Male' => 'For Male',
    		'Women' => 'For women',
    		
        );
    	if (array_key_exists($data, $map)) {
        return $map[$data];
    }
    	if (mb_strpos($data, 'children') !== false) {
        return 'for children';
    }
    	if (mb_strpos($data, 'toddlers') !== false) {
        return 'for babies';
    }
    	return null;
        return ( array_key_exists( $data, $map ) ) ? $map[ $data ] : $data;
    }

    I am sharing this code with you, suddenly it will be useful to someone.
    But there is a nuance. I don’t know if you can help me with this or not.
    For the speed of the site, I connected a VPS cloud hosting.
    I noticed that when I use this feature my hosting often drops the connection and the site gets an error – No database access.
    The hosting says that the problem is in the site scripts – they need to be optimized. RAM of 1 GB is not enough for this job.
    I specifically checked on a YML file, which contains only 5 products. And I don’t think this operation wastes more than 1 GB of RAM.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    I noticed that when I use this feature my hosting often drops the connection and the site gets an error – No database access.

    By “this feature”, do you mean when you run an import? If so, imports can be very resource-intensive and your server needs to be able to handle the amount, and type, of data that you’re importing. This guide will help you optimize the import and use as little resources as possible: https://gist.github.com/trey8611/72fec5969651d5272fcb85f99b09b8bb.

    I specifically checked on a YML file, which contains only 5 products. And I don’t think this operation wastes more than 1 GB of RAM.

    You wouldn’t think so, but it really depends on the data that’s being imported and what’s happening in the background. For example, if you try to import 500 taxonomy terms and 50 images per-record, it’s likely going to take up a lot of resources. Also, keep in mind that your theme and other plugins could be doing a lot of heavy operations in the background that you’re not even aware of (these could be per-image imported, per-term, per-record, etc).

    If the guide I sent you above doesn’t help narrow down what’s causing the resource usage, you’ll need to work with a sysadmin to figure out exactly what’s going on and exactly how your server needs to be configured to handle it.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    I’m marking this as resolved since we haven’t heard back in a while. You can follow up in this thread if you have more questions.

    Anyone else reading this, please open a new topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Overwriting Attribute Values’ is closed to new replies.