silvercommerce /
tax-admin
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace SilverCommerce\TaxAdmin\Tests\Model; |
||||
| 4 | |||||
| 5 | use SilverStripe\i18n\i18n; |
||||
| 6 | use SilverStripe\Dev\TestOnly; |
||||
| 7 | use SilverStripe\ORM\DataObject; |
||||
| 8 | use SilverCommerce\TaxAdmin\Model\TaxRate; |
||||
| 9 | use SilverCommerce\TaxAdmin\Traits\Taxable; |
||||
| 10 | use SilverCommerce\TaxAdmin\Model\TaxCategory; |
||||
| 11 | use SilverCommerce\TaxAdmin\Interfaces\TaxableProvider; |
||||
| 12 | |||||
| 13 | class TestProduct extends DataObject implements TestOnly, TaxableProvider |
||||
| 14 | { |
||||
| 15 | use Taxable; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * Default behaviour for price with tax (if current instance not set) |
||||
| 19 | * |
||||
| 20 | * @var boolean |
||||
| 21 | */ |
||||
| 22 | private static $show_price_with_tax = false; |
||||
|
0 ignored issues
–
show
|
|||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * Default behaviour for adding the tax string to the rendered currency. |
||||
| 26 | * |
||||
| 27 | * @var boolean |
||||
| 28 | */ |
||||
| 29 | private static $show_tax_string = false; |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | |||||
| 31 | private static $db = [ |
||||
|
0 ignored issues
–
show
|
|||||
| 32 | "Title" => "Varchar", |
||||
| 33 | "BasePrice" => 'Decimal(9,3)', |
||||
| 34 | "StockID" => "Varchar", |
||||
| 35 | "StockLevel" => "Int", |
||||
| 36 | "Weight" => "Decimal" |
||||
| 37 | ]; |
||||
| 38 | |||||
| 39 | private static $has_one = [ |
||||
|
0 ignored issues
–
show
|
|||||
| 40 | 'TaxRate' => TaxRate::class, |
||||
| 41 | 'TaxCategory' => TaxCategory::class |
||||
| 42 | ]; |
||||
| 43 | |||||
| 44 | public function getBasePrice() |
||||
| 45 | { |
||||
| 46 | return $this->dbObject('BasePrice')->getValue(); |
||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Find a tax rate based on the selected ID, or revert to using the valid tax |
||||
| 51 | * from the current category |
||||
| 52 | * |
||||
| 53 | * @return \SilverCommerce\TaxAdmin\Model\TaxRate |
||||
| 54 | */ |
||||
| 55 | public function getTaxRate() |
||||
| 56 | { |
||||
| 57 | $tax = TaxRate::get()->byID($this->getOwner()->TaxRateID); |
||||
|
0 ignored issues
–
show
The method
getOwner() does not exist on SilverCommerce\TaxAdmin\Tests\Model\TestProduct. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 58 | |||||
| 59 | // If no tax explicity set, try to get from category |
||||
| 60 | if (empty($tax)) { |
||||
| 61 | $category = TaxCategory::get()->byID($this->getOwner()->TaxCategoryID); |
||||
| 62 | |||||
| 63 | $tax = (!empty($category)) ? $category->ValidTax() : null ; |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | if (empty($tax)) { |
||||
| 67 | $tax = TaxRate::create(); |
||||
| 68 | $tax->ID = -1; |
||||
| 69 | } |
||||
| 70 | |||||
| 71 | return $tax; |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | /** |
||||
| 75 | * Get should this field automatically show the price including TAX? |
||||
| 76 | * |
||||
| 77 | * @return bool |
||||
| 78 | */ |
||||
| 79 | public function getShowPriceWithTax() |
||||
| 80 | { |
||||
| 81 | return (bool)$this->config()->get('show_price_with_tax'); |
||||
| 82 | } |
||||
| 83 | |||||
| 84 | /** |
||||
| 85 | * Get if this field should add a "Tax String" (EG Includes VAT) to the rendered |
||||
| 86 | * currency? |
||||
| 87 | * |
||||
| 88 | * @return bool|null |
||||
| 89 | */ |
||||
| 90 | public function getShowTaxString() |
||||
| 91 | { |
||||
| 92 | return (bool)$this->config()->get('show_tax_string'); |
||||
| 93 | } |
||||
| 94 | |||||
| 95 | /** |
||||
| 96 | * Return the currently available locale |
||||
| 97 | * |
||||
| 98 | * @return string |
||||
| 99 | */ |
||||
| 100 | public function getLocale() |
||||
| 101 | { |
||||
| 102 | return i18n::get_locale(); |
||||
| 103 | } |
||||
| 104 | } |
||||
| 105 |