1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* After a bug in the saving of orders in the CMS |
5
|
|
|
* This "fixer" was introduced to fix older orders |
6
|
|
|
* without a submission record. |
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 EcommerceTaskArchiveAllSubmittedOrders extends BuildTask |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
protected $title = 'Archive all submitted orders'; |
16
|
|
|
|
17
|
|
|
protected $description = " |
18
|
|
|
This task moves all orders to the 'Archived' (last) Order Step without running any of the tasks in between."; |
19
|
|
|
|
20
|
|
|
public function run($request) |
21
|
|
|
{ |
22
|
|
|
//IMPORTANT! |
23
|
|
|
Config::inst()->update('Email', 'send_all_emails_to', 'no-one@localhost'); |
24
|
|
|
Email::set_mailer(new Ecommerce_Dummy_Mailer()); |
|
|
|
|
25
|
|
|
$orderStatusLogClassName = 'OrderStatusLog'; |
26
|
|
|
$submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
27
|
|
|
if ($submittedOrderStatusLogClassName) { |
28
|
|
|
$sampleSubmittedStatusLog = $submittedOrderStatusLogClassName::get() |
29
|
|
|
->First(); |
30
|
|
|
if ($sampleSubmittedStatusLog) { |
31
|
|
|
$lastOrderStep = OrderStep::get()->sort('Sort', 'DESC')->First(); |
32
|
|
|
if ($lastOrderStep) { |
33
|
|
|
$joinSQL = "INNER JOIN \"$orderStatusLogClassName\" ON \"$orderStatusLogClassName\".\"OrderID\" = \"Order\".\"ID\""; |
34
|
|
|
$whereSQL = 'WHERE "StatusID" <> '.$lastOrderStep->ID." AND \"$orderStatusLogClassName\".ClassName = '$submittedOrderStatusLogClassName'"; |
35
|
|
|
$count = DB::query(" |
36
|
|
|
SELECT COUNT (\"Order\".\"ID\") |
37
|
|
|
FROM \"Order\" |
38
|
|
|
$joinSQL |
39
|
|
|
$whereSQL |
40
|
|
|
")->value(); |
41
|
|
|
$do = DB::query(" |
|
|
|
|
42
|
|
|
UPDATE \"Order\" |
43
|
|
|
$joinSQL |
44
|
|
|
SET \"Order\".\"StatusID\" = ".$lastOrderStep->ID." |
45
|
|
|
$whereSQL |
46
|
|
|
"); |
47
|
|
|
if ($count) { |
48
|
|
|
DB::alteration_message("NOTE: $count records were updated.", 'created'); |
49
|
|
|
} else { |
50
|
|
|
DB::alteration_message('No records were updated.'); |
51
|
|
|
} |
52
|
|
|
} else { |
53
|
|
|
DB::alteration_message('Could not find the last order step.', 'deleted'); |
54
|
|
|
} |
55
|
|
|
} else { |
56
|
|
|
DB::alteration_message('Could not find any submitted order logs.', 'deleted'); |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
DB::alteration_message('Could not find a class name for submitted orders.', 'deleted'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.