News:

Looking for documentation? Take a look on our wiki

Main Menu

Only show original and sales price if there is a discount?

Started by modernmagic, September 01, 2023, 08:37:54 AM

Previous topic - Next topic

modernmagic

J4.3.3
VM4.0.12

I cannot figure out how to only show the 2 prices when there is a discount.

See attached.

The product on the left has a discount, so we want to show the original price. 
The product on the right does NOT have a discount, so we only want to display the price once.


GJC Web Design

From memory unless some tax is applied the logic in components\com_virtuemart\sublayouts\prices.php for displaying the sales price is wrong

You need to adjust it there in the code via an over ride
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

modernmagic

Interesting, seems like a major flaw that would cause confusion and looks unprofessional.

Anyone else already fix this and can supply the revised code?

sirius

Hi,
I simply use
if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {
J3.10.12 | PHP 7.4.33 + APC + Opcode
VM Prod : 3.8.6 | VM Test : 4.4.4 11100

modernmagic

Quote from: sirius on September 04, 2023, 17:32:15 PM
if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {

That line is already in prices.php as shown here:
//echo $currency->createPriceDiv ('salesPriceQu', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {
echo $currency->createPriceDiv ('discountedPriceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
echo $currency->createPriceDiv ('discountedPriceWithoutTaxTt', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX_TT', $product->prices);
} else {
echo $currency->createPriceDiv ('priceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
echo $currency->createPriceDiv ('priceWithoutTaxTt', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX_TT', $product->prices);
}
echo $currency->createPriceDiv ('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $product->prices);
echo $currency->createPriceDiv ('discountAmountTt', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT_TT', $product->prices);
echo $currency->createPriceDiv ('taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $product->prices);
echo $currency->createPriceDiv ('taxAmountTt', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT_TT', $product->prices);
$unitPriceDescription = vmText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE', vmText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.strtoupper($product->product_unit)));
echo $currency->createPriceDiv ('unitPrice', $unitPriceDescription, $product->prices);
}


Did you edit anything else? 

sirius

ok
in the case of your "Trim - Textured Slatwall" the "Total without tax:" is use.
but in the "Old Paint White Brick Slatwall" this is the "Sales without tax:".
So those are not the same prices type called.
you must hide the "Sales without tax:" in all case. (if you do not need it at all for sure)
//echo $currency->createPriceDiv ('priceWithoutTaxTt', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX_TT', $product->prices);
And so you will only have two prices in case of a discount.
J3.10.12 | PHP 7.4.33 + APC + Opcode
VM Prod : 3.8.6 | VM Test : 4.4.4 11100

frederi80

I came across your post tonight as I was having the same issue, and was searching all over the place for a solution. It's not a quickstart installation issue and not a template issue. After a lot of playing around with a few different stores and comparing notes, I figured out how to get it to work, except there's another issue that ends up affecting shipping calculation on states that charge sales tax on shipping on the front end while having this active, though calculations show up correctly on the backend receipt. I think this has more to do with their shipping calculation display algos than this solution. I'll explain after showing you how to get it to work. This isn't a joomlart issue, I tried this on three different templates one from base install, one from joomlart quickstart, and one from yootheme, this is an issue that goes back to Joomla 3 virtuemart 3.4.x and still exists on Joomla 5 virtuemart 4.4.10 (tested on both of these versions tonight and it works the same way).

To Make it show how you want it to with the base price crossed out and the sales price showing only when an item is on sale (overwrite price to be taxed), like the following:
$49.95
Sales price $44.95
Discount -$5.00

Then do this:

In Virtuemart goto Configuration > Products > Tax & Calculation Rule

Create a New Rule (I just called it "0 rule" for the time being)
Type of Arithmetic Operation: Tax per product    <---This is the trick to activating what you want
Math Operation: +
Value 0
Currency USD
Category (you have to put all of your categories)
Country USA

Click Save & Close.

It should now work for you on items that have a price overide (overwrite price to be taxed).

The dumb thing here, is this only works via the tax calculation rule being active on the categories you choose.

Now here's the issue I was referring to earlier that goes with this one... and virtuemart team should really fix this (I'm a paid subscription customer).
Any states that you collect tax for, this is where it messes up the front end calculation for shipping, but it ends up being correct on the emailed receipt and the order receipt in the backend. So a customer may get confused initially and possibly complain.

Example:
With this Enabled I get the following at checkout on a state that collects tax on shipping

Subtotal $44.95
Shipment Fee $7.14  (when it should be $6.60, it's adding in the state tax of $0.535 to this fee in the front end)
NM Tax $4.18 (it's also adding in the shipping tax in this) (tax on product is $3.65 as it shows in the back end receipt)
Total $55.73 (this of course doesn't add up to $55.73 if you do the math, but $55.73 is the correct total that includes the $3.65 product tax and $0.535 shipping tax, when all is said and done in the backend)

If I disable this tax & calculation rule then it'll show the following on the front end for the customer
Subtotal $44.95
Shipment Fee $6.60 (this is correct)
NM Tax $4.18 (this is correct)
Total $55.73 (this is correct)

And this reminded me of another shipping price issue that has nothing to do with this one. I've had this issue since vm 3.4.x, the tax calculation on the shipping (some states require tax on shipping) on the front end under the shipping selection section it miscalculates, though it's correct again in the backend receipt and emailed receipt.
It shows $7.67 on front end (tax on $6.60 shipping should be $0.535 = $7.14, but it likes to add in 2x the shipping tax). And I know there's been other complaints about this for the last 8 years, but no one fixes it.... :(

Anyway, hope that helps someone out there. If anyone has a solution for the tax miscalcs on the shipping please let me know.

frederi80

ONE MORE THING! Under Virtuemart Configuration > Configuration > Configuration > Pricing
Make sure the following are selected:
*Baseprice with Tax, but without discounts
*Final salesprice
*Discount amount

frederi80

One more thing, Since I have to charge tax on shipping to some states I've tried using Vat Tax (which adds the tax into the product and tax into the shipping cost on front end, but it also makes this happen on the back end so when importing orders it messes everything up and pulls tax twice....and Tax per bill well, seems to be the only method that makes the numbers right, but it won't cross out the base price (just goes blank and shows the sales price if we have the baseprice with tax, but without discounts checked)... so, I don't think this works at all still... just have to go with having two prices showing all the time...
This works great if you don't have to charge tax on shipping anywhere.
But the shipping calcs get goofy with both methods if you have to tax shipping.