Source of file PostageOption.php
Size: 2,964 Bytes - Last Modified: 2021-12-23T10:24:37+00:00
/var/www/docs.ssmods.com/process/src/src/Helpers/PostageOption.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 | <?php namespace SilverCommerce\Postage\Helpers; use SilverCommerce\TaxAdmin\Model\TaxRate; use SilverStripe\Core\Injector\Injectable; use SilverStripe\ORM\FieldType\DBCurrency; /** * Generic container for postage data, PossiblePostage objects need to be * created by PostageTypes and then returned as part of the ArrayList * * This object contains 3 generic params: * * - name (the name of the postage) * - price (the cost of this object) * - tax (the TaxCategory assigned to this object) */ class PostageOption { use Injectable; /** * The Name of the current postage item */ protected $name = null; /** * Get the value of name */ public function getName() { return $this->name; } /** * Set the value of name * * @return self */ public function setName($name) { $this->name = $name; return $this; } /** * The price of this current shipping option * * @var int */ protected $price = 0; /** * Get the value of price */ public function getPrice() { return $this->price; } /** * Set the value of price * * @return self */ public function setPrice($price) { $this->price = $price; return $this; } /** * Assign tax to this item, this should be an instance of * TaxCategory * * @var TaxRate */ protected $tax = null; /** * Get the value of tax */ public function getTax() { return $this->tax; } /** * Set the value of tax * * @return self */ public function setTax(TaxRate $tax) { $this->tax = $tax; return $this; } /** * Get the monitary value of tax for this option * * @return float */ public function getTaxPrice() { $price = $this->getPrice(); $tax = $this->getTax(); $rate = ($tax && $tax->exists()) ? $tax->Rate : 0; return ($price / 100 * $rate); } /** * Get the total monitary value of this option * * @return float */ public function getTotalPrice() { return $this->getPrice() + $this->getTaxPrice(); } /** * Generate a summary of this postage option * * @var string */ public function getSummary() { $area_currency = new DBCurrency("Cost"); $area_currency->setValue($this->getTotalPrice()); return $this->getName() . " (" . $area_currency->Nice() . ")"; } /** * Generate a unique key for this parcel * * @return string */ public function getKey() { return base64_encode(json_encode((array)$this)); } public function __construct($name, $price, TaxRate $tax = null) { $this->name = $name; $this->price = $price; $this->tax = $tax; } } |