Create Addon For Setting Product's Price Value To 0 After Clone

Hello everyone,

I want to override fn_clone_poduct function in fn.catalog.php file. My purpose is to set cloned product price to zero. I don't want the product price copied to the cloned product price.

In 'fn_clone_product' function when I comment out the lines for clone price section, everything is right and price value will be set to 0 after it is cloned!

I've decided to create addon to override this function. Here are the steps I've done:

1- In my_addon 'init.php' file I registered 'clone_product_post' hooks.

2- In my_addon 'func.php' I copied 'fn_clone_product' function (with all it's content) and changed the name to 'fn_my_addon_clone_product_post'.

3- In 'fn_my_addon_clone_product_post' I commented clone price codes.

4- In products.php controller (located in app/controllers/backend) I changed the line '$pdata = fn_clone_product($pid);' to

'$pdata = fn_my_addon_clone_product_post($pid);' in clone mode section.

5- Installed my_addon.

But In backend when I click on Clone button a blank page is appeared!

It's my second addon so I don't know if I've created it right! I think my registered hooks name is the problem! In 'fn_clone_product' function there are three hooks which are set:

- clone_product_pre

- clone_product

and clone_product_post

Which hook name should I use for the addon?

Thanks

There is no need to change the controller. Your custom function in the addon should look like

function fn_my_addon_clone_product_post($product_id, $pid, $orig_name, $new_name)
{
    db_query("UPDATE ?:product_prices SET price = ?d WHERE product_id = ?i", 0,  $pid);
    if (fn_allowed_for('ULTIMATE')) {
        db_query("UPDATE ?:ult_product_prices SET price = ?d WHERE product_id = ?i", 0,  $pid);
    }
}

It will reset product prices after the product is cloned

There is no need to change the controller. Your custom function in the addon should look like

function fn_my_addon_clone_product_post($product_id, $pid, $orig_name, $new_name)
{
    db_query("UPDATE ?:product_prices SET price = ?d WHERE product_id = ?i", 0,  $pid);
    if (fn_allowed_for('ULTIMATE')) {
        db_query("UPDATE ?:ult_product_prices SET price = ?d WHERE product_id = ?i", 0,  $pid);
    }
}

It will reset product prices after the product is cloned

Thank you so much. It works well :)

You are welcome!