Source of file OrderStepConfirmed.php
Size: 3,703 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Process/OrderSteps/OrderStepConfirmed.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | <?php namespace Sunnysideup\Ecommerce\Model\Process\OrderSteps; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use Sunnysideup\Ecommerce\Config\EcommerceConfig; use Sunnysideup\Ecommerce\Interfaces\OrderStepInterface; use Sunnysideup\Ecommerce\Model\Order; use Sunnysideup\Ecommerce\Model\Process\OrderStatusLogs\OrderStatusLogPaymentCheck; use Sunnysideup\Ecommerce\Model\Process\OrderStep; /** * @authors: Nicolaas [at] Sunny Side Up .co.nz * @package: ecommerce * @sub-package: model */ class OrderStepConfirmed extends OrderStep implements OrderStepInterface { /** * @var string */ protected $relevantLogEntryClassName = OrderStatusLogPaymentCheck::class; /** * @var array */ private static $list_of_things_to_check = [ 'check1' => 'Payment has arrived in Bank Account', 'check2' => 'Products are available', ]; private static $defaults = [ 'CustomerCanEdit' => 0, 'CustomerCanCancel' => 0, 'CustomerCanPay' => 0, 'Name' => 'Confirm', 'Code' => 'CONFIRMED', 'ShowAsInProcessOrder' => 1, 'HideStepFromCustomer' => 1, ]; /** *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 { 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 { return true; } /** * can go to next step if order payment has been confirmed... * * @return null|OrderStep */ public function nextStep(Order $order) { $className = $this->getRelevantLogEntryClassName(); $orderStatusLog_PaymentChecks = $className::get() ->Filter([ 'OrderID' => $order->ID, 'PaymentConfirmed' => 1, ]) ; if ($orderStatusLog_PaymentChecks->exists()) { return parent::nextStep($order); } return null; } /** * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. * * @return \SilverStripe\Forms\FieldList */ public function addOrderStepFields(FieldList $fields, Order $order, ?bool $nothingToDo = false) { $fields = parent::addOrderStepFields($fields, $order); $title = _t('OrderStep.MUSTDOPAYMENTCHECK', ' ... To move this order to the next step you must carry out a payment check (is the money in the bank?) by creating a record here (click me)'); $fields->addFieldsToTab( 'Root.Next', [ $order->getOrderStatusLogsTableField(OrderStatusLogPaymentCheck::class, $title), new LiteralField('ExampleOfThingsToCheck', '<ul><li>' . implode('</li><li>', EcommerceConfig::get(OrderStepConfirmed::class, 'list_of_things_to_check')) . '</li></ul>'), ] ); return $fields; } /** * Explains the current order step. * * @return string */ protected function myDescription() { return _t('OrderStep.CONFIRMED_DESCRIPTION', 'The shop administrator confirms all the details for the current order.'); } } |