News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Cart net price does not consider discounts same for order prints

Started by AH, June 21, 2013, 12:31:45 PM

Previous topic - Next topic

AH

Apply an override to an item or add a discount before tax. Check the product page and you should see the adjusted product price (without tax) and inclusive of tax (if set)

Head over the cart and ? price is the base price, not what you just saw on the product page - very confusing and incorrect!

This fault also persists in the cart data so database "product_item_price" is incorrect  See images

Code from default_pricelist.php


echo $this->currencyDisplay->createPriceDiv ('basePriceVariant', '', $this->cart->pricesUnformatted[$pkey], FALSE);



BUT  basePriceVariant does not have any discounts applied?

Looking through the calculationh.php



      if (!empty($variant)) {
         $basePriceShopCurrency = $basePriceShopCurrency + doubleval($variant);
         $this->productPrices['basePrice'] = $this->productPrices['basePriceVariant'] = $basePriceShopCurrency;
      }
      if (empty($this->productPrices['basePrice'])) {
         return $this->fillVoidPrices($this->productPrices);
      }
      if (empty($this->productPrices['basePriceVariant'])) {
         $this->productPrices['basePriceVariant'] = $this->productPrices['basePrice'];
      }

      $this->productPrices['basePriceWithTax'] = $this->roundInternal($this->executeCalculation($this->rules['Tax'], $this->productPrices['basePrice'], true),'basePriceWithTax');
      if(!empty($this->rules['VatTax'])){
         $price = !empty($this->productPrices['basePriceWithTax']) ? $this->productPrices['basePriceWithTax'] : $this->productPrices['basePrice'];
         $this->productPrices['basePriceWithTax'] = $this->roundInternal($this->executeCalculation($this->rules['VatTax'], $price,true),'basePriceWithTax');
      }

      $this->productPrices['discountedPriceWithoutTax'] = $this->roundInternal($this->executeCalculation($this->rules['DBTax'], $this->productPrices['basePrice']),'discountedPriceWithoutTax');

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

$priceBeforeTax = !empty($this->productPrices['discountedPriceWithoutTax']) ? $this->productPrices['discountedPriceWithoutTax'] : $this->productPrices['basePrice'];

      $this->productPrices['priceBeforeTax'] = $priceBeforeTax;
      $this->productPrices['salesPrice'] = $this->roundInternal($this->executeCalculation($this->rules['Tax'], $priceBeforeTax, true),'salesPrice');

      $salesPrice = !empty($this->productPrices['salesPrice']) ? $this->productPrices['salesPrice'] : $priceBeforeTax;

      $this->productPrices['taxAmount'] = $this->roundInternal($salesPrice - $priceBeforeTax);




Recommend that the calculationh.php


if (!empty($variant)) {
$basePriceShopCurrency = $basePriceShopCurrency + doubleval($variant);
$this->productPrices['basePrice'] = $this->productPrices['basePriceVariant'] = $basePriceShopCurrency;
}
if (empty($this->productPrices['basePrice'])) {
return $this->fillVoidPrices($this->productPrices);
}

//quorvia moved
//if (empty($this->productPrices['basePriceVariant'])) {
// $this->productPrices['basePriceVariant'] = $this->productPrices['basePrice'];
//}


$this->productPrices['basePriceWithTax'] = $this->roundInternal($this->executeCalculation($this->rules['Tax'], $this->productPrices['basePrice'], true),'basePriceWithTax');
if(!empty($this->rules['VatTax'])){
$price = !empty($this->productPrices['basePriceWithTax']) ? $this->productPrices['basePriceWithTax'] : $this->productPrices['basePrice'];
$this->productPrices['basePriceWithTax'] = $this->roundInternal($this->executeCalculation($this->rules['VatTax'], $price,true),'basePriceWithTax');
}

$this->productPrices['discountedPriceWithoutTax'] = $this->roundInternal($this->executeCalculation($this->rules['DBTax'], $this->productPrices['basePrice']),'discountedPriceWithoutTax');

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

$priceBeforeTax = !empty($this->productPrices['discountedPriceWithoutTax']) ? $this->productPrices['discountedPriceWithoutTax'] : $this->productPrices['basePrice'];

