• Resolved bobezac

    (@bobezac)


    Hi,

    Is there an easy way to programmatically adjust / edit the rules?

    My site manages prices automatically from an external database and I need to link the bulk discount rules to this, any suggestions?

    I have found previous mentions of these:

    WDP_Importer::import_rules
    //which appears to be calling
    return \ADP\Factory::callStaticMethod('Admin_Importer', 'importRules', $data, $resetRules);
    

    I can’t get either of these functions to accept rule json, they both throw critical errors no matter what I pass in, any idea what I’m doing wrong?

    Kind Regards,
    Bob

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    try

    use ADP\BaseVersion\Includes\ImportExport\Importer;
    //$data - json , you see it at tab Tools 
    //$resetRules - boolean, set true to reimport all rules
    Importer::importRules($data, $resetRules);
    Thread Starter bobezac

    (@bobezac)

    Hi, thanks that works to call the function correctly, however I can’t get it to import the rules from the JSON, the JSON I’m parsing works in the “import tool” if I paste it in there, but not when I call it myself in PHP, any ideas what I’m doing wrong, does the json need to be decoded before being parsed in any way?

    use ADP\BaseVersion\Includes\ImportExport\Importer;
    function test_function_shortcode() {
    	$data = 'the json from exporter';
    	return var_dump(Importer::importRules($data, true));
    }
    Thread Starter bobezac

    (@bobezac)

    I think I’ve figured it out by reading what the importer is doing, this seems to work:

    use ADP\BaseVersion\Includes\ImportExport\Importer;
    function test_function_shortcode() {
    	$data = 'the json from exporter';
    	$data = json_decode(str_replace('\\', '', wp_unslash($data)), true);
    	return var_dump(Importer::importRules($data, true));
    }
    Plugin Support thisisirene

    (@thisisirene)

    Hello!
    This code must work fine!

    Thread Starter bobezac

    (@bobezac)

    Hi, one more question, I believe product only rules have a cache that needs to be regenerated? is there a way to call this cache update from php?

    Plugin Support thisisirene

    (@thisisirene)

    It is possible, but has some difficulties. Could you create a ticket via our helpdesk, and we can help you find a better solution after the holidays?

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

The topic ‘How to import rules via function / api’ is closed to new replies.