Source of file OrderItem.php
Size: 4,649 Bytes - Last Modified: 2021-12-24T05:16:53+00:00
/var/www/docs.ssmods.com/process/src/code/model/OrderItem.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 | <?php /** * OrderItem is a physical component of an order, that describes a product * * @author morven */ class OrderItem extends DataObject { /** * @config */ private static $db = array( "Title" => "Varchar", "StockID" => "Varchar(100)", "Type" => "Varchar", "Customisation" => "Text", "Quantity" => "Int", "Price" => "Currency", "TaxRate" => "Decimal" ); /** * @config */ private static $has_one = array( "Parent" => "Order" ); /** * @config */ private static $summary_fields = array( "Quantity", "Title", "StockID", "CustomisationList", "Price", "TaxRate" ); /** * @config */ private static $casting = array( "Tax" => "Currency" ); /** * Get the amount of tax for a single unit of this item * * @return Float */ public function Tax() { return ($this->Price / 100) * $this->TaxRate; } /** * Unserialise the list of customisations * * @return ArrayList */ public function Customisations() { $customisations = unserialize($this->Customisation); return ($customisations) ? $customisations : ArrayList::create(); } /** * Provide a string of customisations seperated by a comma * * @return String */ public function CustomisationList() { $return = ""; $items = $this->Customisations(); if ($items && $items->exists()) { $i = 1; foreach ($items as $item) { $return .= $item->Title . ': ' . $item->Value; if ($i < $items->count()) { $return .= ", "; } $i++; } } return $return; } /** * Unserialise the list of customisations and rendering into a basic * HTML string * */ public function CustomisationHTML() { $return = HTMLText::create(); $items = $this->Customisations(); $html = ""; if ($items && $items->exists()) { foreach ($items as $item) { $html .= $item->Title . ': ' . $item->Value . ";<br/>"; } } $return->setValue($html); return $return; } /** * Match this item to another object in the Database, by the * provided details. * * @param $relation_name = The class name of the related dataobject * @param $relation_col = The column name of the related object * @param $match_col = The column we use to match the two objects * @return DataObject */ public function Match($relation_name = "Product", $relation_col = "StockID", $match_col = "StockID") { return $relation_name::get() ->filter($relation_col, $this->owner->$match_col) ->first(); } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName("Customisation"); return $fields; } /** * Only order creators or users with VIEW admin rights can view * * @return Boolean */ public function canView($member = null) { $extended = $this->extend('canView', $member); if ($extended && $extended !== null) { return $extended; } return $this->Parent()->canView($member); } /** * Anyone can create an order item * * @return Boolean */ public function canCreate($member = null) { $extended = $this->extend('canCreate', $member); if ($extended && $extended !== null) { return $extended; } return true; } /** * No one can edit items once they are created * * @return Boolean */ public function canEdit($member = null) { $extended = $this->extend('canEdit', $member); if ($extended && $extended !== null) { return $extended; } return $this->Parent()->canEdit($member); } /** * No one can delete items once they are created * * @return Boolean */ public function canDelete($member = null) { $extended = $this->extend('canDelete', $member); if ($extended && $extended !== null) { return $extended; } return $this->Parent()->canEdit($member); } } |