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 | 'Title', |
||
| 46 | 'Total', |
||
| 47 | 'SubTotal', |
||
| 48 | 'TotalPaid', |
||
| 49 | 'TotalOutstanding', |
||
| 50 | 'ExchangeRate', |
||
| 51 | 'CurrencyUsed', |
||
| 52 | 'TotalItems', |
||
| 53 | 'TotalItemsTimesQuantity', |
||
| 54 | 'IsCancelled', |
||
| 55 | 'Country', |
||
| 56 | 'FullNameCountry', |
||
| 57 | 'IsSubmitted', |
||
| 58 | 'CustomerStatus', |
||
| 59 | 'CanHaveShippingAddress', |
||
| 60 | 'CancelledBy', |
||
| 61 | 'CurrencyUsed', |
||
| 62 | 'BillingAddress', |
||
| 63 | 'UseShippingAddress', |
||
| 64 | 'ShippingAddress', |
||
| 65 | 'Status', |
||
| 66 | 'Attributes', |
||
| 67 | 'OrderStatusLogs', |
||
| 68 | 'MemberID', |
||
| 69 | ), |
||
| 70 | ); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * standard SS variable. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | private static $db = array( |
||
| 78 | '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 |
||
| 79 | 'UseShippingAddress' => 'Boolean', |
||
| 80 | 'CustomerOrderNote' => 'Text', |
||
| 81 | 'ExchangeRate' => 'Double', |
||
| 82 | //'TotalItems_Saved' => 'Double', |
||
| 83 | //'TotalItemsTimesQuantity_Saved' => 'Double' |
||
| 84 | ); |
||
| 85 | |||
| 86 | private static $has_one = array( |
||
| 87 | 'Member' => 'Member', |
||
| 88 | 'BillingAddress' => 'BillingAddress', |
||
| 89 | 'ShippingAddress' => 'ShippingAddress', |
||
| 90 | 'Status' => 'OrderStep', |
||
| 91 | 'CancelledBy' => 'Member', |
||
| 92 | 'CurrencyUsed' => 'EcommerceCurrency', |
||
| 93 | ); |
||
| 94 | |||
| 95 | /** |
||
| 96 | * standard SS variable. |
||
| 97 | * |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | private static $has_many = array( |
||
| 101 | 'Attributes' => 'OrderAttribute', |
||
| 102 | 'OrderStatusLogs' => 'OrderStatusLog', |
||
| 103 | 'Payments' => 'EcommercePayment', |
||
| 104 | 'Emails' => 'OrderEmailRecord', |
||
| 105 | 'OrderProcessQueue' => 'OrderProcessQueue' //there is usually only one. |
||
| 106 | ); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * standard SS variable. |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | private static $indexes = array( |
||
| 114 | 'SessionID' => true, |
||
| 115 | ); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * standard SS variable. |
||
| 119 | * |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | private static $default_sort = '"LastEdited" DESC'; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * standard SS variable. |
||
| 126 | * |
||
| 127 | * @var array |
||
| 128 | */ |
||
| 129 | private static $casting = array( |
||
| 130 | 'OrderEmail' => 'Text', |
||
| 131 | 'EmailLink' => 'Text', |
||
| 132 | 'PrintLink' => 'Text', |
||
| 133 | 'ShareLink' => 'Text', |
||
| 134 | 'RetrieveLink' => 'Text', |
||
| 135 | 'Title' => 'Text', |
||
| 136 | 'Total' => 'Currency', |
||
| 137 | 'TotalAsMoney' => 'Money', |
||
| 138 | 'SubTotal' => 'Currency', |
||
| 139 | 'SubTotalAsMoney' => 'Money', |
||
| 140 | 'TotalPaid' => 'Currency', |
||
| 141 | 'TotalPaidAsMoney' => 'Money', |
||
| 142 | 'TotalOutstanding' => 'Currency', |
||
| 143 | 'TotalOutstandingAsMoney' => 'Money', |
||
| 144 | 'HasAlternativeCurrency' => 'Boolean', |
||
| 145 | 'TotalItems' => 'Double', |
||
| 146 | 'TotalItemsTimesQuantity' => 'Double', |
||
| 147 | 'IsCancelled' => 'Boolean', |
||
| 148 | 'IsPaidNice' => 'Boolean', |
||
| 149 | 'Country' => 'Varchar(3)', //This is the applicable country for the order - for tax purposes, etc.... |
||
| 150 | 'FullNameCountry' => 'Varchar', |
||
| 151 | 'IsSubmitted' => 'Boolean', |
||
| 152 | 'CustomerStatus' => 'Varchar', |
||
| 153 | 'CanHaveShippingAddress' => 'Boolean', |
||
| 154 | ); |
||
| 155 | |||
| 156 | /** |
||
| 157 | * standard SS variable. |
||
| 158 | * |
||
| 159 | * @var string |
||
| 160 | */ |
||
| 161 | private static $singular_name = 'Order'; |
||
| 162 | public function i18n_singular_name() |
||
| 166 | |||
| 167 | /** |
||
| 168 | * standard SS variable. |
||
| 169 | * |
||
| 170 | * @var string |
||
| 171 | */ |
||
| 172 | private static $plural_name = 'Orders'; |
||
| 173 | public function i18n_plural_name() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Standard SS variable. |
||
| 180 | * |
||
| 181 | * @var string |
||
| 182 | */ |
||
| 183 | private static $description = "A collection of items that together make up the 'Order'. An order can be placed."; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Tells us if an order needs to be recalculated |
||
| 187 | * can save one for each order... |
||
| 188 | * |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | private static $_needs_recalculating = array(); |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param bool (optional) $b |
||
| 195 | * @param int (optional) $orderID |
||
| 196 | * |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | public static function set_needs_recalculating($b = true, $orderID = 0) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param int (optional) $orderID |
||
| 206 | * |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | public static function get_needs_recalculating($orderID = 0) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Total Items : total items in cart |
||
| 216 | * We start with -1 to easily identify if it has been run before. |
||
| 217 | * |
||
| 218 | * @var int |
||
| 219 | */ |
||
| 220 | protected $totalItems = null; |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Total Items : total items in cart |
||
| 224 | * We start with -1 to easily identify if it has been run before. |
||
| 225 | * |
||
| 226 | * @var float |
||
| 227 | */ |
||
| 228 | protected $totalItemsTimesQuantity = null; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Returns a set of modifier forms for use in the checkout order form, |
||
| 232 | * Controller is optional, because the orderForm has its own default controller. |
||
| 233 | * |
||
| 234 | * This method only returns the Forms that should be included outside |
||
| 235 | * the editable table... Forms within it can be called |
||
| 236 | * from through the modifier itself. |
||
| 237 | * |
||
| 238 | * @param Controller $optionalController |
||
| 239 | * @param Validator $optionalValidator |
||
| 240 | * |
||
| 241 | * @return ArrayList (ModifierForms) | Null |
||
| 242 | **/ |
||
| 243 | public function getModifierForms(Controller $optionalController = null, Validator $optionalValidator = null) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * This function returns the OrderSteps. |
||
| 268 | * |
||
| 269 | * @return ArrayList (OrderSteps) |
||
| 270 | **/ |
||
| 271 | public static function get_order_status_options() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Like the standard byID, but it checks whether we are allowed to view the order. |
||
| 278 | * |
||
| 279 | * @return: Order | Null |
||
| 280 | **/ |
||
| 281 | public static function get_by_id_if_can_view($id) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * returns a Datalist with the submitted order log included |
||
| 298 | * this allows you to sort the orders by their submit dates. |
||
| 299 | * You can retrieve this list and then add more to it (e.g. additional filters, additional joins, etc...). |
||
| 300 | * |
||
| 301 | * @param bool $onlySubmittedOrders - only include Orders that have already been submitted. |
||
| 302 | * @param bool $includeCancelledOrders - only include Orders that have already been submitted. |
||
| 303 | * |
||
| 304 | * @return DataList (Orders) |
||
| 305 | */ |
||
| 306 | public static function get_datalist_of_orders_with_submit_record($onlySubmittedOrders = true, $includeCancelledOrders = false) |
||
| 328 | |||
| 329 | /******************************************************* |
||
| 330 | * 1. CMS STUFF |
||
| 331 | *******************************************************/ |
||
| 332 | |||
| 333 | /** |
||
| 334 | * fields that we remove from the parent::getCMSFields object set. |
||
| 335 | * |
||
| 336 | * @var array |
||
| 337 | */ |
||
| 338 | protected $fieldsAndTabsToBeRemoved = array( |
||
| 339 | 'MemberID', |
||
| 340 | 'Attributes', |
||
| 341 | 'SessionID', |
||
| 342 | 'Emails', |
||
| 343 | 'BillingAddressID', |
||
| 344 | 'ShippingAddressID', |
||
| 345 | 'UseShippingAddress', |
||
| 346 | 'OrderStatusLogs', |
||
| 347 | 'Payments', |
||
| 348 | 'OrderDate', |
||
| 349 | 'ExchangeRate', |
||
| 350 | 'CurrencyUsedID', |
||
| 351 | 'StatusID', |
||
| 352 | 'Currency', |
||
| 353 | ); |
||
| 354 | |||
| 355 | /** |
||
| 356 | * STANDARD SILVERSTRIPE STUFF. |
||
| 357 | **/ |
||
| 358 | private static $summary_fields = array( |
||
| 359 | 'Title' => 'Title', |
||
| 360 | 'Status.Title' => 'Next Step', |
||
| 361 | 'Member.Surname' => 'Name', |
||
| 362 | 'Member.Email' => 'Email', |
||
| 363 | 'TotalAsMoney.Nice' => 'Total', |
||
| 364 | 'TotalItemsTimesQuantity' => 'Units', |
||
| 365 | 'IsPaidNice' => 'Paid' |
||
| 366 | ); |
||
| 367 | |||
| 368 | /** |
||
| 369 | * STANDARD SILVERSTRIPE STUFF. |
||
| 370 | * |
||
| 371 | * @todo: how to translate this? |
||
| 372 | **/ |
||
| 373 | private static $searchable_fields = array( |
||
| 374 | 'ID' => array( |
||
| 375 | 'field' => 'NumericField', |
||
| 376 | 'title' => 'Order Number', |
||
| 377 | ), |
||
| 378 | 'MemberID' => array( |
||
| 379 | 'field' => 'TextField', |
||
| 380 | 'filter' => 'OrderFilters_MemberAndAddress', |
||
| 381 | 'title' => 'Customer Details', |
||
| 382 | ), |
||
| 383 | 'Created' => array( |
||
| 384 | 'field' => 'TextField', |
||
| 385 | 'filter' => 'OrderFilters_AroundDateFilter', |
||
| 386 | 'title' => 'Date (e.g. Today, 1 jan 2007, or last week)', |
||
| 387 | ), |
||
| 388 | //make sure to keep the items below, otherwise they do not show in form |
||
| 389 | 'StatusID' => array( |
||
| 390 | 'filter' => 'OrderFilters_MultiOptionsetStatusIDFilter', |
||
| 391 | ), |
||
| 392 | 'CancelledByID' => array( |
||
| 393 | 'filter' => 'OrderFilters_HasBeenCancelled', |
||
| 394 | 'title' => 'Cancelled by ...', |
||
| 395 | ), |
||
| 396 | ); |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Determine which properties on the DataObject are |
||
| 400 | * searchable, and map them to their default {@link FormField} |
||
| 401 | * representations. Used for scaffolding a searchform for {@link ModelAdmin}. |
||
| 402 | * |
||
| 403 | * Some additional logic is included for switching field labels, based on |
||
| 404 | * how generic or specific the field type is. |
||
| 405 | * |
||
| 406 | * Used by {@link SearchContext}. |
||
| 407 | * |
||
| 408 | * @param array $_params |
||
| 409 | * 'fieldClasses': Associative array of field names as keys and FormField classes as values |
||
| 410 | * 'restrictFields': Numeric array of a field name whitelist |
||
| 411 | * |
||
| 412 | * @return FieldList |
||
| 413 | */ |
||
| 414 | public function scaffoldSearchFields($_params = null) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * link to edit the record. |
||
| 466 | * |
||
| 467 | * @param string | Null $action - e.g. edit |
||
| 468 | * |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public function CMSEditLink($action = null) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * STANDARD SILVERSTRIPE STUFF |
||
| 482 | * broken up into submitted and not (yet) submitted. |
||
| 483 | **/ |
||
| 484 | public function getCMSFields() |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Field to add and edit Order Items. |
||
| 864 | * |
||
| 865 | * @return GridField |
||
| 866 | */ |
||
| 867 | protected function getOrderItemsField() |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Field to add and edit Modifiers. |
||
| 877 | * |
||
| 878 | * @return GridField |
||
| 879 | */ |
||
| 880 | public function getModifierTableField() |
||
| 887 | |||
| 888 | /** |
||
| 889 | *@return GridField |
||
| 890 | **/ |
||
| 891 | protected function getBillingAddressField() |
||
| 907 | |||
| 908 | /** |
||
| 909 | *@return GridField |
||
| 910 | **/ |
||
| 911 | protected function getShippingAddressField() |
||
| 927 | |||
| 928 | /** |
||
| 929 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 930 | * |
||
| 931 | * @param string $sourceClass |
||
| 932 | * @param string $title |
||
| 933 | * |
||
| 934 | * @return GridField |
||
| 935 | **/ |
||
| 936 | public function getOrderStatusLogsTableField( |
||
| 951 | |||
| 952 | /** |
||
| 953 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 954 | * |
||
| 955 | * @param string $sourceClass |
||
| 956 | * @param string $title |
||
| 957 | * |
||
| 958 | * @return GridField |
||
| 959 | **/ |
||
| 960 | public function getOrderStatusLogsTableFieldEditable( |
||
| 970 | |||
| 971 | /** |
||
| 972 | * @param string $sourceClass |
||
| 973 | * @param string $title |
||
| 974 | * @param FieldList $fieldList (Optional) |
||
| 975 | * @param FieldList $detailedFormFields (Optional) |
||
| 976 | * |
||
| 977 | * @return GridField |
||
| 978 | **/ |
||
| 979 | protected function getOrderStatusLogsTableField_Archived( |
||
| 996 | |||
| 997 | /** |
||
| 998 | * @return GridField |
||
| 999 | **/ |
||
| 1000 | public function getEmailsTableField() |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * @return GridField |
||
| 1011 | */ |
||
| 1012 | protected function getPaymentsField() |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * @return OrderStepField |
||
| 1024 | */ |
||
| 1025 | public function OrderStepField() |
||
| 1029 | |||
| 1030 | /******************************************************* |
||
| 1031 | * 2. MAIN TRANSITION FUNCTIONS |
||
| 1032 | *******************************************************/ |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * init runs on start of a new Order (@see onAfterWrite) |
||
| 1036 | * it adds all the modifiers to the orders and the starting OrderStep. |
||
| 1037 | * |
||
| 1038 | * @param bool $recalculate |
||
| 1039 | * |
||
| 1040 | * @return DataObject (Order) |
||
| 1041 | **/ |
||
| 1042 | public function init($recalculate = false) |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * @var array |
||
| 1105 | */ |
||
| 1106 | private static $_try_to_finalise_order_is_running = array(); |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Goes through the order steps and tries to "apply" the next status to the order. |
||
| 1110 | * |
||
| 1111 | * @param bool $runAgain |
||
| 1112 | * @param bool $fromOrderQueue - is it being called from the OrderProcessQueue (or similar) |
||
| 1113 | **/ |
||
| 1114 | public function tryToFinaliseOrder($runAgain = false, $fromOrderQueue = false) |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Goes through the order steps and tries to "apply" the next step |
||
| 1169 | * Step is updated after the other one is completed... |
||
| 1170 | * |
||
| 1171 | * @return int (StatusID or false if the next status can not be "applied") |
||
| 1172 | **/ |
||
| 1173 | public function doNextStatus() |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * cancel an order. |
||
| 1191 | * |
||
| 1192 | * @param Member $member - (optional) the user cancelling the order |
||
| 1193 | * @param string $reason - (optional) the reason the order is cancelled |
||
| 1194 | * |
||
| 1195 | * @return OrderStatusLog_Cancel |
||
| 1196 | */ |
||
| 1197 | public function Cancel($member = null, $reason = '') |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * returns true if successful. |
||
| 1230 | * |
||
| 1231 | * @param bool $avoidWrites |
||
| 1232 | * |
||
| 1233 | * @return bool |
||
| 1234 | */ |
||
| 1235 | public function Archive($avoidWrites = true) |
||
| 1258 | |||
| 1259 | /******************************************************* |
||
| 1260 | * 3. STATUS RELATED FUNCTIONS / SHORTCUTS |
||
| 1261 | *******************************************************/ |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Avoids caching of $this->Status(). |
||
| 1265 | * |
||
| 1266 | * @return DataObject (current OrderStep) |
||
| 1267 | */ |
||
| 1268 | public function MyStep() |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Return the OrderStatusLog that is relevant to the Order status. |
||
| 1289 | * |
||
| 1290 | * @return OrderStatusLog |
||
| 1291 | */ |
||
| 1292 | public function RelevantLogEntry() |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * @return OrderStep (current OrderStep that can be seen by customer) |
||
| 1299 | */ |
||
| 1300 | public function CurrentStepVisibleToCustomer() |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * works out if the order is still at the first OrderStep. |
||
| 1315 | * |
||
| 1316 | * @return bool |
||
| 1317 | */ |
||
| 1318 | public function IsFirstStep() |
||
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Is the order still being "edited" by the customer? |
||
| 1333 | * |
||
| 1334 | * @return bool |
||
| 1335 | */ |
||
| 1336 | public function IsInCart() |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * The order has "passed" the IsInCart phase. |
||
| 1343 | * |
||
| 1344 | * @return bool |
||
| 1345 | */ |
||
| 1346 | public function IsPastCart() |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Are there still steps the order needs to go through? |
||
| 1353 | * |
||
| 1354 | * @return bool |
||
| 1355 | */ |
||
| 1356 | public function IsUncomplete() |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * Is the order in the :"processing" phaase.? |
||
| 1363 | * |
||
| 1364 | * @return bool |
||
| 1365 | */ |
||
| 1366 | public function IsProcessing() |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * Is the order completed? |
||
| 1373 | * |
||
| 1374 | * @return bool |
||
| 1375 | */ |
||
| 1376 | public function IsCompleted() |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Has the order been paid? |
||
| 1383 | * TODO: why do we check if there is a total at all? |
||
| 1384 | * |
||
| 1385 | * @return bool |
||
| 1386 | */ |
||
| 1387 | public function IsPaid() |
||
| 1395 | /** |
||
| 1396 | * Has the order been paid? |
||
| 1397 | * TODO: why do we check if there is a total at all? |
||
| 1398 | * |
||
| 1399 | * @return Boolean (object) |
||
| 1400 | */ |
||
| 1401 | public function IsPaidNice() |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Has the order been paid? |
||
| 1408 | * TODO: why do we check if there is a total at all? |
||
| 1409 | * |
||
| 1410 | * @return bool |
||
| 1411 | */ |
||
| 1412 | public function PaymentIsPending() |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * shows payments that are meaningfull |
||
| 1431 | * if the order has been paid then only show successful payments. |
||
| 1432 | * |
||
| 1433 | * @return DataList |
||
| 1434 | */ |
||
| 1435 | public function RelevantPayments() |
||
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Has the order been cancelled? |
||
| 1448 | * |
||
| 1449 | * @return bool |
||
| 1450 | */ |
||
| 1451 | public function IsCancelled() |
||
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Has the order been cancelled by the customer? |
||
| 1462 | * |
||
| 1463 | * @return bool |
||
| 1464 | */ |
||
| 1465 | public function IsCustomerCancelled() |
||
| 1473 | |||
| 1474 | /** |
||
| 1475 | * Has the order been cancelled by the administrator? |
||
| 1476 | * |
||
| 1477 | * @return bool |
||
| 1478 | */ |
||
| 1479 | public function IsAdminCancelled() |
||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * Is the Shop Closed for business? |
||
| 1497 | * |
||
| 1498 | * @return bool |
||
| 1499 | */ |
||
| 1500 | public function ShopClosed() |
||
| 1504 | |||
| 1505 | /******************************************************* |
||
| 1506 | * 4. LINKING ORDER WITH MEMBER AND ADDRESS |
||
| 1507 | *******************************************************/ |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * Returns a member linked to the order. |
||
| 1511 | * If a member is already linked, it will return the existing member. |
||
| 1512 | * Otherwise it will return a new Member. |
||
| 1513 | * |
||
| 1514 | * Any new member is NOT written, because we dont want to create a new member unless we have to! |
||
| 1515 | * We will not add a member to the order unless a new one is created in the checkout |
||
| 1516 | * OR the member is logged in / logs in. |
||
| 1517 | * |
||
| 1518 | * Also note that if a new member is created, it is not automatically written |
||
| 1519 | * |
||
| 1520 | * @param bool $forceCreation - if set to true then the member will always be saved in the database. |
||
| 1521 | * |
||
| 1522 | * @return Member |
||
| 1523 | **/ |
||
| 1524 | public function CreateOrReturnExistingMember($forceCreation = false) |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Returns either the existing one or a new Order Address... |
||
| 1550 | * All Orders will have a Shipping and Billing address attached to it. |
||
| 1551 | * Method used to retrieve object e.g. for $order->BillingAddress(); "BillingAddress" is the method name you can use. |
||
| 1552 | * If the method name is the same as the class name then dont worry about providing one. |
||
| 1553 | * |
||
| 1554 | * @param string $className - ClassName of the Address (e.g. BillingAddress or ShippingAddress) |
||
| 1555 | * @param string $alternativeMethodName - method to retrieve Address |
||
| 1556 | **/ |
||
| 1557 | public function CreateOrReturnExistingAddress($className = 'BillingAddress', $alternativeMethodName = '') |
||
| 1601 | |||
| 1602 | /** |
||
| 1603 | * Sets the country in the billing and shipping address. |
||
| 1604 | * |
||
| 1605 | * @param string $countryCode - code for the country e.g. NZ |
||
| 1606 | * @param bool $includeBillingAddress |
||
| 1607 | * @param bool $includeShippingAddress |
||
| 1608 | **/ |
||
| 1609 | public function SetCountryFields($countryCode, $includeBillingAddress = true, $includeShippingAddress = true) |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Sets the region in the billing and shipping address. |
||
| 1631 | * |
||
| 1632 | * @param int $regionID - ID for the region to be set |
||
| 1633 | **/ |
||
| 1634 | public function SetRegionFields($regionID) |
||
| 1649 | |||
| 1650 | /** |
||
| 1651 | * Stores the preferred currency of the order. |
||
| 1652 | * IMPORTANTLY we store the exchange rate for future reference... |
||
| 1653 | * |
||
| 1654 | * @param EcommerceCurrency $currency |
||
| 1655 | */ |
||
| 1656 | public function UpdateCurrency($newCurrency) |
||
| 1669 | |||
| 1670 | /** |
||
| 1671 | * alias for UpdateCurrency. |
||
| 1672 | * |
||
| 1673 | * @param EcommerceCurrency $currency |
||
| 1674 | */ |
||
| 1675 | public function SetCurrency($currency) |
||
| 1679 | |||
| 1680 | /******************************************************* |
||
| 1681 | * 5. CUSTOMER COMMUNICATION |
||
| 1682 | *******************************************************/ |
||
| 1683 | |||
| 1684 | /** |
||
| 1685 | * Send the invoice of the order by email. |
||
| 1686 | * |
||
| 1687 | * @param string $emailClassName (optional) class used to send email |
||
| 1688 | * @param string $subject (optional) subject for the email |
||
| 1689 | * @param string $message (optional) the main message in the email |
||
| 1690 | * @param bool $resend (optional) send the email even if it has been sent before |
||
| 1691 | * @param bool $adminOnlyOrToEmail (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1692 | * |
||
| 1693 | * @return bool TRUE on success, FALSE on failure |
||
| 1694 | */ |
||
| 1695 | public function sendEmail( |
||
| 1710 | |||
| 1711 | /** |
||
| 1712 | * Sends a message to the shop admin ONLY and not to the customer |
||
| 1713 | * This can be used by ordersteps and orderlogs to notify the admin of any potential problems. |
||
| 1714 | * |
||
| 1715 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1716 | * @param string $subject - (optional) subject for the email |
||
| 1717 | * @param string $message - (optional) message to be added with the email |
||
| 1718 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1719 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1720 | * |
||
| 1721 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1722 | */ |
||
| 1723 | public function sendAdminNotification( |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * returns the order formatted as an email. |
||
| 1741 | * |
||
| 1742 | * @param string $emailClassName - template to use. |
||
| 1743 | * @param string $subject - (optional) the subject (which can be used as title in email) |
||
| 1744 | * @param string $message - (optional) the additional message |
||
| 1745 | * |
||
| 1746 | * @return string (html) |
||
| 1747 | */ |
||
| 1748 | public function renderOrderInEmailFormat( |
||
| 1762 | |||
| 1763 | /** |
||
| 1764 | * Send a mail of the order to the client (and another to the admin). |
||
| 1765 | * |
||
| 1766 | * @param string $emailClassName - (optional) template to be used ... |
||
| 1767 | * @param string $subject - (optional) subject for the email |
||
| 1768 | * @param string $message - (optional) message to be added with the email |
||
| 1769 | * @param bool $resend - (optional) can it be sent twice? |
||
| 1770 | * @param bool | string $adminOnlyOrToEmail - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1771 | * |
||
| 1772 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1773 | */ |
||
| 1774 | protected function prepareAndSendEmail( |
||
| 1831 | |||
| 1832 | /** |
||
| 1833 | * returns the Data that can be used in the body of an order Email |
||
| 1834 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1835 | * of the email template. |
||
| 1836 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1837 | * of the email template. |
||
| 1838 | * |
||
| 1839 | * @param string $subject - (optional) subject for email |
||
| 1840 | * @param string $message - (optional) the additional message |
||
| 1841 | * |
||
| 1842 | * @return ArrayData |
||
| 1843 | * - Subject - EmailSubject |
||
| 1844 | * - Message - specific message for this order |
||
| 1845 | * - Message - custom message |
||
| 1846 | * - OrderStepMessage - generic message for step |
||
| 1847 | * - Order |
||
| 1848 | * - EmailLogo |
||
| 1849 | * - ShopPhysicalAddress |
||
| 1850 | * - CurrentDateAndTime |
||
| 1851 | * - BaseURL |
||
| 1852 | * - CC |
||
| 1853 | * - BCC |
||
| 1854 | */ |
||
| 1855 | protected function createReplacementArrayForEmail($subject = '', $message = '') |
||
| 1884 | |||
| 1885 | /******************************************************* |
||
| 1886 | * 6. ITEM MANAGEMENT |
||
| 1887 | *******************************************************/ |
||
| 1888 | |||
| 1889 | /** |
||
| 1890 | * returns a list of Order Attributes by type. |
||
| 1891 | * |
||
| 1892 | * @param array | String $types |
||
| 1893 | * |
||
| 1894 | * @return ArrayList |
||
| 1895 | */ |
||
| 1896 | public function getOrderAttributesByType($types) |
||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Returns the items of the order. |
||
| 1923 | * Items are the order items (products) and NOT the modifiers (discount, tax, etc...). |
||
| 1924 | * |
||
| 1925 | * N. B. this method returns Order Items |
||
| 1926 | * also see Buaybles |
||
| 1927 | |||
| 1928 | * |
||
| 1929 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1930 | * |
||
| 1931 | * @return DataList (OrderItems) |
||
| 1932 | */ |
||
| 1933 | public function Items($filterOrClassName = '') |
||
| 1941 | |||
| 1942 | /** |
||
| 1943 | * @alias function of Items |
||
| 1944 | * |
||
| 1945 | * N. B. this method returns Order Items |
||
| 1946 | * also see Buaybles |
||
| 1947 | * |
||
| 1948 | * @param string filter - where statement to exclude certain items. |
||
| 1949 | * @alias for Items |
||
| 1950 | * @return DataList (OrderItems) |
||
| 1951 | */ |
||
| 1952 | public function OrderItems($filterOrClassName = '') |
||
| 1956 | |||
| 1957 | /** |
||
| 1958 | * returns the buyables asscoiated with the order items. |
||
| 1959 | * |
||
| 1960 | * NB. this method retursn buyables |
||
| 1961 | * |
||
| 1962 | * @param string filter - where statement to exclude certain items. |
||
| 1963 | * |
||
| 1964 | * @return ArrayList (Buyables) |
||
| 1965 | */ |
||
| 1966 | public function Buyables($filterOrClassName = '') |
||
| 1976 | |||
| 1977 | /** |
||
| 1978 | * Return all the {@link OrderItem} instances that are |
||
| 1979 | * available as records in the database. |
||
| 1980 | * |
||
| 1981 | * @param string filter - where statement to exclude certain items, |
||
| 1982 | * 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) |
||
| 1983 | * |
||
| 1984 | * @return DataList (OrderItems) |
||
| 1985 | */ |
||
| 1986 | protected function itemsFromDatabase($filterOrClassName = '') |
||
| 2000 | |||
| 2001 | /** |
||
| 2002 | * @alias for Modifiers |
||
| 2003 | * |
||
| 2004 | * @return DataList (OrderModifiers) |
||
| 2005 | */ |
||
| 2006 | public function OrderModifiers() |
||
| 2010 | |||
| 2011 | /** |
||
| 2012 | * Returns the modifiers of the order, if it hasn't been saved yet |
||
| 2013 | * it returns the modifiers from session, if it has, it returns them |
||
| 2014 | * from the DB entry. ONLY USE OUTSIDE ORDER. |
||
| 2015 | * |
||
| 2016 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2017 | * |
||
| 2018 | * @return DataList (OrderModifiers) |
||
| 2019 | */ |
||
| 2020 | public function Modifiers($filterOrClassName = '') |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Get all {@link OrderModifier} instances that are |
||
| 2027 | * available as records in the database. |
||
| 2028 | * NOTE: includes REMOVED Modifiers, so that they do not get added again... |
||
| 2029 | * |
||
| 2030 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 2031 | * |
||
| 2032 | * @return DataList (OrderModifiers) |
||
| 2033 | */ |
||
| 2034 | protected function modifiersFromDatabase($filterOrClassName = '') |
||
| 2048 | |||
| 2049 | /** |
||
| 2050 | * Calculates and updates all the order attributes. |
||
| 2051 | * |
||
| 2052 | * @param bool $recalculate - run it, even if it has run already |
||
| 2053 | */ |
||
| 2054 | public function calculateOrderAttributes($recalculate = false) |
||
| 2068 | |||
| 2069 | /** |
||
| 2070 | * Calculates and updates all the product items. |
||
| 2071 | * |
||
| 2072 | * @param bool $recalculate - run it, even if it has run already |
||
| 2073 | */ |
||
| 2074 | protected function calculateOrderItems($recalculate = false) |
||
| 2089 | |||
| 2090 | /** |
||
| 2091 | * Calculates and updates all the modifiers. |
||
| 2092 | * |
||
| 2093 | * @param bool $recalculate - run it, even if it has run already |
||
| 2094 | */ |
||
| 2095 | protected function calculateModifiers($recalculate = false) |
||
| 2107 | |||
| 2108 | /** |
||
| 2109 | * Returns the subtotal of the modifiers for this order. |
||
| 2110 | * If a modifier appears in the excludedModifiers array, it is not counted. |
||
| 2111 | * |
||
| 2112 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2113 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2114 | * |
||
| 2115 | * @return float |
||
| 2116 | */ |
||
| 2117 | public function ModifiersSubTotal($excluded = null, $stopAtExcludedModifier = false) |
||
| 2144 | |||
| 2145 | /** |
||
| 2146 | * returns a modifier that is an instanceof the classname |
||
| 2147 | * it extends. |
||
| 2148 | * |
||
| 2149 | * @param string $className: class name for the modifier |
||
| 2150 | * |
||
| 2151 | * @return DataObject (OrderModifier) |
||
| 2152 | **/ |
||
| 2153 | public function RetrieveModifier($className) |
||
| 2164 | |||
| 2165 | /******************************************************* |
||
| 2166 | * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...) |
||
| 2167 | *******************************************************/ |
||
| 2168 | |||
| 2169 | /** |
||
| 2170 | * @param Member $member |
||
| 2171 | * |
||
| 2172 | * @return DataObject (Member) |
||
| 2173 | **/ |
||
| 2174 | //TODO: please comment why we make use of this function |
||
| 2175 | protected function getMemberForCanFunctions(Member $member = null) |
||
| 2187 | |||
| 2188 | /** |
||
| 2189 | * @param Member $member |
||
| 2190 | * |
||
| 2191 | * @return bool |
||
| 2192 | **/ |
||
| 2193 | public function canCreate($member = null) |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Standard SS method - can the current member view this order? |
||
| 2207 | * |
||
| 2208 | * @param Member $member |
||
| 2209 | * |
||
| 2210 | * @return bool |
||
| 2211 | **/ |
||
| 2212 | public function canView($member = null) |
||
| 2257 | |||
| 2258 | /** |
||
| 2259 | * @param Member $member optional |
||
| 2260 | * @return bool |
||
| 2261 | */ |
||
| 2262 | public function canOverrideCanView($member = null) |
||
| 2283 | |||
| 2284 | /** |
||
| 2285 | * @return bool |
||
| 2286 | */ |
||
| 2287 | public function IsInSession() |
||
| 2293 | |||
| 2294 | /** |
||
| 2295 | * returns a pseudo random part of the session id. |
||
| 2296 | * |
||
| 2297 | * @param int $size |
||
| 2298 | * |
||
| 2299 | * @return string |
||
| 2300 | */ |
||
| 2301 | public function LessSecureSessionID($size = 7, $start = null) |
||
| 2309 | /** |
||
| 2310 | * |
||
| 2311 | * @param Member (optional) $member |
||
| 2312 | * |
||
| 2313 | * @return bool |
||
| 2314 | **/ |
||
| 2315 | public function canViewAdminStuff($member = null) |
||
| 2326 | |||
| 2327 | /** |
||
| 2328 | * if we set canEdit to false then we |
||
| 2329 | * can not see the child records |
||
| 2330 | * Basically, you can edit when you can view and canEdit (even as a customer) |
||
| 2331 | * Or if you are a Shop Admin you can always edit. |
||
| 2332 | * Otherwise it is false... |
||
| 2333 | * |
||
| 2334 | * @param Member $member |
||
| 2335 | * |
||
| 2336 | * @return bool |
||
| 2337 | **/ |
||
| 2338 | public function canEdit($member = null) |
||
| 2357 | |||
| 2358 | /** |
||
| 2359 | * is the order ready to go through to the |
||
| 2360 | * checkout process. |
||
| 2361 | * |
||
| 2362 | * This method checks all the order items and order modifiers |
||
| 2363 | * If any of them need immediate attention then this is done |
||
| 2364 | * first after which it will go through to the checkout page. |
||
| 2365 | * |
||
| 2366 | * @param Member (optional) $member |
||
| 2367 | * |
||
| 2368 | * @return bool |
||
| 2369 | **/ |
||
| 2370 | public function canCheckout(Member $member = null) |
||
| 2384 | |||
| 2385 | /** |
||
| 2386 | * Can the order be submitted? |
||
| 2387 | * this method can be used to stop an order from being submitted |
||
| 2388 | * due to something not being completed or done. |
||
| 2389 | * |
||
| 2390 | * @see Order::SubmitErrors |
||
| 2391 | * |
||
| 2392 | * @param Member $member |
||
| 2393 | * |
||
| 2394 | * @return bool |
||
| 2395 | **/ |
||
| 2396 | public function canSubmit(Member $member = null) |
||
| 2413 | |||
| 2414 | /** |
||
| 2415 | * Can a payment be made for this Order? |
||
| 2416 | * |
||
| 2417 | * @param Member $member |
||
| 2418 | * |
||
| 2419 | * @return bool |
||
| 2420 | **/ |
||
| 2421 | public function canPay(Member $member = null) |
||
| 2434 | |||
| 2435 | /** |
||
| 2436 | * Can the given member cancel this order? |
||
| 2437 | * |
||
| 2438 | * @param Member $member |
||
| 2439 | * |
||
| 2440 | * @return bool |
||
| 2441 | **/ |
||
| 2442 | public function canCancel(Member $member = null) |
||
| 2459 | |||
| 2460 | /** |
||
| 2461 | * @param Member $member |
||
| 2462 | * |
||
| 2463 | * @return bool |
||
| 2464 | **/ |
||
| 2465 | public function canDelete($member = null) |
||
| 2481 | |||
| 2482 | /** |
||
| 2483 | * Returns all the order logs that the current member can view |
||
| 2484 | * i.e. some order logs can only be viewed by the admin (e.g. suspected fraud orderlog). |
||
| 2485 | * |
||
| 2486 | * @return ArrayList (OrderStatusLogs) |
||
| 2487 | **/ |
||
| 2488 | public function CanViewOrderStatusLogs() |
||
| 2500 | |||
| 2501 | /** |
||
| 2502 | * returns all the logs that can be viewed by the customer. |
||
| 2503 | * |
||
| 2504 | * @return ArrayList (OrderStausLogs) |
||
| 2505 | */ |
||
| 2506 | public function CustomerViewableOrderStatusLogs() |
||
| 2520 | |||
| 2521 | /******************************************************* |
||
| 2522 | * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...) |
||
| 2523 | *******************************************************/ |
||
| 2524 | |||
| 2525 | /** |
||
| 2526 | * returns the email to be used for customer communication. |
||
| 2527 | * |
||
| 2528 | * @return string |
||
| 2529 | */ |
||
| 2530 | public function OrderEmail() |
||
| 2552 | |||
| 2553 | /** |
||
| 2554 | * Returns true if there is a prink or email link. |
||
| 2555 | * |
||
| 2556 | * @return bool |
||
| 2557 | */ |
||
| 2558 | public function HasPrintOrEmailLink() |
||
| 2562 | |||
| 2563 | /** |
||
| 2564 | * returns the absolute link to the order that can be used in the customer communication (email). |
||
| 2565 | * |
||
| 2566 | * @return string |
||
| 2567 | */ |
||
| 2568 | public function EmailLink($type = 'Order_StatusEmail') |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * returns the absolute link to the order for printing. |
||
| 2583 | * |
||
| 2584 | * @return string |
||
| 2585 | */ |
||
| 2586 | public function PrintLink() |
||
| 2598 | |||
| 2599 | /** |
||
| 2600 | * returns the absolute link to the order for printing. |
||
| 2601 | * |
||
| 2602 | * @return string |
||
| 2603 | */ |
||
| 2604 | public function PackingSlipLink() |
||
| 2614 | |||
| 2615 | /** |
||
| 2616 | * returns the absolute link that the customer can use to retrieve the email WITHOUT logging in. |
||
| 2617 | * |
||
| 2618 | * @return string |
||
| 2619 | */ |
||
| 2620 | public function RetrieveLink() |
||
| 2624 | |||
| 2625 | public function getRetrieveLink() |
||
| 2639 | |||
| 2640 | public function ShareLink() |
||
| 2644 | |||
| 2645 | public function getShareLink() |
||
| 2663 | |||
| 2664 | /** |
||
| 2665 | * link to delete order. |
||
| 2666 | * |
||
| 2667 | * @return string |
||
| 2668 | */ |
||
| 2669 | public function DeleteLink() |
||
| 2681 | |||
| 2682 | /** |
||
| 2683 | * link to copy order. |
||
| 2684 | * |
||
| 2685 | * @return string |
||
| 2686 | */ |
||
| 2687 | public function CopyOrderLink() |
||
| 2699 | |||
| 2700 | /** |
||
| 2701 | * A "Title" for the order, which summarises the main details (date, and customer) in a string. |
||
| 2702 | * |
||
| 2703 | * @param string $dateFormat - e.g. "D j M Y, G:i T" |
||
| 2704 | * @param bool $includeName - e.g. by Mr Johnson |
||
| 2705 | * |
||
| 2706 | * @return string |
||
| 2707 | **/ |
||
| 2708 | public function Title($dateFormat = null, $includeName = false) |
||
| 2771 | |||
| 2772 | /** |
||
| 2773 | * Returns the subtotal of the items for this order. |
||
| 2774 | * |
||
| 2775 | * @return float |
||
| 2776 | */ |
||
| 2777 | public function SubTotal() |
||
| 2795 | |||
| 2796 | /** |
||
| 2797 | * @return Currency (DB Object) |
||
| 2798 | **/ |
||
| 2799 | public function SubTotalAsCurrencyObject() |
||
| 2803 | |||
| 2804 | /** |
||
| 2805 | * @return Money |
||
| 2806 | **/ |
||
| 2807 | public function SubTotalAsMoney() |
||
| 2815 | |||
| 2816 | /** |
||
| 2817 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2818 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2819 | * |
||
| 2820 | * @return Currency (DB Object) |
||
| 2821 | **/ |
||
| 2822 | public function ModifiersSubTotalAsCurrencyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2826 | |||
| 2827 | /** |
||
| 2828 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2829 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2830 | * |
||
| 2831 | * @return Money (DB Object) |
||
| 2832 | **/ |
||
| 2833 | public function ModifiersSubTotalAsMoneyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2837 | |||
| 2838 | /** |
||
| 2839 | * Returns the total cost of an order including the additional charges or deductions of its modifiers. |
||
| 2840 | * |
||
| 2841 | * @return float |
||
| 2842 | */ |
||
| 2843 | public function Total() |
||
| 2851 | |||
| 2852 | /** |
||
| 2853 | * @return Currency (DB Object) |
||
| 2854 | **/ |
||
| 2855 | public function TotalAsCurrencyObject() |
||
| 2859 | |||
| 2860 | /** |
||
| 2861 | * @return Money |
||
| 2862 | **/ |
||
| 2863 | public function TotalAsMoney() |
||
| 2871 | |||
| 2872 | /** |
||
| 2873 | * Checks to see if any payments have been made on this order |
||
| 2874 | * and if so, subracts the payment amount from the order. |
||
| 2875 | * |
||
| 2876 | * @return float |
||
| 2877 | **/ |
||
| 2878 | public function TotalOutstanding() |
||
| 2898 | |||
| 2899 | /** |
||
| 2900 | * @return Currency (DB Object) |
||
| 2901 | **/ |
||
| 2902 | public function TotalOutstandingAsCurrencyObject() |
||
| 2906 | |||
| 2907 | /** |
||
| 2908 | * @return Money |
||
| 2909 | **/ |
||
| 2910 | public function TotalOutstandingAsMoney() |
||
| 2918 | |||
| 2919 | /** |
||
| 2920 | * @return float |
||
| 2921 | */ |
||
| 2922 | public function TotalPaid() |
||
| 2943 | |||
| 2944 | /** |
||
| 2945 | * @return Currency (DB Object) |
||
| 2946 | **/ |
||
| 2947 | public function TotalPaidAsCurrencyObject() |
||
| 2951 | |||
| 2952 | /** |
||
| 2953 | * @return Money |
||
| 2954 | **/ |
||
| 2955 | public function TotalPaidAsMoney() |
||
| 2963 | |||
| 2964 | /** |
||
| 2965 | * returns the total number of OrderItems (not modifiers). |
||
| 2966 | * This is meant to run as fast as possible to quickly check |
||
| 2967 | * if there is anything in the cart. |
||
| 2968 | * |
||
| 2969 | * @param bool $recalculate - do we need to recalculate (value is retained during lifetime of Object) |
||
| 2970 | * |
||
| 2971 | * @return int |
||
| 2972 | **/ |
||
| 2973 | public function TotalItems($recalculate = false) |
||
| 2987 | |||
| 2988 | /** |
||
| 2989 | * Little shorthand. |
||
| 2990 | * |
||
| 2991 | * @param bool $recalculate |
||
| 2992 | * |
||
| 2993 | * @return bool |
||
| 2994 | **/ |
||
| 2995 | public function MoreThanOneItemInCart($recalculate = false) |
||
| 2999 | |||
| 3000 | /** |
||
| 3001 | * returns the total number of OrderItems (not modifiers) times their respectective quantities. |
||
| 3002 | * |
||
| 3003 | * @param bool $recalculate - force recalculation |
||
| 3004 | * |
||
| 3005 | * @return float |
||
| 3006 | **/ |
||
| 3007 | public function TotalItemsTimesQuantity($recalculate = false) |
||
| 3027 | |||
| 3028 | /** |
||
| 3029 | * |
||
| 3030 | * @return string (country code) |
||
| 3031 | **/ |
||
| 3032 | public function Country() |
||
| 3036 | |||
| 3037 | /** |
||
| 3038 | * Returns the country code for the country that applies to the order. |
||
| 3039 | * @alias for getCountry |
||
| 3040 | * |
||
| 3041 | * @return string - country code e.g. NZ |
||
| 3042 | */ |
||
| 3043 | public function getCountry() |
||
| 3080 | |||
| 3081 | /** |
||
| 3082 | * @alias for getFullNameCountry |
||
| 3083 | * |
||
| 3084 | * @return string - country name |
||
| 3085 | **/ |
||
| 3086 | public function FullNameCountry() |
||
| 3090 | |||
| 3091 | /** |
||
| 3092 | * returns name of coutry. |
||
| 3093 | * |
||
| 3094 | * @return string - country name |
||
| 3095 | **/ |
||
| 3096 | public function getFullNameCountry() |
||
| 3100 | |||
| 3101 | /** |
||
| 3102 | * @alis for getExpectedCountryName |
||
| 3103 | * @return string - country name |
||
| 3104 | **/ |
||
| 3105 | public function ExpectedCountryName() |
||
| 3109 | |||
| 3110 | /** |
||
| 3111 | * returns name of coutry that we expect the customer to have |
||
| 3112 | * This takes into consideration more than just what has been entered |
||
| 3113 | * for example, it looks at GEO IP. |
||
| 3114 | * |
||
| 3115 | * @todo: why do we dont return a string IF there is only one item. |
||
| 3116 | * |
||
| 3117 | * @return string - country name |
||
| 3118 | **/ |
||
| 3119 | public function getExpectedCountryName() |
||
| 3123 | |||
| 3124 | /** |
||
| 3125 | * return the title of the fixed country (if any). |
||
| 3126 | * |
||
| 3127 | * @return string | empty string |
||
| 3128 | **/ |
||
| 3129 | public function FixedCountry() |
||
| 3142 | |||
| 3143 | /** |
||
| 3144 | * Returns the region that applies to the order. |
||
| 3145 | * we check both billing and shipping, in case one of them is empty. |
||
| 3146 | * |
||
| 3147 | * @return DataObject | Null (EcommerceRegion) |
||
| 3148 | **/ |
||
| 3149 | public function Region() |
||
| 3186 | |||
| 3187 | /** |
||
| 3188 | * Casted variable |
||
| 3189 | * Currency is not the same as the standard one? |
||
| 3190 | * |
||
| 3191 | * @return bool |
||
| 3192 | **/ |
||
| 3193 | public function HasAlternativeCurrency() |
||
| 3209 | |||
| 3210 | /** |
||
| 3211 | * Makes sure exchange rate is updated and maintained before order is submitted |
||
| 3212 | * This method is public because it could be called from a shopping Cart Object. |
||
| 3213 | **/ |
||
| 3214 | public function EnsureCorrectExchangeRate() |
||
| 3232 | |||
| 3233 | /** |
||
| 3234 | * speeds up processing by storing the IsSubmitted value |
||
| 3235 | * we start with -1 to know if it has been requested before. |
||
| 3236 | * |
||
| 3237 | * @var bool |
||
| 3238 | */ |
||
| 3239 | protected $_isSubmittedTempVar = -1; |
||
| 3240 | |||
| 3241 | /** |
||
| 3242 | * Casted variable - has the order been submitted? |
||
| 3243 | * alias |
||
| 3244 | * @param bool $recalculate |
||
| 3245 | * |
||
| 3246 | * @return bool |
||
| 3247 | **/ |
||
| 3248 | public function IsSubmitted($recalculate = true) |
||
| 3252 | |||
| 3253 | /** |
||
| 3254 | * Casted variable - has the order been submitted? |
||
| 3255 | * |
||
| 3256 | * @param bool $recalculate |
||
| 3257 | * |
||
| 3258 | * @return bool |
||
| 3259 | **/ |
||
| 3260 | public function getIsSubmitted($recalculate = false) |
||
| 3272 | |||
| 3273 | /** |
||
| 3274 | * |
||
| 3275 | * |
||
| 3276 | * @return bool |
||
| 3277 | */ |
||
| 3278 | public function IsArchived() |
||
| 3288 | |||
| 3289 | /** |
||
| 3290 | * Submission Log for this Order (if any). |
||
| 3291 | * |
||
| 3292 | * @return Submission Log (OrderStatusLog_Submitted) | Null |
||
| 3293 | **/ |
||
| 3294 | public function SubmissionLog() |
||
| 3302 | |||
| 3303 | /** |
||
| 3304 | * @return int |
||
| 3305 | */ |
||
| 3306 | public function SecondsSinceBeingSubmitted() |
||
| 3314 | |||
| 3315 | /** |
||
| 3316 | * if the order can not be submitted, |
||
| 3317 | * then the reasons why it can not be submitted |
||
| 3318 | * will be returned by this method. |
||
| 3319 | * |
||
| 3320 | * @see Order::canSubmit |
||
| 3321 | * |
||
| 3322 | * @return ArrayList | null |
||
| 3323 | */ |
||
| 3324 | public function SubmitErrors() |
||
| 3340 | |||
| 3341 | /** |
||
| 3342 | * Casted variable - has the order been submitted? |
||
| 3343 | * |
||
| 3344 | * @param bool $withDetail |
||
| 3345 | * |
||
| 3346 | * @return string |
||
| 3347 | **/ |
||
| 3348 | public function CustomerStatus($withDetail = true) |
||
| 3370 | |||
| 3371 | /** |
||
| 3372 | * Casted variable - does the order have a potential shipping address? |
||
| 3373 | * |
||
| 3374 | * @return bool |
||
| 3375 | **/ |
||
| 3376 | public function CanHaveShippingAddress() |
||
| 3384 | |||
| 3385 | /** |
||
| 3386 | * returns the link to view the Order |
||
| 3387 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3388 | * |
||
| 3389 | * @return CartPage | Null |
||
| 3390 | */ |
||
| 3391 | public function DisplayPage() |
||
| 3408 | |||
| 3409 | /** |
||
| 3410 | * returns the link to view the Order |
||
| 3411 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3412 | * If a cart page has been created then we refer through to Cart Page. |
||
| 3413 | * Otherwise it will default to the checkout page. |
||
| 3414 | * |
||
| 3415 | * @param string $action - any action that should be added to the link. |
||
| 3416 | * |
||
| 3417 | * @return String(URLSegment) |
||
| 3418 | */ |
||
| 3419 | public function Link($action = null) |
||
| 3434 | |||
| 3435 | /** |
||
| 3436 | * Returns to link to access the Order's API. |
||
| 3437 | * |
||
| 3438 | * @param string $version |
||
| 3439 | * @param string $extension |
||
| 3440 | * |
||
| 3441 | * @return String(URL) |
||
| 3442 | */ |
||
| 3443 | public function APILink($version = 'v1', $extension = 'xml') |
||
| 3447 | |||
| 3448 | /** |
||
| 3449 | * returns the link to finalise the Order. |
||
| 3450 | * |
||
| 3451 | * @return String(URLSegment) |
||
| 3452 | */ |
||
| 3453 | public function CheckoutLink() |
||
| 3467 | |||
| 3468 | /** |
||
| 3469 | * Converts the Order into HTML, based on the Order Template. |
||
| 3470 | * |
||
| 3471 | * @return HTML Object |
||
| 3472 | **/ |
||
| 3473 | public function ConvertToHTML() |
||
| 3483 | |||
| 3484 | /** |
||
| 3485 | * Converts the Order into a serialized string |
||
| 3486 | * TO DO: check if this works and check if we need to use special sapphire serialization code. |
||
| 3487 | * |
||
| 3488 | * @return string - serialized object |
||
| 3489 | **/ |
||
| 3490 | public function ConvertToString() |
||
| 3494 | |||
| 3495 | /** |
||
| 3496 | * Converts the Order into a JSON object |
||
| 3497 | * TO DO: check if this works and check if we need to use special sapphire JSON code. |
||
| 3498 | * |
||
| 3499 | * @return string - JSON |
||
| 3500 | **/ |
||
| 3501 | public function ConvertToJSON() |
||
| 3505 | |||
| 3506 | /** |
||
| 3507 | * returns itself wtih more data added as variables. |
||
| 3508 | * We add has_one and has_many as variables like this: $this->MyHasOne_serialized = serialize($this->MyHasOne()). |
||
| 3509 | * |
||
| 3510 | * @return Order - with most important has one and has many items included as variables. |
||
| 3511 | **/ |
||
| 3512 | protected function addHasOneAndHasManyAsVariables() |
||
| 3525 | |||
| 3526 | /******************************************************* |
||
| 3527 | * 9. TEMPLATE RELATED STUFF |
||
| 3528 | *******************************************************/ |
||
| 3529 | |||
| 3530 | /** |
||
| 3531 | * returns the instance of EcommerceConfigAjax for use in templates. |
||
| 3532 | * In templates, it is used like this: |
||
| 3533 | * $EcommerceConfigAjax.TableID. |
||
| 3534 | * |
||
| 3535 | * @return EcommerceConfigAjax |
||
| 3536 | **/ |
||
| 3537 | public function AJAXDefinitions() |
||
| 3541 | |||
| 3542 | /** |
||
| 3543 | * returns the instance of EcommerceDBConfig. |
||
| 3544 | * |
||
| 3545 | * @return EcommerceDBConfig |
||
| 3546 | **/ |
||
| 3547 | public function EcomConfig() |
||
| 3551 | |||
| 3552 | /** |
||
| 3553 | * Collects the JSON data for an ajax return of the cart. |
||
| 3554 | * |
||
| 3555 | * @param array $js |
||
| 3556 | * |
||
| 3557 | * @return array (for use in AJAX for JSON) |
||
| 3558 | **/ |
||
| 3559 | public function updateForAjax(array $js) |
||
| 3612 | |||
| 3613 | /** |
||
| 3614 | * @ToDO: move to more appropriate class |
||
| 3615 | * |
||
| 3616 | * @return float |
||
| 3617 | **/ |
||
| 3618 | public function SubTotalCartValue() |
||
| 3622 | |||
| 3623 | /******************************************************* |
||
| 3624 | * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...) |
||
| 3625 | *******************************************************/ |
||
| 3626 | |||
| 3627 | /** |
||
| 3628 | *standard SS method. |
||
| 3629 | **/ |
||
| 3630 | public function populateDefaults() |
||
| 3634 | |||
| 3635 | public function onBeforeWrite() |
||
| 3650 | |||
| 3651 | /** |
||
| 3652 | * standard SS method |
||
| 3653 | * adds the ability to update order after writing it. |
||
| 3654 | **/ |
||
| 3655 | public function onAfterWrite() |
||
| 3679 | |||
| 3680 | /** |
||
| 3681 | *standard SS method. |
||
| 3682 | * |
||
| 3683 | * delete attributes, statuslogs, and payments |
||
| 3684 | * THIS SHOULD NOT BE USED AS ORDERS SHOULD BE CANCELLED NOT DELETED |
||
| 3685 | */ |
||
| 3686 | public function onBeforeDelete() |
||
| 3731 | |||
| 3732 | /******************************************************* |
||
| 3733 | * 11. DEBUG |
||
| 3734 | *******************************************************/ |
||
| 3735 | |||
| 3736 | /** |
||
| 3737 | * Debug helper method. |
||
| 3738 | * Can be called from /shoppingcart/debug/. |
||
| 3739 | * |
||
| 3740 | * @return string |
||
| 3741 | */ |
||
| 3742 | public function debug() |
||
| 3748 | } |
||
| 3749 |
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.