VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: rdcustom on December 09, 2022, 08:10:54 AM

Title: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 09, 2022, 08:10:54 AM
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
Title: Re: Price override and custom fields price - fix for new releases
Post by: 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
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 10, 2022, 11:58:09 AM
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

Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 17, 2022, 11:35:55 AM
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
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on December 20, 2022, 21:41:27 PM
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.
Title: Re: Price override and custom fields price - fix for new releases
Post by: 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
Title: Re: Price override and custom fields price - fix for new releases
Post by: sirius on December 27, 2022, 15:59:55 PM
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 ?
Title: Re: Price override and custom fields price - fix for new releases
Post by: Jörgen on December 27, 2022, 16:06:34 PM
It is now a hidden config. Search the forum or check the docs.
Jörgen
Title: Re: Price override and custom fields price - fix for new releases
Post by: sirius on December 27, 2022, 16:07:47 PM
hidden config on the new admin template so, because with the old one it's ok
Title: Re: Price override and custom fields price - fix for new releases
Post by: jenkinhill on December 27, 2022, 17:52:36 PM
Turn on "Show expert pricing options" on the Configuration/Pricing/Price Configuration tab.
Title: Re: Price override and custom fields price - fix for new releases
Post by: sirius on December 29, 2022, 17:18:11 PM
Thanks jenkinhill...
Title: Re: Price override and custom fields price - fix for new releases
Post by: 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?
Title: Re: Price override and custom fields price - fix for new releases
Post by: 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.
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 30, 2022, 08:56:10 AM
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
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 30, 2022, 08:59:33 AM
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.
Title: Re: Price override and custom fields price - fix for new releases
Post by: GJC Web Design on December 30, 2022, 10:16:14 AM
??

if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
if(!empty($this->rules['VatTax'])){
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}else{
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
}
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on December 30, 2022, 10:49:26 AM
nothing, I think the only solution for this is to handle the override without VAT and then apply the rule if needed.

this works with and without VAT applied, but needs the override WITHOUT vat

"//OVERRIDE

      if ($override==1) {

         if(empty($this->rules['VatTax']))
             {$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice;}

               else
               {$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
            $this->productPrices['salesPrice'] = $product_override_price/$vat + $salesPrice - $costPrice/$vat ;}
      }

         //OVERRIDE END"
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on January 08, 2023, 22:05:02 PM
Quote from: rdcustom on December 30, 2022, 08:56:10 AM
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

Yes, because you was just in it. Additionally, it often happens that i add something like that and the real work comes later, if people with other configurations get problems. Lets see how it works.


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.

Exactly, but great that you keep on it.
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on January 08, 2023, 22:07:03 PM
Quote from: rdcustom on December 30, 2022, 10:49:26 AM
this works with and without VAT applied, but needs the override WITHOUT vat
You mean they should set the price as net, as we do normally? And now you see the problems developing VM or ecommerce. Some people use it to remove rounding erros of the final price and most people use it for a fast discount. So the solution must be to enter the final price, the brutto price.
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on January 09, 2023, 10:59:54 AM
I think it should just look like that

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

if($variant){
if(!empty($this->rules['VatTax'])){
$variant = $this->roundInternal($this->executeCalculation($this->rules['VatTax'], $variant),'salesPrice');
}
$this->productPrices['salesPrice'] += $variant;
}
}
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on January 09, 2023, 12:05:43 PM
Quote from: Milbo on January 08, 2023, 22:07:03 PM
Quote from: rdcustom on December 30, 2022, 10:49:26 AM
this works with and without VAT applied, but needs the override WITHOUT vat
You mean they should set the price as net, as we do normally? And now you see the problems developing VM or ecommerce. Some people use it to remove rounding erros of the final price and most people use it for a fast discount. So the solution must be to enter the final price, the brutto price.

this is the issue I found:

with the normal price, there's the "calculate cost price" options that automatically removes VAT if applied.
On the override field there's no option to do this, so we need to put the "new base price" manually and then the system will apply the VAT if needed.
Minor issue, but this can be an idea for future upgrades (placing a "calculate" flag also on override).

Anyway, in this way this option can also be used as a temporary discounted price and I think it can be useful (at least... I use it in this way).
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on January 11, 2023, 22:00:32 PM
Did you check my code?

You can just set the final price, with tax. People want an easy way to set a discount, with tax. They see the old price with tax for example 49.90 an they want to make it 39.9, thats it. and imho the new code works.

I plan the whole time to enable also the direct input with finalprices. But I think I need a fundraising campaign for that.
Title: Re: Price override and custom fields price - fix for new releases
Post by: sirius on January 12, 2023, 14:50:26 PM
Hi all,
I tested Milbo's patch
My results with VM 4.0.12 10777
My VAT is 20%

Override the final price set to 700
Results without variant applied
Results with variant +50 applied
Overcharge the price before VAT set to 700
Results without variant applied
Results with variant +50 applied
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on May 08, 2023, 15:44:45 PM
in case of Override of "price without tax":

line 413:

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

         if($variant){

            $this->productPrices['discountedPriceWithoutTax'] += $variant;
         }
      }
Title: Re: Price override and custom fields price - fix for new releases
Post by: rdcustom on May 29, 2023, 08:56:15 AM
...just for being sure that my last post was read and implemented in the update
Title: Re: Price override and custom fields price - fix for new releases
Post by: Milbo on May 30, 2023, 19:33:11 PM
Thank you, just added
Title: Re: Price override and custom fields price - fix for new releases
Post by: balai on June 02, 2023, 16:45:31 PM
So this is adding VAT to the price override.
Max i think that you will break many sites by adding that modification.

For years the price override is the final/sales price