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 | ); |
||
| 106 | |||
| 107 | /** |
||
| 108 | * standard SS variable. |
||
| 109 | * |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | private static $indexes = array( |
||
| 113 | 'SessionID' => true, |
||
| 114 | ); |
||
| 115 | |||
| 116 | /** |
||
| 117 | * standard SS variable. |
||
| 118 | * |
||
| 119 | * @var string |
||
| 120 | */ |
||
| 121 | private static $default_sort = '"LastEdited" DESC'; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * standard SS variable. |
||
| 125 | * |
||
| 126 | * @var array |
||
| 127 | */ |
||
| 128 | private static $casting = array( |
||
| 129 | 'OrderEmail' => 'Text', |
||
| 130 | 'EmailLink' => 'Text', |
||
| 131 | 'PrintLink' => 'Text', |
||
| 132 | 'ShareLink' => 'Text', |
||
| 133 | 'RetrieveLink' => 'Text', |
||
| 134 | 'Title' => 'Text', |
||
| 135 | 'Total' => 'Currency', |
||
| 136 | 'TotalAsMoney' => 'Money', |
||
| 137 | 'SubTotal' => 'Currency', |
||
| 138 | 'SubTotalAsMoney' => 'Money', |
||
| 139 | 'TotalPaid' => 'Currency', |
||
| 140 | 'TotalPaidAsMoney' => 'Money', |
||
| 141 | 'TotalOutstanding' => 'Currency', |
||
| 142 | 'TotalOutstandingAsMoney' => 'Money', |
||
| 143 | 'HasAlternativeCurrency' => 'Boolean', |
||
| 144 | 'TotalItems' => 'Double', |
||
| 145 | 'TotalItemsTimesQuantity' => 'Double', |
||
| 146 | 'IsCancelled' => 'Boolean', |
||
| 147 | 'Country' => 'Varchar(3)', //This is the applicable country for the order - for tax purposes, etc.... |
||
| 148 | 'FullNameCountry' => 'Varchar', |
||
| 149 | 'IsSubmitted' => 'Boolean', |
||
| 150 | 'CustomerStatus' => 'Varchar', |
||
| 151 | 'CanHaveShippingAddress' => 'Boolean', |
||
| 152 | ); |
||
| 153 | |||
| 154 | /** |
||
| 155 | * standard SS variable. |
||
| 156 | * |
||
| 157 | * @var string |
||
| 158 | */ |
||
| 159 | private static $singular_name = 'Order'; |
||
| 160 | public function i18n_singular_name() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * standard SS variable. |
||
| 167 | * |
||
| 168 | * @var string |
||
| 169 | */ |
||
| 170 | private static $plural_name = 'Orders'; |
||
| 171 | public function i18n_plural_name() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Standard SS variable. |
||
| 178 | * |
||
| 179 | * @var string |
||
| 180 | */ |
||
| 181 | private static $description = "A collection of items that together make up the 'Order'. An order can be placed."; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Tells us if an order needs to be recalculated |
||
| 185 | * can save one for each order... |
||
| 186 | * |
||
| 187 | * @var array |
||
| 188 | */ |
||
| 189 | private static $_needs_recalculating = array(); |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param bool (optional) $b |
||
| 193 | * @param int (optional) $orderID |
||
| 194 | * |
||
| 195 | * @return bool |
||
| 196 | */ |
||
| 197 | public static function set_needs_recalculating($b = true, $orderID = 0) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param int (optional) $orderID |
||
| 204 | * |
||
| 205 | * @return bool |
||
| 206 | */ |
||
| 207 | public static function get_needs_recalculating($orderID = 0) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Total Items : total items in cart |
||
| 214 | * We start with -1 to easily identify if it has been run before. |
||
| 215 | * |
||
| 216 | * @var int |
||
| 217 | */ |
||
| 218 | protected $totalItems = null; |
||
| 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 float |
||
| 225 | */ |
||
| 226 | protected $totalItemsTimesQuantity = null; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Returns a set of modifier forms for use in the checkout order form, |
||
| 230 | * Controller is optional, because the orderForm has its own default controller. |
||
| 231 | * |
||
| 232 | * This method only returns the Forms that should be included outside |
||
| 233 | * the editable table... Forms within it can be called |
||
| 234 | * from through the modifier itself. |
||
| 235 | * |
||
| 236 | * @param Controller $optionalController |
||
| 237 | * @param Validator $optionalValidator |
||
| 238 | * |
||
| 239 | * @return ArrayList (ModifierForms) | Null |
||
| 240 | **/ |
||
| 241 | public function getModifierForms(Controller $optionalController = null, Validator $optionalValidator = null) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * This function returns the OrderSteps. |
||
| 266 | * |
||
| 267 | * @return ArrayList (OrderSteps) |
||
| 268 | **/ |
||
| 269 | public static function get_order_status_options() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Like the standard byID, but it checks whether we are allowed to view the order. |
||
| 276 | * |
||
| 277 | * @return: Order | Null |
||
| 278 | **/ |
||
| 279 | public static function get_by_id_if_can_view($id) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * returns a Datalist with the submitted order log included |
||
| 296 | * this allows you to sort the orders by their submit dates. |
||
| 297 | * You can retrieve this list and then add more to it (e.g. additional filters, additional joins, etc...). |
||
| 298 | * |
||
| 299 | * @param bool $onlySubmittedOrders - only include Orders that have already been submitted. |
||
| 300 | * @param bool $includeCancelledOrders - only include Orders that have already been submitted. |
||
| 301 | * |
||
| 302 | * @return DataList (Orders) |
||
| 303 | */ |
||
| 304 | public static function get_datalist_of_orders_with_submit_record($onlySubmittedOrders = true, $includeCancelledOrders = false) |
||
| 326 | |||
| 327 | /******************************************************* |
||
| 328 | * 1. CMS STUFF |
||
| 329 | *******************************************************/ |
||
| 330 | |||
| 331 | /** |
||
| 332 | * fields that we remove from the parent::getCMSFields object set. |
||
| 333 | * |
||
| 334 | * @var array |
||
| 335 | */ |
||
| 336 | protected $fieldsAndTabsToBeRemoved = array( |
||
| 337 | 'MemberID', |
||
| 338 | 'Attributes', |
||
| 339 | 'SessionID', |
||
| 340 | 'Emails', |
||
| 341 | 'BillingAddressID', |
||
| 342 | 'ShippingAddressID', |
||
| 343 | 'UseShippingAddress', |
||
| 344 | 'OrderStatusLogs', |
||
| 345 | 'Payments', |
||
| 346 | 'OrderDate', |
||
| 347 | 'ExchangeRate', |
||
| 348 | 'CurrencyUsedID', |
||
| 349 | 'StatusID', |
||
| 350 | 'Currency', |
||
| 351 | ); |
||
| 352 | |||
| 353 | /** |
||
| 354 | * STANDARD SILVERSTRIPE STUFF. |
||
| 355 | **/ |
||
| 356 | private static $summary_fields = array( |
||
| 357 | 'Title' => 'Title', |
||
| 358 | 'Status.Title' => 'Next Step', |
||
| 359 | 'Member.Surname' => 'Name', |
||
| 360 | 'Member.Email' => 'Email', |
||
| 361 | 'TotalAsMoney.Nice' => 'Total', |
||
| 362 | 'TotalItemsTimesQuantity' => 'Units' |
||
| 363 | ); |
||
| 364 | |||
| 365 | /** |
||
| 366 | * STANDARD SILVERSTRIPE STUFF. |
||
| 367 | * |
||
| 368 | * @todo: how to translate this? |
||
| 369 | **/ |
||
| 370 | private static $searchable_fields = array( |
||
| 371 | 'ID' => array( |
||
| 372 | 'field' => 'NumericField', |
||
| 373 | 'title' => 'Order Number', |
||
| 374 | ), |
||
| 375 | 'MemberID' => array( |
||
| 376 | 'field' => 'TextField', |
||
| 377 | 'filter' => 'OrderFilters_MemberAndAddress', |
||
| 378 | 'title' => 'Customer Details', |
||
| 379 | ), |
||
| 380 | 'Created' => array( |
||
| 381 | 'field' => 'TextField', |
||
| 382 | 'filter' => 'OrderFilters_AroundDateFilter', |
||
| 383 | 'title' => 'Date (e.g. Today, 1 jan 2007, or last week)', |
||
| 384 | ), |
||
| 385 | //make sure to keep the items below, otherwise they do not show in form |
||
| 386 | 'StatusID' => array( |
||
| 387 | 'filter' => 'OrderFilters_MultiOptionsetStatusIDFilter', |
||
| 388 | ), |
||
| 389 | 'CancelledByID' => array( |
||
| 390 | 'filter' => 'OrderFilters_HasBeenCancelled', |
||
| 391 | 'title' => 'Cancelled by ...', |
||
| 392 | ), |
||
| 393 | ); |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Determine which properties on the DataObject are |
||
| 397 | * searchable, and map them to their default {@link FormField} |
||
| 398 | * representations. Used for scaffolding a searchform for {@link ModelAdmin}. |
||
| 399 | * |
||
| 400 | * Some additional logic is included for switching field labels, based on |
||
| 401 | * how generic or specific the field type is. |
||
| 402 | * |
||
| 403 | * Used by {@link SearchContext}. |
||
| 404 | * |
||
| 405 | * @param array $_params |
||
| 406 | * 'fieldClasses': Associative array of field names as keys and FormField classes as values |
||
| 407 | * 'restrictFields': Numeric array of a field name whitelist |
||
| 408 | * |
||
| 409 | * @return FieldList |
||
| 410 | */ |
||
| 411 | public function scaffoldSearchFields($_params = null) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * link to edit the record. |
||
| 454 | * |
||
| 455 | * @param string | Null $action - e.g. edit |
||
| 456 | * |
||
| 457 | * @return string |
||
| 458 | */ |
||
| 459 | public function CMSEditLink($action = null) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * STANDARD SILVERSTRIPE STUFF |
||
| 470 | * broken up into submitted and not (yet) submitted. |
||
| 471 | **/ |
||
| 472 | public function getCMSFields() |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Field to add and edit Order Items. |
||
| 836 | * |
||
| 837 | * @return GridField |
||
| 838 | */ |
||
| 839 | protected function getOrderItemsField() |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Field to add and edit Modifiers. |
||
| 849 | * |
||
| 850 | * @return GridField |
||
| 851 | */ |
||
| 852 | public function getModifierTableField() |
||
| 859 | |||
| 860 | /** |
||
| 861 | *@return GridField |
||
| 862 | **/ |
||
| 863 | protected function getBillingAddressField() |
||
| 879 | |||
| 880 | /** |
||
| 881 | *@return GridField |
||
| 882 | **/ |
||
| 883 | protected function getShippingAddressField() |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 902 | * |
||
| 903 | * @param string $sourceClass |
||
| 904 | * @param string $title |
||
| 905 | * |
||
| 906 | * @return GridField |
||
| 907 | **/ |
||
| 908 | public function getOrderStatusLogsTableField( |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Needs to be public because the OrderStep::getCMSFIelds accesses it. |
||
| 926 | * |
||
| 927 | * @param string $sourceClass |
||
| 928 | * @param string $title |
||
| 929 | * |
||
| 930 | * @return GridField |
||
| 931 | **/ |
||
| 932 | public function getOrderStatusLogsTableFieldEditable( |
||
| 942 | |||
| 943 | /** |
||
| 944 | * @param string $sourceClass |
||
| 945 | * @param string $title |
||
| 946 | * @param FieldList $fieldList (Optional) |
||
| 947 | * @param FieldList $detailedFormFields (Optional) |
||
| 948 | * |
||
| 949 | * @return GridField |
||
| 950 | **/ |
||
| 951 | protected function getOrderStatusLogsTableField_Archived( |
||
| 968 | |||
| 969 | /** |
||
| 970 | * @return GridField |
||
| 971 | **/ |
||
| 972 | public function getEmailsTableField() |
||
| 980 | |||
| 981 | /** |
||
| 982 | * @return GridField |
||
| 983 | */ |
||
| 984 | protected function getPaymentsField() |
||
| 993 | |||
| 994 | /** |
||
| 995 | * @return OrderStepField |
||
| 996 | */ |
||
| 997 | public function OrderStepField() |
||
| 1001 | |||
| 1002 | /******************************************************* |
||
| 1003 | * 2. MAIN TRANSITION FUNCTIONS |
||
| 1004 | *******************************************************/ |
||
| 1005 | |||
| 1006 | /** |
||
| 1007 | * init runs on start of a new Order (@see onAfterWrite) |
||
| 1008 | * it adds all the modifiers to the orders and the starting OrderStep. |
||
| 1009 | * |
||
| 1010 | * @param bool $recalculate |
||
| 1011 | * |
||
| 1012 | * @return DataObject (Order) |
||
| 1013 | **/ |
||
| 1014 | public function init($recalculate = false) |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * @var array |
||
| 1077 | */ |
||
| 1078 | private static $_try_to_finalise_order_is_running = array(); |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Goes through the order steps and tries to "apply" the next status to the order. |
||
| 1082 | * |
||
| 1083 | * @param bool $runAgain |
||
| 1084 | * @param bool $fromOrderQueue - is it being called from the OrderProcessQueue (or similar) |
||
| 1085 | **/ |
||
| 1086 | public function tryToFinaliseOrder($runAgain = false, $fromOrderQueue = false) |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Goes through the order steps and tries to "apply" the next step |
||
| 1136 | * Step is updated after the other one is completed... |
||
| 1137 | * |
||
| 1138 | * @return int (StatusID or false if the next status can not be "applied") |
||
| 1139 | **/ |
||
| 1140 | public function doNextStatus() |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * cancel an order. |
||
| 1158 | * |
||
| 1159 | * @param Member $member - the user cancelling the order |
||
| 1160 | * @param string $reason - the reason the order is cancelled |
||
| 1161 | * |
||
| 1162 | * @return OrderStatusLog_Cancel |
||
| 1163 | */ |
||
| 1164 | public function Cancel(Member $member, $reason = '') |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * returns true if successful. |
||
| 1183 | * |
||
| 1184 | * @param bool $avoidWrites |
||
| 1185 | * |
||
| 1186 | * @return bool |
||
| 1187 | */ |
||
| 1188 | public function Archive($avoidWrites = true) |
||
| 1211 | |||
| 1212 | /******************************************************* |
||
| 1213 | * 3. STATUS RELATED FUNCTIONS / SHORTCUTS |
||
| 1214 | *******************************************************/ |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Avoids caching of $this->Status(). |
||
| 1218 | * |
||
| 1219 | * @return DataObject (current OrderStep) |
||
| 1220 | */ |
||
| 1221 | public function MyStep() |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * Return the OrderStatusLog that is relevant to the Order status. |
||
| 1242 | * |
||
| 1243 | * @return OrderStatusLog |
||
| 1244 | */ |
||
| 1245 | public function RelevantLogEntry() |
||
| 1249 | |||
| 1250 | /** |
||
| 1251 | * @return OrderStep (current OrderStep that can be seen by customer) |
||
| 1252 | */ |
||
| 1253 | public function CurrentStepVisibleToCustomer() |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * works out if the order is still at the first OrderStep. |
||
| 1268 | * |
||
| 1269 | * @return bool |
||
| 1270 | */ |
||
| 1271 | public function IsFirstStep() |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Is the order still being "edited" by the customer? |
||
| 1286 | * |
||
| 1287 | * @return bool |
||
| 1288 | */ |
||
| 1289 | public function IsInCart() |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * The order has "passed" the IsInCart phase. |
||
| 1296 | * |
||
| 1297 | * @return bool |
||
| 1298 | */ |
||
| 1299 | public function IsPastCart() |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Are there still steps the order needs to go through? |
||
| 1306 | * |
||
| 1307 | * @return bool |
||
| 1308 | */ |
||
| 1309 | public function IsUncomplete() |
||
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Is the order in the :"processing" phaase.? |
||
| 1316 | * |
||
| 1317 | * @return bool |
||
| 1318 | */ |
||
| 1319 | public function IsProcessing() |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Is the order completed? |
||
| 1326 | * |
||
| 1327 | * @return bool |
||
| 1328 | */ |
||
| 1329 | public function IsCompleted() |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Has the order been paid? |
||
| 1336 | * TODO: why do we check if there is a total at all? |
||
| 1337 | * |
||
| 1338 | * @return bool |
||
| 1339 | */ |
||
| 1340 | public function IsPaid() |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Has the order been paid? |
||
| 1351 | * TODO: why do we check if there is a total at all? |
||
| 1352 | * |
||
| 1353 | * @return bool |
||
| 1354 | */ |
||
| 1355 | public function PaymentIsPending() |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * shows payments that are meaningfull |
||
| 1374 | * if the order has been paid then only show successful payments. |
||
| 1375 | * |
||
| 1376 | * @return DataList |
||
| 1377 | */ |
||
| 1378 | public function RelevantPayments() |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Has the order been cancelled? |
||
| 1391 | * |
||
| 1392 | * @return bool |
||
| 1393 | */ |
||
| 1394 | public function IsCancelled() |
||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * Has the order been cancelled by the customer? |
||
| 1405 | * |
||
| 1406 | * @return bool |
||
| 1407 | */ |
||
| 1408 | public function IsCustomerCancelled() |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Has the order been cancelled by the administrator? |
||
| 1419 | * |
||
| 1420 | * @return bool |
||
| 1421 | */ |
||
| 1422 | public function IsAdminCancelled() |
||
| 1437 | |||
| 1438 | /** |
||
| 1439 | * Is the Shop Closed for business? |
||
| 1440 | * |
||
| 1441 | * @return bool |
||
| 1442 | */ |
||
| 1443 | public function ShopClosed() |
||
| 1447 | |||
| 1448 | /******************************************************* |
||
| 1449 | * 4. LINKING ORDER WITH MEMBER AND ADDRESS |
||
| 1450 | *******************************************************/ |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Returns a member linked to the order. |
||
| 1454 | * If a member is already linked, it will return the existing member. |
||
| 1455 | * Otherwise it will return a new Member. |
||
| 1456 | * |
||
| 1457 | * Any new member is NOT written, because we dont want to create a new member unless we have to! |
||
| 1458 | * We will not add a member to the order unless a new one is created in the checkout |
||
| 1459 | * OR the member is logged in / logs in. |
||
| 1460 | * |
||
| 1461 | * Also note that if a new member is created, it is not automatically written |
||
| 1462 | * |
||
| 1463 | * @param bool $forceCreation - if set to true then the member will always be saved in the database. |
||
| 1464 | * |
||
| 1465 | * @return Member |
||
| 1466 | **/ |
||
| 1467 | public function CreateOrReturnExistingMember($forceCreation = false) |
||
| 1490 | |||
| 1491 | /** |
||
| 1492 | * Returns either the existing one or a new Order Address... |
||
| 1493 | * All Orders will have a Shipping and Billing address attached to it. |
||
| 1494 | * Method used to retrieve object e.g. for $order->BillingAddress(); "BillingAddress" is the method name you can use. |
||
| 1495 | * If the method name is the same as the class name then dont worry about providing one. |
||
| 1496 | * |
||
| 1497 | * @param string $className - ClassName of the Address (e.g. BillingAddress or ShippingAddress) |
||
| 1498 | * @param string $alternativeMethodName - method to retrieve Address |
||
| 1499 | **/ |
||
| 1500 | public function CreateOrReturnExistingAddress($className = 'BillingAddress', $alternativeMethodName = '') |
||
| 1544 | |||
| 1545 | /** |
||
| 1546 | * Sets the country in the billing and shipping address. |
||
| 1547 | * |
||
| 1548 | * @param string $countryCode - code for the country e.g. NZ |
||
| 1549 | * @param bool $includeBillingAddress |
||
| 1550 | * @param bool $includeShippingAddress |
||
| 1551 | **/ |
||
| 1552 | public function SetCountryFields($countryCode, $includeBillingAddress = true, $includeShippingAddress = true) |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Sets the region in the billing and shipping address. |
||
| 1574 | * |
||
| 1575 | * @param int $regionID - ID for the region to be set |
||
| 1576 | **/ |
||
| 1577 | public function SetRegionFields($regionID) |
||
| 1592 | |||
| 1593 | /** |
||
| 1594 | * Stores the preferred currency of the order. |
||
| 1595 | * IMPORTANTLY we store the exchange rate for future reference... |
||
| 1596 | * |
||
| 1597 | * @param EcommerceCurrency $currency |
||
| 1598 | */ |
||
| 1599 | public function UpdateCurrency($newCurrency) |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * alias for UpdateCurrency. |
||
| 1615 | * |
||
| 1616 | * @param EcommerceCurrency $currency |
||
| 1617 | */ |
||
| 1618 | public function SetCurrency($currency) |
||
| 1622 | |||
| 1623 | /******************************************************* |
||
| 1624 | * 5. CUSTOMER COMMUNICATION |
||
| 1625 | *******************************************************/ |
||
| 1626 | |||
| 1627 | /** |
||
| 1628 | * Send the invoice of the order by email. |
||
| 1629 | * |
||
| 1630 | * @param string $subject - subject for the email |
||
| 1631 | * @param string $message - the main message in the email |
||
| 1632 | * @param bool $resend - send the email even if it has been sent before |
||
| 1633 | * @param bool $adminOnlyOrToEmail - do not send to customer, only send to shop admin |
||
| 1634 | * @param string $emailClassName - class used to send email |
||
| 1635 | * |
||
| 1636 | * @return bool TRUE on success, FALSE on failure (in theory) |
||
| 1637 | */ |
||
| 1638 | public function sendEmail( |
||
| 1653 | |||
| 1654 | /** |
||
| 1655 | * Sends a message to the shop admin ONLY and not to the customer |
||
| 1656 | * This can be used by ordersteps and orderlogs to notify the admin of any potential problems. |
||
| 1657 | * |
||
| 1658 | * @param string $subject - subject for the email |
||
| 1659 | * @param string $message - message to be added with the email |
||
| 1660 | * |
||
| 1661 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1662 | */ |
||
| 1663 | public function sendError($subject = '', $message = '') |
||
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Sends a message to the shop admin ONLY and not to the customer |
||
| 1670 | * This can be used by ordersteps and orderlogs to notify the admin of any potential problems. |
||
| 1671 | * |
||
| 1672 | * @param string $subject - subject for the email |
||
| 1673 | * @param string $message - message to be added with the email |
||
| 1674 | * @param bool $resend - can it be sent twice? |
||
| 1675 | * @param string $emailClassName - template to be used ... |
||
| 1676 | * |
||
| 1677 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1678 | */ |
||
| 1679 | public function sendAdminNotification( |
||
| 1687 | |||
| 1688 | /** |
||
| 1689 | * Send a mail of the order to the client (and another to the admin). |
||
| 1690 | * |
||
| 1691 | * @param string $emailClassName - the class name of the email you wish to send |
||
| 1692 | * @param string $subject - email subject |
||
| 1693 | * @param bool $copyToAdmin - true by default, whether it should send a copy to the admin |
||
| 1694 | * @param bool $resend - sends the email even it has been sent before. |
||
| 1695 | * @param bool | string $adminOnlyOrToEmail - sends the email to the ADMIN ONLY, if you provide an email, it will go to the email... |
||
| 1696 | * |
||
| 1697 | * @return bool TRUE for success, FALSE for failure (not tested) |
||
| 1698 | */ |
||
| 1699 | protected function prepareAndSendEmail( |
||
| 1756 | |||
| 1757 | /** |
||
| 1758 | * returns the Data that can be used in the body of an order Email |
||
| 1759 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1760 | * of the email template. |
||
| 1761 | * we add the subject here so that the subject, for example, can be added to the <title> |
||
| 1762 | * of the email template. |
||
| 1763 | * |
||
| 1764 | * @param string $message - the additional message |
||
| 1765 | * @param string $subject - subject for email - |
||
| 1766 | * |
||
| 1767 | * @return ArrayData |
||
| 1768 | * - Subject - EmailSubject |
||
| 1769 | * - Message - specific message for this order |
||
| 1770 | * - OrderStepMessage - generic message for step |
||
| 1771 | * - Order |
||
| 1772 | * - EmailLogo |
||
| 1773 | * - ShopPhysicalAddress |
||
| 1774 | * - CurrentDateAndTime |
||
| 1775 | * - BaseURL |
||
| 1776 | * - CC |
||
| 1777 | * - BCC |
||
| 1778 | */ |
||
| 1779 | public function createReplacementArrayForEmail($message = '', $subject = '') |
||
| 1807 | |||
| 1808 | /** |
||
| 1809 | * returns the order formatted as an email. |
||
| 1810 | * |
||
| 1811 | * @param string $message - the additional message |
||
| 1812 | * @param string $emailClassName - template to use. |
||
| 1813 | * |
||
| 1814 | * @return array (Message, Order, EmailLogo, ShopPhysicalAddress) |
||
| 1815 | */ |
||
| 1816 | public function renderOrderInEmailFormat($message = '', $emailClassName) |
||
| 1826 | |||
| 1827 | /******************************************************* |
||
| 1828 | * 6. ITEM MANAGEMENT |
||
| 1829 | *******************************************************/ |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * returns a list of Order Attributes by type. |
||
| 1833 | * |
||
| 1834 | * @param array | String $types |
||
| 1835 | * |
||
| 1836 | * @return ArrayList |
||
| 1837 | */ |
||
| 1838 | public function getOrderAttributesByType($types) |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Returns the items of the order. |
||
| 1865 | * Items are the order items (products) and NOT the modifiers (discount, tax, etc...). |
||
| 1866 | * |
||
| 1867 | * N. B. this method returns Order Items |
||
| 1868 | * also see Buaybles |
||
| 1869 | |||
| 1870 | * |
||
| 1871 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1872 | * |
||
| 1873 | * @return DataList (OrderItems) |
||
| 1874 | */ |
||
| 1875 | public function Items($filterOrClassName = '') |
||
| 1883 | |||
| 1884 | /** |
||
| 1885 | * @alias function of Items |
||
| 1886 | * |
||
| 1887 | * N. B. this method returns Order Items |
||
| 1888 | * also see Buaybles |
||
| 1889 | * |
||
| 1890 | * @param string filter - where statement to exclude certain items. |
||
| 1891 | * @alias for Items |
||
| 1892 | * @return DataList (OrderItems) |
||
| 1893 | */ |
||
| 1894 | public function OrderItems($filterOrClassName = '') |
||
| 1898 | |||
| 1899 | /** |
||
| 1900 | * returns the buyables asscoiated with the order items. |
||
| 1901 | * |
||
| 1902 | * NB. this method retursn buyables |
||
| 1903 | * |
||
| 1904 | * @param string filter - where statement to exclude certain items. |
||
| 1905 | * |
||
| 1906 | * @return ArrayList (Buyables) |
||
| 1907 | */ |
||
| 1908 | public function Buyables($filterOrClassName = '') |
||
| 1918 | |||
| 1919 | /** |
||
| 1920 | * Return all the {@link OrderItem} instances that are |
||
| 1921 | * available as records in the database. |
||
| 1922 | * |
||
| 1923 | * @param string filter - where statement to exclude certain items, |
||
| 1924 | * 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) |
||
| 1925 | * |
||
| 1926 | * @return DataList (OrderItems) |
||
| 1927 | */ |
||
| 1928 | protected function itemsFromDatabase($filterOrClassName = '') |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * @alias for Modifiers |
||
| 1945 | * |
||
| 1946 | * @return DataList (OrderModifiers) |
||
| 1947 | */ |
||
| 1948 | public function OrderModifiers() |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Returns the modifiers of the order, if it hasn't been saved yet |
||
| 1955 | * it returns the modifiers from session, if it has, it returns them |
||
| 1956 | * from the DB entry. ONLY USE OUTSIDE ORDER. |
||
| 1957 | * |
||
| 1958 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1959 | * |
||
| 1960 | * @return DataList (OrderModifiers) |
||
| 1961 | */ |
||
| 1962 | public function Modifiers($filterOrClassName = '') |
||
| 1966 | |||
| 1967 | /** |
||
| 1968 | * Get all {@link OrderModifier} instances that are |
||
| 1969 | * available as records in the database. |
||
| 1970 | * NOTE: includes REMOVED Modifiers, so that they do not get added again... |
||
| 1971 | * |
||
| 1972 | * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier') |
||
| 1973 | * |
||
| 1974 | * @return DataList (OrderModifiers) |
||
| 1975 | */ |
||
| 1976 | protected function modifiersFromDatabase($filterOrClassName = '') |
||
| 1990 | |||
| 1991 | /** |
||
| 1992 | * Calculates and updates all the order attributes. |
||
| 1993 | * |
||
| 1994 | * @param bool $recalculate - run it, even if it has run already |
||
| 1995 | */ |
||
| 1996 | public function calculateOrderAttributes($recalculate = false) |
||
| 2010 | |||
| 2011 | /** |
||
| 2012 | * Calculates and updates all the product items. |
||
| 2013 | * |
||
| 2014 | * @param bool $recalculate - run it, even if it has run already |
||
| 2015 | */ |
||
| 2016 | protected function calculateOrderItems($recalculate = false) |
||
| 2031 | |||
| 2032 | /** |
||
| 2033 | * Calculates and updates all the modifiers. |
||
| 2034 | * |
||
| 2035 | * @param bool $recalculate - run it, even if it has run already |
||
| 2036 | */ |
||
| 2037 | protected function calculateModifiers($recalculate = false) |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * Returns the subtotal of the modifiers for this order. |
||
| 2052 | * If a modifier appears in the excludedModifiers array, it is not counted. |
||
| 2053 | * |
||
| 2054 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2055 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2056 | * |
||
| 2057 | * @return float |
||
| 2058 | */ |
||
| 2059 | public function ModifiersSubTotal($excluded = null, $stopAtExcludedModifier = false) |
||
| 2086 | |||
| 2087 | /** |
||
| 2088 | * returns a modifier that is an instanceof the classname |
||
| 2089 | * it extends. |
||
| 2090 | * |
||
| 2091 | * @param string $className: class name for the modifier |
||
| 2092 | * |
||
| 2093 | * @return DataObject (OrderModifier) |
||
| 2094 | **/ |
||
| 2095 | public function RetrieveModifier($className) |
||
| 2106 | |||
| 2107 | /******************************************************* |
||
| 2108 | * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...) |
||
| 2109 | *******************************************************/ |
||
| 2110 | |||
| 2111 | /** |
||
| 2112 | * @param Member $member |
||
| 2113 | * |
||
| 2114 | * @return DataObject (Member) |
||
| 2115 | **/ |
||
| 2116 | //TODO: please comment why we make use of this function |
||
| 2117 | protected function getMemberForCanFunctions(Member $member = null) |
||
| 2129 | |||
| 2130 | /** |
||
| 2131 | * @param Member $member |
||
| 2132 | * |
||
| 2133 | * @return bool |
||
| 2134 | **/ |
||
| 2135 | public function canCreate($member = null) |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Standard SS method - can the current member view this order? |
||
| 2149 | * |
||
| 2150 | * @param Member $member |
||
| 2151 | * |
||
| 2152 | * @return bool |
||
| 2153 | **/ |
||
| 2154 | public function canView($member = null) |
||
| 2199 | |||
| 2200 | /** |
||
| 2201 | * @param Member $member optional |
||
| 2202 | * @return bool |
||
| 2203 | */ |
||
| 2204 | public function canOverrideCanView($member = null) |
||
| 2225 | |||
| 2226 | /** |
||
| 2227 | * @return bool |
||
| 2228 | */ |
||
| 2229 | public function IsInSession() |
||
| 2235 | |||
| 2236 | /** |
||
| 2237 | * returns a pseudo random part of the session id. |
||
| 2238 | * |
||
| 2239 | * @param int $size |
||
| 2240 | * |
||
| 2241 | * @return string |
||
| 2242 | */ |
||
| 2243 | public function LessSecureSessionID($size = 7, $start = null) |
||
| 2251 | /** |
||
| 2252 | * |
||
| 2253 | * @param Member (optional) $member |
||
| 2254 | * |
||
| 2255 | * @return bool |
||
| 2256 | **/ |
||
| 2257 | public function canViewAdminStuff($member = null) |
||
| 2268 | |||
| 2269 | /** |
||
| 2270 | * if we set canEdit to false then we |
||
| 2271 | * can not see the child records |
||
| 2272 | * Basically, you can edit when you can view and canEdit (even as a customer) |
||
| 2273 | * Or if you are a Shop Admin you can always edit. |
||
| 2274 | * Otherwise it is false... |
||
| 2275 | * |
||
| 2276 | * @param Member $member |
||
| 2277 | * |
||
| 2278 | * @return bool |
||
| 2279 | **/ |
||
| 2280 | public function canEdit($member = null) |
||
| 2299 | |||
| 2300 | /** |
||
| 2301 | * is the order ready to go through to the |
||
| 2302 | * checkout process. |
||
| 2303 | * |
||
| 2304 | * This method checks all the order items and order modifiers |
||
| 2305 | * If any of them need immediate attention then this is done |
||
| 2306 | * first after which it will go through to the checkout page. |
||
| 2307 | * |
||
| 2308 | * @param Member (optional) $member |
||
| 2309 | * |
||
| 2310 | * @return bool |
||
| 2311 | **/ |
||
| 2312 | public function canCheckout(Member $member = null) |
||
| 2326 | |||
| 2327 | /** |
||
| 2328 | * Can the order be submitted? |
||
| 2329 | * this method can be used to stop an order from being submitted |
||
| 2330 | * due to something not being completed or done. |
||
| 2331 | * |
||
| 2332 | * @see Order::SubmitErrors |
||
| 2333 | * |
||
| 2334 | * @param Member $member |
||
| 2335 | * |
||
| 2336 | * @return bool |
||
| 2337 | **/ |
||
| 2338 | public function canSubmit(Member $member = null) |
||
| 2355 | |||
| 2356 | /** |
||
| 2357 | * Can a payment be made for this Order? |
||
| 2358 | * |
||
| 2359 | * @param Member $member |
||
| 2360 | * |
||
| 2361 | * @return bool |
||
| 2362 | **/ |
||
| 2363 | public function canPay(Member $member = null) |
||
| 2376 | |||
| 2377 | /** |
||
| 2378 | * Can the given member cancel this order? |
||
| 2379 | * |
||
| 2380 | * @param Member $member |
||
| 2381 | * |
||
| 2382 | * @return bool |
||
| 2383 | **/ |
||
| 2384 | public function canCancel(Member $member = null) |
||
| 2401 | |||
| 2402 | /** |
||
| 2403 | * @param Member $member |
||
| 2404 | * |
||
| 2405 | * @return bool |
||
| 2406 | **/ |
||
| 2407 | public function canDelete($member = null) |
||
| 2423 | |||
| 2424 | /** |
||
| 2425 | * Returns all the order logs that the current member can view |
||
| 2426 | * i.e. some order logs can only be viewed by the admin (e.g. suspected fraud orderlog). |
||
| 2427 | * |
||
| 2428 | * @return ArrayList (OrderStatusLogs) |
||
| 2429 | **/ |
||
| 2430 | public function CanViewOrderStatusLogs() |
||
| 2442 | |||
| 2443 | /** |
||
| 2444 | * returns all the logs that can be viewed by the customer. |
||
| 2445 | * |
||
| 2446 | * @return ArrayList (OrderStausLogs) |
||
| 2447 | */ |
||
| 2448 | public function CustomerViewableOrderStatusLogs() |
||
| 2462 | |||
| 2463 | /******************************************************* |
||
| 2464 | * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...) |
||
| 2465 | *******************************************************/ |
||
| 2466 | |||
| 2467 | /** |
||
| 2468 | * returns the email to be used for customer communication. |
||
| 2469 | * |
||
| 2470 | * @return string |
||
| 2471 | */ |
||
| 2472 | public function OrderEmail() |
||
| 2494 | |||
| 2495 | /** |
||
| 2496 | * Returns true if there is a prink or email link. |
||
| 2497 | * |
||
| 2498 | * @return bool |
||
| 2499 | */ |
||
| 2500 | public function HasPrintOrEmailLink() |
||
| 2504 | |||
| 2505 | /** |
||
| 2506 | * returns the absolute link to the order that can be used in the customer communication (email). |
||
| 2507 | * |
||
| 2508 | * @return string |
||
| 2509 | */ |
||
| 2510 | public function EmailLink($type = 'Order_StatusEmail') |
||
| 2522 | |||
| 2523 | /** |
||
| 2524 | * returns the absolute link to the order for printing. |
||
| 2525 | * |
||
| 2526 | * @return string |
||
| 2527 | */ |
||
| 2528 | public function PrintLink() |
||
| 2540 | |||
| 2541 | /** |
||
| 2542 | * returns the absolute link to the order for printing. |
||
| 2543 | * |
||
| 2544 | * @return string |
||
| 2545 | */ |
||
| 2546 | public function PackingSlipLink() |
||
| 2556 | |||
| 2557 | /** |
||
| 2558 | * returns the absolute link that the customer can use to retrieve the email WITHOUT logging in. |
||
| 2559 | * |
||
| 2560 | * @return string |
||
| 2561 | */ |
||
| 2562 | public function RetrieveLink() |
||
| 2566 | |||
| 2567 | public function getRetrieveLink() |
||
| 2581 | |||
| 2582 | public function ShareLink() |
||
| 2586 | |||
| 2587 | public function getShareLink() |
||
| 2605 | |||
| 2606 | /** |
||
| 2607 | * link to delete order. |
||
| 2608 | * |
||
| 2609 | * @return string |
||
| 2610 | */ |
||
| 2611 | public function DeleteLink() |
||
| 2623 | |||
| 2624 | /** |
||
| 2625 | * link to copy order. |
||
| 2626 | * |
||
| 2627 | * @return string |
||
| 2628 | */ |
||
| 2629 | public function CopyOrderLink() |
||
| 2641 | |||
| 2642 | /** |
||
| 2643 | * A "Title" for the order, which summarises the main details (date, and customer) in a string. |
||
| 2644 | * |
||
| 2645 | * @param string $dateFormat - e.g. "D j M Y, G:i T" |
||
| 2646 | * @param bool $includeName - e.g. by Mr Johnson |
||
| 2647 | * |
||
| 2648 | * @return string |
||
| 2649 | **/ |
||
| 2650 | public function Title($dateFormat = null, $includeName = false) |
||
| 2713 | |||
| 2714 | /** |
||
| 2715 | * Returns the subtotal of the items for this order. |
||
| 2716 | * |
||
| 2717 | * @return float |
||
| 2718 | */ |
||
| 2719 | public function SubTotal() |
||
| 2737 | |||
| 2738 | /** |
||
| 2739 | * @return Currency (DB Object) |
||
| 2740 | **/ |
||
| 2741 | public function SubTotalAsCurrencyObject() |
||
| 2745 | |||
| 2746 | /** |
||
| 2747 | * @return Money |
||
| 2748 | **/ |
||
| 2749 | public function SubTotalAsMoney() |
||
| 2757 | |||
| 2758 | /** |
||
| 2759 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2760 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2761 | * |
||
| 2762 | * @return Currency (DB Object) |
||
| 2763 | **/ |
||
| 2764 | public function ModifiersSubTotalAsCurrencyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2768 | |||
| 2769 | /** |
||
| 2770 | * @param string|array $excluded - Class(es) of modifier(s) to ignore in the calculation. |
||
| 2771 | * @param bool $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier. |
||
| 2772 | * |
||
| 2773 | * @return Money (DB Object) |
||
| 2774 | **/ |
||
| 2775 | public function ModifiersSubTotalAsMoneyObject($excluded = null, $stopAtExcludedModifier = false) |
||
| 2779 | |||
| 2780 | /** |
||
| 2781 | * Returns the total cost of an order including the additional charges or deductions of its modifiers. |
||
| 2782 | * |
||
| 2783 | * @return float |
||
| 2784 | */ |
||
| 2785 | public function Total() |
||
| 2793 | |||
| 2794 | /** |
||
| 2795 | * @return Currency (DB Object) |
||
| 2796 | **/ |
||
| 2797 | public function TotalAsCurrencyObject() |
||
| 2801 | |||
| 2802 | /** |
||
| 2803 | * @return Money |
||
| 2804 | **/ |
||
| 2805 | public function TotalAsMoney() |
||
| 2813 | |||
| 2814 | /** |
||
| 2815 | * Checks to see if any payments have been made on this order |
||
| 2816 | * and if so, subracts the payment amount from the order. |
||
| 2817 | * |
||
| 2818 | * @return float |
||
| 2819 | **/ |
||
| 2820 | public function TotalOutstanding() |
||
| 2840 | |||
| 2841 | /** |
||
| 2842 | * @return Currency (DB Object) |
||
| 2843 | **/ |
||
| 2844 | public function TotalOutstandingAsCurrencyObject() |
||
| 2848 | |||
| 2849 | /** |
||
| 2850 | * @return Money |
||
| 2851 | **/ |
||
| 2852 | public function TotalOutstandingAsMoney() |
||
| 2860 | |||
| 2861 | /** |
||
| 2862 | * @return float |
||
| 2863 | */ |
||
| 2864 | public function TotalPaid() |
||
| 2885 | |||
| 2886 | /** |
||
| 2887 | * @return Currency (DB Object) |
||
| 2888 | **/ |
||
| 2889 | public function TotalPaidAsCurrencyObject() |
||
| 2893 | |||
| 2894 | /** |
||
| 2895 | * @return Money |
||
| 2896 | **/ |
||
| 2897 | public function TotalPaidAsMoney() |
||
| 2905 | |||
| 2906 | /** |
||
| 2907 | * returns the total number of OrderItems (not modifiers). |
||
| 2908 | * This is meant to run as fast as possible to quickly check |
||
| 2909 | * if there is anything in the cart. |
||
| 2910 | * |
||
| 2911 | * @param bool $recalculate - do we need to recalculate (value is retained during lifetime of Object) |
||
| 2912 | * |
||
| 2913 | * @return int |
||
| 2914 | **/ |
||
| 2915 | public function TotalItems($recalculate = false) |
||
| 2929 | |||
| 2930 | /** |
||
| 2931 | * Little shorthand. |
||
| 2932 | * |
||
| 2933 | * @param bool $recalculate |
||
| 2934 | * |
||
| 2935 | * @return bool |
||
| 2936 | **/ |
||
| 2937 | public function MoreThanOneItemInCart($recalculate = false) |
||
| 2941 | |||
| 2942 | /** |
||
| 2943 | * returns the total number of OrderItems (not modifiers) times their respectective quantities. |
||
| 2944 | * |
||
| 2945 | * @param bool $recalculate - force recalculation |
||
| 2946 | * |
||
| 2947 | * @return float |
||
| 2948 | **/ |
||
| 2949 | public function TotalItemsTimesQuantity($recalculate = false) |
||
| 2969 | |||
| 2970 | /** |
||
| 2971 | * |
||
| 2972 | * @return string (country code) |
||
| 2973 | **/ |
||
| 2974 | public function Country() |
||
| 2978 | |||
| 2979 | /** |
||
| 2980 | * Returns the country code for the country that applies to the order. |
||
| 2981 | * @alias for getCountry |
||
| 2982 | * |
||
| 2983 | * @return string - country code e.g. NZ |
||
| 2984 | */ |
||
| 2985 | public function getCountry() |
||
| 3022 | |||
| 3023 | /** |
||
| 3024 | * @alias for getFullNameCountry |
||
| 3025 | * |
||
| 3026 | * @return string - country name |
||
| 3027 | **/ |
||
| 3028 | public function FullNameCountry() |
||
| 3032 | |||
| 3033 | /** |
||
| 3034 | * returns name of coutry. |
||
| 3035 | * |
||
| 3036 | * @return string - country name |
||
| 3037 | **/ |
||
| 3038 | public function getFullNameCountry() |
||
| 3042 | |||
| 3043 | /** |
||
| 3044 | * @alis for getExpectedCountryName |
||
| 3045 | * @return string - country name |
||
| 3046 | **/ |
||
| 3047 | public function ExpectedCountryName() |
||
| 3051 | |||
| 3052 | /** |
||
| 3053 | * returns name of coutry that we expect the customer to have |
||
| 3054 | * This takes into consideration more than just what has been entered |
||
| 3055 | * for example, it looks at GEO IP. |
||
| 3056 | * |
||
| 3057 | * @todo: why do we dont return a string IF there is only one item. |
||
| 3058 | * |
||
| 3059 | * @return string - country name |
||
| 3060 | **/ |
||
| 3061 | public function getExpectedCountryName() |
||
| 3065 | |||
| 3066 | /** |
||
| 3067 | * return the title of the fixed country (if any). |
||
| 3068 | * |
||
| 3069 | * @return string | empty string |
||
| 3070 | **/ |
||
| 3071 | public function FixedCountry() |
||
| 3084 | |||
| 3085 | /** |
||
| 3086 | * Returns the region that applies to the order. |
||
| 3087 | * we check both billing and shipping, in case one of them is empty. |
||
| 3088 | * |
||
| 3089 | * @return DataObject | Null (EcommerceRegion) |
||
| 3090 | **/ |
||
| 3091 | public function Region() |
||
| 3128 | |||
| 3129 | /** |
||
| 3130 | * Casted variable |
||
| 3131 | * Currency is not the same as the standard one? |
||
| 3132 | * |
||
| 3133 | * @return bool |
||
| 3134 | **/ |
||
| 3135 | public function HasAlternativeCurrency() |
||
| 3151 | |||
| 3152 | /** |
||
| 3153 | * Makes sure exchange rate is updated and maintained before order is submitted |
||
| 3154 | * This method is public because it could be called from a shopping Cart Object. |
||
| 3155 | **/ |
||
| 3156 | public function EnsureCorrectExchangeRate() |
||
| 3174 | |||
| 3175 | /** |
||
| 3176 | * speeds up processing by storing the IsSubmitted value |
||
| 3177 | * we start with -1 to know if it has been requested before. |
||
| 3178 | * |
||
| 3179 | * @var bool |
||
| 3180 | */ |
||
| 3181 | protected $_isSubmittedTempVar = -1; |
||
| 3182 | |||
| 3183 | /** |
||
| 3184 | * Casted variable - has the order been submitted? |
||
| 3185 | * alias |
||
| 3186 | * @param bool $recalculate |
||
| 3187 | * |
||
| 3188 | * @return bool |
||
| 3189 | **/ |
||
| 3190 | public function IsSubmitted($recalculate = true) |
||
| 3194 | |||
| 3195 | /** |
||
| 3196 | * Casted variable - has the order been submitted? |
||
| 3197 | * |
||
| 3198 | * @param bool $recalculate |
||
| 3199 | * |
||
| 3200 | * @return bool |
||
| 3201 | **/ |
||
| 3202 | public function getIsSubmitted($recalculate = false) |
||
| 3214 | |||
| 3215 | /** |
||
| 3216 | * |
||
| 3217 | * |
||
| 3218 | * @return bool |
||
| 3219 | */ |
||
| 3220 | public function IsArchived() |
||
| 3230 | |||
| 3231 | /** |
||
| 3232 | * Submission Log for this Order (if any). |
||
| 3233 | * |
||
| 3234 | * @return Submission Log (OrderStatusLog_Submitted) | Null |
||
| 3235 | **/ |
||
| 3236 | public function SubmissionLog() |
||
| 3244 | |||
| 3245 | /** |
||
| 3246 | * @return int |
||
| 3247 | */ |
||
| 3248 | public function SecondsSinceBeingSubmitted() |
||
| 3256 | |||
| 3257 | /** |
||
| 3258 | * if the order can not be submitted, |
||
| 3259 | * then the reasons why it can not be submitted |
||
| 3260 | * will be returned by this method. |
||
| 3261 | * |
||
| 3262 | * @see Order::canSubmit |
||
| 3263 | * |
||
| 3264 | * @return ArrayList | null |
||
| 3265 | */ |
||
| 3266 | public function SubmitErrors() |
||
| 3282 | |||
| 3283 | /** |
||
| 3284 | * Casted variable - has the order been submitted? |
||
| 3285 | * |
||
| 3286 | * @param bool $withDetail |
||
| 3287 | * |
||
| 3288 | * @return string |
||
| 3289 | **/ |
||
| 3290 | public function CustomerStatus($withDetail = true) |
||
| 3312 | |||
| 3313 | /** |
||
| 3314 | * Casted variable - does the order have a potential shipping address? |
||
| 3315 | * |
||
| 3316 | * @return bool |
||
| 3317 | **/ |
||
| 3318 | public function CanHaveShippingAddress() |
||
| 3326 | |||
| 3327 | /** |
||
| 3328 | * returns the link to view the Order |
||
| 3329 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3330 | * |
||
| 3331 | * @return CartPage | Null |
||
| 3332 | */ |
||
| 3333 | public function DisplayPage() |
||
| 3350 | |||
| 3351 | /** |
||
| 3352 | * returns the link to view the Order |
||
| 3353 | * WHY NOT CHECKOUT PAGE: first we check for cart page. |
||
| 3354 | * If a cart page has been created then we refer through to Cart Page. |
||
| 3355 | * Otherwise it will default to the checkout page. |
||
| 3356 | * |
||
| 3357 | * @param string $action - any action that should be added to the link. |
||
| 3358 | * |
||
| 3359 | * @return String(URLSegment) |
||
| 3360 | */ |
||
| 3361 | public function Link($action = null) |
||
| 3376 | |||
| 3377 | /** |
||
| 3378 | * Returns to link to access the Order's API. |
||
| 3379 | * |
||
| 3380 | * @param string $version |
||
| 3381 | * @param string $extension |
||
| 3382 | * |
||
| 3383 | * @return String(URL) |
||
| 3384 | */ |
||
| 3385 | public function APILink($version = 'v1', $extension = 'xml') |
||
| 3389 | |||
| 3390 | /** |
||
| 3391 | * returns the link to finalise the Order. |
||
| 3392 | * |
||
| 3393 | * @return String(URLSegment) |
||
| 3394 | */ |
||
| 3395 | public function CheckoutLink() |
||
| 3409 | |||
| 3410 | /** |
||
| 3411 | * Converts the Order into HTML, based on the Order Template. |
||
| 3412 | * |
||
| 3413 | * @return HTML Object |
||
| 3414 | **/ |
||
| 3415 | public function ConvertToHTML() |
||
| 3425 | |||
| 3426 | /** |
||
| 3427 | * Converts the Order into a serialized string |
||
| 3428 | * TO DO: check if this works and check if we need to use special sapphire serialization code. |
||
| 3429 | * |
||
| 3430 | * @return string - serialized object |
||
| 3431 | **/ |
||
| 3432 | public function ConvertToString() |
||
| 3436 | |||
| 3437 | /** |
||
| 3438 | * Converts the Order into a JSON object |
||
| 3439 | * TO DO: check if this works and check if we need to use special sapphire JSON code. |
||
| 3440 | * |
||
| 3441 | * @return string - JSON |
||
| 3442 | **/ |
||
| 3443 | public function ConvertToJSON() |
||
| 3447 | |||
| 3448 | /** |
||
| 3449 | * returns itself wtih more data added as variables. |
||
| 3450 | * We add has_one and has_many as variables like this: $this->MyHasOne_serialized = serialize($this->MyHasOne()). |
||
| 3451 | * |
||
| 3452 | * @return Order - with most important has one and has many items included as variables. |
||
| 3453 | **/ |
||
| 3454 | protected function addHasOneAndHasManyAsVariables() |
||
| 3467 | |||
| 3468 | /******************************************************* |
||
| 3469 | * 9. TEMPLATE RELATED STUFF |
||
| 3470 | *******************************************************/ |
||
| 3471 | |||
| 3472 | /** |
||
| 3473 | * returns the instance of EcommerceConfigAjax for use in templates. |
||
| 3474 | * In templates, it is used like this: |
||
| 3475 | * $EcommerceConfigAjax.TableID. |
||
| 3476 | * |
||
| 3477 | * @return EcommerceConfigAjax |
||
| 3478 | **/ |
||
| 3479 | public function AJAXDefinitions() |
||
| 3483 | |||
| 3484 | /** |
||
| 3485 | * returns the instance of EcommerceDBConfig. |
||
| 3486 | * |
||
| 3487 | * @return EcommerceDBConfig |
||
| 3488 | **/ |
||
| 3489 | public function EcomConfig() |
||
| 3493 | |||
| 3494 | /** |
||
| 3495 | * Collects the JSON data for an ajax return of the cart. |
||
| 3496 | * |
||
| 3497 | * @param array $js |
||
| 3498 | * |
||
| 3499 | * @return array (for use in AJAX for JSON) |
||
| 3500 | **/ |
||
| 3501 | public function updateForAjax(array $js) |
||
| 3554 | |||
| 3555 | /** |
||
| 3556 | * @ToDO: move to more appropriate class |
||
| 3557 | * |
||
| 3558 | * @return float |
||
| 3559 | **/ |
||
| 3560 | public function SubTotalCartValue() |
||
| 3564 | |||
| 3565 | /******************************************************* |
||
| 3566 | * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...) |
||
| 3567 | *******************************************************/ |
||
| 3568 | |||
| 3569 | /** |
||
| 3570 | *standard SS method. |
||
| 3571 | **/ |
||
| 3572 | public function populateDefaults() |
||
| 3576 | |||
| 3577 | public function onBeforeWrite() |
||
| 3592 | |||
| 3593 | /** |
||
| 3594 | * standard SS method |
||
| 3595 | * adds the ability to update order after writing it. |
||
| 3596 | **/ |
||
| 3597 | public function onAfterWrite() |
||
| 3621 | |||
| 3622 | /** |
||
| 3623 | *standard SS method. |
||
| 3624 | * |
||
| 3625 | * delete attributes, statuslogs, and payments |
||
| 3626 | * THIS SHOULD NOT BE USED AS ORDERS SHOULD BE CANCELLED NOT DELETED |
||
| 3627 | */ |
||
| 3628 | public function onBeforeDelete() |
||
| 3673 | |||
| 3674 | /******************************************************* |
||
| 3675 | * 11. DEBUG |
||
| 3676 | *******************************************************/ |
||
| 3677 | |||
| 3678 | /** |
||
| 3679 | * Debug helper method. |
||
| 3680 | * Can be called from /shoppingcart/debug/. |
||
| 3681 | * |
||
| 3682 | * @return string |
||
| 3683 | */ |
||
| 3684 | public function debug() |
||
| 3690 | } |
||
| 3691 |
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.