Double Processing Issue In Function

I have a function in func.php



fn_myaddon_place_order …



In this function, I put a file on the folder on the host. By the same time, I want to send this content, which is put in place_order function, to customer at the bottom of the invoice. So, I created invoice.post.tpl and passed the variable in fn_myaddon_place_order.



Like this: ```php


{$variable|fn_myaddon_place_order}

<br />
I can get this content in tpl but the file that is put in place_order function is being put twice. So, it is being put one time when I don't use {$variable|fn_myaddon_place_order} in tpl.[i] ($variable returns content of the file which is put)[/i] But when I use it in tpl it is being put twice. I think that shows that function is processing twice.<br />
<br />
How can I prevent the function from processing twice?

hi,



CS-Cart has PHP hook called place_order so it seems that you used it. In this case you should:


  1. Create a new function, e.g. fn_myaddon_generate_order_file and move code of fn_myaddon_place_order into new function
  2. Inside body of fn_myaddon_place_order replace content with call of fn_myaddon_generate_order_file
  3. in invoice.post.tpl call fn_myaddon_generate_order_file instead of fn_myaddon_place_order



    if it is not the case, you may assign extra Smarty variables or use PHP static variables, e.g.:
    function fn_myaddon_place_order($variable)
    {
    static $count = 0;
    $count++;

    ... // original code
    }




    now when you call function for the first time $count will be equal to 1 and on the second time it will be 2 so you can use $count variable to return different values inside the function.



    hope it helps.



    best regards,

    WSA team

You can just use the file_exists php function in your custom function. If the file already exists, do not make any changes in the file system

Thanks to both of you.

you are welcome

Welcome!