Issues (42)

src/Model/CartReservation.php (9 issues)

1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Model;
4
5
use Dynamic\Foxy\Model\FoxyHelper;
6
use SilverStripe\CMS\Model\SiteTree;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\ReadonlyField;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use SilverStripe\Security\Permission;
12
use SilverStripe\Security\Security;
13
14
/**
15
 * Class CartReservation
16
 * @package Dynamic\Foxy\Inventory\Model
17
 *
18
 * @property int $ProductID
19
 * @property int $CartProductID
20
 * @property string $Code
21
 * @property DBDatetime $Expires
22
 * @property string $Cart
23
 */
24
class CartReservation extends DataObject
25
{
26
    /**
27
     * @var string
28
     */
29
    private static $singular_name = 'Cart Reservation';
0 ignored issues
show
The private property $singular_name is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @var string
33
     */
34
    private static $plural_name = 'Cart Reservations';
0 ignored issues
show
The private property $plural_name is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @var string
38
     */
39
    private static $table_name = 'FoxyCartReservation';
0 ignored issues
show
The private property $table_name is not used, and could be removed.
Loading history...
40
41
    /**
42
     * @var array
43
     */
44
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
45
        'ProductID' => 'Int',
46
        'CartProductID' => 'Int',
47
        'Code' => 'Varchar(255)',
48
        'Expires' => 'DBDatetime',
49
        'Cart' => 'Varchar(255)',
50
    ];
51
52
    /**
53
     * @var array
54
     */
55
    private static $summary_fields = [
0 ignored issues
show
The private property $summary_fields is not used, and could be removed.
Loading history...
56
        'Cart' => 'Cart Reference',
57
        'Expires.Nice' => 'Expires',
58
    ];
59
60
    /**
61
     * @return FieldList
62
     */
63
    public function getCMSFields()
64
    {
65
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
66
            $fields->addFieldToTab('Root.Main', ReadonlyField::create('ReservationCode')->setTitle('Reservation Code'));
67
        });
68
        return parent::getCMSFields();
69
    }
70
71
    /**
72
     *
73
     */
74
    public function onBeforeWrite()
75
    {
76
        parent::onBeforeWrite();
77
        if (!$this->ProductID) {
78
            $helper = FoxyHelper::create();
79
            if ($product = $helper->getProducts()->filter('Code', $this->Code)->first()) {
80
                $this->ProductID = $product->ID;
81
            }
82
        }
83
    }
84
85
    /**
86
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
87
     * @param array $context
88
     * @return bool
89
     */
90
    public function canCreate($member = null, $context = [])
91
    {
92
        return false;
93
    }
94
95
    /**
96
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
97
     * @return bool
98
     */
99
    public function canEdit($member = null)
100
    {
101
        return false;
102
    }
103
104
    /**
105
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
106
     * @return bool|int
107
     */
108
    public function canDelete($member = null)
109
    {
110
        return Permission::check('ADMIN', 'any', Security::getCurrentUser());
111
    }
112
113
    /**
114
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
115
     * @return bool
116
     */
117
    public function canView($member = null)
118
    {
119
        return true;
120
    }
121
}
122