-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShippoPlugin.php
97 lines (81 loc) · 1.81 KB
/
ShippoPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Craft;
use CommerceShippo\ShippingMethod as ShippingMethod;
class ShippoPlugin extends BasePlugin
{
private $_name = 'Shippo';
private $_description = 'Live shipping rates with Shippo.';
private $_version = '1.0.0';
private $_developer = 'Taylor Daughtry';
private $_developerUrl = 'https://taylordaughtry.com';
public function getName()
{
return $this->_name;
}
public function getDescription()
{
return $this->_description;
}
public function getVersion()
{
return $this->_version;
}
public function getDeveloper()
{
return $this->_developer;
}
public function getDeveloperUrl()
{
return $this->_developerUrl;
}
public function hasSettings()
{
return true;
}
public function defineSettings()
{
return [
'apiKey' => [
AttributeType::String,
'default' => '',
'required' => true
],
'fromAddress' => [
AttributeType::Mixed,
'default' => [
'name' => 'Default Name',
'company' => craft()->getSiteName(),
'street1' => '1600 Pennsylvania Ave NW',
'city' => 'Washington',
'state' => 'DC',
'zip' => '20500',
'country' => 'US',
'phone' => '+1 234 567 8901',
'email' => craft()->email->settings['emailAddress']
],
'required' => true
]
];
}
public function getSettingsHtml()
{
return craft()->templates->render('shippo/Shippo_Settings', [
'settings' => $this->getSettings()
]);
}
public function init()
{
require CRAFT_PLUGINS_PATH . 'shippo/vendor/autoload.php';
}
public function commerce_registerShippingMethods($order = null)
{
if ($order && $order->shippingAddress) {
$shippingMethods = [];
$rates = craft()->shippo_rates->getRates($order);
foreach ($rates as $rate) {
$shippingMethods[] = new ShippingMethod($order, $rate);
}
return $shippingMethods;
}
}
}