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 | public function getModifierForms(Controller $optionalController = null, Validator $optionalValidator = null) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * This function returns the OrderSteps. |
||
| 274 | * |
||
| 275 | * @return ArrayList (OrderSteps) |
||
| 276 | **/ |
||
| 277 | public static function get_order_status_options() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Like the standard byID, but it checks whether we are allowed to view the order. |
||
| 284 | * |
||
| 285 | * @return: Order | Null |
||
| 286 | **/ |
||
| 287 | public static function get_by_id_if_can_view($id) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * returns a Datalist with the submitted order log included |
||
| 304 | * this allows you to sort the orders by their submit dates. |
||
| 305 | * You can retrieve this list and then add more to it (e.g. additional filters, additional joins, etc...). |
||
| 306 | * |
||
| 307 | * @param bool $onlySubmittedOrders - only include Orders that have already been submitted. |
||
| 308 | * @param bool $includeCancelledOrders - only include Orders that have already been submitted. |
||
| 309 | * |
||
| 310 | * @return DataList (Orders) |
||
| 311 | */ |
||
| 312 | public static function get_datalist_of_orders_with_submit_record($onlySubmittedOrders = true, $includeCancelledOrders = false) |
||
| 334 | |||
| 335 | /******************************************************* |
||
| 336 | * 1. CMS STUFF |
||
| 337 | *******************************************************/ |
||
| 338 | |||
| 339 | /** |
||
| 340 | * fields that we remove from the parent::getCMSFields object set. |
||
| 341 | * |
||
| 342 | * @var array |
||
| 343 | */ |
||
| 344 | protected $fieldsAndTabsToBeRemoved = array( |
||
| 345 | 'MemberID', |
||
| 346 | 'Attributes', |
||
| 347 | 'SessionID', |
||
| 348 | 'Emails', |
||
| 349 | 'BillingAddressID', |
||
| 350 | 'ShippingAddressID', |
||
| 351 | 'UseShippingAddress', |
||
| 352 | 'OrderStatusLogs', |
||
| 353 | 'Payments', |
||
| 354 | 'OrderDate', |
||
| 355 | 'ExchangeRate', |
||
| 356 | 'CurrencyUsedID', |
||
| 357 | 'StatusID', |
||
| 358 | 'Currency', |
||
| 359 | ); |
||
| 360 | |||
| 361 | /** |
||
| 362 | * STANDARD SILVERSTRIPE STUFF. |
||
| 363 | **/ |
||
| 364 | private static $summary_fields = array( |
||
| 365 | 'Title' => 'Title', |
||
| 366 | 'Status.Title' => 'Next Step', |
||
| 367 | 'Member.Surname' => 'Name', |
||
| 368 | 'Member.Email' => 'Email', |
||
| 369 | 'TotalAsMoney.Nice' => 'Total', |
||
| 370 | 'TotalItemsTimesQuantity' => 'Units', |
||
| 371 | 'IsPaidNice' => 'Paid' |
||
| 372 | ); |
||
| 373 | |||
| 374 | /** |
||
| 375 | * STANDARD SILVERSTRIPE STUFF. |
||
| 376 | * |
||
| 377 | * @todo: how to translate this? |
||
| 378 | **/ |
||
| 379 | private static $searchable_fields = array( |
||
| 380 | 'ID' => array( |
||
| 381 | 'field' => 'NumericField', |
||
| 382 | 'title' => 'Order Number', |
||
| 383 | ), |
||
| 384 | 'MemberID' => array( |
||
| 385 | 'field' => 'TextField', |
||
| 386 | 'filter' => 'OrderFilters_MemberAndAddress', |
||
| 387 | 'title' => 'Customer Details', |
||
| 388 | ), |
||
| 389 | 'Created' => array( |
||
| 390 | 'field' => 'TextField', |
||
| 391 | 'filter' => 'OrderFilters_AroundDateFilter', |
||
| 392 | 'title' => 'Date (e.g. Today, 1 jan 2007, or last week)', |
||
| 393 | ), |
||
| 394 | //make sure to keep the items below, otherwise they do not show in form |
||
| 395 | 'StatusID' => array( |
||
| 396 | 'filter' => 'OrderFilters_MultiOptionsetStatusIDFilter', |
||
| 397 | ), |
||
| 398 | 'CancelledByID' => array( |
||
| 399 | 'filter' => 'OrderFilters_HasBeenCancelled', |
||
| 400 | 'title' => 'Cancelled by ...', |
||
| 401 | ), |
||
| 402 | ); |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Determine which properties on the DataObject are |
||
| 406 | * searchable, and map them to their default {@link FormField} |
||
| 407 | * representations. Used for scaffolding a searchform for {@link ModelAdmin}. |
||
| 408 | * |
||
| 409 | * Some additional logic is included for switching field labels, based on |
||
| 410 | * how generic or specific the field type is. |
||
| 411 | * |
||
| 412 | * Used by {@link SearchContext}. |
||
| 413 | * |
||
| 414 | * @param array $_params |
||
| 415 | * 'fieldClasses': Associative array of field names as keys and FormField classes as values |
||
| 416 | * 'restrictFields': Numeric array of a field name whitelist |
||
| 417 | * |
||
| 418 | * @return FieldList |
||
| 419 | */ |
||
| 420 | public function scaffoldSearchFields($_params = null) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * link to edit the record. |
||
| 472 | * |
||
| 473 | * @param string | Null $action - e.g. edit |
||
| 474 | * |
||
| 475 | * @return string |
||
| 476 | */ |
||
| 477 | public function CMSEditLink($action = null) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * STANDARD SILVERSTRIPE STUFF |
||
| 484 | * broken up into submitted and not (yet) submitted. |
||
| 485 | **/ |
||
| 486 | public function getCMSFields() |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Field to add and edit Order Items. |
||
| 879 | * |
||
| 880 | * @return GridField |
||
| 881 | */ |
||
| 882 | protected function getOrderItemsField() |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Field to add and edit Modifiers. |
||
| 892 | * |
||
| 893 | * @return GridField |
||
| 894 | */ |
||
| 895 | public function getModifierTableField() |
||
| 902 | |||
| 903 | /** |
||
| 904 | *@return GridField |
||
| 905 | **/ |
||
| 906 | protected function getBillingAddressField() |
||
| 922 | |||
| 923 | /** |
||
| 924 | *@return GridField |
||
| 925 | **/ |
||
| 926 | protected function getShippingAddressField() |
||
| 942 | |||
| 943 | /** |
||
| 944 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 945 | * |
||
| 946 | * @param string $sourceClass |
||
| 947 | * @param string $title |
||
| 948 | * |
||
| 949 | * @return GridField |
||
| 950 | **/ |
||
| 951 | public function getOrderStatusLogsTableField( |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 969 | * |
||
| 970 | * @param string $sourceClass |
||
| 971 | * @param string $title |
||
| 972 | * |
||
| 973 | * @return GridField |
||
| 974 | **/ |
||
| 975 | public function getOrderStatusLogsTableFieldEditable( |
||
| 985 | |||
| 986 | /** |
||
| 987 | * @param string $sourceClass |
||
| 988 | * @param string $title |
||
| 989 | * @param FieldList $fieldList (Optional) |
||
| 990 | * @param FieldList $detailedFormFields (Optional) |
||
| 991 | * |
||
| 992 | * @return GridField |
||
| 993 | **/ |
||
| 994 | protected function getOrderStatusLogsTableField_Archived( |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * @return GridField |
||
| 1014 | **/ |
||
| 1015 | public function getEmailsTableField() |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * @return GridField |
||
| 1026 | */ |
||
| 1027 | protected function getPaymentsField() |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * @return OrderStepField |
||
| 1039 | */ |
||
| 1040 | public function OrderStepField() |
||
| 1044 | |||
| 1045 | /******************************************************* |
||
| 1046 | * 2. MAIN TRANSITION FUNCTIONS |
||
| 1047 | *******************************************************/ |
||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * init runs on start of a new Order (@see onAfterWrite) |
||
| 1051 | * it adds all the modifiers to the orders and the starting OrderStep. |
||
| 1052 | * |
||
| 1053 | * @param bool $recalculate |
||
| 1054 | * |
||
| 1055 | * @return DataObject (Order) |
||
| 1056 | **/ |
||
| 1057 | public function init($recalculate = false) |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * @var array |
||
| 1120 | */ |
||
| 1121 | private static $_try_to_finalise_order_is_running = array(); |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Goes through the order steps and tries to "apply" the next status to the order. |
||
| 1125 | * |
||
| 1126 | * @param bool $runAgain |
||
| 1127 | * @param bool $fromOrderQueue - is it being called from the OrderProcessQueue (or similar) |
||
| 1128 | * |
||
| 1129 | * @return null |
||
| 1130 | **/ |
||
| 1131 | public function tryToFinaliseOrder($runAgain = false, $fromOrderQueue = false) |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Goes through the order steps and tries to "apply" the next step |
||
| 1189 | * Step is updated after the other one is completed... |
||
| 1190 | * |
||
| 1191 | * @return int (StatusID or false if the next status can not be "applied") |
||
| 1192 | **/ |
||
| 1193 | public function doNextStatus() |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * cancel an order. |
||
| 1211 | * |
||
| 1212 | * @param Member $member - (optional) the user cancelling the order |
||
| 1213 | * @param string $reason - (optional) the reason the order is cancelled |
||
| 1214 | * |
||
| 1215 | * @return OrderStatusLog_Cancel |
||
| 1216 | */ |
||
| 1217 | public function Cancel($member = null, $reason = '') |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * returns true if successful. |
||
| 1253 | * |
||
| 1254 | * @param bool $avoidWrites |
||
| 1255 | * |
||
| 1256 | * @return bool |
||
| 1257 | */ |
||
| 1258 | public function Archive($avoidWrites = true) |
||
| 1281 | |||
| 1282 | /******************************************************* |
||
| 1283 | * 3. STATUS RELATED FUNCTIONS / SHORTCUTS |
||
| 1284 | *******************************************************/ |
||
| 1285 | |||
| 1286 | /** |
||
| 1287 | * Avoids caching of $this->Status(). |
||
| 1288 | * |
||
| 1289 | * @return DataObject (current OrderStep) |
||
| 1290 | */ |
||
| 1291 | public function MyStep() |
||
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Return the OrderStatusLog that is relevant to the Order status. |
||
| 1316 | * |
||
| 1317 | * @return OrderStatusLog |
||
| 1318 | */ |
||
| 1319 | public function RelevantLogEntry() |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * @return OrderStep (current OrderStep that can be seen by customer) |
||
| 1326 | */ |
||
| 1327 | public function CurrentStepVisibleToCustomer() |
||
| 1339 | |||
| 1340 | /** |
||
| 1341 | * works out if the order is still at the first OrderStep. |
||
| 1342 | * |
||
| 1343 | * @return bool |
||
| 1344 | */ |
||
| 1345 | public function IsFirstStep() |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Is the order still being "edited" by the customer? |
||
| 1360 | * |
||
| 1361 | * @return bool |
||
| 1362 | */ |
||
| 1363 | public function IsInCart() |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * The order has "passed" the IsInCart phase. |
||
| 1370 | * |
||
| 1371 | * @return bool |
||
| 1372 | */ |
||
| 1373 | public function IsPastCart() |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Are there still steps the order needs to go through? |
||
| 1380 | * |
||
| 1381 | * @return bool |
||
| 1382 | */ |
||
| 1383 | public function IsUncomplete() |
||
| 1387 | |||
| 1388 | /** |
||
| 1389 | * Is the order in the :"processing" phaase.? |
||
| 1390 | * |
||
| 1391 | * @return bool |
||
| 1392 | */ |
||
| 1393 | public function IsProcessing() |
||
| 1397 | |||
| 1398 | /** |
||
| 1399 | * Is the order completed? |
||
| 1400 | * |
||
| 1401 | * @return bool |
||
| 1402 | */ |
||
| 1403 | public function IsCompleted() |
||
| 1407 | |||
| 1408 | /** |
||
| 1409 | * Has the order been paid? |
||
| 1410 | * TODO: why do we check if there is a total at all? |
||
| 1411 | * |
||
| 1412 | * @return bool |
||
| 1413 | */ |
||
| 1414 | public function IsPaid() |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * @alias for getIsPaidNice |
||
| 1425 | * @return string |
||
| 1426 | */ |
||
| 1427 | public function IsPaidNice() |
||
| 1431 | |||
| 1432 | |||
| 1433 | public function getIsPaidNice() |
||
| 1437 | |||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Has the order been paid? |
||
| 1441 | * TODO: why do we check if there is a total at all? |
||
| 1442 | * |
||
| 1443 | * @return bool |
||
| 1444 | */ |
||
| 1445 | public function PaymentIsPending() |
||
| 1461 | |||
| 1462 | /** |
||
| 1463 | * shows payments that are meaningfull |
||
| 1464 | * if the order has been paid then only show successful payments. |
||
| 1465 | * |
||
| 1466 | * @return DataList |
||
| 1467 | */ |
||
| 1468 | public function RelevantPayments() |
||
| 1478 | |||
| 1479 | |||
| 1480 | /** |
||
| 1481 | * Has the order been cancelled? |
||
| 1482 | * |
||
| 1483 | * @return bool |
||
| 1484 | */ |
||
| 1485 | public function IsCancelled() |
||
| 1493 | |||
| 1494 | /** |
||
| 1495 | * Has the order been cancelled by the customer? |
||
| 1496 | * |
||
| 1497 | * @return bool |
||
| 1498 | */ |
||
| 1499 | public function IsCustomerCancelled() |
||
| 1507 | |||
| 1508 | /** |
||
| 1509 | * Has the order been cancelled by the administrator? |
||
| 1510 | * |
||
| 1511 | * @return bool |
||
| 1512 | */ |
||
| 1513 | public function IsAdminCancelled() |
||
| 1528 | |||
| 1529 | /** |
||
| 1530 | * Is the Shop Closed for business? |
||
| 1531 | * |
||
| 1532 | * @return bool |
||
| 1533 | */ |
||
| 1534 | public function ShopClosed() |
||
| 1538 | |||
| 1539 | /******************************************************* |
||
| 1540 | * 4. LINKING ORDER WITH MEMBER AND ADDRESS |
||
| 1541 | *******************************************************/ |
||
| 1542 | |||
| 1543 | /** |
||
| 1544 | * Returns a member linked to the order. |
||
| 1545 | * If a member is already linked, it will return the existing member. |
||
| 1546 | * Otherwise it will return a new Member. |
||
| 1547 | * |
||
| 1548 | * Any new member is NOT written, because we dont want to create a new member unless we have to! |
||
| 1549 | * We will not add a member to the order unless a new one is created in the checkout |
||
| 1550 | * OR the member is logged in / logs in. |
||
| 1551 | * |
||
| 1552 | * Also note that if a new member is created, it is not automatically written |
||
| 1553 | * |
||
| 1554 | * @param bool $forceCreation - if set to true then the member will always be saved in the database. |
||
| 1555 | * |
||
| 1556 | * @return Member |
||
| 1557 | **/ |
||
| 1558 | public function CreateOrReturnExistingMember($forceCreation = false) |
||
| 1581 | |||
| 1582 | /** |
||
| 1583 | * Returns either the existing one or a new Order Address... |
||
| 1584 | * All Orders will have a Shipping and Billing address attached to it. |
||
| 1585 | * Method used to retrieve object e.g. for $order->BillingAddress(); "BillingAddress" is the method name you can use. |
||
| 1586 | * If the method name is the same as the class name then dont worry about providing one. |
||
| 1587 | * |
||
| 1588 | * @param string $className - ClassName of the Address (e.g. BillingAddress or ShippingAddress) |
||
| 1589 | * @param string $alternativeMethodName - method to retrieve Address |
||
| 1590 | **/ |
||
| 1591 | public function CreateOrReturnExistingAddress($className = 'BillingAddress', $alternativeMethodName = '') |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Sets the country in the billing and shipping address. |
||
| 1638 | * |
||
| 1639 | * @param string $countryCode - code for the country e.g. NZ |
||
| 1640 | * @param bool $includeBillingAddress |
||
| 1641 | * @param bool $includeShippingAddress |
||
| 1642 | **/ |
||
| 1643 | public function SetCountryFields($countryCode, $includeBillingAddress = true, $includeShippingAddress = true) |
||
| 1662 | |||
| 1663 | /** |
||
| 1664 | * Sets the region in the billing and shipping address. |
||
| 1665 | * |
||
| 1666 | * @param int $regionID - ID for the region to be set |
||
| 1667 | **/ |
||
| 1668 | public function SetRegionFields($regionID) |
||
| 1683 | |||
| 1684 | /** |
||
| 1685 | * Stores the preferred currency of the order. |
||
| 1686 | * IMPORTANTLY we store the exchange rate for future reference... |
||
| 1687 | * |
||
| 1688 | * @param EcommerceCurrency $currency |
||
| 1689 | */ |
||
| 1690 | public function UpdateCurrency($newCurrency) |
||
| 1703 | |||
| 1704 | /** |
||
| 1705 | * alias for UpdateCurrency. |
||
| 1706 | * |
||
| 1707 | * @param EcommerceCurrency $currency |
||
| 1708 | */ |
||
| 1709 | public function SetCurrency($currency) |
||
| 1713 | |||
| 1714 | /******************************************************* |
||
| 1715 | * 5. CUSTOMER COMMUNICATION |
||
| 1716 | *******************************************************/ |
||
| 1717 | |||
| 1718 | /** |
||
| 1719 | * Send the invoice of the order by email. |
||
| 1720 | * |
||
| 1721 | * @param string $emailClassName (optional) class used to send email |
||
| 1722 | * @param string $subject (optional) subject for the email |
||
| 1723 | * @param string $message (optional) the main message in the email |
||
| 1724 | * @param bool $resend (optional) send the email even if it has been sent before |
||
| 1725 | * @param bool $adminOnlyOrToEmail (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1726 | * |
||
| 1727 | * @return bool TRUE on success, FALSE on failure |
||
| 1728 | */ |
||
| 1729 | public function sendEmail( |
||
| 1744 | |||
| 1745 | /** |
||
| 1746 | * Sends a message to the shop admin ONLY and not to the customer |
||
| 1747 | * This can be used by ordersteps and orderlogs to notify the admin of any potential problems. |
||
| 1748 | * |
||
| 1749 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1750 | * @param string $subject - (optional) subject for the email |
||
| 1751 | * @param string $message - (optional) message to be added with the email |
||
| 1752 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1753 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1754 | * |
||
| 1755 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1756 | */ |
||
| 1757 | public function sendAdminNotification( |
||
| 1772 | |||
| 1773 | /** |
||
| 1774 | * returns the order formatted as an email. |
||
| 1775 | * |
||
| 1776 | * @param string $emailClassName - template to use. |
||
| 1777 | * @param string $subject - (optional) the subject (which can be used as title in email) |
||
| 1778 | * @param string $message - (optional) the additional message |
||
| 1779 | * |
||
| 1780 | * @return string (html) |
||
| 1781 | */ |
||
| 1782 | public function renderOrderInEmailFormat( |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Send a mail of the order to the client (and another to the admin). |
||
| 1799 | * |
||
| 1800 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1801 | * @param string $subject - (optional) subject for the email |
||
| 1802 | * @param string $message - (optional) message to be added with the email |
||
| 1803 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1804 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1805 | * |
||
| 1806 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1807 | */ |
||
| 1808 | protected function prepareAndSendEmail( |
||
| 1868 | |||
| 1869 | /** |
||
| 1870 | * returns the Data that can be used in the body of an order Email |
||
| 1871 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1872 | * of the email template. |
||
| 1873 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1874 | * of the email template. |
||
| 1875 | * |
||
| 1876 | * @param string $subject - (optional) subject for email |
||
| 1877 | * @param string $message - (optional) the additional message |
||
| 1878 | * |
||
| 1879 | * @return ArrayData |
||
| 1880 | * - Subject - EmailSubject |
||
| 1881 | * - Message - specific message for this order |
||
| 1882 | * - Message - custom message |
||
| 1883 | * - OrderStepMessage - generic message for step |
||
| 1884 | * - Order |
||
| 1885 | * - EmailLogo |
||
| 1886 | * - ShopPhysicalAddress |
||
| 1887 | * - CurrentDateAndTime |
||
| 1888 | * - BaseURL |
||
| 1889 | * - CC |
||
| 1890 | * - BCC |
||
| 1891 | */ |
||
| 1892 | protected function createReplacementArrayForEmail($subject = '', $message = '') |
||
| 1921 | |||
| 1922 | /******************************************************* |
||
| 1923 | * 6. ITEM MANAGEMENT |
||
| 1924 | *******************************************************/ |
||
| 1925 | |||
| 1926 | /** |
||
| 1927 | * returns a list of Order Attributes by type. |
||
| 1928 | * |
||
| 1929 | * @param array | String $types |
||
| 1930 | * |
||
| 1931 | * @return ArrayList |
||
| 1932 | */ |
||
| 1933 | public function getOrderAttributesByType($types) |
||
| 1957 | |||
| 1958 | /** |
||
| 1959 | * Returns the items of the order. |
||
| 1960 | * Items are the order items (products) and NOT the modifiers (discount, tax, etc...). |
||
| 1961 | * |
||
| 1962 | * N. B. this method returns Order Items |
||
| 1963 | * also see Buaybles |
||
| 1964 | |||
| 1965 | * |
||
| 1966 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1967 | * |
||
| 1968 | * @return DataList (OrderItems) |
||
| 1969 | */ |
||
| 1970 | public function Items($filterOrClassName = '') |
||
| 1978 | |||
| 1979 | /** |
||
| 1980 | * @alias function of Items |
||
| 1981 | * |
||
| 1982 | * N. B. this method returns Order Items |
||
| 1983 | * also see Buaybles |
||
| 1984 | * |
||
| 1985 | * @param string filter - where statement to exclude certain items. |
||
| 1986 | * @alias for Items |
||
| 1987 | * @return DataList (OrderItems) |
||
| 1988 | */ |
||
| 1989 | public function OrderItems($filterOrClassName = '') |
||
| 1993 | |||
| 1994 | /** |
||
| 1995 | * returns the buyables asscoiated with the order items. |
||
| 1996 | * |
||
| 1997 | * NB. this method retursn buyables |
||
| 1998 | * |
||
| 1999 | * @param string filter - where statement to exclude certain items. |
||
| 2000 | * |
||
| 2001 | * @return ArrayList (Buyables) |
||
| 2002 | */ |
||
| 2003 | public function Buyables($filterOrClassName = '') |
||
| 2013 | |||
| 2014 | /** |
||
| 2015 | * Return all the {@link OrderItem} instances that are |
||
| 2016 | * available as records in the database. |
||
| 2017 | * |
||
| 2018 | * @param string filter - where statement to exclude certain items, |
||
| 2019 | * 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) |
||
| 2020 | * |
||
| 2021 | * @return DataList (OrderItems) |
||
| 2022 | */ |
||
| 2023 | protected function itemsFromDatabase($filterOrClassName = '') |
||
| 2037 | |||
| 2038 | /** |
||
| 2039 | * @alias for Modifiers |
||
| 2040 | * |
||
| 2041 | * @return DataList (OrderModifiers) |
||
| 2042 | */ |
||
| 2043 | public function OrderModifiers() |
||
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Returns the modifiers of the order, if it hasn't been saved yet |
||
| 2050 | * it returns the modifiers from session, if it has, it returns them |
||
| 2051 | * from the DB entry. ONLY USE OUTSIDE ORDER. |
||
| 2052 | * |
||
| 2053 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2054 | * |
||
| 2055 | * @return DataList (OrderModifiers) |
||
| 2056 | */ |
||
| 2057 | public function Modifiers($filterOrClassName = '') |
||
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Get all {@link OrderModifier} instances that are |
||
| 2064 | * available as records in the database. |
||
| 2065 | * NOTE: includes REMOVED Modifiers, so that they do not get added again... |
||
| 2066 | * |
||
| 2067 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2068 | * |
||
| 2069 | * @return DataList (OrderModifiers) |
||
| 2070 | */ |
||
| 2071 | protected function modifiersFromDatabase($filterOrClassName = '') |
||
| 2085 | |||
| 2086 | /** |
||
| 2087 | * Calculates and updates all the order attributes. |
||
| 2088 | * |
||
| 2089 | * @param bool $recalculate - run it, even if it has run already |
||
| 2090 | */ |
||
| 2091 | public function calculateOrderAttributes($recalculate = false) |
||
| 2105 | |||
| 2106 | /** |
||
| 2107 | * Calculates and updates all the product items. |
||
| 2108 | * |
||
| 2109 | * @param bool $recalculate - run it, even if it has run already |
||
| 2110 | */ |
||
| 2111 | protected function calculateOrderItems($recalculate = false) |
||
| 2126 | |||
| 2127 | /** |
||
| 2128 | * Calculates and updates all the modifiers. |
||
| 2129 | * |
||
| 2130 | * @param bool $recalculate - run it, even if it has run already |
||
| 2131 | */ |
||
| 2132 | protected function calculateModifiers($recalculate = false) |
||
| 2144 | |||
| 2145 | /** |
||
| 2146 | * Returns the subtotal of the modifiers for this order. |
||
| 2147 | * If a modifier appears in the excludedModifiers array, it is not counted. |
||
| 2148 | * |
||
| 2149 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2150 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2151 | * |
||
| 2152 | * @return float |
||
| 2153 | */ |
||
| 2154 | public function ModifiersSubTotal($excluded = null, $stopAtExcludedModifier = false) |
||
| 2181 | |||
| 2182 | /** |
||
| 2183 | * returns a modifier that is an instanceof the classname |
||
| 2184 | * it extends. |
||
| 2185 | * |
||
| 2186 | * @param string $className: class name for the modifier |
||
| 2187 | * |
||
| 2188 | * @return DataObject (OrderModifier) |
||
| 2189 | **/ |
||
| 2190 | public function RetrieveModifier($className) |
||
| 2201 | |||
| 2202 | /******************************************************* |
||
| 2203 | * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...) |
||
| 2204 | *******************************************************/ |
||
| 2205 | |||
| 2206 | /** |
||
| 2207 | * @param Member $member |
||
| 2208 | * |
||
| 2209 | * @return DataObject (Member) |
||
| 2210 | **/ |
||
| 2211 | //TODO: please comment why we make use of this function |
||
| 2212 | protected function getMemberForCanFunctions(Member $member = null) |
||
| 2224 | |||
| 2225 | /** |
||
| 2226 | * @param Member $member |
||
| 2227 | * |
||
| 2228 | * @return bool |
||
| 2229 | **/ |
||
| 2230 | public function canCreate($member = null) |
||
| 2241 | |||
| 2242 | /** |
||
| 2243 | * Standard SS method - can the current member view this order? |
||
| 2244 | * |
||
| 2245 | * @param Member $member |
||
| 2246 | * |
||
| 2247 | * @return bool |
||
| 2248 | **/ |
||
| 2249 | public function canView($member = null) |
||
| 2294 | |||
| 2295 | /** |
||
| 2296 | * @param Member $member optional |
||
| 2297 | * @return bool |
||
| 2298 | */ |
||
| 2299 | public function canOverrideCanView($member = null) |
||
| 2320 | |||
| 2321 | /** |
||
| 2322 | * @return bool |
||
| 2323 | */ |
||
| 2324 | public function IsInSession() |
||
| 2330 | |||
| 2331 | /** |
||
| 2332 | * returns a pseudo random part of the session id. |
||
| 2333 | * |
||
| 2334 | * @param int $size |
||
| 2335 | * |
||
| 2336 | * @return string |
||
| 2337 | */ |
||
| 2338 | public function LessSecureSessionID($size = 7, $start = null) |
||
| 2346 | /** |
||
| 2347 | * |
||
| 2348 | * @param Member (optional) $member |
||
| 2349 | * |
||
| 2350 | * @return bool |
||
| 2351 | **/ |
||
| 2352 | public function canViewAdminStuff($member = null) |
||
| 2363 | |||
| 2364 | /** |
||
| 2365 | * if we set canEdit to false then we |
||
| 2366 | * can not see the child records |
||
| 2367 | * Basically, you can edit when you can view and canEdit (even as a customer) |
||
| 2368 | * Or if you are a Shop Admin you can always edit. |
||
| 2369 | * Otherwise it is false... |
||
| 2370 | * |
||
| 2371 | * @param Member $member |
||
| 2372 | * |
||
| 2373 | * @return bool |
||
| 2374 | **/ |
||
| 2375 | public function canEdit($member = null) |
||
| 2394 | |||
| 2395 | /** |
||
| 2396 | * is the order ready to go through to the |
||
| 2397 | * checkout process. |
||
| 2398 | * |
||
| 2399 | * This method checks all the order items and order modifiers |
||
| 2400 | * If any of them need immediate attention then this is done |
||
| 2401 | * first after which it will go through to the checkout page. |
||
| 2402 | * |
||
| 2403 | * @param Member (optional) $member |
||
| 2404 | * |
||
| 2405 | * @return bool |
||
| 2406 | **/ |
||
| 2407 | public function canCheckout(Member $member = null) |
||
| 2421 | |||
| 2422 | /** |
||
| 2423 | * Can the order be submitted? |
||
| 2424 | * this method can be used to stop an order from being submitted |
||
| 2425 | * due to something not being completed or done. |
||
| 2426 | * |
||
| 2427 | * @see Order::SubmitErrors |
||
| 2428 | * |
||
| 2429 | * @param Member $member |
||
| 2430 | * |
||
| 2431 | * @return bool |
||
| 2432 | **/ |
||
| 2433 | public function canSubmit(Member $member = null) |
||
| 2450 | |||
| 2451 | /** |
||
| 2452 | * Can a payment be made for this Order? |
||
| 2453 | * |
||
| 2454 | * @param Member $member |
||
| 2455 | * |
||
| 2456 | * @return bool |
||
| 2457 | **/ |
||
| 2458 | public function canPay(Member $member = null) |
||
| 2471 | |||
| 2472 | /** |
||
| 2473 | * Can the given member cancel this order? |
||
| 2474 | * |
||
| 2475 | * @param Member $member |
||
| 2476 | * |
||
| 2477 | * @return bool |
||
| 2478 | **/ |
||
| 2479 | public function canCancel(Member $member = null) |
||
| 2496 | |||
| 2497 | /** |
||
| 2498 | * @param Member $member |
||
| 2499 | * |
||
| 2500 | * @return bool |
||
| 2501 | **/ |
||
| 2502 | public function canDelete($member = null) |
||
| 2518 | |||
| 2519 | /** |
||
| 2520 | * Returns all the order logs that the current member can view |
||
| 2521 | * i.e. some order logs can only be viewed by the admin (e.g. suspected fraud orderlog). |
||
| 2522 | * |
||
| 2523 | * @return ArrayList (OrderStatusLogs) |
||
| 2524 | **/ |
||
| 2525 | public function CanViewOrderStatusLogs() |
||
| 2537 | |||
| 2538 | /** |
||
| 2539 | * returns all the logs that can be viewed by the customer. |
||
| 2540 | * |
||
| 2541 | * @return ArrayList (OrderStausLogs) |
||
| 2542 | */ |
||
| 2543 | public function CustomerViewableOrderStatusLogs() |
||
| 2557 | |||
| 2558 | /******************************************************* |
||
| 2559 | * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...) |
||
| 2560 | *******************************************************/ |
||
| 2561 | |||
| 2562 | /** |
||
| 2563 | * returns the email to be used for customer communication. |
||
| 2564 | * |
||
| 2565 | * @return string |
||
| 2566 | */ |
||
| 2567 | public function OrderEmail() |
||
| 2589 | |||
| 2590 | /** |
||
| 2591 | * Returns true if there is a prink or email link. |
||
| 2592 | * |
||
| 2593 | * @return bool |
||
| 2594 | */ |
||
| 2595 | public function HasPrintOrEmailLink() |
||
| 2599 | |||
| 2600 | /** |
||
| 2601 | * returns the absolute link to the order that can be used in the customer communication (email). |
||
| 2602 | * |
||
| 2603 | * @return string |
||
| 2604 | */ |
||
| 2605 | public function EmailLink($type = 'Order_StatusEmail') |
||
| 2617 | |||
| 2618 | /** |
||
| 2619 | * returns the absolute link to the order for printing. |
||
| 2620 | * |
||
| 2621 | * @return string |
||
| 2622 | */ |
||
| 2623 | public function PrintLink() |
||
| 2635 | |||
| 2636 | /** |
||
| 2637 | * returns the absolute link to the order for printing. |
||
| 2638 | * |
||
| 2639 | * @return string |
||
| 2640 | */ |
||
| 2641 | public function PackingSlipLink() |
||
| 2651 | |||
| 2652 | /** |
||
| 2653 | * returns the absolute link that the customer can use to retrieve the email WITHOUT logging in. |
||
| 2654 | * |
||
| 2655 | * @return string |
||
| 2656 | */ |
||
| 2657 | public function RetrieveLink() |
||
| 2661 | |||
| 2662 | public function getRetrieveLink() |
||
| 2676 | |||
| 2677 | public function ShareLink() |
||
| 2681 | |||
| 2682 | public function getShareLink() |
||
| 2700 | |||
| 2701 | /** |
||
| 2702 | * @alias for getFeedbackLink |
||
| 2703 | * @return string |
||
| 2704 | */ |
||
| 2705 | public function FeedbackLink() |
||
| 2709 | |||
| 2710 | /** |
||
| 2711 | * @return string | null |
||
| 2712 | */ |
||
| 2713 | public function getFeedbackLink() |
||
| 2721 | |||
| 2722 | /** |
||
| 2723 | * link to delete order. |
||
| 2724 | * |
||
| 2725 | * @return string |
||
| 2726 | */ |
||
| 2727 | public function DeleteLink() |
||
| 2739 | |||
| 2740 | /** |
||
| 2741 | * link to copy order. |
||
| 2742 | * |
||
| 2743 | * @return string |
||
| 2744 | */ |
||
| 2745 | public function CopyOrderLink() |
||
| 2757 | |||
| 2758 | /** |
||
| 2759 | * A "Title" for the order, which summarises the main details (date, and customer) in a string. |
||
| 2760 | * |
||
| 2761 | * @param string $dateFormat - e.g. "D j M Y, G:i T" |
||
| 2762 | * @param bool $includeName - e.g. by Mr Johnson |
||
| 2763 | * |
||
| 2764 | * @return string |
||
| 2765 | **/ |
||
| 2766 | public function Title($dateFormat = null, $includeName = false) |
||
| 2829 | |||
| 2830 | /** |
||
| 2831 | * Returns the subtotal of the items for this order. |
||
| 2832 | * |
||
| 2833 | * @return float |
||
| 2834 | */ |
||
| 2835 | public function SubTotal() |
||
| 2853 | |||
| 2854 | /** |
||
| 2855 | * @return Currency (DB Object) |
||
| 2856 | **/ |
||
| 2857 | public function SubTotalAsCurrencyObject() |
||
| 2861 | |||
| 2862 | /** |
||
| 2863 | * @return Money |
||
| 2864 | **/ |
||
| 2865 | public function SubTotalAsMoney() |
||
| 2873 | |||
| 2874 | /** |
||
| 2875 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2876 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2877 | * |
||
| 2878 | * @return Currency (DB Object) |
||
| 2879 | **/ |
||
| 2880 | public function ModifiersSubTotalAsCurrencyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2884 | |||
| 2885 | /** |
||
| 2886 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2887 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2888 | * |
||
| 2889 | * @return Money (DB Object) |
||
| 2890 | **/ |
||
| 2891 | public function ModifiersSubTotalAsMoneyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2895 | |||
| 2896 | /** |
||
| 2897 | * Returns the total cost of an order including the additional charges or deductions of its modifiers. |
||
| 2898 | * |
||
| 2899 | * @return float |
||
| 2900 | */ |
||
| 2901 | public function Total() |
||
| 2909 | |||
| 2910 | /** |
||
| 2911 | * @return Currency (DB Object) |
||
| 2912 | **/ |
||
| 2913 | public function TotalAsCurrencyObject() |
||
| 2917 | |||
| 2918 | /** |
||
| 2919 | * @return Money |
||
| 2920 | **/ |
||
| 2921 | public function TotalAsMoney() |
||
| 2929 | |||
| 2930 | /** |
||
| 2931 | * Checks to see if any payments have been made on this order |
||
| 2932 | * and if so, subracts the payment amount from the order. |
||
| 2933 | * |
||
| 2934 | * @return float |
||
| 2935 | **/ |
||
| 2936 | public function TotalOutstanding() |
||
| 2956 | |||
| 2957 | /** |
||
| 2958 | * @return Currency (DB Object) |
||
| 2959 | **/ |
||
| 2960 | public function TotalOutstandingAsCurrencyObject() |
||
| 2964 | |||
| 2965 | /** |
||
| 2966 | * @return Money |
||
| 2967 | **/ |
||
| 2968 | public function TotalOutstandingAsMoney() |
||
| 2976 | |||
| 2977 | /** |
||
| 2978 | * @return float |
||
| 2979 | */ |
||
| 2980 | public function TotalPaid() |
||
| 3001 | |||
| 3002 | /** |
||
| 3003 | * @return Currency (DB Object) |
||
| 3004 | **/ |
||
| 3005 | public function TotalPaidAsCurrencyObject() |
||
| 3009 | |||
| 3010 | /** |
||
| 3011 | * @return Money |
||
| 3012 | **/ |
||
| 3013 | public function TotalPaidAsMoney() |
||
| 3021 | |||
| 3022 | /** |
||
| 3023 | * returns the total number of OrderItems (not modifiers). |
||
| 3024 | * This is meant to run as fast as possible to quickly check |
||
| 3025 | * if there is anything in the cart. |
||
| 3026 | * |
||
| 3027 | * @param bool $recalculate - do we need to recalculate (value is retained during lifetime of Object) |
||
| 3028 | * |
||
| 3029 | * @return int |
||
| 3030 | **/ |
||
| 3031 | public function TotalItems($recalculate = false) |
||
| 3045 | |||
| 3046 | /** |
||
| 3047 | * Little shorthand. |
||
| 3048 | * |
||
| 3049 | * @param bool $recalculate |
||
| 3050 | * |
||
| 3051 | * @return bool |
||
| 3052 | **/ |
||
| 3053 | public function MoreThanOneItemInCart($recalculate = false) |
||
| 3057 | |||
| 3058 | /** |
||
| 3059 | * returns the total number of OrderItems (not modifiers) times their respectective quantities. |
||
| 3060 | * |
||
| 3061 | * @param bool $recalculate - force recalculation |
||
| 3062 | * |
||
| 3063 | * @return float |
||
| 3064 | **/ |
||
| 3065 | public function TotalItemsTimesQuantity($recalculate = false) |
||
| 3085 | |||
| 3086 | /** |
||
| 3087 | * |
||
| 3088 | * @return string (country code) |
||
| 3089 | **/ |
||
| 3090 | public function Country() |
||
| 3094 | |||
| 3095 | /** |
||
| 3096 | * Returns the country code for the country that applies to the order. |
||
| 3097 | * @alias for getCountry |
||
| 3098 | * |
||
| 3099 | * @return string - country code e.g. NZ |
||
| 3100 | */ |
||
| 3101 | public function getCountry() |
||
| 3138 | |||
| 3139 | /** |
||
| 3140 | * is this a gift / separate shippingAddress? |
||
| 3141 | * @return Boolean |
||
| 3142 | */ |
||
| 3143 | public function IsSeparateShippingAddress() |
||
| 3147 | |||
| 3148 | /** |
||
| 3149 | * @alias for getFullNameCountry |
||
| 3150 | * |
||
| 3151 | * @return string - country name |
||
| 3152 | **/ |
||
| 3153 | public function FullNameCountry() |
||
| 3157 | |||
| 3158 | /** |
||
| 3159 | * returns name of coutry. |
||
| 3160 | * |
||
| 3161 | * @return string - country name |
||
| 3162 | **/ |
||
| 3163 | public function getFullNameCountry() |
||
| 3167 | |||
| 3168 | /** |
||
| 3169 | * @alis for getExpectedCountryName |
||
| 3170 | * @return string - country name |
||
| 3171 | **/ |
||
| 3172 | public function ExpectedCountryName() |
||
| 3176 | |||
| 3177 | /** |
||
| 3178 | * returns name of coutry that we expect the customer to have |
||
| 3179 | * This takes into consideration more than just what has been entered |
||
| 3180 | * for example, it looks at GEO IP. |
||
| 3181 | * |
||
| 3182 | * @todo: why do we dont return a string IF there is only one item. |
||
| 3183 | * |
||
| 3184 | * @return string - country name |
||
| 3185 | **/ |
||
| 3186 | public function getExpectedCountryName() |
||
| 3190 | |||
| 3191 | /** |
||
| 3192 | * return the title of the fixed country (if any). |
||
| 3193 | * |
||
| 3194 | * @return string | empty string |
||
| 3195 | **/ |
||
| 3196 | public function FixedCountry() |
||
| 3209 | |||
| 3210 | /** |
||
| 3211 | * Returns the region that applies to the order. |
||
| 3212 | * we check both billing and shipping, in case one of them is empty. |
||
| 3213 | * |
||
| 3214 | * @return DataObject | Null (EcommerceRegion) |
||
| 3215 | **/ |
||
| 3216 | public function Region() |
||
| 3253 | |||
| 3254 | /** |
||
| 3255 | * Casted variable |
||
| 3256 | * Currency is not the same as the standard one? |
||
| 3257 | * |
||
| 3258 | * @return bool |
||
| 3259 | **/ |
||
| 3260 | public function HasAlternativeCurrency() |
||
| 3276 | |||
| 3277 | /** |
||
| 3278 | * Makes sure exchange rate is updated and maintained before order is submitted |
||
| 3279 | * This method is public because it could be called from a shopping Cart Object. |
||
| 3280 | **/ |
||
| 3281 | public function EnsureCorrectExchangeRate() |
||
| 3299 | |||
| 3300 | /** |
||
| 3301 | * speeds up processing by storing the IsSubmitted value |
||
| 3302 | * we start with -1 to know if it has been requested before. |
||
| 3303 | * |
||
| 3304 | * @var bool |
||
| 3305 | */ |
||
| 3306 | protected $_isSubmittedTempVar = -1; |
||
| 3307 | |||
| 3308 | /** |
||
| 3309 | * Casted variable - has the order been submitted? |
||
| 3310 | * alias |
||
| 3311 | * @param bool $recalculate |
||
| 3312 | * |
||
| 3313 | * @return bool |
||
| 3314 | **/ |
||
| 3315 | public function IsSubmitted($recalculate = true) |
||
| 3319 | |||
| 3320 | /** |
||
| 3321 | * Casted variable - has the order been submitted? |
||
| 3322 | * |
||
| 3323 | * @param bool $recalculate |
||
| 3324 | * |
||
| 3325 | * @return bool |
||
| 3326 | **/ |
||
| 3327 | public function getIsSubmitted($recalculate = false) |
||
| 3339 | |||
| 3340 | /** |
||
| 3341 | * |
||
| 3342 | * |
||
| 3343 | * @return bool |
||
| 3344 | */ |
||
| 3345 | public function IsArchived() |
||
| 3355 | |||
| 3356 | /** |
||
| 3357 | * Submission Log for this Order (if any). |
||
| 3358 | * |
||
| 3359 | * @return Submission Log (OrderStatusLog_Submitted) | Null |
||
| 3360 | **/ |
||
| 3361 | public function SubmissionLog() |
||
| 3369 | |||
| 3370 | /** |
||
| 3371 | * Submission Log for this Order (if any). |
||
| 3372 | * |
||
| 3373 | * @return DateTime |
||
| 3374 | **/ |
||
| 3375 | public function OrderDate() |
||
| 3386 | |||
| 3387 | /** |
||
| 3388 | * @return int |
||
| 3389 | */ |
||
| 3390 | public function SecondsSinceBeingSubmitted() |
||
| 3398 | |||
| 3399 | /** |
||
| 3400 | * if the order can not be submitted, |
||
| 3401 | * then the reasons why it can not be submitted |
||
| 3402 | * will be returned by this method. |
||
| 3403 | * |
||
| 3404 | * @see Order::canSubmit |
||
| 3405 | * |
||
| 3406 | * @return ArrayList | null |
||
| 3407 | */ |
||
| 3408 | public function SubmitErrors() |
||
| 3424 | |||
| 3425 | /** |
||
| 3426 | * Casted variable - has the order been submitted? |
||
| 3427 | * |
||
| 3428 | * @param bool $withDetail |
||
| 3429 | * |
||
| 3430 | * @return string |
||
| 3431 | **/ |
||
| 3432 | public function CustomerStatus($withDetail = true) |
||
| 3454 | |||
| 3455 | /** |
||
| 3456 | * Casted variable - does the order have a potential shipping address? |
||
| 3457 | * |
||
| 3458 | * @return bool |
||
| 3459 | **/ |
||
| 3460 | public function CanHaveShippingAddress() |
||
| 3468 | |||
| 3469 | /** |
||
| 3470 | * returns the link to view the Order |
||
| 3471 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3472 | * |
||
| 3473 | * @return CartPage | Null |
||
| 3474 | */ |
||
| 3475 | public function DisplayPage() |
||
| 3493 | |||
| 3494 | /** |
||
| 3495 | * returns the link to view the Order |
||
| 3496 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3497 | * If a cart page has been created then we refer through to Cart Page. |
||
| 3498 | * Otherwise it will default to the checkout page. |
||
| 3499 | * |
||
| 3500 | * @param string $action - any action that should be added to the link. |
||
| 3501 | * |
||
| 3502 | * @return String(URLSegment) |
||
| 3503 | */ |
||
| 3504 | public function Link($action = null) |
||
| 3520 | |||
| 3521 | /** |
||
| 3522 | * Returns to link to access the Order's API. |
||
| 3523 | * |
||
| 3524 | * @param string $version |
||
| 3525 | * @param string $extension |
||
| 3526 | * |
||
| 3527 | * @return String(URL) |
||
| 3528 | */ |
||
| 3529 | public function APILink($version = 'v1', $extension = 'xml') |
||
| 3533 | |||
| 3534 | /** |
||
| 3535 | * returns the link to finalise the Order. |
||
| 3536 | * |
||
| 3537 | * @return String(URLSegment) |
||
| 3538 | */ |
||
| 3539 | public function CheckoutLink() |
||
| 3554 | |||
| 3555 | /** |
||
| 3556 | * Converts the Order into HTML, based on the Order Template. |
||
| 3557 | * |
||
| 3558 | * @return HTML Object |
||
| 3559 | **/ |
||
| 3560 | public function ConvertToHTML() |
||
| 3570 | |||
| 3571 | /** |
||
| 3572 | * Converts the Order into a serialized string |
||
| 3573 | * TO DO: check if this works and check if we need to use special sapphire serialization code. |
||
| 3574 | * |
||
| 3575 | * @return string - serialized object |
||
| 3576 | **/ |
||
| 3577 | public function ConvertToString() |
||
| 3581 | |||
| 3582 | /** |
||
| 3583 | * Converts the Order into a JSON object |
||
| 3584 | * TO DO: check if this works and check if we need to use special sapphire JSON code. |
||
| 3585 | * |
||
| 3586 | * @return string - JSON |
||
| 3587 | **/ |
||
| 3588 | public function ConvertToJSON() |
||
| 3592 | |||
| 3593 | /** |
||
| 3594 | * returns itself wtih more data added as variables. |
||
| 3595 | * We add has_one and has_many as variables like this: $this->MyHasOne_serialized = serialize($this->MyHasOne()). |
||
| 3596 | * |
||
| 3597 | * @return Order - with most important has one and has many items included as variables. |
||
| 3598 | **/ |
||
| 3599 | protected function addHasOneAndHasManyAsVariables() |
||
| 3612 | |||
| 3613 | /******************************************************* |
||
| 3614 | * 9. TEMPLATE RELATED STUFF |
||
| 3615 | *******************************************************/ |
||
| 3616 | |||
| 3617 | /** |
||
| 3618 | * returns the instance of EcommerceConfigAjax for use in templates. |
||
| 3619 | * In templates, it is used like this: |
||
| 3620 | * $EcommerceConfigAjax.TableID. |
||
| 3621 | * |
||
| 3622 | * @return EcommerceConfigAjax |
||
| 3623 | **/ |
||
| 3624 | public function AJAXDefinitions() |
||
| 3628 | |||
| 3629 | /** |
||
| 3630 | * returns the instance of EcommerceDBConfig. |
||
| 3631 | * |
||
| 3632 | * @return EcommerceDBConfig |
||
| 3633 | **/ |
||
| 3634 | public function EcomConfig() |
||
| 3638 | |||
| 3639 | /** |
||
| 3640 | * Collects the JSON data for an ajax return of the cart. |
||
| 3641 | * |
||
| 3642 | * @param array $js |
||
| 3643 | * |
||
| 3644 | * @return array (for use in AJAX for JSON) |
||
| 3645 | **/ |
||
| 3646 | public function updateForAjax(array $js) |
||
| 3699 | |||
| 3700 | /** |
||
| 3701 | * @ToDO: move to more appropriate class |
||
| 3702 | * |
||
| 3703 | * @return float |
||
| 3704 | **/ |
||
| 3705 | public function SubTotalCartValue() |
||
| 3709 | |||
| 3710 | /******************************************************* |
||
| 3711 | * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...) |
||
| 3712 | *******************************************************/ |
||
| 3713 | |||
| 3714 | /** |
||
| 3715 | *standard SS method. |
||
| 3716 | **/ |
||
| 3717 | public function populateDefaults() |
||
| 3721 | |||
| 3722 | public function onBeforeWrite() |
||
| 3737 | |||
| 3738 | /** |
||
| 3739 | * standard SS method |
||
| 3740 | * adds the ability to update order after writing it. |
||
| 3741 | **/ |
||
| 3742 | public function onAfterWrite() |
||
| 3766 | |||
| 3767 | /** |
||
| 3768 | *standard SS method. |
||
| 3769 | * |
||
| 3770 | * delete attributes, statuslogs, and payments |
||
| 3771 | * THIS SHOULD NOT BE USED AS ORDERS SHOULD BE CANCELLED NOT DELETED |
||
| 3772 | */ |
||
| 3773 | public function onBeforeDelete() |
||
| 3818 | |||
| 3819 | /******************************************************* |
||
| 3820 | * 11. DEBUG |
||
| 3821 | *******************************************************/ |
||
| 3822 | |||
| 3823 | /** |
||
| 3824 | * Debug helper method. |
||
| 3825 | * Can be called from /shoppingcart/debug/. |
||
| 3826 | * |
||
| 3827 | * @return string |
||
| 3828 | */ |
||
| 3829 | public function debug() |
||
| 3835 | } |
||
| 3836 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.