lib/composer/DiscountBundle/src/VisualMedia/DiscountBundle/Discount/Factory/FixedDiscount.php line 35

Open in your IDE?
  1. <?php
  2. /**
  3. * Fixed Discount
  4. *
  5. * (c) Bertin van den Ham <b.vandenham@dappr.nl>
  6. */
  7. namespace VisualMedia\DiscountBundle\Discount\Factory;
  8. use VisualMedia\DiscountBundle\Discount\DiscountFactory;
  9. use VisualMedia\DiscountBundle\Discount\DiscountFactoryInterface;
  10. use VisualMedia\OrderBundle\Service\Cart;
  11. /**
  12. * Fixed Discount
  13. *
  14. * Fixed Discount on the order
  15. * @example €5,- off the order total
  16. */
  17. class FixedDiscount extends DiscountFactory implements DiscountFactoryInterface
  18. {
  19. public const NAME = 'fixed_discount';
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public static function getName(): string
  24. {
  25. return static::NAME;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function getDiscount(Cart $cart = null): float
  31. {
  32. if (null === $order = $cart->getOrder()) {
  33. return 0;
  34. }
  35. if (null === $discount = $order->getDiscount()) {
  36. return 0;
  37. }
  38. return (float) $discount->getValue();
  39. }
  40. }