Completed
Pull Request — master (#292)
by Jason
09:05
created

CustomerExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 32
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A onBeforeWrite() 0 16 2
1
<?php
2
3
class CustomerExtension extends DataExtension{
4
5
    private static $db = array(
6
        'Customer_ID' => 'Int'
7
    );
8
9
    private static $has_many = array(
10
        'Orders' => 'Order'
11
    );
12
13
    private static $indexes = array(
14
        'Customer_ID' => true // make unique
15
    );
16
17
    public function onBeforeWrite() {
18
        parent::onBeforeWrite();
19
20
        // if Member data was imported from FoxyCart, PasswordEncryption will be set to 'none'.
21
        // Change to sh1_v2.4 to ensure SilverStripe is using the same hash as FoxyCart API 1.1
22
        $this->owner->PasswordEncryption = 'sha1_v2.4';
23
24
        // Send updated customer data to Foxy Cart via API
25
        $response = FoxyCart::putCustomer($this->owner);
26
27
        // Grab customer_id record from FoxyCart response, store in Member
28
		if($response){
29
        	$foxyResponse = new SimpleXMLElement($response);
30
        	$this->owner->Customer_ID = (int) $foxyResponse->customer_id;
31
		}
32
    }
33
34
}