Price override and custom fields price - fix for new releases

Started by rdcustom, December 09, 2022, 08:10:54 AM

Previous topic - Next topic

rdcustom

Hello.
Since years users keep asking a solution to the custom fields price not applied when price override is active.

I wrote a temporary fix, but when this can be integrated in VM?

calculationh.php - line 443
Replace:

"if ($override==1) {
         $this->productPrices['salesPrice'] = $product_override_price;
      }"

With:

"iif ($override==1) {
         if(empty($this->rules['VatTax'])){
      $this->productPrices['salesPrice'] = $product_override_price/1.22 + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
   $this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice*1.22 ;
}
      }"

(this has been done for Italian 22% VAT but can be changed with the rule applied)

It is annoying, I need to manually change it on every update

Milbo

Quote from: rdcustom on December 09, 2022, 08:10:54 AM
...., but when this can be integrated in VM?

First time that I am aware of this fix. It can be integrated, if someone delivers the code.

Quote from: rdcustom on December 09, 2022, 08:10:54 AM

It is annoying, I need to manually change it on every update

Sadly you posted it one day too late to be part of the core already. If you would have posted the solution earlier, you could be less annoyed :-)

Anyway I can add it
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rdcustom

Quote from: Milbo on December 09, 2022, 21:15:35 PM
Quote from: rdcustom on December 09, 2022, 08:10:54 AM
...., but when this can be integrated in VM?

First time that I am aware of this fix. It can be integrated, if someone delivers the code.

Quote from: rdcustom on December 09, 2022, 08:10:54 AM

It is annoying, I need to manually change it on every update

Sadly you posted it one day too late to be part of the core already. If you would have posted the solution earlier, you could be less annoyed :-)

Anyway I can add it

thanks Milbo,

this code is not perfect (as it only works with Italian VAT). It should be modified with the applied TAX variable, but I am not a programmer and honestly I don't know how to manage this.
i will try to find a solution for this unless someone can help


rdcustom

how can I replace 1.22 with the applied tax rule?

which is the variable?

also, I need to transform the (example) 22% into 1.22 but I am not good at PHP and I think this need a calculation

Milbo

ah,. dam, I forgot to add it, I fear.

The main problem here is, that this "override price" thing was never really meant to be used, it was an old vm1.1 thing.

The override price is currently used for rounding problems. with your fix it can be used as "individual discount by setting fixed price". Good that you mention that with the tax. Yeh but I hope you know that will take maybe an hour or so to get it work.

There are two things left in VM, one is the possibility to set the final prices (not net) and the other is to set a simple discount.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rdcustom

Okay, I think I found the solution:


Line 443:

"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
      if ($override==1) {
         if(empty($this->rules['VatTax'])){
      $this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
   $this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
      }"

this should work with all taxes applied

sirius

hi
I'm with the VirtueMart 4.0.12 10777
but I can't see anymore the price override option on the price section, is this normal ?
J3.10.12 | PHP 7.4.33 + APC + memcached + Opcode
VM Prod : 3.8.6 | VM Test : 4.0.12.10777

Jörgen

It is now a hidden config. Search the forum or check the docs.
Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

sirius

hidden config on the new admin template so, because with the old one it's ok
J3.10.12 | PHP 7.4.33 + APC + memcached + Opcode
VM Prod : 3.8.6 | VM Test : 4.0.12.10777

jenkinhill

Turn on "Show expert pricing options" on the Configuration/Pricing/Price Configuration tab.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

sirius

J3.10.12 | PHP 7.4.33 + APC + memcached + Opcode
VM Prod : 3.8.6 | VM Test : 4.0.12.10777

Milbo

Quote from: rdcustom on December 22, 2022, 18:59:35 PM
Okay, I think I found the solution:


Line 443:

"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
      if ($override==1) {
         if(empty($this->rules['VatTax'])){
      $this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
   $this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
      }"

this should work with all taxes applied

Great :-) How long did it take?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

Do you mean it like that?

if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}


I added it to the code like that. Lets see what tests say.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rdcustom

Quote from: Milbo on December 29, 2022, 22:22:19 PM
Quote from: rdcustom on December 22, 2022, 18:59:35 PM
Okay, I think I found the solution:


Line 443:

"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
      if ($override==1) {
         if(empty($this->rules['VatTax'])){
      $this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
   $this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
      }"

this should work with all taxes applied

Great :-) How long did it take?

around 15 minutes :D

rdcustom

Quote from: Milbo on December 29, 2022, 22:35:27 PM
Do you mean it like that?

if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}


I added it to the code like that. Lets see what tests say.

thanks! but I am still working on it cause I found a bug.
This works only when the Vat is applied.
In all cases without VAT (when the VAT is 0%) it gives a calculation error (division by zero).

the issue is:

i override the price INCLUDING the vat, this is fine as long as I sell with VAT applied.
but if the customer is in a group without VAT, the rule can't know how much is the VAT applied to override.

Still working on it, I think I have to apply the VAT and then subtract it.