Source of file OrderStepSecurityCheck.php
Size: 3,801 Bytes - Last Modified: 2021-12-23T10:41:15+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Process/OrderStepSecurityCheck.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | <?php namespace Sunnysideup\EcommerceSecurity\Model\Process; use SilverStripe\Forms\FieldList; use Sunnysideup\Ecommerce\Interfaces\OrderStepInterface; use Sunnysideup\Ecommerce\Model\Order; use Sunnysideup\Ecommerce\Model\Process\OrderStep; /** * @authors: Nicolaas [at] Sunny Side Up .co.nz * @package: ecommerce * @sub-package: model * @inspiration: Silverstripe Ltd, Jeremy */ class OrderStepSecurityCheck extends OrderStep implements OrderStepInterface { /** * The OrderStatusLog that is relevant to the particular step. * * @var string */ protected $relevantLogEntryClassName = OrderStatusLogSecurityCheck::class; private static $table_name = 'OrderStepSecurityCheck'; private static $defaults = [ 'CustomerCanEdit' => 0, 'CustomerCanCancel' => 0, 'CustomerCanPay' => 0, 'Name' => 'Security Check for Order', 'Code' => 'SECURITY_CHECK', 'ShowAsInProcessOrder' => 1, 'HideStepFromCustomer' => 1, ]; private static $_my_order; public function getCMSFields() { return parent::getCMSFields(); } /** *initStep: * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). * should be able to run this function many times to check if the step is ready. * * @see Order::doNextStatus * * @return bool - true if the current step is ready to be run... */ public function initStep(Order $order): bool { $logsExist = $this->RelevantLogEntries($order)->exists(); if (! $logsExist) { $className = $this->relevantLogEntryClassName; $object = $className::create(); $object->OrderID = $order->ID; $object->write(); } return true; } /** *doStep: * should only be able to run this function once * (init stops you from running it twice - in theory....) * runs the actual step. * * @see Order::doNextStatus * * @return bool - true if run correctly */ public function doStep(Order $order): bool { $entry = $this->RelevantLogEntry($order); if ($entry) { return $entry->pass(); } return false; } /** *nextStep: * returns the next step (after it checks if everything is in place for the next step to run...). * * @see Order::doNextStatus * * @return null|OrderStep (next step OrderStep object) */ public function nextStep(Order $order) { if ($this->doStep($order)) { return parent::nextStep($order); } return null; } /** * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. * * @return FieldList */ public function addOrderStepFields(FieldList $fields, Order $order, ?bool $nothingToDo = false) { $fields = parent::addOrderStepFields($fields, $order); $title = _t('OrderStep.MUST_ACTION_SECURITY_CHECKS', ' ... To move this order to the next step you have to carry out a bunch of security checks.'); $field = $order->getOrderStatusLogsTableFieldEditable(OrderStatusLogSecurityCheck::class, $title); $fields->addFieldsToTab( 'Root.Next', [ $field, ] ); return $fields; } /** * For some ordersteps this returns true... * * @return bool */ protected function hasCustomerMessage() { return false; } /** * Explains the current order step. * * @return string */ protected function myDescription() { return 'Make sure that the Order is safe to proceed'; } } |