Jump to content

Refund to voucher default settings


Recommended Posts

Hi All,

I hope someone may be able to help. Ive setup this shop prettymuch exactly how I want it apart from one thing which I am unable to solve.

When I issue a refund back to Voucher, it generates a voucher automatically which is great but what I want it to do is either

a:  generate the voucher without a voucher code so that it is automatically added when the customer places the next order

b:  If the above isnt possible the change the "highlight" value from no to yes by default so it shows a promo code is available when they reach checkout..

 

Ideally I would like option a) as it means the code is automatically added with no chance of the customer forgetting it. It also needs to work if the customer doesnt spend the full value so when it generates another voucher code it leaves the actualy code blank so it auto adds on the next order again.

Many Thanks

Simon

Link to comment
Share on other sites

39 minutes ago, BellesBows said:

Hi All,

I hope someone may be able to help. Ive setup this shop prettymuch exactly how I want it apart from one thing which I am unable to solve.

When I issue a refund back to Voucher, it generates a voucher automatically which is great but what I want it to do is either

a:  generate the voucher without a voucher code so that it is automatically added when the customer places the next order

b:  If the above isnt possible the change the "highlight" value from no to yes by default so it shows a promo code is available when they reach checkout..

 

Ideally I would like option a) as it means the code is automatically added with no chance of the customer forgetting it. It also needs to work if the customer doesnt spend the full value so when it generates another voucher code it leaves the actualy code blank so it auto adds on the next order again.

Many Thanks

Simon

 

Do you have some knowledge of PHP?

Link to comment
Share on other sites

im afraid I don't so rely on forums to provide answers to most of my questions and this is the only question I havent seen on here.

Its not a massive issue as I can edit the voucher manually but for convenience would like it to be automatic.

If someone does have an answer then fantastic, if not ill resort to manual adjustments.

Link to comment
Share on other sites

3 hours ago, BellesBows said:

im afraid I don't so rely on forums to provide answers to most of my questions and this is the only question I havent seen on here.

Its not a massive issue as I can edit the voucher manually but for convenience would like it to be automatic.

If someone does have an answer then fantastic, if not ill resort to manual adjustments.

 

Which PS are you using?

Link to comment
Share on other sites

// Generate voucher
if (Tools::isSubmit('generateDiscountRefund') && !count($this->errors) && $amount > 0) {
    $cart_rule = new CartRule();
    $cart_rule->description = $this->trans('Credit slip for order #%d', array('#%d' => $order->id), 'Admin.Orderscustomers.Feature');
    $language_ids = Language::getIDs(false);
    foreach ($language_ids as $id_lang) {
        // Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    }

    // Define a temporary code
    $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    $cart_rule->quantity = 1;
    $cart_rule->quantity_per_user = 1;

    // Specific to the customer
    $cart_rule->id_customer = $order->id_customer;
    $now = time();
    $cart_rule->date_from = date('Y-m-d H:i:s', $now);
    $cart_rule->date_to = date('Y-m-d H:i:s', strtotime('+1 year'));
    $cart_rule->partial_use = 1;
    $cart_rule->active = 1;

    $cart_rule->reduction_amount = $amount;
    $cart_rule->reduction_tax = $order->getTaxCalculationMethod() != PS_TAX_EXC;
    $cart_rule->minimum_amount_currency = $order->id_currency;
    $cart_rule->reduction_currency = $order->id_currency;
    ...
}

 

*This line should be the first one, but thanks to our marvellous forum it has been removed and now I cannot put it above the code :

This voucher is generated at \controllers\admin\AdminOrdersController.php, function postProcess() around line 790:

 

Comment line:

$cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);

 

Edited by joseantgv (see edit history)
Link to comment
Share on other sites

4 hours ago, joseantgv said:

