concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Discounts: show discounted price AND original price #794

Closed mlocati closed 1 year ago

mlocati commented 1 year ago

Case 1

If I set the discounted price for a product, like this:

immagine

website visitors will see the following:

immagine

Case 2

If instead I do the following:

  1. At /dashboard/store/products/groups I create a product group named "10% off"
  2. At /dashboard/store/discounts I create a 10% percentage discount for products in the "10% off" group
  3. Add the product to the "10% off" group

website visitors will see the following:

immagine

Question

Is there a way to show for Case 2 the discounted price and the original price with discounts as when we adopt the Case 1? I mean, I'd like to define discounted products using groups, but display the original & discounted price like when I define the discounted price on a per-product basis.

mlocati commented 1 year ago

I think that in order to do this, we'd need these changes in the view files of the community_product_list and community_product block types:

- $salePrice = $product->getSalePrice();
+ $salePrice = $product->getSalePrice() ?: $product->getPrice();

- $price = $product->getPrice();
+ $price = $product->getPrice(1, true);

- if (isset($salePrice) && "" != $salePrice) {
+ if (isset($salePrice) && "" != $salePrice && $salePrice != $price) {

- $formattedSalePrice = $product->getFormattedSalePrice();
+ $formattedSalePrice = $product->getFormattedSalePrice() ?: $product->getFormattedPrice(1, false);

If that's ok, I can submit a PR