eKomi_integration - Version 1.3.1

Version Notes

Country Code auto addition.

Download this release

Release Info

Developer Abdullah Shah
Extension eKomi_integration
Version 1.3.1
Comparing to
See all releases


Code changes from version 1.3.0 to 1.3.1

app/code/community/Ekomi/EkomiIntegration/Helper/Data.php CHANGED
@@ -66,4 +66,33 @@ class Ekomi_EkomiIntegration_Helper_Data extends Mage_Core_Helper_Abstract
66
  }
67
  return false;
68
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
66
  }
67
  return false;
68
  }
69
+
70
+ /**
71
+ * @param $phone
72
+ * @param $country
73
+ *
74
+ * @return mixed|string
75
+ */
76
+ function addCountryCode($phone, $country)
77
+ {
78
+ $ApiUrl = 'https://plugins-dashboard.ekomiapps.de/api/v1/country-code';
79
+ $ch = curl_init();
80
+ curl_setopt($ch, CURLOPT_URL, $ApiUrl . '?shop_id=' . $this->getShopId() . '&interface_password=' . $this->getShopPassword() . '&country_code=' . $country);
81
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
82
+ $json = curl_exec($ch);
83
+ curl_close($ch);
84
+
85
+ $response = json_decode($json, true);
86
+ if($response['status']['type'] == 'success'){
87
+ $phoneCode = $response['data']['phone_code'];
88
+
89
+ if(substr($phone, 0 , 1) == '0') {
90
+ $phone = substr_replace($phone, $phoneCode, 0, 1);
91
+ } else if(substr($phone, 0 , 2) != $phoneCode) {
92
+ $phone = $phoneCode . $phone;
93
+ }
94
+
95
+ return $phone;
96
+ }
97
+ }
98
  }
app/code/community/Ekomi/EkomiIntegration/Model/Observer.php CHANGED
@@ -50,15 +50,30 @@ class Ekomi_EkomiIntegration_Model_Observer
50
  */
51
  protected function getData($order, $storeId)
52
  {
53
- $helper = Mage::helper('ekomi_ekomiIntegration');
54
- $scheduleTime = date('d-m-Y H:i:s', strtotime($order->getCreatedAtStoreDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)));
55
- $apiMode = $this->getRecipientType($order->getBillingAddress()->getTelephone(), $storeId);
56
- $fields = array('recipient_type' => $apiMode, 'shop_id' => $helper->getShopId($storeId), 'password' => $helper->getShopPassword($storeId), 'salutation' => '',
57
- 'first_name' => $order->getBillingAddress()->getFirstname(),
58
- 'last_name' => $order->getBillingAddress()->getLastname(),
59
- 'email' => $order->getCustomerEmail(), 'transaction_id' => $order->getIncrementId(),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  'transaction_time' => $scheduleTime,
61
- 'telephone' => $order->getBillingAddress()->getTelephone(),
62
  'sender_name' => Mage::getStoreConfig('trans_email/ident_sales/name'),
63
  'sender_email' => Mage::getStoreConfig('trans_email/ident_sales/email')
64
  );
@@ -68,8 +83,8 @@ class Ekomi_EkomiIntegration_Model_Observer
68
  $fields['screen_name'] = $this->getCustomerScreenName($order->getCustomerId());
69
  } else {
70
  $fields['client_id'] = 'guest_oId_' . $order->getIncrementId();
71
- $lname = $order->getBillingAddress()->getLastname();
72
- $fields['screen_name'] = $order->getBillingAddress()->getFirstname() . $lname[0];
73
  }
74
 
