Lexity_GoogleShopping - Version 1.0.0

Version Notes

Initial Release

Download this release

Release Info

Developer Lexity
Extension Lexity_GoogleShopping
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/LexityGoogleShopping/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class LexityGoogleShopping_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+ ?>
app/code/local/LexityGoogleShopping/Model/Core.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class LexityGoogleShopping_Model_Core extends Mage_Core_Model_Config
3
+ {
4
+ public $app_name = 'google_shopping';
5
+ public $platform = 'magento';
6
+
7
+ public function has_lexity_user()
8
+ {
9
+ $resource = Mage::getSingleton('core/resource');
10
+ $readConnection = $resource->getConnection('core_read');
11
+ $tableName = $resource->getTableName('api/user');
12
+ $results = $readConnection->fetchALL("SELECT * FROM api_user where username = 'lexity_google_shopping' LIMIT 1");
13
+ return isset($results[0]);
14
+ }
15
+
16
+ public function add_lexity_user($api_key)
17
+ {
18
+ $role = Mage::getModel('api/roles')
19
+ ->setName('lexity_google_shopping')
20
+ ->setPid(false)
21
+ ->setRoleType('G')
22
+ ->save();
23
+
24
+ Mage::getModel("api/rules")
25
+ ->setRoleId($role->getId())
26
+ ->setResources(array('all'))
27
+ ->saveRel();
28
+
29
+ $user = Mage::getModel('api/user');
30
+ $user->setData(array(
31
+ 'username' => 'lexity_google_shopping',
32
+ 'firstname' => 'lexity',
33
+ 'lastname' => 'lexity',
34
+ 'email' => 'support+google_shopping@lexity.com',
35
+ 'api_key' => $api_key,
36
+ 'api_key_confirmation' => $api_key,
37
+ 'is_active' => 1,
38
+ 'user_roles' => '',
39
+ 'assigned_user_role' => '',
40
+ 'role_name' => '',
41
+ 'roles' => array($role->getId())
42
+ ));
43
+
44
+ $user->save()->load($user->getId());
45
+
46
+ $user->setRoleIds(array($role->getId()))
47
+ ->setRoleUserId($user->getUserId())
48
+ ->saveRelations();
49
+ }
50
+
51
+ public function create_account($new_token = null)
52
+ {
53
+ $user = Mage::getModel('api/user');
54
+ $user->loadByUsername('lexity_google_shopping');
55
+
56
+ $hash = $user->getApiKey();
57
+ $hashArr = explode(':', $hash);
58
+ switch (count($hashArr)) {
59
+ case 1:
60
+ $token = $hash;
61
+ break;
62
+ case 2:
63
+ $token = $hashArr[0];
64
+ $skey = $hashArr[1];
65
+ break;
66
+ }
67
+ $hashed_token = $token;
68
+
69
+ if (isset($new_token)) {
70
+ $token = $new_token;
71
+ }
72
+
73
+ $admin_user = Mage::getSingleton('admin/session');
74
+ $admin_email = $admin_user->getUser()->getEmail();
75
+ $uri = "https://lexity.com/api/account/create?app="
76
+ . $this->app_name
77
+ . "&platform=" . $this->platform . "&password=" . $token
78
+ . "&login=lexity_google_shopping"
79
+ . "&email=" . urlencode($admin_email)
80
+ . "&url=" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
81
+
82
+ if (isset($skey)) {
83
+ $uri .= "&skey=${skey}";
84
+ }
85
+
86
+ # initiate handshake
87
+ $client = new Varien_Http_Client($uri);
88
+ $response = $client->request('GET');
89
+ $body = $response->getBody();
90
+
91
+ $decode = json_decode($body);
92
+ if (!isset($decode->error) && isset($decode->public_id)) {
93
+ $this->saveConfig('lexity/google_shopping/public_id', $decode->public_id);
94
+ $this->saveConfig('lexity/google_shopping/email', $admin_email);
95
+ Mage::getConfig()->reinit();
96
+ Mage::app()->reinitStores();
97
+ }
98
+
99
+ return "https://lexity.com/api/account/login?app="
100
+ . $this->app_name
101
+ . "&email=" . urlencode($admin_email)
102
+ . "&platform=" . $this->platform . "&token=" . $hashed_token
103
+ . "&public_id=" . $decode->public_id
104
+ . "&domain=" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
105
+ }
106
+
107
+ public function get_lexity_login_url($target = null)
108
+ {
109
+ $user = Mage::getModel('api/user');
110
+ $user->loadByUsername('lexity_google_shopping');
111
+
112
+ $hash = $user->getApiKey();
113
+ $hashArr = explode(':', $hash);
114
+ switch (count($hashArr)) {
115
+ case 1:
116
+ $token = $hash;
117
+ break;
118
+ case 2:
119
+ $token = $hashArr[0];
120
+ $skey = $hashArr[1];
121
+ break;
122
+ }
123
+
124
+ Mage::app()->getCacheInstance()->cleanType('config');
125
+ $public_id = Mage::getStoreConfig('lexity/google_shopping/public_id');
126
+ $login_email = Mage::getStoreConfig('lexity/google_shopping/email');
127
+
128
+ $redirect_url = "https://lexity.com/api/account/login?app="
129
+ . $this->app_name
130
+ . "&platform=" . $this->platform . "&token=" . $token
131
+ . "&public_id=" . $public_id
132
+ . "&email=" . urlencode($login_email)
133
+ . "&domain=" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
134
+
135
+ if (!empty($target)) {
136
+ $redirect_url .= "&target=${target}";
137
+ }
138
+
139
+ return $redirect_url;
140
+ }
141
+
142
+ public function loginAndRedirect($target = null)
143
+ {
144
+ Mage::app()->getCacheInstance()->cleanType('config');
145
+ $public_id = Mage::getStoreConfig('lexity/google_shopping/public_id');
146
+ if (empty($public_id)) {
147
+ $token = md5(uniqid());
148
+
149
+ if (!$this->has_lexity_user()) {
150
+ $this->add_lexity_user($token);
151
+ } else {
152
+ $user = Mage::getModel('api/user')->loadByUsername("lexity_google_shopping");
153
+ $user->setApiKey($token);
154
+ $user->save();
155
+ }
156
+ $this->create_account($token);
157
+ }
158
+
159
+ return $this->get_lexity_login_url($target);
160
+ }
161
+ }
162
+ ?>
app/code/local/LexityGoogleShopping/Model/Core/Api.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class LexityGoogleShopping_Model_Core_Api extends Mage_Api_Model_Resource_Abstract
4
+ {
5
+ public function getMisc()
6
+ {
7
+ Mage::app()->getCacheInstance()->cleanType('config');
8
+ $js = Mage::getStoreConfig('design/head/includes');
9
+ return $js;
10
+ }
11
+
12
+ public function setMisc($js)
13
+ {
14
+ Mage::app()->getCacheInstance()->cleanType('config');
15
+ Mage::getModel('core/config')->saveConfig('design/head/includes', $js );
16
+ return array('status' => 'updated');
17
+ }
18
+ }
app/code/local/LexityGoogleShopping/Model/Order/Api.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class LexityGoogleShopping_Model_Order_Api extends Mage_Sales_Model_Order_Api_V2
4
+ {
5
+ public function limiteditems($size='3',$page='1',$filters = null)
6
+ {
7
+ // Why the hell is this scoping brace here?!
8
+ {
9
+ //TODO: add full name logic
10
+ $billingAliasName = 'billing_o_a';
11
+ $shippingAliasName = 'shipping_o_a';
12
+
13
+ $collection = Mage::getModel("sales/order")->getCollection()
14
+ ->addAttributeToSelect('*')
15
+ ->addAddressFields()
16
+ ->addExpressionFieldToSelect(
17
+ 'billing_firstname', "{{billing_firstname}}", array('billing_firstname'=>"$billingAliasName.firstname")
18
+ )
19
+ ->addExpressionFieldToSelect(
20
+ 'billing_lastname', "{{billing_lastname}}", array('billing_lastname'=>"$billingAliasName.lastname")
21
+ )
22
+ ->addExpressionFieldToSelect(
23
+ 'shipping_firstname', "{{shipping_firstname}}", array('shipping_firstname'=>"$shippingAliasName.firstname")
24
+ )
25
+ ->addExpressionFieldToSelect(
26
+ 'shipping_lastname', "{{shipping_lastname}}", array('shipping_lastname'=>"$shippingAliasName.lastname")
27
+ )
28
+ ->addExpressionFieldToSelect(
29
+ 'billing_name',
30
+ "CONCAT({{billing_firstname}}, ' ', {{billing_lastname}})",
31
+ array('billing_firstname'=>"$billingAliasName.firstname", 'billing_lastname'=>"$billingAliasName.lastname")
32
+ )
33
+ ->addExpressionFieldToSelect(
34
+ 'shipping_name',
35
+ 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
36
+ array('shipping_firstname'=>"$shippingAliasName.firstname", 'shipping_lastname'=>"$shippingAliasName.lastname")
37
+ )
38
+ ->setPageSize($size)
39
+ ->setCurPage($page);
40
+ }
41
+
42
+
43
+ $preparedFilters = array();
44
+ if (isset($filters->filter)) {
45
+ foreach ($filters->filter as $_filter) {
46
+ $preparedFilters[][$_filter->key] = $_filter->value;
47
+ }
48
+ }
49
+
50
+ if (isset($filters->complex_filter)) {
51
+ foreach ($filters->complex_filter as $_filter) {
52
+ $_value = $_filter->value;
53
+ if (is_object($_value)) {
54
+ $preparedFilters[][$_filter->key] = array(
55
+ $_value->key => $_value->value
56
+ );
57
+ }
58
+ elseif (is_array($_value)) {
59
+ $preparedFilters[][$_filter->key] = array(
60
+ $_value['key'] => $_value['value']
61
+ );
62
+ }
63
+ else {
64
+ $preparedFilters[][$_filter->key] = $_value;
65
+ }
66
+ }
67
+ }
68
+
69
+ if (!empty($preparedFilters)) {
70
+ try {
71
+ foreach ($preparedFilters as $preparedFilter) {
72
+ foreach ($preparedFilter as $field => $value) {
73
+ if (isset($this->_attributesMap['order'][$field])) {
74
+ $field = $this->_attributesMap['order'][$field];
75
+ }
76
+
77
+ $collection->addFieldToFilter($field, $value);
78
+ }
79
+ }
80
+ }
81
+ catch (Mage_Core_Exception $e) {
82
+ $this->_fault('filters_invalid', $e->getMessage());
83
+ }
84
+ }
85
+
86
+ $result = array();
87
+
88
+ foreach ($collection as $order) {
89
+ $result[] = $this->_getAttributes($order, 'order');
90
+ }
91
+
92
+ return $result;
93
+ }
94
+ }
95
+ ?>
app/code/local/LexityGoogleShopping/controllers/CoreController.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class LexityGoogleShopping_CoreController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ public function golexityAction()
5
+ {
6
+ if (Mage::getModel('lexitygoogle_shopping/core')->has_lexity_user()) {
7
+ Mage::Log('Found lexity user, redirecting for login.');
8
+ }
9
+ else {
10
+ Mage::Log('No lexity user found, redirecting for account creation.');
11
+
12
+ $token = uniqid();
13
+ Mage::Log("Shared public key is: " . Mage::getModel('lexitygoogle_shopping/core')->shared_key);
14
+ Mage::Log("Token is: ${token}");
15
+ Mage::getModel('lexitygoogle_shopping/core')->add_lexity_user($token);
16
+ //$this->getResponse()->setRedirect("http://lexity.com/?token=${token}");
17
+ }
18
+ }
19
+ }
20
+ ?>
app/code/local/LexityGoogleShopping/controllers/MarketingController.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class LexityGoogleShopping_MarketingController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ public function golexityAction()
5
+ {
6
+ $uri = Mage::getModel('lexitygoogle_shopping/core')->loginAndRedirect();
7
+ $this->getResponse()->setRedirect($uri);
8
+ }
9
+ }
10
+ ?>
app/code/local/LexityGoogleShopping/etc/api.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <lexitygoogle_shopping_core translate="title" module="lexitygoogle_shopping">
6
+ <model>lexitygoogle_shopping/core_api</model>
7
+ <title>Lexity Core API</title>
8
+ <acl>lexitygoogle_shopping/core</acl>
9
+ <methods>
10
+ <getMisc translate="title" module="lexitygoogle_shopping">
11
+ <title>Get header scripts</title>
12
+ <method>getMisc</method>
13
+ </getMisc>
14
+ <setMisc translate="title" module="lexitygoogle_shopping">
15
+ <title>Set header scripts</title>
16
+ <method>setMisc</method>
17
+ </setMisc>
18
+ </methods>
19
+ </lexitygoogle_shopping_core>
20
+ </resources>
21
+ </api>
22
+ </config>
app/code/local/LexityGoogleShopping/etc/config.xml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <lexitygoogle_shopping>
5
+ <version>0.1.0</version>
6
+ </lexitygoogle_shopping>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <lexitygoogle_shopping>
11
+ <class>LexityGoogleShopping_Helper</class>
12
+ </lexitygoogle_shopping>
13
+ </helpers>
14
+ <models>
15
+ <lexitygoogle_shopping>
16
+ <class>LexityGoogleShopping_Model</class>
17
+ </lexitygoogle_shopping>
18
+ </models>
19
+ <blocks>
20
+ <lexitygoogle_shopping>
21
+ <class>LexityGoogleShopping_Block</class>
22
+ </lexitygoogle_shopping>
23
+ </blocks>
24
+ </global>
25
+
26
+ <admin>
27
+ <routers>
28
+ <lexitygoogle_shopping>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>LexityGoogleShopping</module>
32
+ <frontName>lexitygoogle_shopping</frontName>
33
+ </args>
34
+ </lexitygoogle_shopping>
35
+ </routers>
36
+ </admin>
37
+
38
+ <adminhtml>
39
+ <menu>
40
+ <Lexity translate="title">
41
+ <title>Marketing</title>
42
+ <children>
43
+ <lexitygoogle_shopping translate="title" module="lexitygoogle_shopping">
44
+ <title>Lexity Google Shopping</title>
45
+ <action>lexitygoogle_shopping/marketing/golexity</action>
46
+ <sort_order>0</sort_order>
47
+ </lexitygoogle_shopping>
48
+ </children>
49
+ <sort_order>900</sort_order>
50
+ </Lexity>
51
+ </menu>
52
+ </adminhtml>
53
+
54
+ </config>
app/etc/modules/LexityGoogleShopping.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <LexityGoogleShopping>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </LexityGoogleShopping>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Lexity_GoogleShopping</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>BSD License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Get your products listed on Google Shopping, Google's new paid listings replacing Google Product Search.</summary>
10
+ <description>Transition painlessly to new Google Shopping from Google Product Search&#xD;
11
+ &#xD;
12
+ Google is moving from a free model to a paid model, with its transition from the old Google Product Search to the new Google Shopping. We built Lexity Google Shopping to make your onboarding to the new Google Shopping as easy as possible.&#xD;
13
+ &#xD;
14
+ Automatically synchronize listings with store inventory&#xD;
15
+ &#xD;
16
+ Item out of stock? No problem! We&#x2019;ll update your listings without your needing to lift a finger. Lexity automatically synchronizes with your store and automatically updates your feeds with current information on your inventory and catalog, including stock, pricing, and product images.&#xD;
17
+ &#xD;
18
+ Fine control over product selection&#xD;
19
+ &#xD;
20
+ We give you fine control over exactly which products you want advertised, so you won&#x2019;t waste a cent. Focus your campaigns where you want them focused, whether that&#x2019;s your top selling products, a new line you&#x2019;re launching, or something else.</description>
21
+ <notes>Initial Release</notes>
22
+ <authors><author><name>Lexity</name><user>lexity</user><email>support@lexity.com</email></author></authors>
23
+ <date>2012-08-31</date>
24
+ <time>23:14:13</time>
25
+ <contents><target name="magelocal"><dir name="LexityGoogleShopping"><dir name="Helper"><file name="Data.php" hash="9e4c8fe0f1c2c6c58779d6eab5abc155"/></dir><dir name="Model"><dir name="Core"><file name="Api.php" hash="7cb5721dc220cff5c90e7f0012b481f6"/></dir><file name="Core.php" hash="422e21c0acc2e953216f18a1905e3447"/><dir name="Order"><file name="Api.php" hash="1cc4747b57196c793e73a3e130e0c9b2"/></dir></dir><dir name="controllers"><file name="CoreController.php" hash="cf2b12376d7eed38c6379bb742cbad51"/><file name="MarketingController.php" hash="d3a74764f9fab95ce7a1468e5b0476f0"/></dir><dir name="etc"><file name="api.xml" hash="6a40b2924958c1568f01a0f07be87618"/><file name="config.xml" hash="32d9deba127cc2517bd23f9d27321043"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="LexityGoogleShopping.xml" hash="9deb73045bba529c3ebbd8374eb14d3c"/></dir></target></contents>
26
+ <compatible/>
27
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
28
+ </package>