$this->productPrices['priceBeforeTax'] = $priceBeforeTax;
//quorvia moved here and set to $priceBeforeTax
if (empty($this->productPrices['basePriceVariant'])) {
$this->productPrices['basePriceVariant'] = $priceBeforeTax;
}






This does not solve the CART price issue when a discount is applied, just sorts out the display of the cart - what gets written to the database is still the base price without a discount!!

[attachment cleanup by admin]
Regards
A

Joomla 4.4.5
php 8.1

AH

Regards
A

Joomla 4.4.5
php 8.1

K&K media production


AH

Does the change sort the cart/order print and database details??
Regards
A

Joomla 4.4.5
php 8.1

Milbo

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

K&K media production

You have on all views the old price with line-through and the new discounted price

the prices are in DB in order_items table and now there is also the discounted price without tax

AH

Milbo and KK

Installed and ran through a number of tests.

The "product_item_price" should be the Net Price. What is still being stored in the database is the Base price

Creating another variable, allows for a visual display of a price but does not resolve the situtation

This becomes more apparent when looking at the database "order_items" and running a revenue report

Revenue report correctly sees netto as qty * product_item_price (on the order item database table)

$selectFields[] = 'SUM(product_item_price * product_quantity) as order_subtotal_netto';
$selectFields[] = 'SUM(product_subtotal_with_tax) as order_subtotal_brutto';



IN addition - can you let me know where this configuration variable is available for setting?


<?php
if (VmConfig::get ('checkout_show_origprice'1) && $this->cart->pricesUnformatted[$pkey]['discountedPriceWithoutTax']) {
echo '<span class="line-through">' $this->currencyDisplay->createPriceDiv ('basePriceVariant'''$this->cart->pricesUnformatted[$pkey], TRUEFALSE) . '</span><br />';
}
if ($this->cart->pricesUnformatted[$pkey]['discountedPriceWithoutTax']) {
echo $this->currencyDisplay->createPriceDiv ('discountedPriceWithoutTax'''$this->cart->pricesUnformatted[$pkey], FALSEFALSE);
} else {
echo $this->currencyDisplay->createPriceDiv ('basePriceVariant'''$this->cart->pricesUnformatted[$pkey], FALSEFALSE);
}
//  echo $prow->salesPrice ;
?>





Regards
A

Joomla 4.4.5
php 8.1

K&K media production

sorry, I don't understand your problem ... all views of prices and discounts are the same and all prices are stored in DB (order and order_items)

AH

KK

product_price is not correct and just adding another variable has not solved the issue.  Product_item price should be the Net Price.

See my database displays in the image:-

Base price = 100
Tax Vat per product = 20%
Discount Item before tax =  -10%

Example A is with discount applied
Example B is with no discount


Example A Discount is set to be on.

The discount is BEFORE tax (DBTax) therefore the product price is 100 - 10%  = 90.00
Product_tax is  18 - but that is  NOT the tax on an product item price of 100.00

The product_basePriceWithTax is not 120.00 it is  108.00

The product_item_price is  90.00



The revenue report shows that the systems views product_item_price as the NET price.



[attachment cleanup by admin]
Regards
A

Joomla 4.4.5
php 8.1

K&K media production

#9
All is right

DBTax:

(item_price - DBTax) + VatTax = final_price

(100 - 10) + 90 * 20% = 108

basePriceWithTax:

item_price + VatTax = basePriceWithTax

100 + 100 * 20% = 120

AH

KK

Thanks for taking the time to discuss this.

Final price = 108.00

If tax is 20%. What is the Net price of the item (item_price) ?

And what revenue will I receive from an order of 1 item with a final price of 108.00 ?

If you run the VM revenue report you will see the problem with not saving the Actual Net Price as product_item_price

The original base price has relevance only to the calculation of the product price

In this instance the net price of the item is (baseprice - discounts before tax = 100 - 10% = 90)

The product item price for the purpose of taxation is thus 90 + 20% = 108

Apologies for not posting the dbase results in the example below, I have attached them here.







[attachment cleanup by admin]
Regards
A

Joomla 4.4.5
php 8.1

AH

Fixed.
revenue report can be run and so can your own reports using dtabase values!
2.0.22
Regards
A

Joomla 4.4.5
php 8.1