75
  if ($helper->isProductReviewEnabled($storeId)) {
@@ -180,25 +195,46 @@ class Ekomi_EkomiIntegration_Model_Observer
180
  * @param $storeId
181
  * @return string
182
  */
183
- protected function getRecipientType($telephone, $storeId) {
 
184
  $helper = Mage::helper('ekomi_ekomiIntegration');
185
  $reviewMod = $helper->getReviewMod($storeId);
186
- $apiMode = 'email';
187
- switch($reviewMod){
188
- case 'sms':
189
- $apiMode = 'sms';
190
- break;
191
- case 'email':
192
- $apiMode = 'email';
193
- break;
194
- case 'fallback':
195
- if($helper->validateE164($telephone))
196
- $apiMode = 'sms';
197
- else
198
- $apiMode = 'email';
199
- break;
200
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
- return $apiMode;
203
  }
204
  }
50
  */
51
  protected function getData($order, $storeId)
52
  {
53
+ $helper = Mage::helper('ekomi_ekomiIntegration');
54
+ $scheduleTime = date('d-m-Y H:i:s', strtotime($order->getCreatedAtStoreDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)));
55
+ $telephone = $order->getShippingAddress()->getTelephone();
56
+ $country = $order->getShippingAddress()->getCountry();
57
+ $recipientData = $this->getRecipientData($telephone, $country, $storeId);
58
+
59
+ if(!$recipientData['success']){
60
+ return '';
61
+ }
62
+
63
+ $apiMode = $recipientData['api-mode'];
64
+ $phoneNumber = $recipientData['phone-number'];
65
+
66
+ $fields = array(
67
+ 'recipient_type' => $apiMode,
68
+ 'shop_id' => $helper->getShopId($storeId),
69
+ 'password' => $helper->getShopPassword($storeId),
70
+ 'salutation' => '',
71
+ 'first_name' => $order->getShippingAddress()->getFirstname(),
72
+ 'last_name' => $order->getShippingAddress()->getLastname(),
73
+ 'email' => $order->getCustomerEmail(),
74
+ 'transaction_id' => $order->getIncrementId(),
75
  'transaction_time' => $scheduleTime,
76
+ 'telephone' => $phoneNumber,
77
  'sender_name' => Mage::getStoreConfig('trans_email/ident_sales/name'),
78
  'sender_email' => Mage::getStoreConfig('trans_email/ident_sales/email')
79
  );
83
  $fields['screen_name'] = $this->getCustomerScreenName($order->getCustomerId());
84
  } else {
85
  $fields['client_id'] = 'guest_oId_' . $order->getIncrementId();
86
+ $lname = $order->getShippingAddress()->getLastname();
87
+ $fields['screen_name'] = $order->getShippingAddress()->getFirstname() . $lname[0];
88
  }
89
 
90
  if ($helper->isProductReviewEnabled($storeId)) {
195
  * @param $storeId
196
  * @return string
197
  */
198
+ protected function getRecipientData($telephone, $country, $storeId)
199
+ {
200
  $helper = Mage::helper('ekomi_ekomiIntegration');
201
  $reviewMod = $helper->getReviewMod($storeId);
202
+ $recipientData = array(
203
+ 'success' => false,
204
+ 'api-mode' => 'email',
205
+ 'phone-number' => $telephone
206
+ );
207
+
208
+ if($reviewMod == 'email') {
209
+ $recipientData['success'] = true;
210
+ $recipientData['api-mode'] = 'email';
211
+ } else {
212
+ if (substr($telephone, 0, 1) == '+') {
213
+ $recipientData['phone-number'] = $telephone;
214
+ } else if (substr($telephone, 0, 1) == '0') {
215
+ $telephone = $helper->addCountryCode($telephone, $country);
216
+ } else if ($helper->validateE164($telephone)) {
217
+ $telephone = $helper->addCountryCode($telephone, $country);
218
+ }
219
+
220
+ if ($helper->validateE164($telephone)) {
221
+ $recipientData['success'] = true;
222
+ $recipientData['api-mode'] = 'sms';
223
+ $recipientData['phone-number'] = $telephone;
224
+ } else {
225
+ switch ($reviewMod) {
226
+ case 'sms':
227
+ $recipientData['success'] = false;
228
+ $recipientData['api-mode'] = 'sms';
229
+ break;
230
+ case 'fallback':
231
+ $recipientData['success'] = true;
232
+ $recipientData['api-mode'] = 'email';
233
+ break;
234
+ }
235
+ }
236
+ };
237
 
238
+ return $recipientData;
239
  }
240
  }
