wagnerwagner / merx

Merx is a plugin to create online shops with Kirby.
https://merx.wagnerwagner.de
104 stars 10 forks source link

Discount per product? #58

Closed Tazi0 closed 2 years ago

Tazi0 commented 2 years ago

Is there a way to have a discount on a product? I've fumbled around with the ww.merx.cart & editing the price itself, but there doesn't seem a way to correctly apply the discount.

tobiasfabian commented 2 years ago

Hi @Tazi0,

thanks for your question. In the first place, Merx only needs to know the price to be paid in the end (in your case, that would be the discount price). Any other price (e.g. the original price) is not relevant for Merx. It is only a question of the user interface, in the first place.

If you want to store the original price (e.g. to show the original price on the invoice) you can to pass the original price to the Cart::add() method as shown below.

Add item to cart

$productPage = page('bike');
$cart->add([
  'id' => $productPage->id(),
  'price' => $productPage->price(), // something like `$productPage->originalPrice() * 0.8` would be possible as well
  'originalPrice' => $productPage->originalPrice(),
]);

View cart

echo $cartItem->originalPrice()