sluice_connect - Version 0.1.4

Version Notes

Extend standart Magento WebApi for SluiceHQ.

Download this release

Release Info

Developer Shavrukov Konstantin
Extension sluice_connect
Version 0.1.4
Comparing to
See all releases


Code changes from version 0.1.3 to 0.1.4

app/code/local/Sluice/Connect/Model/Api.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Sluice_Connect_Model_Api extends Mage_Catalog_Model_Product_Api {
3
+ public function parent($arg){
4
+ if(empty($arg)){
5
+ return array();
6
+ }
7
+
8
+ $result = array();
9
+ foreach($arg as $productId){
10
+ if(!is_numeric($productId)){
11
+ continue;
12
+ }
13
+
14
+ $product = Mage::getModel('catalog/product')->load($productId);
15
+ if(empty($product) || $product->getTypeId() != "simple"){
16
+ $result[$productId] = null;
17
+ continue;
18
+ }
19
+
20
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
21
+ if(isset($parentIds[0]) && !empty($parentIds[0])){
22
+ $result[$productId] = $parentIds[0];
23
+ } else {
24
+ $result[$productId] = null;
25
+ }
26
+ }
27
+ return $result;
28
+ }
29
+
30
+ public function childs($arg){
31
+ if(empty($arg)){
32
+ return array();
33
+ }
34
+
35
+ $result = array();
36
+ foreach($arg as $productId){
37
+ if(!is_numeric($productId)){
38
+ continue;
39
+ }
40
+
41
+ $product = Mage::getModel('catalog/product')->load($productId);
42
+ if(empty($product) || $product->getTypeId() != "configurable"){
43
+ $result[$productId] = null;
44
+ continue;
45
+ }
46
+
47
+ $childs = $product->getTypeInstance()->getUsedProducts();
48
+ if(empty($childs)) {
49
+ $result[$productId] = null;
50
+ continue;
51
+ }
52
+
53
+ $result[$productId] = array();
54
+ foreach($childs as $child){
55
+ $result[$productId][] = $child->getId();
56
+ }
57
+ }
58
+ return $result;
59
+ }
60
+ }
61
+ ?>
app/code/local/Sluice/Connect/Model/Observer.php CHANGED
@@ -5,7 +5,7 @@ use UnitedPrototype\GoogleAnalytics;
5
  class Sluice_Connect_Model_Observer {
6
 
7
  public $errorLog = 'sluice_connect.log';
8
- // Add to cartd trecking
9
  public function hookToAddToCart($observer) {
10
 
11
  if (!Mage::helper('googleanalytics')->isGoogleAnalyticsAvailable()) {
@@ -61,7 +61,7 @@ class Sluice_Connect_Model_Observer {
61
  $role = Mage::getModel("api/roles")->setName($roleName)->setRoleType('G')->save();
62
  Mage::getModel("api/rules")->setRoleId($role->getId())->setResources(array("all"))->saveRel();
63
 
64
- $apiKey = md5(uniqid(rand(), true));
65
  $user = Mage::getModel('api/user');
66
  $user->setData(array(
67
  'username' => $userName,
@@ -78,8 +78,16 @@ class Sluice_Connect_Model_Observer {
78
  ));
79
  $user->save()->load($user->getId());
80
  $user->setRoleIds(array($role->getId()))->setRoleUserId($user->getUserId())->saveRelations();
 
 
 
 
 
 
 
 
 
81
  }
82
- $apiKey = $user->getApiKey();
83
  } catch (Exception $ex) {
84
  Mage::log("User/Role saving error" . $ex->getMessage(), 3, $this->errorLog);
85
  Mage::getSingleton('core/session')->addError("User/Role saving error");
@@ -90,8 +98,12 @@ class Sluice_Connect_Model_Observer {
90
  $data = $arrayName = array(
91
  'username' => $userName,
92
  'apiKey' => $apiKey,
93
- 'token' => trim($token));
 
 
 
94
  $sluiceApiUrl = $sluiceApiUrl . '&' . http_build_query($data);
 
95
  file_get_contents($sluiceApiUrl);
96
  } catch (Exception $ex) {
97
  Mage::log("Error is request to sluice " . $ex->getMessage(), 3, $this->errorLog);
5
  class Sluice_Connect_Model_Observer {
6
 
7
  public $errorLog = 'sluice_connect.log';
8
+ // Add to cart trecking
9
  public function hookToAddToCart($observer) {
10
 
11
  if (!Mage::helper('googleanalytics')->isGoogleAnalyticsAvailable()) {
61
  $role = Mage::getModel("api/roles")->setName($roleName)->setRoleType('G')->save();
62
  Mage::getModel("api/rules")->setRoleId($role->getId())->setResources(array("all"))->saveRel();
63
 
64
+ $apiKey = md5(time());
65
  $user = Mage::getModel('api/user');
66
  $user->setData(array(
67
  'username' => $userName,
78
  ));
79
  $user->save()->load($user->getId());
80
  $user->setRoleIds(array($role->getId()))->setRoleUserId($user->getUserId())->saveRelations();
81
+ Mage::getModel('core/config')->saveConfig('sluice_section/sluice_group/api_field', $apiKey );
82
+ Mage::getConfig()->reinit();
83
+ Mage::app()->reinitStores();
84
+ }
85
+ $apiKey = Mage::getStoreConfig('sluice_section/sluice_group/api_field', Mage::app()->getStore());
86
+ if(empty($apiKey)){
87
+ Mage::log("Apy key is empty" . $ex->getMessage(), 3, $this->errorLog);
88
+ Mage::getSingleton('core/session')->addError("Please delete 'sluice-connect' user and try agan");
89
+ return;
90
  }
 
91
  } catch (Exception $ex) {
92
  Mage::log("User/Role saving error" . $ex->getMessage(), 3, $this->errorLog);
93
  Mage::getSingleton('core/session')->addError("User/Role saving error");
98
  $data = $arrayName = array(
99
  'username' => $userName,
100
  'apiKey' => $apiKey,
101
+ 'token' => trim($token),
102
+ 'url'=>Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
103
+ );
104
+
105
  $sluiceApiUrl = $sluiceApiUrl . '&' . http_build_query($data);
106
+ Mage::log("Sended data: " . $sluiceApiUrl , 3, $this->errorLog);
107
  file_get_contents($sluiceApiUrl);
108
  } catch (Exception $ex) {
109
  Mage::log("Error is request to sluice " . $ex->getMessage(), 3, $this->errorLog);
app/code/local/Sluice/Connect/etc/api.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <api>
3
+ <resources>
4
+ <catalog_product translate="title" module="sluice_connect">
5
+ <model>sluice_connect/api</model>
6
+ <methods>
7
+ <parent translate="title" module="sluice_connect">
8
+ <title>Return parent</title>
9
+ <method>parent</method>
10
+ </parent>
11
+ <childs translate="title" module="sluice_connect">
12
+ <title>Product parent</title>
13
+ <method>childs</method>
14
+ </childs>
15
+ </methods>
16
+ </catalog_product>
17
+ </resources>
18
+ </api>
19
+ </config>
app/code/local/Sluice/Connect/etc/system.xml CHANGED
@@ -31,6 +31,14 @@
31
  <show_in_store>1</show_in_store>
32
  <frontend_type>text</frontend_type>
33
  </sluice_field>
 
 
 
 
 
 
 
 
34
  </fields>
35
  </sluice_group>
36
  </groups>
31
  <show_in_store>1</show_in_store>
32
  <frontend_type>text</frontend_type>
33
  </sluice_field>
34
+ <api_field translate="label">
35
+ <label>Api Key:</label>
36
+ <comment>Api Key</comment>
37
+ <show_in_default>0</show_in_default>
38
+ <show_in_website>0</show_in_website>
39
+ <show_in_store>0</show_in_store>
40
+ <frontend_type>hidden</frontend_type>
41
+ </api_field>
42
  </fields>
43
  </sluice_group>
44
  </groups>
app/etc/modules/Sluice_Connect.xml CHANGED
@@ -1,9 +1,9 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <config>
3
- <modules>
4
- <Sluice_Connect>
5
- <active>true</active>
6
- <codePool>local</codePool>
7
- </Sluice_Connect>
8
- </modules>
9
  </config>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Sluice_Connect>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Sluice_Connect>
8
+ </modules>
9
  </config>
package.xml CHANGED
@@ -1,19 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>sluice_connect</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
- <license uri="http://www.gnu.org/licenses/gpl.html">GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Integration tool for SluiceHQ</summary>
10
  <description>This extension helps connect your Magento Store to SluiceHQ service.</description>
11
- <notes>- Track add to cart event (via google analitics)&#xD;
12
- - Give Magento data access to Sluice HQ (via Web Services)</notes>
13
- <authors><author><name>Konstantin</name><user>flyb1z0n</user><email>flyb1z0n@gmail.com</email></author></authors>
14
- <date>2013-05-11</date>
15
- <time>17:04:50</time>
16
- <contents><target name="magelocal"><dir name="Sluice"><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="72f7af6ab8f4dd94d7e0d56f2355e84a"/></dir><dir name="Model"><file name="Observer.php" hash="330268fd45446d9d8af7cdb60ce12769"/></dir><dir name="etc"><file name="config.xml" hash="a0d266785b3068b867d5110c7df8b397"/><file name="system.xml" hash="7c00c55ed5ec73bc35df97d4781ca4bd"/></dir></dir></dir></target><target name="magelib"><dir><dir name="GA-client"><file name="GA-client.php" hash="9d36d0998d30e475d0417b790a244261"/></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Sluice_Connect.xml" hash="87aa6be6cfdc5eea59f2033098c8fe78"/></dir></dir></target></contents>
17
  <compatible/>
18
- <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>sluice_connect</name>
4
+ <version>0.1.4</version>
5
  <stability>stable</stability>
6
+ <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>This extension helps connect your Magento Store to SluiceHQ service.</summary>
10
  <description>This extension helps connect your Magento Store to SluiceHQ service.</description>
11
+ <notes>Extend standart Magento WebApi for SluiceHQ.</notes>
12
+ <authors><author><name>Shavrukov Konstantin</name><user>flyb1z0n</user><email>flyb1z0n@gmail.com</email></author></authors>
13
+ <date>2013-07-29</date>
14
+ <time>11:41:32</time>
15
+ <contents><target name="magelocal"><dir name="Sluice"><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="72f7af6ab8f4dd94d7e0d56f2355e84a"/></dir><dir name="Model"><file name="Api.php" hash="9eec889ce6efe0e6574abe78d3b2e248"/><file name="Observer.php" hash="b96ce48bbe1df2b619cbfadc94053948"/></dir><dir name="etc"><file name="api.xml" hash="55bb4b5b4b09ae98c08095333b7ea584"/><file name="config.xml" hash="a0d266785b3068b867d5110c7df8b397"/><file name="system.xml" hash="a469061bfca6ddaf7d0625f713b3a160"/></dir></dir></dir></target><target name="magelib"><dir name="GA-client"><file name="GA-client.php" hash="9d36d0998d30e475d0417b790a244261"/></dir></target><target name="mageetc"><dir name="modules"><file name="Sluice_Connect.xml" hash="48740fb7c99b29de0af86399e578c5b9"/></dir></target></contents>
 
16
  <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.8</max></package></required></dependencies>
18
  </package>