app/code/community/Ekomi/EkomiIntegration/etc/config.xml CHANGED
@@ -16,7 +16,7 @@
16
  <config>
17
  <modules>
18
  <Ekomi_EkomiIntegration>
19
- <version>1.0.0.0</version>
20
  </Ekomi_EkomiIntegration>
21
  </modules>
22
  <global>
16
  <config>
17
  <modules>
18
  <Ekomi_EkomiIntegration>
19
+ <version>1.3.0.0</version>
20
  </Ekomi_EkomiIntegration>
21
  </modules>
22
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>eKomi_integration</name>
4
- <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license>AFL</license>
7
  <channel>community</channel>
@@ -11,8 +11,8 @@
11
  <notes>Country Code auto addition.</notes>
12
  <authors><author><name>Abdullah Shah</name><user>sbarics</user><email>sbarics@ekomi.de</email></author></authors>
13
  <date>2017-05-29</date>
14
- <time>10:02:31</time>
15
- <contents><target name="magecommunity"><dir name="Ekomi"><dir name="EkomiIntegration"><dir name="Helper"><file name="Data.php" hash="0ab0b327a3a36b085053fa9095671f3c"/></dir><dir name="Model"><file name="Observer.php" hash="cfcbb45ce19146fcce29ef63417f1fed"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Mod.php" hash="39cfbafdf917b466f5b0ce5e4d7c9ea5"/><file name="Status.php" hash="890aab8d85bd23b7a46ab8b87758a018"/></dir></dir></dir></dir><file name="Validate.php" hash="b9de4708ae8fb88f9bb9c9dd0f13abc2"/></dir><dir name="etc"><file name="adminhtml.xml" hash="bfb8c20cbf01af974039b5e71a040f71"/><file name="config.xml" hash="f3151a3f31c31cefb97959c71c2c6b02"/><file name="system.xml" hash="d4c5b8d9c2ddf5dfcb73969d2cf01c3a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ekomi_EkomiIntegration.xml" hash="e84d0589f7081183d0d3d1e1c66c059e"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>7.1.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>eKomi_integration</name>
4
+ <version>1.3.1</version>
5
  <stability>stable</stability>
6
  <license>AFL</license>
7
  <channel>community</channel>
11
  <notes>Country Code auto addition.</notes>
12
  <authors><author><name>Abdullah Shah</name><user>sbarics</user><email>sbarics@ekomi.de</email></author></authors>
13
  <date>2017-05-29</date>
14
+ <time>10:17:09</time>
15
+ <contents><target name="magecommunity"><dir name="Ekomi"><dir name="EkomiIntegration"><dir name="Helper"><file name="Data.php" hash="b67445ff0f07de4feee9dd05bcabf82a"/></dir><dir name="Model"><file name="Observer.php" hash="7b6437296acb1ce2284460aafb2de95e"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Mod.php" hash="39cfbafdf917b466f5b0ce5e4d7c9ea5"/><file name="Status.php" hash="890aab8d85bd23b7a46ab8b87758a018"/></dir></dir></dir></dir><file name="Validate.php" hash="b9de4708ae8fb88f9bb9c9dd0f13abc2"/></dir><dir name="etc"><file name="adminhtml.xml" hash="bfb8c20cbf01af974039b5e71a040f71"/><file name="config.xml" hash="ef12a656fbfc25cac5936b57c6c462cb"/><file name="system.xml" hash="d4c5b8d9c2ddf5dfcb73969d2cf01c3a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ekomi_EkomiIntegration.xml" hash="e84d0589f7081183d0d3d1e1c66c059e"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>7.1.0</max></php></required></dependencies>
18
  </package>