Source of file OrderStepPaid.php
Size: 3,830 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Process/OrderSteps/OrderStepPaid.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | <?php namespace Sunnysideup\Ecommerce\Model\Process\OrderSteps; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use Sunnysideup\Ecommerce\Forms\Fields\EcommerceCMSButtonField; 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 */ class OrderStepPaid extends OrderStep implements OrderStepInterface { private static $defaults = [ 'CustomerCanEdit' => 0, 'CustomerCanCancel' => 0, //the one below may seem a bit paradoxical, but the thing is that the customer can pay up to and inclusive of this step //that ist he code PAID means that the Order has been paid ONCE this step is completed 'CustomerCanPay' => 1, 'Name' => 'Pay', 'Code' => 'PAID', 'ShowAsInProcessOrder' => 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 * * @param Order $order object * * @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 * * @param Order $order object * * @return bool - true if run correctly */ public function doStep(Order $order): bool { return true; } /** * can go to next step if order has been paid. * * @see Order::doNextStatus * * @return null|OrderStep (next step OrderStep object) */ public function nextStep(Order $order) { if ($order->IsPaid()) { 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); if (! $order->IsPaid()) { $msg = _t( 'OrderStep.ORDERNOTPAID', ' This order can not be completed, because it has not been paid. You can either create a payment or change the status of any existing payment to <i>success</i>. See Payments tab for more details. ' ); $fields->addFieldsToTab( 'Root.Next', [ new LiteralField('NotPaidMessage', '<p>' . $msg . '</p>'), EcommerceCMSButtonField::create( 'EditPayment', $order->Payments()->first()->CMSEditLink(), 'Edit Payment' ), ] ); } $paymentField = $fields->fieldByName('Root.Payments.Payments'); if ($paymentField) { $fields->addFieldsToTab( 'Root.Next', [ $paymentField, ] ); } return $fields; } /** * Explains the current order step. * * @return string */ protected function myDescription() { return _t('OrderStep.PAID_DESCRIPTION', 'The order is paid in full.'); } } |