Source of file OrderStep_CheckAvailability.php
Size: 5,067 Bytes - Last Modified: 2021-12-23T10:40:33+00:00
/var/www/docs.ssmods.com/process/src/code/model/OrderStep_CheckAvailability.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 | <?php class OrderStep_CheckAvailability extends OrderStep { public static $db = array( "MinimumOrderAmount" => "Int" ); public static $defaults = array( "CustomerCanEdit" => 1, "CustomerCanCancel" => 1, "CustomerCanPay" => 1, "Name" => "Check Availability", "Code" => "CHECKAVAILABILITY", "Sort" => 15, "ShowAsInProcessOrder" => 1 ); public function initStep($order) { return true; } public function doStep($order) { $noNeedToCheck = false; if ($this->doesNotNeedToBeChecked($order)) { $subject = $this->EmailSubject; if ($subject) { $message = ""; if (!$this->hasBeenSent($order)) { $order->sendEmail($subject, $message, $resend = false, $adminOnly = false, $emailClass = 'Order_StatusEmail'); } } } else { $noNeedToCheck = true; } if ($noNeedToCheck || $this->hasBeenChecked($order)) { if (!$order->IsSubmitted()) { $className = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order"); if (class_exists($className)) { $obj = new $className(); if ($obj instanceof OrderStatusLog) { $obj->OrderID = $order->ID; $obj->Title = $this->Name; //it is important we add this here so that we can save the 'submitted' version. //this is particular important for the Order Item Links. $obj->write(); $saved = false; if ($this->SaveOrderAsJSON) { $obj->OrderAsJSON = $order->ConvertToJSON(); $saved = true; } if ($this->SaveOrderAsHTML) { $obj->OrderAsHTML = $order->ConvertToHTML(); $saved = true; } if ($this->SaveOrderAsSerializedObject || !$saved) { $obj->OrderAsString = $order->ConvertToString(); $saved = true; } $obj->write(); } else { user_error('EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order") refers to a class that is NOT an instance of OrderStatusLog'); } } else { user_error('EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order") refers to a non-existing class'); } } return true; } return false; } /** *@param DataObject $order Order *@return DataObject | Null - DataObject = OrderStep **/ public function nextStep($order) { if (($this->doesNotNeedToBeChecked($order)) || $this->hasBeenChecked($order)) { return parent::nextStep($order); } return null; } /** * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields *@param FieldSet $fields *@param Order $order *@return FieldSet **/ public function addOrderStepFields(&$fields, $order) { $msg = _t("OrderStep.MUSTDOAVAILABILITYCHECK", " ... To move this order to the next step you must carry out a availability check (are the products available) by creating a record here (click me)"); $fields->addFieldToTab("Root.Next", $order->OrderStatusLogsTable("OrderStatusLog_CheckAvailability", $msg)); return $fields; } /** * tells the order to display itself with an alternative display page. * in that way, orders can be displayed differently for certain steps * for example, in a print step, the order can be displayed in a * PRINT ONLY format. * * When the method return null, the order is displayed using the standard display page * @see Order::DisplayPage * * * @return Null|Object (Page) **/ public function AlternativeDisplayPage() { return DataObject::get_one("OrderConfirmationPage"); } /** * Explains the current order step. * @return String */ protected function myDescription() { return _t("OrderStep_CheckAvailability.DESCRIPTION", "Allows the shop admin to check product availability for confirming order."); } protected function doesNotNeedToBeChecked($order) { return DataObject::get_one("OrderStatusLog_CheckAvailability", "\"OrderID\" = ".$order->ID." AND \"AvailabilityChecked\" = 1"); } protected function hasBeenChecked($order) { return DataObject::get_one("OrderStatusLog_CheckAvailability", "\"OrderID\" = ".$order->ID." AND \"AvailabilityChecked\" = 1"); } } |