// Generate voucher
if (Tools::isSubmit('generateDiscountRefund') && !count($this->errors) && $amount > 0) {
    $cart_rule = new CartRule();
    $cart_rule->description = $this->trans('Credit slip for order #%d', array('#%d' => $order->id), 'Admin.Orderscustomers.Feature');
    $language_ids = Language::getIDs(false);
    foreach ($language_ids as $id_lang) {
        // Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    }

    // Define a temporary code
    $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    $cart_rule->quantity = 1;
    $cart_rule->quantity_per_user = 1;

    // Specific to the customer
    $cart_rule->id_customer = $order->id_customer;
    $now = time();
    $cart_rule->date_from = date('Y-m-d H:i:s', $now);
    $cart_rule->date_to = date('Y-m-d H:i:s', strtotime('+1 year'));
    $cart_rule->partial_use = 1;
    $cart_rule->active = 1;

    $cart_rule->reduction_amount = $amount;
    $cart_rule->reduction_tax = $order->getTaxCalculationMethod() != PS_TAX_EXC;
    $cart_rule->minimum_amount_currency = $order->id_currency;
    $cart_rule->reduction_currency = $order->id_currency;
    ...
}

 

*This line should be the first one, but thanks to our marvellous forum it has been removed and now I cannot put it above the code :

This voucher is generated at \controllers\admin\AdminOrdersController.php, function postProcess() around line 790:

 

Comment line:


$cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);

Thanks I had a little play with the file and got one part working. When I issue a credit voucher now it no longer generates a voucher code and as such applies to the customers cart straight away however......

If the customer only partially uses that voucher, the system generates another voucher and also generates a 'code' for that new voucher so now I need to find out which file controls that part of the system.

There must be a controller out there that is used to re-generate a voucher if one is not totally used.

 

Thanks for your help.

Link to comment
Share on other sites

I believe I may have found the solution. The file to edit is /classes/PaymentModule.php

You have to remove

   // Set a new voucher code
                            $voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule['obj']->id), 0, 16) : $voucher->code.'-2';
                            if (preg_match('/\-([0-9]{1,2})\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) {
                                $voucher->code = preg_replace('/'.$matches[0].'$/', '-'.(intval($matches[1]) + 1), $voucher->code);
                            }

 

When the customer then partial uses a voucher unique to them (credit voucher for example) it regenerates a new voucher but leaves the voucher code blank so that the voucher value automatically adds to the basket gicing the customer the discount.

It helps to stop the customer missing out on using credits and also means that account credits are used by default on the next order to stop you having loads of credits sitting there doing nothing.

For it to work properly you also need to edit the following in the \controllers\admin\AdminOrdersController.php file

// Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    }

    // Define a temporary code
    $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    $cart_rule->quantity = 1;
    $cart_rule->quantity_per_user = 1;

  Change it to

// Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
        $cart_rule->quantity = 1;
        $cart_rule->quantity_per_user = 1;    
}

Any new vouchers generated from that moment onwards will do what I want it to do :)

    
  

Link to comment
Share on other sites

  • 2 years later...
On 11/6/2018 at 12:15 PM, BellesBows said:

I believe I may have found the solution. The file to edit is /classes/PaymentModule.php

You have to remove

   // Set a new voucher code
                            $voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule['obj']->id), 0, 16) : $voucher->code.'-2';
                            if (preg_match('/\-([0-9]{1,2})\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) {
                                $voucher->code = preg_replace('/'.$matches[0].'$/', '-'.(intval($matches[1]) + 1), $voucher->code);
                            }

 

When the customer then partial uses a voucher unique to them (credit voucher for example) it regenerates a new voucher but leaves the voucher code blank so that the voucher value automatically adds to the basket gicing the customer the discount.

It helps to stop the customer missing out on using credits and also means that account credits are used by default on the next order to stop you having loads of credits sitting there doing nothing.

For it to work properly you also need to edit the following in the \controllers\admin\AdminOrdersController.php file


// Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    }

    // Define a temporary code
    $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
    $cart_rule->quantity = 1;
    $cart_rule->quantity_per_user = 1;

  Change it to

// Define a temporary name
        $cart_rule->name[$id_lang] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
        $cart_rule->quantity = 1;
        $cart_rule->quantity_per_user = 1;    
}

Any new vouchers generated from that moment onwards will do what I want it to do :)

    
  

Thanks a lot, it also worked in PS 1.6

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...