Jump to content

Override the Adapter VoucherGenerator


Recommended Posts

Posted (edited)

Hello,
I need an override for
/src/Adapter/Order/Refund/VoucherGenerator

I have already tried it with these instructions
https://www.prestashop.com/forums/topic/1040771-177-how-should-we-override-srcadapter-adminproductdataprovider/?do=findComment&comment=3357023
unfortunately nothing happened.

The goal is that the voucher code is changed, automatically assigned to the store in which the purchase was made in the case of a multishop and the link to the e-mail is to be released.

Can an adapter be provided with an override? What other solutions are there?

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

Hello,

Yes, you can override adapters.

In our case, the problem is most likely one of the following:
- you did not provide the same service name as the original file uses. This is the name you will need to use in your services.yml: prestashop.adapter.order.refund.voucher_generator
- you did not run 'composer dumpautoload'

I also built a small module that overrides that class. You can find it attached below. Once the module is installed, when you generate a new voucher, you will see that the message from the constructor is dumped.

The other option is to use a decorator, where you basically add functionality on top of the existing one. If you want to change some logic in the 'generateVoucher' method, as opposed to calling that and additionally adding your logic, this approach cannot be used.

vouchergeneratoroverride.zip

Link to comment
Share on other sites

Hello,

Thank you very much. That helped and I was able to add my own logic. In this case, renaming the voucher code, removing the personalization and assigning it to a specific store in a multishop installation.

  • Like 1
Link to comment
Share on other sites

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...