Complex classes like Order often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Order, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class Order extends DataObject implements EditableEcommerceObject |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * API Control. |
||
| 35 | * |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | private static $api_access = array( |
||
|
|
|||
| 39 | 'view' => array( |
||
| 40 | 'OrderEmail', |
||
| 41 | 'EmailLink', |
||
| 42 | 'PrintLink', |
||
| 43 | 'RetrieveLink', |
||
| 44 | 'ShareLink', |
||
| 45 | 'FeedbackLink', |
||
| 46 | 'Title', |
||
| 47 | 'Total', |
||
| 48 | 'SubTotal', |
||
| 49 | 'TotalPaid', |
||
| 50 | 'TotalOutstanding', |
||
| 51 | 'ExchangeRate', |
||
| 52 | 'CurrencyUsed', |
||
| 53 | 'TotalItems', |
||
| 54 | 'TotalItemsTimesQuantity', |
||
| 55 | 'IsCancelled', |
||
| 56 | 'Country', |
||
| 57 | 'FullNameCountry', |
||
| 58 | 'IsSubmitted', |
||
| 59 | 'CustomerStatus', |
||
| 60 | 'CanHaveShippingAddress', |
||
| 61 | 'CancelledBy', |
||
| 62 | 'CurrencyUsed', |
||
| 63 | 'BillingAddress', |
||
| 64 | 'UseShippingAddress', |
||
| 65 | 'ShippingAddress', |
||
| 66 | 'Status', |
||
| 67 | 'Attributes', |
||
| 68 | 'OrderStatusLogs', |
||
| 69 | 'MemberID', |
||
| 70 | ), |
||
| 71 | ); |
||
| 72 | |||
| 73 | /** |
||
| 74 | * standard SS variable. |
||
| 75 | * |
||
| 76 | * @var array |
||
| 77 | */ |
||
| 78 | private static $db = array( |
||
| 79 | 'SessionID' => 'Varchar(32)', //so that in the future we can link sessions with Orders.... One session can have several orders, but an order can onnly have one session |
||
| 80 | 'UseShippingAddress' => 'Boolean', |
||
| 81 | 'CustomerOrderNote' => 'Text', |
||
| 82 | 'ExchangeRate' => 'Double', |
||
| 83 | //'TotalItems_Saved' => 'Double', |
||
| 84 | //'TotalItemsTimesQuantity_Saved' => 'Double' |
||
| 85 | ); |
||
| 86 | |||
| 87 | private static $has_one = array( |
||
| 88 | 'Member' => 'Member', |
||
| 89 | 'BillingAddress' => 'BillingAddress', |
||
| 90 | 'ShippingAddress' => 'ShippingAddress', |
||
| 91 | 'Status' => 'OrderStep', |
||
| 92 | 'CancelledBy' => 'Member', |
||
| 93 | 'CurrencyUsed' => 'EcommerceCurrency', |
||
| 94 | ); |
||
| 95 | |||
| 96 | /** |
||
| 97 | * standard SS variable. |
||
| 98 | * |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | private static $has_many = array( |
||
| 102 | 'Attributes' => 'OrderAttribute', |
||
| 103 | 'OrderStatusLogs' => 'OrderStatusLog', |
||
| 104 | 'Payments' => 'EcommercePayment', |
||
| 105 | 'Emails' => 'OrderEmailRecord', |
||
| 106 | 'OrderProcessQueue' => 'OrderProcessQueue' //there is usually only one. |
||
| 107 | ); |
||
| 108 | |||
| 109 | /** |
||
| 110 | * standard SS variable. |
||
| 111 | * |
||
| 112 | * @var array |
||
| 113 | */ |
||
| 114 | private static $indexes = array( |
||
| 115 | 'SessionID' => true, |
||
| 116 | 'LastEdited' => true |
||
| 117 | ); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * standard SS variable. |
||
| 121 | * |
||
| 122 | * @var string |
||
| 123 | */ |
||
| 124 | private static $default_sort = [ |
||
| 125 | 'LastEdited' => 'DESC', |
||
| 126 | 'ID' => 'DESC' |
||
| 127 | ]; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * standard SS variable. |
||
| 131 | * |
||
| 132 | * @var array |
||
| 133 | */ |
||
| 134 | private static $casting = array( |
||
| 135 | 'OrderEmail' => 'Varchar', |
||
| 136 | 'EmailLink' => 'Varchar', |
||
| 137 | 'PrintLink' => 'Varchar', |
||
| 138 | 'ShareLink' => 'Varchar', |
||
| 139 | 'FeedbackLink' => 'Varchar', |
||
| 140 | 'RetrieveLink' => 'Varchar', |
||
| 141 | 'Title' => 'Varchar', |
||
| 142 | 'Total' => 'Currency', |
||
| 143 | 'TotalAsMoney' => 'Money', |
||
| 144 | 'SubTotal' => 'Currency', |
||
| 145 | 'SubTotalAsMoney' => 'Money', |
||
| 146 | 'TotalPaid' => 'Currency', |
||
| 147 | 'TotalPaidAsMoney' => 'Money', |
||
| 148 | 'TotalOutstanding' => 'Currency', |
||
| 149 | 'TotalOutstandingAsMoney' => 'Money', |
||
| 150 | 'HasAlternativeCurrency' => 'Boolean', |
||
| 151 | 'TotalItems' => 'Double', |
||
| 152 | 'TotalItemsTimesQuantity' => 'Double', |
||
| 153 | 'IsCancelled' => 'Boolean', |
||
| 154 | 'IsPaidNice' => 'Varchar', |
||
| 155 | 'Country' => 'Varchar(3)', //This is the applicable country for the order - for tax purposes, etc.... |
||
| 156 | 'FullNameCountry' => 'Varchar', |
||
| 157 | 'IsSubmitted' => 'Boolean', |
||
| 158 | 'CustomerStatus' => 'Varchar', |
||
| 159 | 'CanHaveShippingAddress' => 'Boolean', |
||
| 160 | ); |
||
| 161 | |||
| 162 | /** |
||
| 163 | * standard SS variable. |
||
| 164 | * |
||
| 165 | * @var string |
||
| 166 | */ |
||
| 167 | private static $singular_name = 'Order'; |
||
| 168 | public function i18n_singular_name() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * standard SS variable. |
||
| 175 | * |
||
| 176 | * @var string |
||
| 177 | */ |
||
| 178 | private static $plural_name = 'Orders'; |
||
| 179 | public function i18n_plural_name() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Standard SS variable. |
||
| 186 | * |
||
| 187 | * @var string |
||
| 188 | */ |
||
| 189 | private static $description = "A collection of items that together make up the 'Order'. An order can be placed."; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Tells us if an order needs to be recalculated |
||
| 193 | * can save one for each order... |
||
| 194 | * |
||
| 195 | * @var array |
||
| 196 | */ |
||
| 197 | private static $_needs_recalculating = array(); |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param bool (optional) $b |
||
| 201 | * @param int (optional) $orderID |
||
| 202 | * |
||
| 203 | * @return bool |
||
| 204 | */ |
||
| 205 | public static function set_needs_recalculating($b = true, $orderID = 0) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @param int (optional) $orderID |
||
| 212 | * |
||
| 213 | * @return bool |
||
| 214 | */ |
||
| 215 | public static function get_needs_recalculating($orderID = 0) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Total Items : total items in cart |
||
| 222 | * We start with -1 to easily identify if it has been run before. |
||
| 223 | * |
||
| 224 | * @var int |
||
| 225 | */ |
||
| 226 | protected $totalItems = null; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Total Items : total items in cart |
||
| 230 | * We start with -1 to easily identify if it has been run before. |
||
| 231 | * |
||
| 232 | * @var float |
||
| 233 | */ |
||
| 234 | protected $totalItemsTimesQuantity = null; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Returns a set of modifier forms for use in the checkout order form, |
||
| 238 | * Controller is optional, because the orderForm has its own default controller. |
||
| 239 | * |
||
| 240 | * This method only returns the Forms that should be included outside |
||
| 241 | * the editable table... Forms within it can be called |
||
| 242 | * from through the modifier itself. |
||
| 243 | * |
||
| 244 | * @param Controller $optionalController |
||
| 245 | * @param Validator $optionalValidator |
||
| 246 | * |
||
| 247 | * @return ArrayList (ModifierForms) | Null |
||
| 248 | **/ |
||
| 249 | |||
| 250 | protected static $_modifier_form_cache = null; |
||
| 251 | |||
| 252 | public function getModifierForms(Controller $optionalController = null, Validator $optionalValidator = null) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * This function returns the OrderSteps. |
||
| 283 | * |
||
| 284 | * @return ArrayList (OrderSteps) |
||
| 285 | **/ |
||
| 286 | public static function get_order_status_options() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Like the standard byID, but it checks whether we are allowed to view the order. |
||
| 293 | * |
||
| 294 | * @return: Order | Null |
||
| 295 | **/ |
||
| 296 | public static function get_by_id_if_can_view($id) |
||
| 310 | |||
| 311 | /** |
||
| 312 | * returns a Datalist with the submitted order log included |
||
| 313 | * this allows you to sort the orders by their submit dates. |
||
| 314 | * You can retrieve this list and then add more to it (e.g. additional filters, additional joins, etc...). |
||
| 315 | * |
||
| 316 | * @param bool $onlySubmittedOrders - only include Orders that have already been submitted. |
||
| 317 | * @param bool $includeCancelledOrders - only include Orders that have already been submitted. |
||
| 318 | * |
||
| 319 | * @return DataList (Orders) |
||
| 320 | */ |
||
| 321 | public static function get_datalist_of_orders_with_submit_record($onlySubmittedOrders = true, $includeCancelledOrders = false) |
||
| 343 | |||
| 344 | /******************************************************* |
||
| 345 | * 1. CMS STUFF |
||
| 346 | *******************************************************/ |
||
| 347 | |||
| 348 | /** |
||
| 349 | * fields that we remove from the parent::getCMSFields object set. |
||
| 350 | * |
||
| 351 | * @var array |
||
| 352 | */ |
||
| 353 | protected $fieldsAndTabsToBeRemoved = array( |
||
| 354 | 'MemberID', |
||
| 355 | 'Attributes', |
||
| 356 | 'SessionID', |
||
| 357 | 'Emails', |
||
| 358 | 'BillingAddressID', |
||
| 359 | 'ShippingAddressID', |
||
| 360 | 'UseShippingAddress', |
||
| 361 | 'OrderStatusLogs', |
||
| 362 | 'Payments', |
||
| 363 | 'OrderDate', |
||
| 364 | 'ExchangeRate', |
||
| 365 | 'CurrencyUsedID', |
||
| 366 | 'StatusID', |
||
| 367 | 'Currency', |
||
| 368 | ); |
||
| 369 | |||
| 370 | /** |
||
| 371 | * STANDARD SILVERSTRIPE STUFF. |
||
| 372 | **/ |
||
| 373 | private static $summary_fields = array( |
||
| 374 | 'Title' => 'Title', |
||
| 375 | 'OrderItemsSummaryNice' => 'Order Items', |
||
| 376 | 'Status.Title' => 'Next Step', |
||
| 377 | 'Member.Surname' => 'Last Name', |
||
| 378 | 'Member.Email' => 'Email', |
||
| 379 | 'TotalAsMoney.Nice' => 'Total', |
||
| 380 | 'TotalItemsTimesQuantity' => 'Units', |
||
| 381 | 'IsPaidNice' => 'Paid' |
||
| 382 | ); |
||
| 383 | |||
| 384 | /** |
||
| 385 | * STANDARD SILVERSTRIPE STUFF. |
||
| 386 | * |
||
| 387 | * @todo: how to translate this? |
||
| 388 | **/ |
||
| 389 | private static $searchable_fields = array( |
||
| 390 | 'ID' => array( |
||
| 391 | 'field' => 'NumericField', |
||
| 392 | 'title' => 'Order Number', |
||
| 393 | ), |
||
| 394 | 'MemberID' => array( |
||
| 395 | 'field' => 'TextField', |
||
| 396 | 'filter' => 'OrderFilters_MemberAndAddress', |
||
| 397 | 'title' => 'Customer Details', |
||
| 398 | ), |
||
| 399 | 'Created' => array( |
||
| 400 | 'field' => 'TextField', |
||
| 401 | 'filter' => 'OrderFilters_AroundDateFilter', |
||
| 402 | 'title' => 'Date (e.g. Today, 1 jan 2007, or last week)', |
||
| 403 | ), |
||
| 404 | //make sure to keep the items below, otherwise they do not show in form |
||
| 405 | 'StatusID' => array( |
||
| 406 | 'filter' => 'OrderFilters_MultiOptionsetStatusIDFilter', |
||
| 407 | ), |
||
| 408 | 'CancelledByID' => array( |
||
| 409 | 'filter' => 'OrderFilters_HasBeenCancelled', |
||
| 410 | 'title' => 'Cancelled by ...', |
||
| 411 | ) |
||
| 412 | ); |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Determine which properties on the DataObject are |
||
| 416 | * searchable, and map them to their default {@link FormField} |
||
| 417 | * representations. Used for scaffolding a searchform for {@link ModelAdmin}. |
||
| 418 | * |
||
| 419 | * Some additional logic is included for switching field labels, based on |
||
| 420 | * how generic or specific the field type is. |
||
| 421 | * |
||
| 422 | * Used by {@link SearchContext}. |
||
| 423 | * |
||
| 424 | * @param array $_params |
||
| 425 | * 'fieldClasses': Associative array of field names as keys and FormField classes as values |
||
| 426 | * 'restrictFields': Numeric array of a field name whitelist |
||
| 427 | * |
||
| 428 | * @return FieldList |
||
| 429 | */ |
||
| 430 | public function scaffoldSearchFields($_params = null) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * link to edit the record. |
||
| 482 | * |
||
| 483 | * @param string | Null $action - e.g. edit |
||
| 484 | * |
||
| 485 | * @return string |
||
| 486 | */ |
||
| 487 | public function CMSEditLink($action = null) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * STANDARD SILVERSTRIPE STUFF |
||
| 494 | * broken up into submitted and not (yet) submitted. |
||
| 495 | **/ |
||
| 496 | public function getCMSFields() |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Field to add and edit Order Items. |
||
| 898 | * |
||
| 899 | * @return GridField |
||
| 900 | */ |
||
| 901 | protected function getOrderItemsField() |
||
| 908 | |||
| 909 | /** |
||
| 910 | * Field to add and edit Modifiers. |
||
| 911 | * |
||
| 912 | * @return GridField |
||
| 913 | */ |
||
| 914 | public function getModifierTableField() |
||
| 921 | |||
| 922 | /** |
||
| 923 | *@return GridField |
||
| 924 | **/ |
||
| 925 | protected function getBillingAddressField() |
||
| 941 | |||
| 942 | /** |
||
| 943 | *@return GridField |
||
| 944 | **/ |
||
| 945 | protected function getShippingAddressField() |
||
| 961 | |||
| 962 | /** |
||
| 963 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 964 | * |
||
| 965 | * @param string $sourceClass |
||
| 966 | * @param string $title |
||
| 967 | * |
||
| 968 | * @return GridField |
||
| 969 | **/ |
||
| 970 | public function getOrderStatusLogsTableField( |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 988 | * |
||
| 989 | * @param string $sourceClass |
||
| 990 | * @param string $title |
||
| 991 | * |
||
| 992 | * @return GridField |
||
| 993 | **/ |
||
| 994 | public function getOrderStatusLogsTableFieldEditable( |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * @param string $sourceClass |
||
| 1007 | * @param string $title |
||
| 1008 | * @param FieldList $fieldList (Optional) |
||
| 1009 | * @param FieldList $detailedFormFields (Optional) |
||
| 1010 | * |
||
| 1011 | * @return GridField |
||
| 1012 | **/ |
||
| 1013 | protected function getOrderStatusLogsTableField_Archived( |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * @return GridField |
||
| 1033 | **/ |
||
| 1034 | public function getEmailsTableField() |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * @return GridField |
||
| 1045 | */ |
||
| 1046 | protected function getPaymentsField() |
||
| 1055 | |||
| 1056 | /** |
||
| 1057 | * @return OrderStepField |
||
| 1058 | */ |
||
| 1059 | public function OrderStepField() |
||
| 1063 | |||
| 1064 | /******************************************************* |
||
| 1065 | * 2. MAIN TRANSITION FUNCTIONS |
||
| 1066 | *******************************************************/ |
||
| 1067 | |||
| 1068 | /** |
||
| 1069 | * init runs on start of a new Order (@see onAfterWrite) |
||
| 1070 | * it adds all the modifiers to the orders and the starting OrderStep. |
||
| 1071 | * |
||
| 1072 | * @param bool $recalculate |
||
| 1073 | * |
||
| 1074 | * @return DataObject (Order) |
||
| 1075 | **/ |
||
| 1076 | public function init($recalculate = false) |
||
| 1136 | |||
| 1137 | /** |
||
| 1138 | * @var array |
||
| 1139 | */ |
||
| 1140 | private static $_try_to_finalise_order_is_running = array(); |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Goes through the order steps and tries to "apply" the next status to the order. |
||
| 1144 | * |
||
| 1145 | * @param bool $runAgain |
||
| 1146 | * @param bool $fromOrderQueue - is it being called from the OrderProcessQueue (or similar) |
||
| 1147 | * |
||
| 1148 | * @return null |
||
| 1149 | **/ |
||
| 1150 | public function tryToFinaliseOrder($runAgain = false, $fromOrderQueue = false) |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Goes through the order steps and tries to "apply" the next step |
||
| 1207 | * Step is updated after the other one is completed... |
||
| 1208 | * |
||
| 1209 | * @return int (StatusID or false if the next status can not be "applied") |
||
| 1210 | **/ |
||
| 1211 | public function doNextStatus() |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * cancel an order. |
||
| 1229 | * |
||
| 1230 | * @param Member $member - (optional) the user cancelling the order |
||
| 1231 | * @param string $reason - (optional) the reason the order is cancelled |
||
| 1232 | * |
||
| 1233 | * @return OrderStatusLog_Cancel |
||
| 1234 | */ |
||
| 1235 | public function Cancel($member = null, $reason = '') |
||
| 1268 | |||
| 1269 | /** |
||
| 1270 | * returns true if successful. |
||
| 1271 | * |
||
| 1272 | * @param bool $avoidWrites |
||
| 1273 | * |
||
| 1274 | * @return bool |
||
| 1275 | */ |
||
| 1276 | public function Archive($avoidWrites = true) |
||
| 1299 | |||
| 1300 | /******************************************************* |
||
| 1301 | * 3. STATUS RELATED FUNCTIONS / SHORTCUTS |
||
| 1302 | *******************************************************/ |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Avoids caching of $this->Status(). |
||
| 1306 | * |
||
| 1307 | * @return DataObject (current OrderStep) |
||
| 1308 | */ |
||
| 1309 | public function MyStep() |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Return the OrderStatusLog that is relevant to the Order status. |
||
| 1334 | * |
||
| 1335 | * @return OrderStatusLog |
||
| 1336 | */ |
||
| 1337 | public function RelevantLogEntry() |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * @return OrderStep (current OrderStep that can be seen by customer) |
||
| 1344 | */ |
||
| 1345 | public function CurrentStepVisibleToCustomer() |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * works out if the order is still at the first OrderStep. |
||
| 1360 | * |
||
| 1361 | * @return bool |
||
| 1362 | */ |
||
| 1363 | public function IsFirstStep() |
||
| 1375 | |||
| 1376 | /** |
||
| 1377 | * Is the order still being "edited" by the customer? |
||
| 1378 | * |
||
| 1379 | * @return bool |
||
| 1380 | */ |
||
| 1381 | public function IsInCart() |
||
| 1385 | |||
| 1386 | /** |
||
| 1387 | * The order has "passed" the IsInCart phase. |
||
| 1388 | * |
||
| 1389 | * @return bool |
||
| 1390 | */ |
||
| 1391 | public function IsPastCart() |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Are there still steps the order needs to go through? |
||
| 1398 | * |
||
| 1399 | * @return bool |
||
| 1400 | */ |
||
| 1401 | public function IsUncomplete() |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Is the order in the :"processing" phaase.? |
||
| 1408 | * |
||
| 1409 | * @return bool |
||
| 1410 | */ |
||
| 1411 | public function IsProcessing() |
||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Is the order completed? |
||
| 1418 | * |
||
| 1419 | * @return bool |
||
| 1420 | */ |
||
| 1421 | public function IsCompleted() |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * Has the order been paid? |
||
| 1428 | * TODO: why do we check if there is a total at all? |
||
| 1429 | * |
||
| 1430 | * @return bool |
||
| 1431 | */ |
||
| 1432 | public function IsPaid() |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * @alias for getIsPaidNice |
||
| 1443 | * @return string |
||
| 1444 | */ |
||
| 1445 | public function IsPaidNice() |
||
| 1449 | |||
| 1450 | |||
| 1451 | public function getIsPaidNice() |
||
| 1455 | |||
| 1456 | |||
| 1457 | /** |
||
| 1458 | * Has the order been paid? |
||
| 1459 | * TODO: why do we check if there is a total at all? |
||
| 1460 | * |
||
| 1461 | * @return bool |
||
| 1462 | */ |
||
| 1463 | public function PaymentIsPending() |
||
| 1479 | |||
| 1480 | /** |
||
| 1481 | * shows payments that are meaningfull |
||
| 1482 | * if the order has been paid then only show successful payments. |
||
| 1483 | * |
||
| 1484 | * @return DataList |
||
| 1485 | */ |
||
| 1486 | public function RelevantPayments() |
||
| 1496 | |||
| 1497 | |||
| 1498 | /** |
||
| 1499 | * Has the order been cancelled? |
||
| 1500 | * |
||
| 1501 | * @return bool |
||
| 1502 | */ |
||
| 1503 | public function IsCancelled() |
||
| 1511 | |||
| 1512 | /** |
||
| 1513 | * Has the order been cancelled by the customer? |
||
| 1514 | * |
||
| 1515 | * @return bool |
||
| 1516 | */ |
||
| 1517 | public function IsCustomerCancelled() |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Has the order been cancelled by the administrator? |
||
| 1528 | * |
||
| 1529 | * @return bool |
||
| 1530 | */ |
||
| 1531 | public function IsAdminCancelled() |
||
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Is the Shop Closed for business? |
||
| 1549 | * |
||
| 1550 | * @return bool |
||
| 1551 | */ |
||
| 1552 | public function ShopClosed() |
||
| 1556 | |||
| 1557 | /******************************************************* |
||
| 1558 | * 4. LINKING ORDER WITH MEMBER AND ADDRESS |
||
| 1559 | *******************************************************/ |
||
| 1560 | |||
| 1561 | /** |
||
| 1562 | * Returns a member linked to the order. |
||
| 1563 | * If a member is already linked, it will return the existing member. |
||
| 1564 | * Otherwise it will return a new Member. |
||
| 1565 | * |
||
| 1566 | * Any new member is NOT written, because we dont want to create a new member unless we have to! |
||
| 1567 | * We will not add a member to the order unless a new one is created in the checkout |
||
| 1568 | * OR the member is logged in / logs in. |
||
| 1569 | * |
||
| 1570 | * Also note that if a new member is created, it is not automatically written |
||
| 1571 | * |
||
| 1572 | * @param bool $forceCreation - if set to true then the member will always be saved in the database. |
||
| 1573 | * |
||
| 1574 | * @return Member |
||
| 1575 | **/ |
||
| 1576 | public function CreateOrReturnExistingMember($forceCreation = false) |
||
| 1599 | |||
| 1600 | /** |
||
| 1601 | * Returns either the existing one or a new Order Address... |
||
| 1602 | * All Orders will have a Shipping and Billing address attached to it. |
||
| 1603 | * Method used to retrieve object e.g. for $order->BillingAddress(); "BillingAddress" is the method name you can use. |
||
| 1604 | * If the method name is the same as the class name then dont worry about providing one. |
||
| 1605 | * |
||
| 1606 | * @param string $className - ClassName of the Address (e.g. BillingAddress or ShippingAddress) |
||
| 1607 | * @param string $alternativeMethodName - method to retrieve Address |
||
| 1608 | **/ |
||
| 1609 | public function CreateOrReturnExistingAddress($className = 'BillingAddress', $alternativeMethodName = '') |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * Sets the country in the billing and shipping address. |
||
| 1656 | * |
||
| 1657 | * @param string $countryCode - code for the country e.g. NZ |
||
| 1658 | * @param bool $includeBillingAddress |
||
| 1659 | * @param bool $includeShippingAddress |
||
| 1660 | **/ |
||
| 1661 | public function SetCountryFields($countryCode, $includeBillingAddress = true, $includeShippingAddress = true) |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Sets the region in the billing and shipping address. |
||
| 1683 | * |
||
| 1684 | * @param int $regionID - ID for the region to be set |
||
| 1685 | **/ |
||
| 1686 | public function SetRegionFields($regionID) |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Stores the preferred currency of the order. |
||
| 1704 | * IMPORTANTLY we store the exchange rate for future reference... |
||
| 1705 | * |
||
| 1706 | * @param EcommerceCurrency $currency |
||
| 1707 | */ |
||
| 1708 | public function UpdateCurrency($newCurrency) |
||
| 1721 | |||
| 1722 | /** |
||
| 1723 | * alias for UpdateCurrency. |
||
| 1724 | * |
||
| 1725 | * @param EcommerceCurrency $currency |
||
| 1726 | */ |
||
| 1727 | public function SetCurrency($currency) |
||
| 1731 | |||
| 1732 | /******************************************************* |
||
| 1733 | * 5. CUSTOMER COMMUNICATION |
||
| 1734 | *******************************************************/ |
||
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Send the invoice of the order by email. |
||
| 1738 | * |
||
| 1739 | * @param string $emailClassName (optional) class used to send email |
||
| 1740 | * @param string $subject (optional) subject for the email |
||
| 1741 | * @param string $message (optional) the main message in the email |
||
| 1742 | * @param bool $resend (optional) send the email even if it has been sent before |
||
| 1743 | * @param bool $adminOnlyOrToEmail (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1744 | * |
||
| 1745 | * @return bool TRUE on success, FALSE on failure |
||
| 1746 | */ |
||
| 1747 | public function sendEmail( |
||
| 1762 | |||
| 1763 | /** |
||
| 1764 | * Sends a message to the shop admin ONLY and not to the customer |
||
| 1765 | * This can be used by ordersteps and orderlogs to notify the admin of any potential problems. |
||
| 1766 | * |
||
| 1767 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1768 | * @param string $subject - (optional) subject for the email |
||
| 1769 | * @param string $message - (optional) message to be added with the email |
||
| 1770 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1771 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1772 | * |
||
| 1773 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1774 | */ |
||
| 1775 | public function sendAdminNotification( |
||
| 1790 | |||
| 1791 | /** |
||
| 1792 | * returns the order formatted as an email. |
||
| 1793 | * |
||
| 1794 | * @param string $emailClassName - template to use. |
||
| 1795 | * @param string $subject - (optional) the subject (which can be used as title in email) |
||
| 1796 | * @param string $message - (optional) the additional message |
||
| 1797 | * |
||
| 1798 | * @return string (html) |
||
| 1799 | */ |
||
| 1800 | public function renderOrderInEmailFormat( |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Send a mail of the order to the client (and another to the admin). |
||
| 1816 | * |
||
| 1817 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1818 | * @param string $subject - (optional) subject for the email |
||
| 1819 | * @param string $message - (optional) message to be added with the email |
||
| 1820 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1821 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1822 | * |
||
| 1823 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1824 | */ |
||
| 1825 | protected function prepareAndSendEmail( |
||
| 1885 | |||
| 1886 | /** |
||
| 1887 | * returns the Data that can be used in the body of an order Email |
||
| 1888 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1889 | * of the email template. |
||
| 1890 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1891 | * of the email template. |
||
| 1892 | * |
||
| 1893 | * @param string $subject - (optional) subject for email |
||
| 1894 | * @param string $message - (optional) the additional message |
||
| 1895 | * |
||
| 1896 | * @return ArrayData |
||
| 1897 | * - Subject - EmailSubject |
||
| 1898 | * - Message - specific message for this order |
||
| 1899 | * - Message - custom message |
||
| 1900 | * - OrderStepMessage - generic message for step |
||
| 1901 | * - Order |
||
| 1902 | * - EmailLogo |
||
| 1903 | * - ShopPhysicalAddress |
||
| 1904 | * - CurrentDateAndTime |
||
| 1905 | * - BaseURL |
||
| 1906 | * - CC |
||
| 1907 | * - BCC |
||
| 1908 | */ |
||
| 1909 | protected function createReplacementArrayForEmail($subject = '', $message = '') |
||
| 1938 | |||
| 1939 | /******************************************************* |
||
| 1940 | * 6. ITEM MANAGEMENT |
||
| 1941 | *******************************************************/ |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * returns a list of Order Attributes by type. |
||
| 1945 | * |
||
| 1946 | * @param array | String $types |
||
| 1947 | * |
||
| 1948 | * @return ArrayList |
||
| 1949 | */ |
||
| 1950 | public function getOrderAttributesByType($types) |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Returns the items of the order. |
||
| 1977 | * Items are the order items (products) and NOT the modifiers (discount, tax, etc...). |
||
| 1978 | * |
||
| 1979 | * N. B. this method returns Order Items |
||
| 1980 | * also see Buaybles |
||
| 1981 | |||
| 1982 | * |
||
| 1983 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1984 | * |
||
| 1985 | * @return DataList (OrderItems) |
||
| 1986 | */ |
||
| 1987 | public function Items($filterOrClassName = '') |
||
| 1995 | |||
| 1996 | /** |
||
| 1997 | * @alias function of Items |
||
| 1998 | * |
||
| 1999 | * N. B. this method returns Order Items |
||
| 2000 | * also see Buaybles |
||
| 2001 | * |
||
| 2002 | * @param string filter - where statement to exclude certain items. |
||
| 2003 | * @alias for Items |
||
| 2004 | * @return DataList (OrderItems) |
||
| 2005 | */ |
||
| 2006 | public function OrderItems($filterOrClassName = '') |
||
| 2010 | |||
| 2011 | /** |
||
| 2012 | * returns the buyables asscoiated with the order items. |
||
| 2013 | * |
||
| 2014 | * NB. this method retursn buyables |
||
| 2015 | * |
||
| 2016 | * @param string filter - where statement to exclude certain items. |
||
| 2017 | * |
||
| 2018 | * @return ArrayList (Buyables) |
||
| 2019 | */ |
||
| 2020 | public function Buyables($filterOrClassName = '') |
||
| 2030 | |||
| 2031 | /** |
||
| 2032 | * Return all the {@link OrderItem} instances that are |
||
| 2033 | * available as records in the database. |
||
| 2034 | * |
||
| 2035 | * @param string filter - where statement to exclude certain items, |
||
| 2036 | * you can also pass a classname (e.g. MyOrderItem), in which case only this class will be returned (and any class extending your given class) |
||
| 2037 | * |
||
| 2038 | * @return DataList (OrderItems) |
||
| 2039 | */ |
||
| 2040 | protected function itemsFromDatabase($filterOrClassName = '') |
||
| 2054 | |||
| 2055 | /** |
||
| 2056 | * @alias for Modifiers |
||
| 2057 | * |
||
| 2058 | * @return DataList (OrderModifiers) |
||
| 2059 | */ |
||
| 2060 | public function OrderModifiers() |
||
| 2064 | |||
| 2065 | /** |
||
| 2066 | * Returns the modifiers of the order, if it hasn't been saved yet |
||
| 2067 | * it returns the modifiers from session, if it has, it returns them |
||
| 2068 | * from the DB entry. ONLY USE OUTSIDE ORDER. |
||
| 2069 | * |
||
| 2070 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2071 | * |
||
| 2072 | * @return DataList (OrderModifiers) |
||
| 2073 | */ |
||
| 2074 | public function Modifiers($filterOrClassName = '') |
||
| 2078 | |||
| 2079 | /** |
||
| 2080 | * Get all {@link OrderModifier} instances that are |
||
| 2081 | * available as records in the database. |
||
| 2082 | * NOTE: includes REMOVED Modifiers, so that they do not get added again... |
||
| 2083 | * |
||
| 2084 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2085 | * |
||
| 2086 | * @return DataList (OrderModifiers) |
||
| 2087 | */ |
||
| 2088 | protected function modifiersFromDatabase($filterOrClassName = '') |
||
| 2102 | |||
| 2103 | /** |
||
| 2104 | * Calculates and updates all the order attributes. |
||
| 2105 | * |
||
| 2106 | * @param bool $recalculate - run it, even if it has run already |
||
| 2107 | */ |
||
| 2108 | public function calculateOrderAttributes($recalculate = false) |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Calculates and updates all the product items. |
||
| 2125 | * |
||
| 2126 | * @param bool $recalculate - run it, even if it has run already |
||
| 2127 | */ |
||
| 2128 | protected function calculateOrderItems($recalculate = false) |
||
| 2143 | |||
| 2144 | /** |
||
| 2145 | * Calculates and updates all the modifiers. |
||
| 2146 | * |
||
| 2147 | * @param bool $recalculate - run it, even if it has run already |
||
| 2148 | */ |
||
| 2149 | protected function calculateModifiers($recalculate = false) |
||
| 2161 | |||
| 2162 | /** |
||
| 2163 | * Returns the subtotal of the modifiers for this order. |
||
| 2164 | * If a modifier appears in the excludedModifiers array, it is not counted. |
||
| 2165 | * |
||
| 2166 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2167 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2168 | * |
||
| 2169 | * @return float |
||
| 2170 | */ |
||
| 2171 | public function ModifiersSubTotal($excluded = null, $stopAtExcludedModifier = false) |
||
| 2198 | |||
| 2199 | /** |
||
| 2200 | * returns a modifier that is an instanceof the classname |
||
| 2201 | * it extends. |
||
| 2202 | * |
||
| 2203 | * @param string $className: class name for the modifier |
||
| 2204 | * |
||
| 2205 | * @return DataObject (OrderModifier) |
||
| 2206 | **/ |
||
| 2207 | public function RetrieveModifier($className) |
||
| 2218 | |||
| 2219 | /******************************************************* |
||
| 2220 | * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...) |
||
| 2221 | *******************************************************/ |
||
| 2222 | |||
| 2223 | /** |
||
| 2224 | * @param Member $member |
||
| 2225 | * |
||
| 2226 | * @return DataObject (Member) |
||
| 2227 | **/ |
||
| 2228 | //TODO: please comment why we make use of this function |
||
| 2229 | protected function getMemberForCanFunctions(Member $member = null) |
||
| 2241 | |||
| 2242 | /** |
||
| 2243 | * @param Member $member |
||
| 2244 | * |
||
| 2245 | * @return bool |
||
| 2246 | **/ |
||
| 2247 | public function canCreate($member = null) |
||
| 2258 | |||
| 2259 | /** |
||
| 2260 | * Standard SS method - can the current member view this order? |
||
| 2261 | * |
||
| 2262 | * @param Member $member |
||
| 2263 | * |
||
| 2264 | * @return bool |
||
| 2265 | **/ |
||
| 2266 | public function canView($member = null) |
||
| 2311 | |||
| 2312 | /** |
||
| 2313 | * @param Member $member optional |
||
| 2314 | * @return bool |
||
| 2315 | */ |
||
| 2316 | public function canOverrideCanView($member = null) |
||
| 2337 | |||
| 2338 | /** |
||
| 2339 | * @return bool |
||
| 2340 | */ |
||
| 2341 | public function IsInSession() |
||
| 2347 | |||
| 2348 | /** |
||
| 2349 | * returns a pseudo random part of the session id. |
||
| 2350 | * |
||
| 2351 | * @param int $size |
||
| 2352 | * |
||
| 2353 | * @return string |
||
| 2354 | */ |
||
| 2355 | public function LessSecureSessionID($size = 7, $start = null) |
||
| 2363 | /** |
||
| 2364 | * |
||
| 2365 | * @param Member (optional) $member |
||
| 2366 | * |
||
| 2367 | * @return bool |
||
| 2368 | **/ |
||
| 2369 | public function canViewAdminStuff($member = null) |
||
| 2380 | |||
| 2381 | /** |
||
| 2382 | * if we set canEdit to false then we |
||
| 2383 | * can not see the child records |
||
| 2384 | * Basically, you can edit when you can view and canEdit (even as a customer) |
||
| 2385 | * Or if you are a Shop Admin you can always edit. |
||
| 2386 | * Otherwise it is false... |
||
| 2387 | * |
||
| 2388 | * @param Member $member |
||
| 2389 | * |
||
| 2390 | * @return bool |
||
| 2391 | **/ |
||
| 2392 | public function canEdit($member = null) |
||
| 2411 | |||
| 2412 | /** |
||
| 2413 | * is the order ready to go through to the |
||
| 2414 | * checkout process. |
||
| 2415 | * |
||
| 2416 | * This method checks all the order items and order modifiers |
||
| 2417 | * If any of them need immediate attention then this is done |
||
| 2418 | * first after which it will go through to the checkout page. |
||
| 2419 | * |
||
| 2420 | * @param Member (optional) $member |
||
| 2421 | * |
||
| 2422 | * @return bool |
||
| 2423 | **/ |
||
| 2424 | public function canCheckout(Member $member = null) |
||
| 2438 | |||
| 2439 | /** |
||
| 2440 | * Can the order be submitted? |
||
| 2441 | * this method can be used to stop an order from being submitted |
||
| 2442 | * due to something not being completed or done. |
||
| 2443 | * |
||
| 2444 | * @see Order::SubmitErrors |
||
| 2445 | * |
||
| 2446 | * @param Member $member |
||
| 2447 | * |
||
| 2448 | * @return bool |
||
| 2449 | **/ |
||
| 2450 | public function canSubmit(Member $member = null) |
||
| 2467 | |||
| 2468 | /** |
||
| 2469 | * Can a payment be made for this Order? |
||
| 2470 | * |
||
| 2471 | * @param Member $member |
||
| 2472 | * |
||
| 2473 | * @return bool |
||
| 2474 | **/ |
||
| 2475 | public function canPay(Member $member = null) |
||
| 2488 | |||
| 2489 | /** |
||
| 2490 | * Can the given member cancel this order? |
||
| 2491 | * |
||
| 2492 | * @param Member $member |
||
| 2493 | * |
||
| 2494 | * @return bool |
||
| 2495 | **/ |
||
| 2496 | public function canCancel(Member $member = null) |
||
| 2513 | |||
| 2514 | /** |
||
| 2515 | * @param Member $member |
||
| 2516 | * |
||
| 2517 | * @return bool |
||
| 2518 | **/ |
||
| 2519 | public function canDelete($member = null) |
||
| 2535 | |||
| 2536 | /** |
||
| 2537 | * Returns all the order logs that the current member can view |
||
| 2538 | * i.e. some order logs can only be viewed by the admin (e.g. suspected fraud orderlog). |
||
| 2539 | * |
||
| 2540 | * @return ArrayList (OrderStatusLogs) |
||
| 2541 | **/ |
||
| 2542 | public function CanViewOrderStatusLogs() |
||
| 2554 | |||
| 2555 | /** |
||
| 2556 | * returns all the logs that can be viewed by the customer. |
||
| 2557 | * |
||
| 2558 | * @return ArrayList (OrderStausLogs) |
||
| 2559 | */ |
||
| 2560 | public function CustomerViewableOrderStatusLogs() |
||
| 2574 | |||
| 2575 | /******************************************************* |
||
| 2576 | * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...) |
||
| 2577 | *******************************************************/ |
||
| 2578 | |||
| 2579 | /** |
||
| 2580 | * returns the email to be used for customer communication. |
||
| 2581 | * |
||
| 2582 | * @return string |
||
| 2583 | */ |
||
| 2584 | public function OrderEmail() |
||
| 2606 | |||
| 2607 | /** |
||
| 2608 | * Returns true if there is a prink or email link. |
||
| 2609 | * |
||
| 2610 | * @return bool |
||
| 2611 | */ |
||
| 2612 | public function HasPrintOrEmailLink() |
||
| 2616 | |||
| 2617 | /** |
||
| 2618 | * returns the absolute link to the order that can be used in the customer communication (email). |
||
| 2619 | * |
||
| 2620 | * @return string |
||
| 2621 | */ |
||
| 2622 | public function EmailLink($type = 'Order_StatusEmail') |
||
| 2634 | |||
| 2635 | /** |
||
| 2636 | * returns the absolute link to the order for printing. |
||
| 2637 | * |
||
| 2638 | * @return string |
||
| 2639 | */ |
||
| 2640 | public function PrintLink() |
||
| 2652 | |||
| 2653 | /** |
||
| 2654 | * returns the absolute link to the order for printing. |
||
| 2655 | * |
||
| 2656 | * @return string |
||
| 2657 | */ |
||
| 2658 | public function PackingSlipLink() |
||
| 2668 | |||
| 2669 | /** |
||
| 2670 | * returns the absolute link that the customer can use to retrieve the email WITHOUT logging in. |
||
| 2671 | * |
||
| 2672 | * @return string |
||
| 2673 | */ |
||
| 2674 | public function RetrieveLink() |
||
| 2678 | |||
| 2679 | public function getRetrieveLink() |
||
| 2693 | |||
| 2694 | public function ShareLink() |
||
| 2698 | |||
| 2699 | public function getShareLink() |
||
| 2717 | |||
| 2718 | /** |
||
| 2719 | * @alias for getFeedbackLink |
||
| 2720 | * @return string |
||
| 2721 | */ |
||
| 2722 | public function FeedbackLink() |
||
| 2726 | |||
| 2727 | /** |
||
| 2728 | * @return string | null |
||
| 2729 | */ |
||
| 2730 | public function getFeedbackLink() |
||
| 2737 | |||
| 2738 | /** |
||
| 2739 | * link to delete order. |
||
| 2740 | * |
||
| 2741 | * @return string |
||
| 2742 | */ |
||
| 2743 | public function DeleteLink() |
||
| 2755 | |||
| 2756 | /** |
||
| 2757 | * link to copy order. |
||
| 2758 | * |
||
| 2759 | * @return string |
||
| 2760 | */ |
||
| 2761 | public function CopyOrderLink() |
||
| 2773 | |||
| 2774 | /** |
||
| 2775 | * A "Title" for the order, which summarises the main details (date, and customer) in a string. |
||
| 2776 | * |
||
| 2777 | * @param string $dateFormat - e.g. "D j M Y, G:i T" |
||
| 2778 | * @param bool $includeName - e.g. by Mr Johnson |
||
| 2779 | * |
||
| 2780 | * @return string |
||
| 2781 | **/ |
||
| 2782 | public function Title($dateFormat = null, $includeName = false) |
||
| 2845 | |||
| 2846 | public function OrderItemsSummaryNice() |
||
| 2850 | |||
| 2851 | public function getOrderItemsSummaryNice() |
||
| 2855 | |||
| 2856 | public function OrderItemsSummaryAsHTML() |
||
| 2882 | |||
| 2883 | /** |
||
| 2884 | * Returns the subtotal of the items for this order. |
||
| 2885 | * |
||
| 2886 | * @return float |
||
| 2887 | */ |
||
| 2888 | public function SubTotal() |
||
| 2906 | |||
| 2907 | /** |
||
| 2908 | * @return Currency (DB Object) |
||
| 2909 | **/ |
||
| 2910 | public function SubTotalAsCurrencyObject() |
||
| 2914 | |||
| 2915 | /** |
||
| 2916 | * @return Money |
||
| 2917 | **/ |
||
| 2918 | public function SubTotalAsMoney() |
||
| 2926 | |||
| 2927 | /** |
||
| 2928 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2929 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2930 | * |
||
| 2931 | * @return Currency (DB Object) |
||
| 2932 | **/ |
||
| 2933 | public function ModifiersSubTotalAsCurrencyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2937 | |||
| 2938 | /** |
||
| 2939 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2940 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2941 | * |
||
| 2942 | * @return Money (DB Object) |
||
| 2943 | **/ |
||
| 2944 | public function ModifiersSubTotalAsMoneyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2948 | |||
| 2949 | /** |
||
| 2950 | * Returns the total cost of an order including the additional charges or deductions of its modifiers. |
||
| 2951 | * |
||
| 2952 | * @return float |
||
| 2953 | */ |
||
| 2954 | public function Total() |
||
| 2962 | |||
| 2963 | /** |
||
| 2964 | * @return Currency (DB Object) |
||
| 2965 | **/ |
||
| 2966 | public function TotalAsCurrencyObject() |
||
| 2970 | |||
| 2971 | /** |
||
| 2972 | * @return Money |
||
| 2973 | **/ |
||
| 2974 | public function TotalAsMoney() |
||
| 2982 | |||
| 2983 | /** |
||
| 2984 | * Checks to see if any payments have been made on this order |
||
| 2985 | * and if so, subracts the payment amount from the order. |
||
| 2986 | * |
||
| 2987 | * @return float |
||
| 2988 | **/ |
||
| 2989 | public function TotalOutstanding() |
||
| 3009 | |||
| 3010 | /** |
||
| 3011 | * @return Currency (DB Object) |
||
| 3012 | **/ |
||
| 3013 | public function TotalOutstandingAsCurrencyObject() |
||
| 3017 | |||
| 3018 | /** |
||
| 3019 | * @return Money |
||
| 3020 | **/ |
||
| 3021 | public function TotalOutstandingAsMoney() |
||
| 3029 | |||
| 3030 | /** |
||
| 3031 | * @return float |
||
| 3032 | */ |
||
| 3033 | public function TotalPaid() |
||
| 3054 | |||
| 3055 | /** |
||
| 3056 | * @return Currency (DB Object) |
||
| 3057 | **/ |
||
| 3058 | public function TotalPaidAsCurrencyObject() |
||
| 3062 | |||
| 3063 | /** |
||
| 3064 | * @return Money |
||
| 3065 | **/ |
||
| 3066 | public function TotalPaidAsMoney() |
||
| 3074 | |||
| 3075 | /** |
||
| 3076 | * returns the total number of OrderItems (not modifiers). |
||
| 3077 | * This is meant to run as fast as possible to quickly check |
||
| 3078 | * if there is anything in the cart. |
||
| 3079 | * |
||
| 3080 | * @param bool $recalculate - do we need to recalculate (value is retained during lifetime of Object) |
||
| 3081 | * |
||
| 3082 | * @return int |
||
| 3083 | **/ |
||
| 3084 | public function TotalItems($recalculate = false) |
||
| 3098 | |||
| 3099 | /** |
||
| 3100 | * Little shorthand. |
||
| 3101 | * |
||
| 3102 | * @param bool $recalculate |
||
| 3103 | * |
||
| 3104 | * @return bool |
||
| 3105 | **/ |
||
| 3106 | public function MoreThanOneItemInCart($recalculate = false) |
||
| 3110 | |||
| 3111 | /** |
||
| 3112 | * returns the total number of OrderItems (not modifiers) times their respectective quantities. |
||
| 3113 | * |
||
| 3114 | * @param bool $recalculate - force recalculation |
||
| 3115 | * |
||
| 3116 | * @return float |
||
| 3117 | **/ |
||
| 3118 | public function TotalItemsTimesQuantity($recalculate = false) |
||
| 3139 | |||
| 3140 | /** |
||
| 3141 | * |
||
| 3142 | * @return string (country code) |
||
| 3143 | **/ |
||
| 3144 | public function Country() |
||
| 3148 | |||
| 3149 | /** |
||
| 3150 | * Returns the country code for the country that applies to the order. |
||
| 3151 | * @alias for getCountry |
||
| 3152 | * |
||
| 3153 | * @return string - country code e.g. NZ |
||
| 3154 | */ |
||
| 3155 | public function getCountry() |
||
| 3192 | |||
| 3193 | /** |
||
| 3194 | * is this a gift / separate shippingAddress? |
||
| 3195 | * @return bool |
||
| 3196 | */ |
||
| 3197 | public function IsSeparateShippingAddress() |
||
| 3201 | |||
| 3202 | /** |
||
| 3203 | * @alias for getFullNameCountry |
||
| 3204 | * |
||
| 3205 | * @return string - country name |
||
| 3206 | **/ |
||
| 3207 | public function FullNameCountry() |
||
| 3211 | |||
| 3212 | /** |
||
| 3213 | * returns name of coutry. |
||
| 3214 | * |
||
| 3215 | * @return string - country name |
||
| 3216 | **/ |
||
| 3217 | public function getFullNameCountry() |
||
| 3221 | |||
| 3222 | /** |
||
| 3223 | * @alis for getExpectedCountryName |
||
| 3224 | * @return string - country name |
||
| 3225 | **/ |
||
| 3226 | public function ExpectedCountryName() |
||
| 3230 | |||
| 3231 | /** |
||
| 3232 | * returns name of coutry that we expect the customer to have |
||
| 3233 | * This takes into consideration more than just what has been entered |
||
| 3234 | * for example, it looks at GEO IP. |
||
| 3235 | * |
||
| 3236 | * @todo: why do we dont return a string IF there is only one item. |
||
| 3237 | * |
||
| 3238 | * @return string - country name |
||
| 3239 | **/ |
||
| 3240 | public function getExpectedCountryName() |
||
| 3244 | |||
| 3245 | /** |
||
| 3246 | * return the title of the fixed country (if any). |
||
| 3247 | * |
||
| 3248 | * @return string | empty string |
||
| 3249 | **/ |
||
| 3250 | public function FixedCountry() |
||
| 3263 | |||
| 3264 | /** |
||
| 3265 | * Returns the region that applies to the order. |
||
| 3266 | * we check both billing and shipping, in case one of them is empty. |
||
| 3267 | * |
||
| 3268 | * @return DataObject | Null (EcommerceRegion) |
||
| 3269 | **/ |
||
| 3270 | public function Region() |
||
| 3307 | |||
| 3308 | /** |
||
| 3309 | * Casted variable |
||
| 3310 | * Currency is not the same as the standard one? |
||
| 3311 | * |
||
| 3312 | * @return bool |
||
| 3313 | **/ |
||
| 3314 | public function HasAlternativeCurrency() |
||
| 3330 | |||
| 3331 | /** |
||
| 3332 | * Makes sure exchange rate is updated and maintained before order is submitted |
||
| 3333 | * This method is public because it could be called from a shopping Cart Object. |
||
| 3334 | **/ |
||
| 3335 | public function EnsureCorrectExchangeRate() |
||
| 3353 | |||
| 3354 | /** |
||
| 3355 | * speeds up processing by storing the IsSubmitted value |
||
| 3356 | * we start with -1 to know if it has been requested before. |
||
| 3357 | * |
||
| 3358 | * @var bool |
||
| 3359 | */ |
||
| 3360 | protected $_isSubmittedTempVar = -1; |
||
| 3361 | |||
| 3362 | /** |
||
| 3363 | * Casted variable - has the order been submitted? |
||
| 3364 | * alias |
||
| 3365 | * @param bool $recalculate |
||
| 3366 | * |
||
| 3367 | * @return bool |
||
| 3368 | **/ |
||
| 3369 | public function IsSubmitted($recalculate = true) |
||
| 3373 | |||
| 3374 | /** |
||
| 3375 | * Casted variable - has the order been submitted? |
||
| 3376 | * |
||
| 3377 | * @param bool $recalculate |
||
| 3378 | * |
||
| 3379 | * @return bool |
||
| 3380 | **/ |
||
| 3381 | public function getIsSubmitted($recalculate = false) |
||
| 3393 | |||
| 3394 | /** |
||
| 3395 | * |
||
| 3396 | * |
||
| 3397 | * @return bool |
||
| 3398 | */ |
||
| 3399 | public function IsArchived() |
||
| 3409 | |||
| 3410 | /** |
||
| 3411 | * Submission Log for this Order (if any). |
||
| 3412 | * |
||
| 3413 | * @return Submission Log (OrderStatusLog_Submitted) | Null |
||
| 3414 | **/ |
||
| 3415 | public function SubmissionLog() |
||
| 3423 | |||
| 3424 | /** |
||
| 3425 | * Submission Log for this Order (if any). |
||
| 3426 | * |
||
| 3427 | * @return DateTime |
||
| 3428 | **/ |
||
| 3429 | public function OrderDate() |
||
| 3440 | |||
| 3441 | /** |
||
| 3442 | * @return int |
||
| 3443 | */ |
||
| 3444 | public function SecondsSinceBeingSubmitted() |
||
| 3452 | |||
| 3453 | /** |
||
| 3454 | * if the order can not be submitted, |
||
| 3455 | * then the reasons why it can not be submitted |
||
| 3456 | * will be returned by this method. |
||
| 3457 | * |
||
| 3458 | * @see Order::canSubmit |
||
| 3459 | * |
||
| 3460 | * @return ArrayList | null |
||
| 3461 | */ |
||
| 3462 | public function SubmitErrors() |
||
| 3478 | |||
| 3479 | /** |
||
| 3480 | * Casted variable - has the order been submitted? |
||
| 3481 | * |
||
| 3482 | * @param bool $withDetail |
||
| 3483 | * |
||
| 3484 | * @return string |
||
| 3485 | **/ |
||
| 3486 | public function CustomerStatus($withDetail = true) |
||
| 3508 | |||
| 3509 | /** |
||
| 3510 | * Casted variable - does the order have a potential shipping address? |
||
| 3511 | * |
||
| 3512 | * @return bool |
||
| 3513 | **/ |
||
| 3514 | public function CanHaveShippingAddress() |
||
| 3522 | |||
| 3523 | /** |
||
| 3524 | * returns the link to view the Order |
||
| 3525 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3526 | * |
||
| 3527 | * @return CartPage | Null |
||
| 3528 | */ |
||
| 3529 | public function DisplayPage() |
||
| 3547 | |||
| 3548 | /** |
||
| 3549 | * returns the link to view the Order |
||
| 3550 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3551 | * If a cart page has been created then we refer through to Cart Page. |
||
| 3552 | * Otherwise it will default to the checkout page. |
||
| 3553 | * |
||
| 3554 | * @param string $action - any action that should be added to the link. |
||
| 3555 | * |
||
| 3556 | * @return String(URLSegment) |
||
| 3557 | */ |
||
| 3558 | public function Link($action = null) |
||
| 3574 | |||
| 3575 | /** |
||
| 3576 | * Returns to link to access the Order's API. |
||
| 3577 | * |
||
| 3578 | * @param string $version |
||
| 3579 | * @param string $extension |
||
| 3580 | * |
||
| 3581 | * @return String(URL) |
||
| 3582 | */ |
||
| 3583 | public function APILink($version = 'v1', $extension = 'xml') |
||
| 3587 | |||
| 3588 | /** |
||
| 3589 | * returns the link to finalise the Order. |
||
| 3590 | * |
||
| 3591 | * @return String(URLSegment) |
||
| 3592 | */ |
||
| 3593 | public function CheckoutLink() |
||
| 3608 | |||
| 3609 | /** |
||
| 3610 | * Converts the Order into HTML, based on the Order Template. |
||
| 3611 | * |
||
| 3612 | * @return HTML Object |
||
| 3613 | **/ |
||
| 3614 | public function ConvertToHTML() |
||
| 3624 | |||
| 3625 | /** |
||
| 3626 | * Converts the Order into a serialized string |
||
| 3627 | * TO DO: check if this works and check if we need to use special sapphire serialization code. |
||
| 3628 | * |
||
| 3629 | * @return string - serialized object |
||
| 3630 | **/ |
||
| 3631 | public function ConvertToString() |
||
| 3635 | |||
| 3636 | /** |
||
| 3637 | * Converts the Order into a JSON object |
||
| 3638 | * TO DO: check if this works and check if we need to use special sapphire JSON code. |
||
| 3639 | * |
||
| 3640 | * @return string - JSON |
||
| 3641 | **/ |
||
| 3642 | public function ConvertToJSON() |
||
| 3646 | |||
| 3647 | /** |
||
| 3648 | * returns itself wtih more data added as variables. |
||
| 3649 | * We add has_one and has_many as variables like this: $this->MyHasOne_serialized = serialize($this->MyHasOne()). |
||
| 3650 | * |
||
| 3651 | * @return Order - with most important has one and has many items included as variables. |
||
| 3652 | **/ |
||
| 3653 | protected function addHasOneAndHasManyAsVariables() |
||
| 3666 | |||
| 3667 | /******************************************************* |
||
| 3668 | * 9. TEMPLATE RELATED STUFF |
||
| 3669 | *******************************************************/ |
||
| 3670 | |||
| 3671 | /** |
||
| 3672 | * returns the instance of EcommerceConfigAjax for use in templates. |
||
| 3673 | * In templates, it is used like this: |
||
| 3674 | * $EcommerceConfigAjax.TableID. |
||
| 3675 | * |
||
| 3676 | * @return EcommerceConfigAjax |
||
| 3677 | **/ |
||
| 3678 | public function AJAXDefinitions() |
||
| 3682 | |||
| 3683 | /** |
||
| 3684 | * returns the instance of EcommerceDBConfig. |
||
| 3685 | * |
||
| 3686 | * @return EcommerceDBConfig |
||
| 3687 | **/ |
||
| 3688 | public function EcomConfig() |
||
| 3692 | |||
| 3693 | /** |
||
| 3694 | * Collects the JSON data for an ajax return of the cart. |
||
| 3695 | * |
||
| 3696 | * @param array $js |
||
| 3697 | * |
||
| 3698 | * @return array (for use in AJAX for JSON) |
||
| 3699 | **/ |
||
| 3700 | public function updateForAjax(array $js) |
||
| 3753 | |||
| 3754 | /** |
||
| 3755 | * @ToDO: move to more appropriate class |
||
| 3756 | * |
||
| 3757 | * @return float |
||
| 3758 | **/ |
||
| 3759 | public function SubTotalCartValue() |
||
| 3763 | |||
| 3764 | /******************************************************* |
||
| 3765 | * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...) |
||
| 3766 | *******************************************************/ |
||
| 3767 | |||
| 3768 | /** |
||
| 3769 | *standard SS method. |
||
| 3770 | **/ |
||
| 3771 | public function populateDefaults() |
||
| 3775 | |||
| 3776 | public function onBeforeWrite() |
||
| 3791 | |||
| 3792 | /** |
||
| 3793 | * standard SS method |
||
| 3794 | * adds the ability to update order after writing it. |
||
| 3795 | **/ |
||
| 3796 | public function onAfterWrite() |
||
| 3820 | |||
| 3821 | /** |
||
| 3822 | *standard SS method. |
||
| 3823 | * |
||
| 3824 | * delete attributes, statuslogs, and payments |
||
| 3825 | * THIS SHOULD NOT BE USED AS ORDERS SHOULD BE CANCELLED NOT DELETED |
||
| 3826 | */ |
||
| 3827 | public function onBeforeDelete() |
||
| 3872 | |||
| 3873 | /******************************************************* |
||
| 3874 | * 11. DEBUG |
||
| 3875 | *******************************************************/ |
||
| 3876 | |||
| 3877 | /** |
||
| 3878 | * Debug helper method. |
||
| 3879 | * Can be called from /shoppingcart/debug/. |
||
| 3880 | * |
||
| 3881 | * @return string |
||
| 3882 | */ |
||
| 3883 | public function debug() |
||
| 3889 | } |
||
| 3890 |