|
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; |
|
|
|
|
|
|
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; |
|
|
|
|
|
|
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; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
private static $db = [ |
|
|
|
|
|
|
32
|
|
|
"Title" => "Varchar", |
|
33
|
|
|
"BasePrice" => 'Decimal(9,3)', |
|
34
|
|
|
"StockID" => "Varchar" |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
38
|
|
|
'TaxRate' => TaxRate::class, |
|
39
|
|
|
'TaxCategory' => TaxCategory::class |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
public function getBasePrice() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->dbObject('BasePrice')->getValue(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Find a tax rate based on the selected ID, or revert to using the valid tax |
|
49
|
|
|
* from the current category |
|
50
|
|
|
* |
|
51
|
|
|
* @return \SilverCommerce\TaxAdmin\Model\TaxRate |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getTaxRate() |
|
54
|
|
|
{ |
|
55
|
|
|
$tax = TaxRate::get()->byID($this->getOwner()->TaxRateID); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
// If no tax explicity set, try to get from category |
|
58
|
|
|
if (empty($tax)) { |
|
59
|
|
|
$category = TaxCategory::get()->byID($this->getOwner()->TaxCategoryID); |
|
60
|
|
|
|
|
61
|
|
|
$tax = (!empty($category)) ? $category->ValidTax() : null ; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (empty($tax)) { |
|
65
|
|
|
$tax = TaxRate::create(); |
|
66
|
|
|
$tax->ID = -1; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $tax; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get should this field automatically show the price including TAX? |
|
74
|
|
|
* |
|
75
|
|
|
* @return bool |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getShowPriceWithTax() |
|
78
|
|
|
{ |
|
79
|
|
|
return (bool)$this->config()->get('show_price_with_tax'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get if this field should add a "Tax String" (EG Includes VAT) to the rendered |
|
84
|
|
|
* currency? |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool|null |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getShowTaxString() |
|
89
|
|
|
{ |
|
90
|
|
|
return (bool)$this->config()->get('show_tax_string'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Return the currently available locale |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getLocale() |
|
99
|
|
|
{ |
|
100
|
|
|
return i18n::get_locale(); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|