VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: aftertaf on August 03, 2017, 13:01:04 PM

Title: how to override (or complement) VM core functions?
Post by: aftertaf on August 03, 2017, 13:01:04 PM
Hi,

When we sell some products per cm (fabrics), i want to display the sale price per metre.
The only way I found to do this is to override the products/category views and when CreatePriceDiv() is called, substitute the function call made in my override with a new function, CreatePriceDivPerMetre().
I just copied the function, changed the name and added "product_price = product_price * 100;"

Another 'hack' to make a custom field mandatory (for sending a gift certificate to a mail address) is done in \plugins\vmcustom\textinput\textinput.php

Obviously I lose them on every new VM upgrade...

Is there a different way to add these functions to my overrides and not have to worry about the core files ?
Title: Re: how to override (or complement) VM core functions?
Post by: Ghost on August 03, 2017, 14:46:21 PM
Another 'hack' to make a custom field mandatory (for sending a gift certificate to a mail address) is done in \plugins\vmcustom\textinput\textinput.phpFor this you can create a plugin based on textinput plugin and make your changes in the new plugin.
Title: Re: how to override (or complement) VM core functions?
Post by: aftertaf on August 03, 2017, 16:06:23 PM
hi, at the risk of sounding stupid, how would I do that? basic copy/paste of the source folder and renaming ?
Title: Re: how to override (or complement) VM core functions?
Post by: Ghost on August 03, 2017, 20:15:47 PM
Pretty much yes. Rename everything with textinput (including code and filenames) to something else. E.g. Textinput.php becomes mytextinput.php,  class plgVmCustomTextinput becomes plgVmCustomMytextinput and so on.
Title: Re: how to override (or complement) VM core functions?
Post by: aftertaf on August 04, 2017, 13:30:59 PM
ok. done that.. Renamed all "textinput" to "textinputso"
Ran the discovery procedure to install the new plugin as a plugin, and enabled it.
Changed the custom field to be textinputso and not textinput.

But it doesn't make the addition of a mail address mandatory like the hacked original textinput...

oh well...

Not  a major thing, its more the other addition that would be helpful to not lose at all during upgrades : CreatePriceDivPerMetre() in helpers\currencydisplay.php
Title: Re: how to override (or complement) VM core functions?
Post by: Milbo on August 05, 2017, 20:29:06 PM
price per meter is the unitprice. it even calculates the price per meter for you.