-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PriceCalculator: Added separated discount implementations
- Loading branch information
Showing
7 changed files
with
265 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Sunfox\PriceCalculator\Discount; | ||
|
||
use Nette; | ||
|
||
|
||
class AmountDiscount extends Nette\Object implements \Sunfox\PriceCalculator\IDiscount | ||
{ | ||
/** @var float */ | ||
protected $value = 0.0; | ||
|
||
|
||
/** | ||
* @param int|float | ||
*/ | ||
public function __construct($value) | ||
{ | ||
$this->setValue($value); | ||
} | ||
|
||
/** | ||
* Get discount value. | ||
* | ||
* @return float | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* Set discount value. | ||
* | ||
* @param int|float | ||
* @return IPriceCalculator | ||
*/ | ||
public function setValue($value) | ||
{ | ||
$this->value = (float) $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns price after discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function addDiscount($price) | ||
{ | ||
return $price - $this->value; | ||
} | ||
|
||
/** | ||
* Returns price before discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function removeDiscount($price) | ||
{ | ||
return $price + $this->value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Sunfox\PriceCalculator\Discount; | ||
|
||
use Nette; | ||
|
||
|
||
class PercentDiscount extends Nette\Object implements \Sunfox\PriceCalculator\IDiscount | ||
{ | ||
/** @var float */ | ||
protected $value = 0.0; | ||
|
||
|
||
/** | ||
* @param int|float | ||
*/ | ||
public function __construct($value) | ||
{ | ||
$this->setValue($value); | ||
} | ||
|
||
/** | ||
* Get discount value. | ||
* | ||
* @return float | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* Set discount value. | ||
* | ||
* @param int|float | ||
* @return IPriceCalculator | ||
*/ | ||
public function setValue($value) | ||
{ | ||
$this->value = (float) $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns price after discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function addDiscount($price) | ||
{ | ||
return $price * (1 - $this->value / 100); | ||
} | ||
|
||
/** | ||
* Returns price before discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function removeDiscount($price) | ||
{ | ||
return $price / (1 - $this->value / 100); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Sunfox\PriceCalculator; | ||
|
||
use Nette; | ||
|
||
|
||
interface IDiscount | ||
{ | ||
|
||
/** | ||
* Get discount value. | ||
* | ||
* @return float | ||
*/ | ||
public function getValue(); | ||
|
||
/** | ||
* Set discount value. | ||
* | ||
* @param int|float | ||
* @return IDiscount | ||
*/ | ||
public function setValue($value); | ||
|
||
/** | ||
* Returns price after discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function addDiscount($price); | ||
|
||
/** | ||
* Returns price before discount. | ||
* @param float | ||
* @return float | ||
*/ | ||
public function removeDiscount($price); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.