Ventata_Connector - Version 1.4.0.0

Version Notes

.

Download this release

Release Info

Developer Magento Core Team
Extension Ventata_Connector
Version 1.4.0.0
Comparing to
See all releases


Code changes from version 1.3.0.0 to 1.4.0.0

app/code/local/Ventata/Connector/Helper/Data.php DELETED
@@ -1,6 +0,0 @@
1
- <?php
2
-
3
- class Ventata_Connector_Helper_Data extends Mage_Core_Helper_Abstract
4
- {
5
-
6
- }
 
 
 
 
 
 
app/code/local/Ventata/Connector/Model/Config/Observer.php DELETED
@@ -1,164 +0,0 @@
1
- <?php
2
- error_reporting(E_ALL);
3
- ini_set('display_errors', '1');
4
- class Ventata_Connector_Model_Config_Observer extends Varien_Event_Observer
5
- {
6
- public function __construct()
7
- {
8
-
9
- }
10
-
11
- public function get_all_stores_api_key($observer)
12
- {
13
- $allStores = Mage::app()->getStores();
14
-
15
- if(Mage::getStoreConfig('ventata/orderhook_group/apipassword') == null) {
16
- $magentoApiKey = $this->createVentataApiUser();
17
- Mage::getModel('core/config')->saveConfig('ventata/orderhook_group/apipassword', $magentoApiKey);
18
- } else {
19
- $magentoApiKey = Mage::getStoreConfig('ventata/orderhook_group/apipassword');
20
- }
21
-
22
- foreach ($allStores as $_eachStoreId => $val) {
23
- $_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
24
- $_storeName = Mage::app()->getStore($_eachStoreId)->getName();
25
- $_storeId = Mage::app()->getStore($_eachStoreId)->getId();
26
- $storeUrl = Mage::app()->getStore($_storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
27
-
28
- if(Mage::getStoreConfig('ventata/orderhook_group/storeapikey', Mage::app()->getStore($_eachStoreId)) == null) {
29
- $data = array();
30
-
31
- $data["Name"] = $_storeName;
32
- $data["URL"] = $storeUrl;
33
-
34
- $storeType = array();
35
- $storeType["Id"] = 1004;
36
- $storeType["Name"] = "Magento";
37
- $data["StoreType"] = $storeType;
38
-
39
-
40
- $data_string = json_encode($data);
41
- $ventataCompanyAPIKey = Mage::getStoreConfig('ventata/orderhook_group/apikey');
42
-
43
- $result = $this->_processRequest("https://api.ventata.com/stores?ApiKey=", $ventataCompanyAPIKey, $data_string);
44
-
45
- //Mage::setStoreConfig('ventata/orderhook_group/storeapikey', $res["ApiKey"], Mage::app()->getStore());
46
- Mage::getModel('core/config')->saveConfig('ventata/orderhook_group/storeapikey', $result['ApiKey'], 'stores', $_storeId);
47
- //Mage::app()->getStore($_storeCode)->setConfig('ventata/orderhook_group/storeapikey', $res['ApiKey']);
48
-
49
- $storeSetting = array();
50
- $storeSetting["Key"] = "ApiPassword";
51
- $storeSetting["Value"] = $magentoApiKey;
52
- //Note we are now using the $ventataStoreApiKey
53
- //4a. Use CURL to POST $storeSetting to https://api.ventata.com/store/setting?ApiKey=$ventataStoreAPIKey
54
-
55
- $settingsResult = $this->_processRequest("https://api.ventata.com/store/setting?ApiKey=", $result['ApiKey'], json_encode($storeSetting));
56
-
57
- $storeSetting = array();
58
- $storeSetting["Key"] = "StoreUrl";
59
- $storeSetting["Value"] = $storeUrl;
60
-
61
- $settingsResult = $this->_processRequest("https://api.ventata.com/store/setting?ApiKey=", $result['ApiKey'], json_encode($storeSetting));
62
-
63
- $storeSetting = array();
64
- $storeSetting["Key"] = "StoreViewId";
65
- $storeSetting["Value"] = $_storeId;
66
-
67
- $settingsResult = $this->_processRequest("https://api.ventata.com/store/setting?ApiKey=", $result['ApiKey'], json_encode($storeSetting));
68
-
69
- }
70
- }
71
-
72
- return $this;
73
- }
74
-
75
- public function _processRequest($url, $apiKey, $data_string)
76
- {
77
- $ch = curl_init();
78
-
79
- $url = $url . $apiKey;
80
-
81
- curl_setopt($ch, CURLOPT_URL, $url);
82
- curl_setopt($ch, CURLOPT_POST, true);
83
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
84
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
85
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
86
- curl_setopt($ch, CURLOPT_VERBOSE, true);
87
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
88
-
89
- $result = curl_exec($ch);
90
-
91
- curl_close($ch);
92
-
93
- return json_decode($result, true);
94
- }
95
-
96
- public function createVentataApiUser()
97
- {
98
- $user = Mage::getModel('api/user')->loadByUsername('VentataConnector');
99
- if(!$user || !$user->getId()) {
100
- $role = Mage::getModel('api/roles')
101
- ->setName('Ventata')
102
- ->setPid(false)
103
- ->setRoleType('G')
104
- ->save();
105
-
106
-
107
- Mage::getModel('api/rules')
108
- ->setRoleId($role->getId())
109
- ->setResources(array('all'))
110
- ->saveRel();
111
-
112
- $magentoApiKey = $this->getRandomString(24);
113
- $user = Mage::getModel('api/user');
114
- $user->setData($this->generateUserData($role->getId(), $magentoApiKey));
115
-
116
- $user->save()->load($user->getId());
117
-
118
- $user->setRoleIds(array($role->getId()))
119
- ->setRoleUserId($user->getUserId())
120
- ->saveRelations();
121
-
122
- $rules = Mage::getModel('api/rules')->getCollection()
123
- ->addFieldToFilter('role_id', $role->getId());
124
-
125
- foreach($rules as $rule) {
126
- $rule->setApiPermission('allow');
127
- }
128
-
129
- $rules->save();
130
- }
131
-
132
- return $magentoApiKey;
133
- }
134
-
135
- public function generateUserData($roleId, $magentoApiKey)
136
- {
137
- $data = array(
138
- 'username' => 'VentataConnector',
139
- 'firstname' => 'Ventata',
140
- 'lastname' => 'Connector',
141
- 'email' => 'magento@ventata.com',
142
- 'api_key' => $magentoApiKey,
143
- 'api_key_confirmation' => $magentoApiKey,
144
- 'is_active' => 1,
145
- 'user_roles' => '',
146
- 'assigned_user_role' => '',
147
- 'role_name' => '',
148
- 'roles' => array($roleId)
149
- );
150
-
151
- return $data;
152
- }
153
-
154
- public function getRandomString($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
155
- {
156
- $str = '';
157
- $count = strlen($charset);
158
- while ($length--) {
159
- $str .= $charset[mt_rand(0, $count-1)];
160
- }
161
- return $str;
162
- }
163
- }
164
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Ventata/Connector/Model/Order/Observer.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
- class Ventata_Connector_Model_Order_Observer extends Varien_Event_Observer
3
- {
4
- public function __construct()
5
- {
6
- }
7
-
8
- public function upload_order_to_ventata($observer)
9
- {
10
- $order = $observer->getOrder();
11
-
12
- $data = array();
13
- $data['DateCreated'] = '/Date(' . date('U', strtotime($order->getCreatedAt())) . '000)/';
14
- $data['ExternalOrderId'] = $order->getIncrementId();
15
- $data['ShippingCost'] = $order->getShippingAmount();
16
- $data['SubTotal'] = $order->getSubtotal();
17
- $data['Taxes'] = $order->getTaxAmount();
18
- $data['TotalPrice'] = $order->getGrandTotal();
19
- $data['OrderDetails'] = array();
20
- $items = $order->getAllItems();
21
-
22
- if ($items) {
23
- foreach ($items as $item) {
24
- $product = $item->getProduct();
25
- $store = Mage::getModel('core/store')->load($item->getStoreId());
26
- $tempData = array(
27
- 'CostPerItem' => $product->getPrice(),
28
- 'ManuCode' => $item->getSku(),
29
- 'Quantity' => $item->getQtyOrdered(),
30
- 'PricePaid' => $item->getPrice(),
31
- 'StoreCode' => $store->getCode(),
32
- );
33
- array_push($data['OrderDetails'], $tempData);
34
- }
35
- }
36
-
37
- $data_string = json_encode($data);
38
- $ch = curl_init();
39
-
40
- $storeApiKey = Mage::getStoreConfig('ventata/orderhook_group/storeapikey', Mage::app()->getStore());;
41
-
42
- $url = "https://api.ventata.com/orders?ApiKey=" . $storeApiKey;
43
-
44
- curl_setopt($ch, CURLOPT_URL, $url);
45
- curl_setopt($ch, CURLOPT_POST, true);
46
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
47
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
48
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
49
- curl_setopt($ch, CURLOPT_VERBOSE, true);
50
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
51
-
52
- $result = curl_exec($ch);
53
- curl_close($ch);
54
-
55
- return $this;
56
- }
57
- }
58
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Ventata/Connector/Model/Product/Observer.php DELETED
@@ -1,121 +0,0 @@
1
- <?php
2
- error_reporting(E_ALL);
3
- ini_set('display_errors', '1');
4
- class Ventata_Connector_Model_Product_Observer extends Varien_Event_Observer
5
- {
6
- public function __construct()
7
- {
8
-
9
- }
10
-
11
- public function product_save_after($observer)
12
- {
13
- $product = $observer->getProduct();
14
- $websiteIds = $product->getWebsiteIds();
15
-
16
- if(Mage::app()->getRequest()->getParam('id') != null) {
17
- $action = 'edit';
18
- } else {
19
- $action = 'new';
20
- }
21
-
22
- switch($action) {
23
- case 'new':
24
- $data = $this->_prepareProductForVentata($product);
25
- $this->sendProductToVentata($data, 'new', $websiteIds);
26
- break;
27
-
28
- case 'edit':
29
- $data = $this->prepareProductForVentata($product);
30
- $this->sendProductToVentata($data, 'update', $websiteIds);
31
- break;
32
-
33
- }
34
-
35
- return $this;
36
- }
37
-
38
-
39
- public function _prepareProductForVentata($product)
40
- {
41
- $data = array(
42
- 'Cost' => ($product->getCost()) ? $product->getCost() : 0,
43
- 'DateCreated' => '/Date(' . date('U', strtotime($product->getCreatedAt())) . '+0000)/',
44
- 'Description' => $product->getDescription(),
45
- //'MANUCODE' => $product['model'],
46
- 'Name' => $product->getName(),
47
- 'Price' => $product->getPrice(),
48
- 'SKU' => $product->getSku(),
49
- 'StoreCode' => $product->getId(),
50
- 'Strategy' => 'Unlimited Supply',
51
- );
52
-
53
- return $data;
54
- }
55
-
56
- public function sendProductToVentata($data, $action, $websiteIds)
57
- {
58
- $data_string = json_encode($data);
59
-
60
- $stores = Mage::app()->getStores();
61
- foreach ($stores as $_eachStoreId => $val) {
62
- $store = Mage::app()->getStore($_eachStoreId);
63
- $_storeCode = $store->getCode();
64
- $_storeName = $store->getName();
65
- $_storeId = $store->getId();
66
- $websiteId = $store->getWebsiteId();
67
-
68
- //echo $store->getWebsiteId() . ": $_storeCode";
69
-
70
- if(!in_array($websiteId, $websiteIds)) {
71
- // echo $store->getWebsiteId() . ": $_storeCode break here\n";
72
- break;
73
- }
74
-
75
- $storeApiKey = Mage::getStoreConfig('ventata/orderhook_group/storeapikey', Mage::app()->getStore($_eachStoreId));
76
- $this->_processRequest($data_string, $action, $storeApiKey);
77
- }
78
-
79
- //exit;
80
- }
81
-
82
- public function _processRequest($data_string, $action, $storeApiKey)
83
- {
84
- $ch = curl_init();
85
-
86
- if($storeApiKey == null) {
87
- return;
88
- }
89
-
90
- $url = "https://api.ventata.com/product?ApiKey=" . $storeApiKey;
91
- curl_setopt($ch, CURLOPT_URL, $url);
92
-
93
- switch($action)
94
- {
95
- case 'new':
96
- curl_setopt($ch, CURLOPT_POST, true);
97
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
98
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
99
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
100
- curl_setopt($ch, CURLOPT_VERBOSE, true);
101
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
102
- break;
103
-
104
- case 'update':
105
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
106
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
107
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
108
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
109
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
110
- break;
111
- }
112
-
113
- $result = curl_exec($ch);
114
- //print_r(json_decode($result, true));
115
- curl_close($ch);
116
-
117
- return $result;
118
- }
119
-
120
- }
121
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Ventata/Connector/etc/adminhtml.xml DELETED
@@ -1,25 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <acl>
4
- <resources>
5
- <all>
6
- <title>Allow Everything</title>
7
- </all>
8
- <admin>
9
- <children>
10
- <system>
11
- <children>
12
- <config>
13
- <children>
14
- <ventata>
15
- <title>Ventata - All</title>
16
- </ventata>
17
- </children>
18
- </config>
19
- </children>
20
- </system>
21
- </children>
22
- </admin>
23
- </resources>
24
- </acl>
25
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Ventata/Connector/etc/config.xml DELETED
@@ -1,50 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Ventata_Connector>
5
- <version>0.1.0</version>
6
- </Ventata_Connector>
7
- </modules>
8
- <global>
9
- <models>
10
- <connector>
11
- <class>Ventata_Connector_Model</class>
12
- </connector>
13
- </models>
14
- <events>
15
- <checkout_type_onepage_save_order_after>
16
- <observers>
17
- <ventata_connector_order_observer>
18
- <type>singleton</type>
19
- <class>Ventata_Connector_Model_Order_Observer</class>
20
- <method>upload_order_to_ventata</method>
21
- </ventata_connector_order_observer>
22
- </observers>
23
- </checkout_type_onepage_save_order_after>
24
- <admin_system_config_changed_section_ventata>
25
- <observers>
26
- <ventata_connector_config_observer>
27
- <type>singleton</type>
28
- <class>Ventata_Connector_Model_Config_Observer</class>
29
- <method>get_all_stores_api_key</method>
30
- </ventata_connector_config_observer>
31
- </observers>
32
- </admin_system_config_changed_section_ventata>
33
- <catalog_product_save_after>
34
- <observers>
35
- <ventata_connector_product_observer>
36
- <type>singleton</type>
37
- <class>Ventata_Connector_Model_Product_Observer</class>
38
- <method>product_save_after</method>
39
- </ventata_connector_product_observer>
40
- </observers>
41
- </catalog_product_save_after>
42
-
43
- </events>
44
- <helpers>
45
- <connector>
46
- <class>Ventata_Connector_Helper</class>
47
- </connector>
48
- </helpers>
49
- </global>
50
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Ventata/Connector/etc/system.xml DELETED
@@ -1,50 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <config>
3
- <sections>
4
- <ventata translate="label" module="connector">
5
- <label>Ventata connector</label>
6
- <tab>general</tab>
7
- <sort_order>1000</sort_order>
8
- <show_in_default>1</show_in_default>
9
- <show_in_website>1</show_in_website>
10
- <show_in_store>1</show_in_store>
11
-
12
- <groups>
13
- <orderhook_group translate="label" module="connector">
14
- <label>General Configuration</label>
15
- <frontend_type>text</frontend_type>
16
- <sort_order>1000</sort_order>
17
- <show_in_default>1</show_in_default>
18
- <show_in_website>1</show_in_website>
19
- <show_in_store>1</show_in_store>
20
- <fields>
21
- <apikey translate="label">
22
- <label>Company API key: </label>
23
- <frontend_type>text</frontend_type>
24
- <sort_order>20</sort_order>
25
- <show_in_default>1</show_in_default>
26
- <show_in_website>0</show_in_website>
27
- <show_in_store>0</show_in_store>
28
- </apikey>
29
- <storeapikey translate="label">
30
- <label>Store API key: </label>
31
- <frontend_type>text</frontend_type>
32
- <sort_order>30</sort_order>
33
- <show_in_default>0</show_in_default>
34
- <show_in_website>0</show_in_website>
35
- <show_in_store>1</show_in_store>
36
- </storeapikey>
37
- <apipassword translate="label">
38
- <label>API password: </label>
39
- <frontend_type>hidden</frontend_type>
40
- <sort_order>30</sort_order>
41
- <show_in_default>1</show_in_default>
42
- <show_in_website>0</show_in_website>
43
- <show_in_store>0</show_in_store>
44
- </apipassword>
45
- </fields>
46
- </orderhook_group>
47
- </groups>
48
- </ventata>
49
- </sections>
50
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ventata_Connector</name>
4
- <version>1.3.0.0</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>Ventata Dynamic Pricing Software</description>
11
  <notes>.</notes>
12
  <authors><author><name>Luke Davis</name><user>auto-converted</user><email>ldavis@ventata.com</email></author></authors>
13
- <date>2012-08-20</date>
14
- <time>04:01:35</time>
15
- <contents><target name="magelocal"><dir name="Ventata"><dir name="Connector"><dir name="Helper"><file name="Data.php" hash="d2838df85bb8d15047db074dd6712ee1"/></dir><dir name="Model"><dir name="Config"><file name="Observer.php" hash="c257d43455aa428b56f2ff34821d33ef"/></dir><dir name="Order"><file name="Observer.php" hash="6ae624e95fdd364bf8485dd73c536aa2"/></dir><dir name="Product"><file name="Observer.php" hash="657bf7705338e5060ca673fecdac24b7"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f8096b19be11130aebca410143f113b8"/><file name="config.xml" hash="06c29828c412a609f925d3b33156999a"/><file name="system.xml" hash="a6b331bac6316b066d800c6ed1117bc4"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ventata_Connector.xml" hash="b88dfd737477ad81895d153fd3a41106"/></dir></target></contents>
16
  <compatible/>
17
- <dependencies><required><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.4.0.0</min><max>1.7</max></package></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ventata_Connector</name>
4
+ <version>1.4.0.0</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
10
  <description>Ventata Dynamic Pricing Software</description>
11
  <notes>.</notes>
12
  <authors><author><name>Luke Davis</name><user>auto-converted</user><email>ldavis@ventata.com</email></author></authors>
13
+ <date>2012-08-21</date>
14
+ <time>02:47:21</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Ventata_Connector.xml" hash="b88dfd737477ad81895d153fd3a41106"/></dir></target><target name="magelocal"><dir name="."><file name="Ventata" hash=""/></dir></target></contents>
16
  <compatible/>
17
+ <dependencies/>
18
  </package>