4f4e331f92f560de38f6bc2b5501d8cb - Version 1.0.0

Version Notes

First release

Download this release

Release Info

Developer Roman Barbotkin
Extension 4f4e331f92f560de38f6bc2b5501d8cb
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Send24/Shipping/Model/Carrier.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Send24_Shipping_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {
4
+
5
+ protected $_code = 'send24_shipping';
6
+
7
+ public function collectRates(
8
+ Mage_Shipping_Model_Rate_Request $request
9
+ ) {
10
+ $result = Mage::getModel('shipping/rate_result');
11
+ $result->append($this->_getStandardShippingRate());
12
+
13
+ $expressWeightThreshold = $this->getConfigData('express_weight_threshold');
14
+
15
+ $eligibleForExpressDelivery = true;
16
+
17
+ if ($eligibleForExpressDelivery) {
18
+ $result->append($this->_getExpressShippingRate());
19
+ }
20
+
21
+ return $result;
22
+ }
23
+
24
+ protected function _getStandardShippingRate() {
25
+ }
26
+
27
+
28
+ public function after_order_placed($observer) {
29
+ $incrementId = $observer->getOrder()->getIncrementId();
30
+ // DK.
31
+ $country = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountryId();
32
+ $postcode = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getPostcode();
33
+ $send24_consumer_key = $this->getConfigData('send24_consumer_key');
34
+ $send24_consumer_secret = $this->getConfigData('send24_consumer_secret');
35
+ $auth = base64_encode($send24_consumer_secret.':'.$send24_consumer_key);
36
+ $select_country = 'Ekspres';
37
+
38
+ // get/check Express.
39
+ $ch = curl_init();
40
+ curl_setopt($ch, CURLOPT_URL, "https://send24.com/wc-api/v3/get_products");
41
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
42
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
43
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
44
+ "Content-Type: application/json",
45
+ "Authorization: Basic ".$auth
46
+ ));
47
+ $send24_countries = json_decode(curl_exec($ch));
48
+ curl_close($ch);
49
+ $n = count($send24_countries);
50
+ for ($i = 0; $i < $n; $i++)
51
+ {
52
+ if ($send24_countries[$i]->title == $select_country)
53
+ {
54
+ $coast = $send24_countries[$i]->price;
55
+ $send24_product_id = $send24_countries[$i]->product_id;
56
+ $i = $n;
57
+ $is_available = true;
58
+ }else{
59
+ $is_available = false;
60
+ }
61
+ }
62
+
63
+ if($is_available == true){
64
+ $insurance_price = 0;
65
+ $discount = "false";
66
+ $ship_total = $type = $price_need = '';
67
+ $user_id = $observer->getOrder()->getCustomerId();
68
+
69
+ $shipping_data = $observer->getOrder()->getShippingAddress()->getData();
70
+ $billing_data = $observer->getOrder()->getBillingAddress()->getData();
71
+
72
+ if($select_country == 'Ekspres'){ $select_country = 'Danmark'; $where_shop_id = 'ekspres'; }
73
+
74
+ // Create order.
75
+ $ch = curl_init();
76
+ curl_setopt($ch, CURLOPT_URL, "https://send24.com/wc-api/v3/create_order");
77
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
78
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
79
+ curl_setopt($ch, CURLOPT_POST, TRUE);
80
+ curl_setopt($ch, CURLOPT_POSTFIELDS, '
81
+ {
82
+ "TO_company": "'.$shipping_data['company'].'",
83
+ "TO_first_name": "'.$shipping_data['firstname'].'",
84
+ "TO_last_name": "'.$shipping_data['lastname'].'",
85
+ "TO_phone": "'.$shipping_data['telephone'].'",
86
+ "TO_email": "'.$shipping_data['email'].'",
87
+ "TO_country": "'.$select_country.'",
88
+ "TO_city": "'.$shipping_data['city'].'",
89
+ "TO_postcode": "'.$postcode.'",
90
+ "Insurance" : "'.$insurance_price.'",
91
+ "Weight": "5",
92
+ "TO_address": "'.$shipping_data['street'].'",
93
+ "WHAT_product_id": "'.$send24_product_id.'",
94
+ "WHERE_shop_id": "'.$where_shop_id.'",
95
+ "discount": "'.$discount.'",
96
+ "type": "'.$type.'",
97
+ "need_points": "'.$price_need.'",
98
+ "total": "'.$ship_total.'",
99
+ "ship_mail": "'.$shipping_data['email'].'",
100
+ "bill_mail": "'.$billing_data['email'].'"
101
+ }
102
+ ');
103
+
104
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
105
+ "Authorization: Basic " .$auth,
106
+ "Content-Type: application/json",
107
+ ));
108
+ $response = curl_exec($ch);
109
+ curl_close($ch);
110
+ }
111
+
112
+
113
+ $response_order = json_decode($response, JSON_FORCE_OBJECT);
114
+
115
+ $history = Mage::getModel('sales/order_status_history')
116
+ ->setStatus($observer->getOrder()->getStatus())
117
+ ->setComment('<strong>Track parsel </strong><br><a href="'.$response_order['track'].'" target="_blank">'.$response_order['track'].'</a>')
118
+ ->setEntityName(Mage_Sales_Model_Order::HISTORY_ENTITY_NAME)
119
+ ->setIsCustomerNotified(false)
120
+ ->setCreatedAt(date('Y-m-d H:i:s', time() - 60*60*24));
121
+
122
+ $observer->getOrder()->addStatusHistory($history);
123
+ $observer->getOrder()->save();
124
+ return true;
125
+ }
126
+
127
+
128
+
129
+
130
+ protected function _getExpressShippingRate() {
131
+ $rate = Mage::getModel('shipping/rate_result_method');
132
+ // DK
133
+ $country = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountryId();
134
+ $postcode = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getPostcode();
135
+
136
+ $send24_consumer_key = $this->getConfigData('send24_consumer_key');
137
+ $send24_consumer_secret = $this->getConfigData('send24_consumer_secret');
138
+ $auth = base64_encode($send24_consumer_secret.':'.$send24_consumer_key);
139
+ $select_country = 'Ekspres';
140
+
141
+ // get/check Express.
142
+ $ch = curl_init();
143
+ curl_setopt($ch, CURLOPT_URL, "https://send24.com/wc-api/v3/get_products");
144
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
145
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
146
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
147
+ "Content-Type: application/json",
148
+ "Authorization: Basic ".$auth
149
+ ));
150
+ $send24_countries = json_decode(curl_exec($ch));
151
+ curl_close($ch);
152
+ $n = count($send24_countries);
153
+ for ($i = 0; $i < $n; $i++)
154
+ {
155
+ if ($send24_countries[$i]->title == $select_country)
156
+ {
157
+ $coast = $send24_countries[$i]->price;
158
+ $product_id = $send24_countries[$i]->product_id;
159
+ $i = $n;
160
+ $is_available = true;
161
+ }else{
162
+ $is_available = false;
163
+ }
164
+ }
165
+
166
+ if($is_available == true){
167
+ //////////////
168
+ $shipping_address_1 = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getData('street');
169
+ $shipping_postcode = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getPostcode();
170
+ $shipping_city = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCity();
171
+ $shipping_country = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountry();
172
+ if($shipping_country == 'DK'){
173
+ $shipping_country = 'Denmark';
174
+ }
175
+
176
+ $ch = curl_init();
177
+ curl_setopt($ch, CURLOPT_URL, "https://send24.com/wc-api/v3/get_user_id");
178
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
179
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
180
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
181
+ "Content-Type: application/json",
182
+ "Authorization: Basic ".$auth
183
+ ));
184
+ $user_meta = json_decode(curl_exec($ch));
185
+
186
+ $billing_address_1 = $user_meta->billing_address_1['0'];
187
+ $billing_postcode = $user_meta->billing_postcode['0'];
188
+ $billing_city = $user_meta->billing_city['0'];
189
+ $billing_country = $user_meta->billing_country['0'];
190
+ if($billing_country == 'DK'){
191
+ $billing_country = 'Denmark';
192
+ }
193
+
194
+ $full_billing_address = "$billing_address_1, $billing_postcode $billing_city, $billing_country";
195
+ $full_shipping_address = "$shipping_address_1, $shipping_postcode $shipping_city, $shipping_country";
196
+
197
+ // Get billing coordinates.
198
+ $billing_url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=".urlencode($full_billing_address);
199
+ $billing_latlng = get_object_vars(json_decode(file_get_contents($billing_url)));
200
+ $billing_lat = $billing_latlng['results'][0]->geometry->location->lat;
201
+ $billing_lng = $billing_latlng['results'][0]->geometry->location->lng;
202
+
203
+ // Get shipping coordinates.
204
+ $shipping_url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=".urlencode($full_shipping_address);
205
+ $shipping_latlng = get_object_vars(json_decode(file_get_contents($shipping_url)));
206
+ $shipping_lat = $shipping_latlng['results'][0]->geometry->location->lat;
207
+ $shipping_lng = $shipping_latlng['results'][0]->geometry->location->lng;
208
+
209
+ // get_is_driver_area_five_km
210
+ $ch = curl_init();
211
+ curl_setopt($ch, CURLOPT_URL, "https://send24.com/wc-api/v3/get_is_driver_area_five_km");
212
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
213
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
214
+ curl_setopt($ch, CURLOPT_POST, TRUE);
215
+ curl_setopt($ch, CURLOPT_POSTFIELDS, '
216
+ {
217
+ "billing_lat": "'.$billing_lat.'",
218
+ "billing_lng": "'.$billing_lng.'",
219
+ "shipping_lat": "'.$shipping_lat.'",
220
+ "shipping_lng": "'.$shipping_lng.'"
221
+ }
222
+ ');
223
+
224
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
225
+ "Content-Type: application/json",
226
+ "Authorization: Basic ".$auth
227
+ ));
228
+
229
+ $response = curl_exec($ch);
230
+ $res = json_decode($response);
231
+ if(!empty($res)){
232
+ $rate->setCarrier($this->_code);
233
+ $rate->setCarrierTitle($this->getConfigData('title'));
234
+ $rate->setMethod('express');
235
+ $rate->setMethodTitle('Send24 Sameday(ETA: '.$res->time.') - ');
236
+ $rate->setPrice($coast);
237
+ $rate->setCost(0);
238
+ }
239
+
240
+ curl_close($ch);
241
+ // print_r($full_billing_address);
242
+ return $rate;
243
+ }
244
+ // die;
245
+
246
+ }
247
+
248
+ public function getAllowedMethods() {
249
+ return array(
250
+ 'express' => 'Send24 Sameday Solution',
251
+ );
252
+ }
253
+
254
+ }
app/code/local/Send24/Shipping/etc/config.xml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Send24_Shipping>
5
+ <module>0.0.1</module>
6
+ </Send24_Shipping>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <send24_shipping>
11
+ <class>Send24_Shipping_Model</class>
12
+ </send24_shipping>
13
+ </models>
14
+ <events>
15
+ <sales_order_place_after>
16
+ <observers>
17
+ <send24_shipping_order_observer>
18
+ <type>singleton</type>
19
+ <class>send24_shipping/carrier</class>
20
+ <method>after_order_placed</method>
21
+ </send24_shipping_order_observer>
22
+ </observers>
23
+ </sales_order_place_after>
24
+
25
+ </events>
26
+ </global>
27
+
28
+ <!-- Default configuration -->
29
+ <default>
30
+ <carriers>
31
+ <send24_shipping>
32
+ <active>1</active>
33
+ <!--
34
+ This configuration should not be made visible
35
+ to the administrator, because it specifies
36
+ the model to be used for this carrier.
37
+ -->
38
+ <model>send24_shipping/carrier</model>
39
+ <!--
40
+ The title as referenced in the carrier class
41
+ -->
42
+ <title>Send24 Shipping</title>
43
+ <!--
44
+ The sort order specifies the position that
45
+ this carrier appears relative to the other
46
+ carriers available in checkout.
47
+ -->
48
+ <sort_order>10</sort_order>
49
+
50
+ </send24_shipping>
51
+ </carriers>
52
+ </default>
53
+ </config>
app/code/local/Send24/Shipping/etc/system.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <carriers translate="label" module="shipping">
5
+ <groups>
6
+ <send24_shipping translate="label">
7
+ <label>Send24</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>2</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <!--
15
+ The following fields are available
16
+ to modify in the admin panel.
17
+ The values are saved in the
18
+ database.
19
+
20
+ This shipping carrier abstract checks
21
+ this value to determine whether
22
+ the carrier should be shown.
23
+ -->
24
+ <active translate="label">
25
+ <label>Enabled</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </active>
33
+
34
+ <!--
35
+ Send24 Consumer Key.
36
+ -->
37
+ <send24_consumer_key translate="label">
38
+ <label>Send24 Consumer Key</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>3</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </send24_consumer_key>
45
+ <!--
46
+ Send24 Consumer Secret
47
+ -->
48
+ <send24_consumer_secret translate="label">
49
+ <label>Send24 Consumer Secret</label>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>4</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ </send24_consumer_secret>
56
+ <!--
57
+ This value can be used to specify a
58
+ custom title for our method.
59
+ -->
60
+ <title translate="label">
61
+ <label>Title</label>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>2</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>1</show_in_store>
67
+ </title>
68
+ <!--
69
+ The sort order is used in Magento
70
+ to determine what order the carrier
71
+ will appear in relative to the
72
+ other carriers available.
73
+ -->
74
+
75
+ <sort_order translate="label">
76
+ <label>Sort Order</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>100</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </sort_order>
83
+
84
+ </fields>
85
+ </send24_shipping>
86
+ </groups>
87
+ </carriers>
88
+ </sections>
89
+ </config>
app/etc/modules/Send24_Shipping.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <!-- ... -->
3
+ <modules>
4
+ <!-- ... -->
5
+ <!-- declare Send24_Shipping module -->
6
+ <Send24_Shipping>
7
+ <active>true</active>
8
+ <codePool>local</codePool>
9
+ </Send24_Shipping>
10
+ <!-- ... -->
11
+ </modules>
12
+ <!-- ... -->
13
+ </config>
package.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>4f4e331f92f560de38f6bc2b5501d8cb</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Offer your customers premium delivery service with Send24 Sameday Express solution. Easy integration into your webshop. Fast and secure delivery service from door to door.</summary>
10
+ <description>WEBSHOP BENEFITS&#xD;
11
+ &#xD;
12
+ With this plugin the webshop is able to meet customers need for a fast and reliable delivery service to an affordable price.&#xD;
13
+ Simply install and enjoy the fast PickUp and Delivery service in cooperation with professionals and private people.&#xD;
14
+ &#xD;
15
+ CUSTOMER BENEFITS&#xD;
16
+ &#xD;
17
+ Customers can get their parcel today. Get notified on when the parcel arrives and track the movement on map. &#xD;
18
+ A personal and fast delivery experience brought to your customers frontdoor.&#xD;
19
+ &#xD;
20
+ FUNCTIONS&#xD;
21
+ &#xD;
22
+ - Integrates with Send24 shipping services&#xD;
23
+ - Printing out shipping labels&#xD;
24
+ - Real-time ETA&#xD;
25
+ - Intelligent Express service - only show when we have a car available&#xD;
26
+ - Send24 Account free of charge&#xD;
27
+ &#xD;
28
+ REQUIRES&#xD;
29
+ &#xD;
30
+ This plugin requires an account on Send24. You will need to enter your api key in this shipping module to activate it. The account is free of charge and is used to administrate your shipments.&#xD;
31
+ Register your free account on Send24.&#xD;
32
+ </description>
33
+ <notes>First release</notes>
34
+ <authors><author><name>Roman Barbotkin</name><user>Barbotkin</user><email>barbotkin@bk.ru</email></author></authors>
35
+ <date>2015-12-24</date>
36
+ <time>12:29:11</time>
37
+ <contents><target name="magelocal"><dir name="Send24"><dir name="Shipping"><dir name="Model"><file name="Carrier.php" hash="f0bde0292575eadd592e602e25aab57a"/></dir><dir name="etc"><file name="config.xml" hash="248e9c21b6075dad2b20f2a34e354f8e"/><file name="system.xml" hash="8a7b836a1a5e720348975b941ed8898e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Send24_Shipping.xml" hash="c365adcf43a601147514106e32ef524e"/></dir></target></contents>
38
+ <compatible/>
39
+ <dependencies><required><php><min>5.1.0</min><max>7.0.0</max></php></required></dependencies>
40
+ </package>