|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @description: cleans up old (abandonned) carts... |
|
6
|
|
|
* |
|
7
|
|
|
* |
|
8
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
9
|
|
|
* @package: ecommerce |
|
10
|
|
|
* @sub-package: tasks |
|
11
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
12
|
|
|
**/ |
|
13
|
|
|
class EcommerceTaskOrdersWithoutOrderStep extends BuildTask |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
protected $sendEmails = true; |
|
16
|
|
|
|
|
17
|
|
|
protected $limit = 1; |
|
18
|
|
|
|
|
19
|
|
|
protected $title = 'Orders without orderstep'; |
|
20
|
|
|
|
|
21
|
|
|
protected $description = ' |
|
22
|
|
|
Orders where the order step does not exist.'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param SS_Request $request |
|
26
|
|
|
**/ |
|
27
|
|
|
public function run($request) |
|
28
|
|
|
{ |
|
29
|
|
|
$doCancel = $request->getVar('cancel'); |
|
30
|
|
|
if(! $doCancel) { |
|
31
|
|
|
DB::alteration_message('You can add <strong>cancel</strong> as a getvar to cancel and archive all orders.', 'edited'); |
|
32
|
|
|
} |
|
33
|
|
|
$submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
|
34
|
|
|
if ($submittedOrderStatusLogClassName) { |
|
35
|
|
|
$submittedStatusLog = $submittedOrderStatusLogClassName::get()->First(); |
|
36
|
|
|
if ($submittedStatusLog) { |
|
37
|
|
|
$orderStepsIDArray = OrderStep::get()->column('ID'); |
|
38
|
|
|
$orders = Order::get() |
|
39
|
|
|
->where('StatusID NOT IN (' . implode(',', $orderStepsIDArray).')') |
|
40
|
|
|
->innerJoin( |
|
41
|
|
|
'OrderStatusLog', |
|
42
|
|
|
"\"OrderStatusLog\".\"OrderID\" = \"Order\".\"ID\"" |
|
43
|
|
|
) |
|
44
|
|
|
->innerJoin( |
|
45
|
|
|
$submittedOrderStatusLogClassName, |
|
46
|
|
|
"\"$submittedOrderStatusLogClassName\".\"ID\" = \"OrderStatusLog\".\"ID\"" |
|
47
|
|
|
); |
|
48
|
|
|
if($orders->count()) { |
|
49
|
|
|
foreach($orders as $order) { |
|
50
|
|
|
$archivingNow = 'Open order to rectify.'; |
|
51
|
|
|
if($doCancel) { |
|
52
|
|
|
$archivingNow = 'This order has been cancelled and archived.'; |
|
53
|
|
|
$order->Cancel(); |
|
54
|
|
|
} |
|
55
|
|
|
DB::alteration_message( |
|
56
|
|
|
'<a href="'.$order->CMSEditLink().'">'.$order->getTitle().'</a><br />'.$archivingNow.'<br /><br />', |
|
57
|
|
|
'deleted' |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} else { |
|
61
|
|
|
DB::alteration_message('There are no orders without a valid order step.', 'created'); |
|
62
|
|
|
} |
|
63
|
|
|
} else { |
|
64
|
|
|
DB::alteration_message('NO submitted order status log.', 'deleted'); |
|
65
|
|
|
} |
|
66
|
|
|
} else { |
|
67
|
|
|
DB::alteration_message('NO EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order")', 'deleted'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
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.