Source of file OrderStatusLogSubmitted.php
Size: 4,390 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Process/OrderStatusLogs/OrderStatusLogSubmitted.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 | <?php namespace Sunnysideup\Ecommerce\Model\Process\OrderStatusLogs; use SilverStripe\ORM\DataObject; use SilverStripe\Security\Security; use Sunnysideup\Ecommerce\Config\EcommerceConfig; use Sunnysideup\Ecommerce\Model\Order; use Sunnysideup\Ecommerce\Model\Process\OrderStatusLog; /** * OrderStatusLogSubmitted is an important class that is created when an order is submitted. * It is created by the order and it signifies to the OrderStep to continue to the next step. * * @authors: Nicolaas [at] Sunny Side Up .co.nz * @package: ecommerce * @sub-package: model */ class OrderStatusLogSubmitted extends OrderStatusLog { private static $table_name = 'OrderStatusLogSubmitted'; private static $db = [ 'OrderAsHTML' => 'HTMLText', 'OrderAsString' => 'Text', 'SequentialOrderNumber' => 'Int', 'Total' => 'Currency', 'SubTotal' => 'Currency', ]; private static $defaults = [ 'InternalUseOnly' => true, ]; private static $casting = [ 'HTMLRepresentation' => 'HTMLText', ]; private static $singular_name = 'Submitted Order'; private static $plural_name = 'Submitted Orders'; /** * Standard SS variable. * * @var string */ private static $description = 'The record that the order has been submitted by the customer. This is important in e-commerce, because from here, nothing can change to the order.'; public function i18n_singular_name() { return _t('OrderStatusLog.SUBMITTEDORDER', 'Submitted Order - Fulltext Backup'); } public function i18n_plural_name() { return _t('OrderStatusLog.SUBMITTEDORDERS', 'Submitted Orders - Fulltext Backup'); } /** * Standard SS method. * * @param \SilverStripe\Security\Member $member * * @return bool */ public function canDelete($member = null) { return false; } /** * Standard SS method. * * @param \SilverStripe\Security\Member $member * @param mixed $context * * @return bool */ public function canEdit($member = null, $context = []) { return false; } /** * Standard SS method. * * @param \SilverStripe\Security\Member $member * @param mixed $context * * @return bool */ public function canCreate($member = null, $context = []) { if (! $member) { $member = Security::getCurrentUser(); } $extended = $this->extendedCan(__FUNCTION__, $member); if (null !== $extended) { return $extended; } return true; } /** * can only be created when the order is submitted. * * @return string */ public function HTMLRepresentation() { return $this->getHTMLRepresentation(); } public function getHTMLRepresentation() { if ($this->OrderAsHTML) { return $this->OrderAsHTML; } if ($this->OrderAsString) { return unserialize($this->OrderAsString); } return _t('OrderStatusLog.NO_FURTHER_INFO_AVAILABLE', 'no further information available'); } /** * adding a sequential order number. */ protected function onBeforeWrite() { parent::onBeforeWrite(); $order = $this->getOrderCached(); if ($order) { if (! $this->Total) { $this->Total = $order->Total(); $this->SubTotal = $order->SubTotal(); } } if (! (int) $this->SequentialOrderNumber) { $this->SequentialOrderNumber = 1; $min = (int) EcommerceConfig::get(Order::class, 'order_id_start_number') - 0; $id = null !== $this->ID ? (int) $this->ID : 0; $lastOne = DataObject::get_one( OrderStatusLogSubmitted::class, "'ID' != '" . $id . "'", $cacheDataObjectGetOne = true, ['SequentialOrderNumber' => 'DESC'] ); if ($lastOne) { $this->SequentialOrderNumber = (int) $lastOne->SequentialOrderNumber + 1; } if ((int) $min && $this->SequentialOrderNumber < $min) { $this->SequentialOrderNumber = $min; } } } } |