Linc_Recommends - Version 1.0.0

Version Notes

Welcome to the Linc Recommends extension for Magento.

This extension requires the Linc Care extenstion. Please install that first or Linc Recommends will not function properly.

Linc Recommends requires only a miminal installation and no configuration. Just install it has you would any extension.

After installation you must enable cron if you it isn't already. Information about this can be found at http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#magento_and_crontab

Send any issues or comments to linc-care-issues-magento@letslinc.com

Download this release

Release Info

Developer Linc Care
Extension Linc_Recommends
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Linc/Recommends/Block/Recommends.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once "Linc/Recommends/common.php";
3
+
4
+ class Linc_Recommends_Block_Recommends extends Mage_Core_Block_Abstract
5
+ {
6
+ protected function _toHtml()
7
+ {
8
+ $html = "";
9
+
10
+ $resource = Mage::getSingleton('core/resource');
11
+ $read = $resource->getConnection('core_read');
12
+ $configDataTable = $read->getTableName('core_config_data');
13
+
14
+ # get store_id
15
+ $store_id = '1';
16
+ $select = $read->select()
17
+ ->from(array('cd'=>$configDataTable))
18
+ ->where("cd.path=?", 'linc_current_store');
19
+ $rows = $read->fetchAll($select);
20
+
21
+ if (count($rows) > 0)
22
+ {
23
+ $store_id = $rows[0]['value'];
24
+ }
25
+
26
+ # get shop_id
27
+ $shop_id = '';
28
+ $select = $read->select()
29
+ ->from(array('cd'=>$configDataTable))
30
+ ->where('cd.scope=?', 'store')
31
+ ->where("cd.scope_id=?", $store_id)
32
+ ->where("cd.path=?", 'linc_shop_id');
33
+ $rows = $read->fetchAll($select);
34
+
35
+ if (count($rows) > 0)
36
+ {
37
+ $shop_id = $rows[0]['value'];
38
+ }
39
+
40
+ if ($shop_id != null)
41
+ {
42
+ $html = "<table border=0 cellspacing=0 cellpadding=20><tr>";
43
+ $order = $this->getOrder();
44
+ $items = $order->getItemsCollection();
45
+
46
+ $query = "";
47
+ $baseurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product';
48
+ foreach ($items as $item)
49
+ {
50
+ $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
51
+ if ($product->isVisibleInSiteVisibility())
52
+ {
53
+ $imgurl = $baseurl.$product->getImage();
54
+
55
+ if ($query != "")
56
+ {
57
+ $query .= "&";
58
+ }
59
+
60
+ $query .= "q=".$item->getQtyOrdered();
61
+ $query .= "&p=".$product->getId();
62
+ $query .= "&pp=".$item->getPrice();
63
+ $query .= "&w=".$item->getWeight();
64
+ $query .= "&i=".$imgurl;
65
+ $query .= "&n=".$item->getName();
66
+ }
67
+ }
68
+
69
+ $s_addr = $order->getShippingAddress();
70
+ if ($s_addr == null)
71
+ {
72
+ /* use billing address for shipping address when the purchase is a download. */
73
+ $s_addr = $order->getBillingAddress();
74
+ }
75
+
76
+ $query .= "&a1=".$this->urlencode($s_addr->getStreet1());
77
+ $query .= "&a2=".$this->urlencode($s_addr->getStreet2());
78
+ $query .= "&au=".$this->urlencode($s_addr->getCountry());
79
+ $query .= "&ac=".$this->urlencode($s_addr->getCity());
80
+ $query .= "&as=".$this->urlencode($s_addr->getRegion());
81
+ $query .= "&az=".$this->urlencode($s_addr->getPostcode());
82
+ $query .= "&fn=".$this->urlencode($order->getCustomerFirstname());
83
+ $query .= "&ln=".$this->urlencode($order->getCustomerLastname());
84
+ $query .= "&e=".$this->urlencode($order->getCustomerEmail());
85
+ $query .= "&g=".$order->getGrandTotal();
86
+ $query .= "&o=".$order->getIncrementId();
87
+ $query .= "&osi=".$order->getIncrementId();
88
+ $query .= "&pd=".$this->urlencode($order->getUpdatedAt('long'));
89
+ $query .= "&ph=".$this->urlencode($s_addr->getTelephone());
90
+ $query .= "&shop_id=".$shop_id;
91
+ $query .= "&source=email";
92
+ $query .= "&v=2";
93
+
94
+
95
+ for ($i = 1; $i < 4; $i++)
96
+ {
97
+ $html .= "<td><a id='prod-rec".$i."' href='https://care.letslinc.com/product_rec?";
98
+ $html .= $query."&pos=1&field=link'><img src='https://care.letslinc.com/product_rec?";
99
+ $html .= $query."&pos=".$i."' width='150'></a></td>";
100
+ }
101
+
102
+ $html .= "</tr></table>";
103
+
104
+ //Mage::log("Recommendations complete - $html", null, 'order.log', true);
105
+ }
106
+ else
107
+ {
108
+ $html = "<p></p>";
109
+ }
110
+
111
+ return $html;
112
+ }
113
+ }
114
+
115
+ ?>
app/code/community/Linc/Recommends/Helper/Data.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Linc_Recommends_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ }
6
+
7
+ ?>
app/code/community/Linc/Recommends/Model/Orders.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once "Linc/Recommends/common.php";
3
+
4
+ class Linc_Recommends_Model_Orders
5
+ {
6
+ public $client = null;
7
+ public $queue = null;
8
+ public $logname = 'orderupload.log';
9
+
10
+ public function log($msg)
11
+ {
12
+ if (DBGLOG) Mage::log($msg, null, $this->logname, true);
13
+ #print("<p>$msg</p>");
14
+ }
15
+
16
+ public function sendorders()
17
+ {
18
+ $this->log("Beginning sendOrders");
19
+
20
+ $stores = Mage::app()->getStores();
21
+ foreach ($stores as $store)
22
+ {
23
+ $name = $store->getName();
24
+ $this->log("sending orders for $name");
25
+
26
+ $store_id = $store->getId();
27
+
28
+ # get access key
29
+ $resource = Mage::getSingleton('core/resource');
30
+ $read = $resource->getConnection('core_read');
31
+ $configDataTable = $read->getTableName('core_config_data');
32
+
33
+ $accessToken = '';
34
+ $select = $read->select()
35
+ ->from(array('cd'=>$configDataTable))
36
+ ->where('cd.scope=?', 'store')
37
+ ->where("cd.scope_id=?", $store_id)
38
+ ->where("cd.path=?", 'linc_access_key');
39
+ $rows = $read->fetchAll($select);
40
+
41
+ if (count($rows) > 0)
42
+ {
43
+ $accessToken = $rows[0]['value'];
44
+ }
45
+
46
+ if ($accessToken != null)
47
+ {
48
+ $this->log("Got access key - $accessToken");
49
+
50
+ $last_order = 0;
51
+ $select = $read->select()
52
+ ->from(array('cd'=>$configDataTable))
53
+ ->where('cd.scope=?', 'store')
54
+ ->where("cd.scope_id=?", $store_id)
55
+ ->where("cd.path=?", 'linc_last_order_sent');
56
+ $rows = $read->fetchAll($select);
57
+
58
+ if (count($rows) > 0)
59
+ {
60
+ $last_order = $rows[0]['value'];
61
+ }
62
+
63
+ $this->log("Starting with order # $last_order");
64
+
65
+ $orders = Mage::getModel('sales/order')->getCollection();
66
+ $orders->addFieldToFilter('store_id', $store_id);
67
+ $orders->addAttributeToFilter('entity_id', array('gt' => $last_order));
68
+ $orders->setOrder('entity_id', 'ASC');
69
+ $orders->getSelect()->limit(50); // limit number of results returned
70
+
71
+ $this->log("Collection ready");
72
+
73
+ foreach ($orders as $order)
74
+ {
75
+ $last_order = $order->getEntityId();
76
+
77
+ $temp = $order->getName();
78
+ $this->log("Sending order $temp");
79
+ $post_data_json = $this->buildJson($order);
80
+
81
+ if ($post_data_json != "")
82
+ {
83
+ $this->sendOrder($accessToken, $post_data_json);
84
+ }
85
+ }
86
+
87
+ Mage::getConfig()->saveConfig('linc_last_order_sent', $last_order, 'store', $store_id);
88
+ Mage::getConfig()->reinit();
89
+ Mage::app()->reinitStores();
90
+ }
91
+ else
92
+ {
93
+ $this->log('No access token');
94
+ }
95
+ }
96
+ }
97
+
98
+ public function sendOrder($accessToken, $postData)
99
+ {
100
+ if ($this->client == null)
101
+ {
102
+ $this->log("Connecting to Linc Care");
103
+ $this->connectToLincCare($accessToken);
104
+ if ($this->client != null && $this->queue != null)
105
+ {
106
+ $this->log("Processing the queue");
107
+ $sendQueue = $this->queue;
108
+ unset($this->queue);
109
+
110
+ foreach ($sendQueue as $data)
111
+ {
112
+ $this->sendOrder($accessToken, $data);
113
+ }
114
+ }
115
+ else
116
+ {
117
+ $this->log("Saving to queue");
118
+ if ($this->queue == null)
119
+ {
120
+ $this->queue = array();
121
+ }
122
+
123
+ array_push($this->queue, $postData);
124
+ }
125
+ }
126
+
127
+ if ($this->client != null)
128
+ {
129
+ $this->log("Building request");
130
+
131
+ $this->client->setRawData($postData, 'application/json');
132
+
133
+ $response = $this->client->request();
134
+
135
+ $temp = $response->getStatus();
136
+ $this->log("Linc_Care HTTP response $temp");
137
+
138
+ if (in_array($temp, array(200, 201, 401)))
139
+ {
140
+ $temp = $response->getHeadersAsString();
141
+ $this->log("Linc_Care Response Headers:<br/>$temp");
142
+ $temp = $response->getBody();
143
+ $this->log("Linc_Care Repsonse Body:<br/>$temp");
144
+ }
145
+ else
146
+ {
147
+ $adapter = $this->client->getAdapter();
148
+ $adapter->close();
149
+ $this->client = null;
150
+ array_push($this->queue, $postData);
151
+ }
152
+ }
153
+ }
154
+
155
+ public function connectToLincCare($accessToken)
156
+ {
157
+ $protocol = SERVER_PROTOCOL;
158
+ $url = SERVER_PATH;
159
+
160
+ $this->client = new Zend_Http_Client();
161
+ $this->client->setUri("$protocol://pub-api.$url/v1/order");
162
+
163
+ $this->client->setConfig(array(
164
+ 'maxredirects' => 0,
165
+ 'timeout' => 30,
166
+ 'keepalive' => true,
167
+ 'adapter' => 'Zend_Http_Client_Adapter_Socket'));
168
+
169
+ $this->client->setMethod(Zend_Http_Client::POST);
170
+ $this->client->setHeaders(array(
171
+ 'Authorization' => 'Bearer '.$accessToken,
172
+ 'Content-Type' => 'application/json'));
173
+ }
174
+
175
+ public function buildJson($order)
176
+ {
177
+ $this->log("buildJson started");
178
+
179
+ $orderdata = $order->getData();
180
+ $this->log("buildJson Got data");
181
+
182
+ $b_addr = $order->getBillingAddress();
183
+ if (DBGLOG)
184
+ {
185
+ $temp = json_encode($b_addr->getData());
186
+ $this->log("buildJson got billing address $temp");
187
+ }
188
+
189
+ $s_addr = $order->getShippingAddress();
190
+ if (DBGLOG && $s_addr != null)
191
+ {
192
+ $temp = json_encode($s_addr->getData());
193
+ $this->log("buildJson got shipping address $temp");
194
+ }
195
+ else
196
+ {
197
+ /* use billing address for shipping address when the purchase is a download. */
198
+ $s_addr = $b_addr;
199
+ }
200
+
201
+ $phone = $b_addr->getTelephone();
202
+ $this->log("buildJson got phone $phone");
203
+
204
+ $items = $order->getItemsCollection();
205
+ $this->log("buildJson got item collection");
206
+
207
+ $dataitems = array();
208
+ foreach ($items as $item)
209
+ {
210
+ $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
211
+
212
+ # if ($product->isVisibleInSiteVisibility())
213
+ # {
214
+ $dataitem = array(
215
+ 'title' => $item->getName(),
216
+ 'description' => $item->getDescription(),
217
+ 'thumbnail' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage(),
218
+ 'price' => $item->getPrice(),
219
+ 'weight' => $item->getWeight());
220
+
221
+ $temp = json_encode($dataitem);
222
+ $this->log("buildJson built an item $temp");
223
+
224
+ array_push($dataitems, $dataitem);
225
+ # }
226
+ }
227
+
228
+ $this->log("buildJson built items");
229
+
230
+ $user = array (
231
+ 'user_id' => $order->getCustomerId(),
232
+ 'first_name' => $order->getCustomerFirstname(),
233
+ 'last_name' => $order->getCustomerLastname(),
234
+ 'email' => $order->getCustomerEmail(),
235
+ 'phone' => $phone);
236
+
237
+ if (DBGLOG)
238
+ {
239
+ $temp = json_encode($user);
240
+ $this->log("buildJson built user $temp");
241
+ }
242
+
243
+ #$country = Mage::getModel('directory/country')->loadByCode($b_addr->getCountry());
244
+ $addrB = array(
245
+ 'address' => $b_addr->getStreet1(),
246
+ 'address2' => $b_addr->getStreet2(),
247
+ 'city' => $b_addr->getCity(),
248
+ 'state' => $b_addr->getRegion(),
249
+ 'country_code' => $b_addr->getCountry(),
250
+ #'country' => $country->getName(),
251
+ 'zip' => $b_addr->getPostcode());
252
+
253
+ if (DBGLOG)
254
+ {
255
+ $temp = json_encode($addrB);
256
+ $this->log("buildJson built billing address $temp");
257
+ }
258
+
259
+ #$country = Mage::getModel('directory/country')->loadByCode($s_addr->getCountry());
260
+ $addrS = array(
261
+ 'address' => $s_addr->getStreet1(),
262
+ 'address2' => $s_addr->getStreet2(),
263
+ 'city' => $s_addr->getCity(),
264
+ 'state' => $s_addr->getRegion(),
265
+ 'country_code' => $s_addr->getCountry(),
266
+ #'country' => $country->getName(),
267
+ 'zip' => $s_addr->getPostcode());
268
+
269
+ if (DBGLOG)
270
+ {
271
+ $temp = json_encode($addrS);
272
+ $this->log("buildJson built shipping address $temp");
273
+ }
274
+
275
+ $dataorder = array(
276
+ 'user' => $user,
277
+ 'order_code' => $order->getIncrementId(),
278
+ 'billing_address' => $addrB,
279
+ 'shipping_address' => $addrS,
280
+ 'purchase_date' => $order->getUpdatedAt(),
281
+ 'grand_total' => $order->getGrandTotal(),
282
+ 'total_taxes' => $order->getTaxAmount(),
283
+ 'products' => $dataitems);
284
+
285
+ $postdata = json_encode($dataorder);
286
+ $this->log($postdata);
287
+
288
+ $this->log("buildJson ended");
289
+
290
+ return $postdata;
291
+ }
292
+ }
293
+
294
+ ?>
app/code/community/Linc/Recommends/Model/Products.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once "Linc/Recommends/common.php";
3
+
4
+ class Linc_Recommends_Model_Products
5
+ {
6
+ public $client = null;
7
+ public $queue = null;
8
+ public $logname = 'productupload.log';
9
+
10
+ public function log($msg)
11
+ {
12
+ if (DBGLOG) Mage::log($msg, null, $this->logname, true);
13
+ #print("<p>$msg</p>");
14
+ }
15
+
16
+ public function sendproducts()
17
+ {
18
+ $this->log("Beginning sendProducts");
19
+
20
+ $stores = Mage::app()->getStores();
21
+ foreach ($stores as $store)
22
+ {
23
+ $name = $store->getName();
24
+ $this->log("Exporting products for $name");
25
+
26
+ $store_id = $store->getId();
27
+ $this->log("Got store_id - $store_id");
28
+
29
+ # get access key
30
+ $resource = Mage::getSingleton('core/resource');
31
+ $this->log("Got Resource");
32
+
33
+ $read = $resource->getConnection('core_read');
34
+ $this->log("Got Read");
35
+
36
+ $configDataTable = $read->getTableName('core_config_data');
37
+ $this->log("Got config table");
38
+
39
+ $accessToken = '';
40
+ $select = $read->select()
41
+ ->from(array('cd'=>$configDataTable))
42
+ ->where('cd.scope=?', 'store')
43
+ ->where("cd.scope_id=?", $store_id)
44
+ ->where("cd.path=?", 'linc_access_key');
45
+ $this->log("Got Select");
46
+
47
+ $rows = $read->fetchAll($select);
48
+
49
+ if (count($rows) > 0)
50
+ {
51
+ $accessToken = $rows[0]['value'];
52
+ }
53
+
54
+ if ($accessToken != null)
55
+ {
56
+ $this->log("Got access key - $accessToken");
57
+
58
+ $last_product = 0;
59
+ $select = $read->select()
60
+ ->from(array('cd'=>$configDataTable))
61
+ ->where('cd.scope=?', 'store')
62
+ ->where("cd.scope_id=?", $store_id)
63
+ ->where("cd.path=?", 'linc_last_product_sent');
64
+ $rows = $read->fetchAll($select);
65
+
66
+ if (count($rows) > 0)
67
+ {
68
+ $last_product = $rows[0]['value'];
69
+ }
70
+
71
+ $this->log("Starting with product # $last_product");
72
+
73
+ $products = Mage::getModel('catalog/product')->getCollection();
74
+ #$products->addAttributeToSelect("*");
75
+ $products->addStoreFilter($store_id);
76
+ $products->addAttributeToFilter('entity_id', array('gt' => $last_product));
77
+ $products->setOrder('entity_id', 'ASC');
78
+ $products->getSelect()->limit(50); // limit number of results returned
79
+
80
+ $this->log("Collection ready");
81
+
82
+ foreach ($products as $product)
83
+ {
84
+ $last_product = $product->getEntityId();
85
+ $type_id = $product->getTypeId();
86
+
87
+ $this->log("Product ID - '$last_product' Type ID - '$type_id'");
88
+
89
+ if ($type_id == 'simple' || $type_id == 'downloadable')
90
+ {
91
+ $this->log('Sending product ' . $product->getName());
92
+ $post_data_json = $this->buildJson($store, $product);
93
+
94
+ if ($post_data_json != "")
95
+ {
96
+ $this->sendProduct($accessToken, $post_data_json);
97
+ }
98
+ }
99
+ }
100
+
101
+ Mage::getConfig()->saveConfig('linc_last_product_sent', $last_product, 'store', $store_id);
102
+ Mage::getConfig()->reinit();
103
+ Mage::app()->reinitStores();
104
+ }
105
+ else
106
+ {
107
+ $this->log('No access token');
108
+ }
109
+ }
110
+ }
111
+
112
+ public function sendProduct($accessToken, $postData)
113
+ {
114
+ if ($this->client == null)
115
+ {
116
+ $this->log("Connecting to Linc Care");
117
+ $this->connectToLincCare($accessToken);
118
+ if ($this->client != null && $this->queue != null)
119
+ {
120
+ $this->log("Processing the queue");
121
+ $sendQueue = $this->queue;
122
+ unset($this->queue);
123
+
124
+ foreach ($sendQueue as $data)
125
+ {
126
+ sendProduct($accessToken, $data);
127
+ }
128
+ }
129
+ else
130
+ {
131
+ $this->log("Saving to queue");
132
+ if ($this->queue == null)
133
+ {
134
+ $this->queue = array();
135
+ }
136
+
137
+ array_push($this->queue, $postData);
138
+ }
139
+ }
140
+
141
+ if ($this->client != null)
142
+ {
143
+ $this->log("Building request");
144
+
145
+ $this->client->setRawData($postData, 'application/json');
146
+ $response = $this->client->request();
147
+
148
+ $temp = $response->getStatus();
149
+ $this->log("Linc_Care HTTP response $temp");
150
+
151
+ if (in_array($temp, array(201)))
152
+ {
153
+ $temp = $response->getHeadersAsString();
154
+ $this->log("Linc_Care Headers:/n$temp");
155
+ $temp = $response->getBody();
156
+ $this->log("Linc_Care Body:/n$temp");
157
+ }
158
+ else
159
+ {
160
+ $adapter = $this->client->getAdapter();
161
+ $adapter->close();
162
+ $this->client = null;
163
+ array_push($this->queue, $postData);
164
+ }
165
+ }
166
+ }
167
+
168
+ public function connectToLincCare($accessToken)
169
+ {
170
+ $protocol = SERVER_PROTOCOL;
171
+ $url = SERVER_PATH;
172
+
173
+ $this->client = new Zend_Http_Client();
174
+ $this->client->setUri("$protocol://pub-api.$url/v1/product");
175
+
176
+ $this->client->setConfig(array(
177
+ 'maxredirects' => 0,
178
+ 'timeout' => 30,
179
+ 'keepalive' => true,
180
+ 'adapter' => 'Zend_Http_Client_Adapter_Socket'));
181
+
182
+ $this->client->setMethod(Zend_Http_Client::POST);
183
+ $this->client->setHeaders(array(
184
+ 'Authorization' => 'Bearer '.$accessToken,
185
+ 'Content-Type' => 'application/json'));
186
+ }
187
+
188
+ public function buildJson($store, $product)
189
+ {
190
+ $postdata = "";
191
+ $this->log("buildJson started");
192
+
193
+ $categoryCollection = $product->getCategoryCollection();
194
+ $categories = $categoryCollection->exportToArray();
195
+ $categsToLinks = array();
196
+ $categoryList = '';
197
+ # Get categories names
198
+ foreach($categories as $category)
199
+ {
200
+ $categoryList .= Mage::getModel('catalog/category')->load($category['entity_id'])->getName() . ' ';
201
+ }
202
+
203
+ $manufacturer = '';
204
+ if ($product->getAttributeText('manufacturer'))
205
+ {
206
+ $manufacturer = $product->getAttributeText('manufacturer');
207
+ }
208
+
209
+ $color = '';
210
+ if ($product->getAttributeText('color'))
211
+ {
212
+ $color = $product->getAttributeText('color');
213
+ }
214
+
215
+ $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
216
+
217
+ $dataitem = array(
218
+ 'brand' => $manufacturer,
219
+ 'manufacturer' => $manufacturer,
220
+ 'model' => $product->getSku(),
221
+ 'ean' => $product->getEancode(),
222
+ 'upc' => '',
223
+ 'mpn' => $product->getInternalID(),
224
+ 'sku' => $product->getSku(),
225
+ 'title' => $product->getName(),
226
+ 'description' => $product->getDescription(),
227
+ 'link' => $product->getProductUrl(),
228
+ 'thumbnail' => Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getThumbnail() ),
229
+ 'images' => Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getImage() ),
230
+ 'categories' => $categoryList,
231
+ 'features' => '',
232
+ 'country' => $product->getAttributeText('country_of_manufacture'),
233
+ 'language' => Mage::getStoreConfig('general/locale/code', $store->getId()),
234
+ 'color' => $color,
235
+ 'weight' => $product->getWeight(),
236
+ 'length' => '',
237
+ 'width' => '',
238
+ 'height' => '',
239
+ 'currency' => $store->getCurrentCurrencyCode(),
240
+ 'price' => $product->getPrice(),
241
+ 'inventory' => $qty,
242
+ 'num_purchased' => '',
243
+ 'updated' => $product->getUpdatedAt(),
244
+ 'created' => $product->getCreatedAt(),
245
+ 'deleted' => 'false');
246
+
247
+ $postdata = json_encode($dataitem);
248
+ $this->log("buildJson built an item $postdata");
249
+
250
+ $this->log("buildJson ended");
251
+
252
+ return $postdata;
253
+ }
254
+ }
255
+
256
+ ?>
app/code/community/Linc/Recommends/common.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ define('DBGLOG', false);
3
+ define('SERVER_PROTOCOL', 'https');
4
+ define('SERVER_PATH', 'letslinc.com');
5
+ ?>
app/code/community/Linc/Recommends/etc/config.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Module configuration
5
+ *
6
+ * @author Rick Murtagh, Linc Global, Inc.
7
+ *
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Linc_Recommends>
13
+ <version>0.0.1</version>
14
+ </Linc_Recommends>
15
+ </modules>
16
+ <global>
17
+ <models>
18
+ <recommends>
19
+ <class>Linc_Recommends_Model</class>
20
+ </recommends>
21
+ </models>
22
+ <blocks>
23
+ <recommends>
24
+ <class>Linc_Recommends_Block</class>
25
+ </recommends>
26
+ </blocks>
27
+ <helpers>
28
+ <recommends>
29
+ <class>Linc_Recommends_Helper</class>
30
+ </recommends>
31
+ </helpers>
32
+ </global>
33
+ <crontab>
34
+ <jobs>
35
+ <linc_recommends_products>
36
+ <schedule><cron_expr>*/15 * * * *</cron_expr></schedule>
37
+ <run><model>recommends/products::sendproducts</model></run>
38
+ </linc_recommends_products>
39
+ <linc_recommends_orders>
40
+ <schedule><cron_expr>*/15 * * * *</cron_expr></schedule>
41
+ <run><model>recommends/orders::sendorders</model></run>
42
+ </linc_recommends_orders>
43
+ </jobs>
44
+ </crontab>
45
+ </config>
app/code/community/Linc/Recommends/etc/system.xml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ </config>
app/code/community/Linc/Recommends/readme ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Welcome to the Linc Recommendations extension for Magento.
2
+
3
+ 1. Log onto your store's admin console.
4
+ 2. Go to System / Magento Connect / Magento Connect Manager and log on
5
+ 3. Click on the Magento Connect link [1]. On their site search for Linc Care and obtain the Extension Key.
6
+ 4. Return to the Magento Downloader and part the key [2] then click the install button.
7
+ 5. Make sure the Package Name and Version are correct then click the Proceed button.
8
+ 6. When the install completes click the refresh button and ensure that Linc Care has been installed.
9
+ 6. Go back to the admin page and navigate to System / Configuration and click on the "General" group on the "Linc Care" tab.
10
+ 7. You will see a message telling you to select a store. Do so and a form will appear. The default URL and Admin Email address
11
+
12
+
13
+
14
+
15
+
16
+
17
+ 7. System/Transactional Email
18
+ 6. If you have a have custom emails already, edit it and insert {{block type='linccare/widget' order=$order}} where you want the Linc Care widget to appear. Then save the template and skip to step 11
19
+ 7. If not Click the Add New Template button.
20
+ 8. On the next page select New Order from the Template dropdown and click the Load Template button
21
+ 9. Name the new template and insert {{block type='linccare/widget' order=$order}} where you want the Linc Care widget to appear. Then save the template.
22
+ 10. Repeat for any other order-based emails you want connected to Linc Care. We suggest New Order Guest
23
+ 11. Go to System / Sales / Sales Email / Order and select the new templates for New Order Confirmation Email
24
+ 12. Save the configuration
25
+
26
+ If you have any comments or questions, please email us at support@linccare.com
app/etc/modules/Linc_Recommends.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Linc Recommends
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * The Linc Recommends Extension for Magento is in development and no license is granted for any purpose.
9
+ *
10
+ * @category Linc
11
+ * @package Linc_Recommends
12
+ * @copyright Copyright (c) 2014 Linc Global, Inc. (http://www.letslinc.com)
13
+ * @license http://www.letslinc.com/legal/LincCareLicenseAgreement/ Linc Global Commecial Licence
14
+ */
15
+ -->
16
+ <config>
17
+ <modules>
18
+ <Linc_Recommends>
19
+ <active>true</active>
20
+ <codePool>community</codePool>
21
+ </Linc_Recommends>
22
+ </modules>
23
+ </config>
package.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Linc_Recommends</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.letslinc.com/legal/LincCareLicenseAgreement/">Linc Global Commercial License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Linc Recommends streamlines a personal and contextual self-serviced customer care experience that drives loyalty.</summary>
10
+ <description>Uber customer care experience is the &lt;strong&gt;#1 driver for customer loyalty&lt;/strong&gt;. Linc Care makes it easy for retailers to offer a personal and contextual &lt;strong&gt;customer care experience&lt;/strong&gt; that wins loyalty and referral, at the same time reduces customer service cost.&#xD;
11
+ &lt;p&gt;&lt;/p&gt;&lt;p&gt;Install in minutes, you will get a major face-lift for all your order confirmation and order shipped notification emails, which has:&#xD;
12
+ &lt;strong&gt;A dynamically updated one-touch service center&lt;/strong&gt; that&#xD;
13
+ &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;1. shows your customers &lt;strong&gt;live order tracking status&lt;/strong&gt; right within the email at the time the customers open the emails. &lt;a href="https://internal.letslinc.com/ecare/dashboard/demo/36ad21cc-eabd-11e3-b42b-22000ac69e83"&gt;&lt;b&gt;Click to see a live demo &amp;gt;&amp;gt;&lt;/b&gt;&lt;/a&gt;&#xD;
14
+ &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;2. offers your customers &lt;strong&gt;text message notifications&lt;/strong&gt; on an opt-in basis for shipping and delivery (we are integrated to all shippers and manages both notifications and customer preference without any development on your end)&#xD;
15
+ &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;3. assists your customers on interactions with you. Let it be a product question or a general inquiry, Linc Care uses the customer&#x2019;s own purchase details to &lt;strong&gt;intelligently guide the customer through a seamless experience&lt;/strong&gt;, plus customers can request a call back or receive answers in text messages. We handle it all, and all you need is a customer service email address and reply the email inquiries :) &lt;a href="https://internal.letslinc.com/ecare/dashboard/demo/36ad21cc-eabd-11e3-b42b-22000ac69e83"&gt;&lt;b&gt;Click to see a live demo &amp;gt;&amp;gt;&lt;/b&gt;&lt;/a&gt;&#xD;
16
+ &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;4. [Optional] assists your customers with return / exchange, where they can directly view the return policy, give you feedback on reasons for return, and directly print out shipping label.&lt;/p&gt;&#xD;
17
+ &#xD;
18
+ &lt;p&gt;&lt;strong&gt; &lt;/strong&gt;&#xD;
19
+ &lt;h2&gt;Responsive Design for all Devices&lt;/h2&gt;&#xD;
20
+ Fully responsive design for large screens or small screens like smart phones, &lt;strong&gt;delighting on-the-go shoppers&lt;/strong&gt; wherever they access their order status.&lt;/p&gt;&#xD;
21
+ &#xD;
22
+ &lt;p&gt;&lt;strong&gt; &lt;/strong&gt;&#xD;
23
+ &lt;h2&gt;Dedicated Customer Success Team and Full Support for A/B Testing&lt;/h2&gt;&#xD;
24
+ Linc Care can be easily installed in minutes. But if you do need help or customization, regardless the size of your organization, we make sure you have a dedicated account manager to assist you.&lt;/p&gt;&#xD;
25
+ &#xD;
26
+ &lt;p&gt;&lt;strong&gt; &lt;/strong&gt;&#xD;
27
+ &lt;h2&gt;Follow Linc&lt;/h2&gt;&#xD;
28
+ Linc Care is built by a team of seasoned technologists who brought to life large scale consumer products for companies like &lt;strong&gt;Google, Yahoo and Amazon&lt;/strong&gt;. We were driven by the passion and believe that technology can truly empower mid-sized retail owners to compete and out-perform large retailers. We are new to Magneto platform, but are&lt;strong&gt; serving internet 1000 everyday&lt;/strong&gt;. If you have feature requests and suggestions for us, please do contact &lt;a href="mailto:linc-care-issues-magento@letslinc.com"&gt;Linc Care Support&lt;/a&gt;. We want to hear from you! &lt;/p&gt;&#xD;
29
+ &lt;p&gt;&lt;a href="http://www.letslinc.com"&gt;www.letslinc.com&lt;/a&gt;&lt;/p&gt;&#xD;
30
+ &#xD;
31
+ &amp;nbsp;&#xD;
32
+ &lt;p&gt;&#xD;
33
+ The Linc Care Professional Services Team is available to help you customize your experience at: &lt;a href="mailto:sales@linccare.com"&gt;sales@linccare.com&lt;/a&gt;&lt;/p&gt;&#xD;
34
+ </description>
35
+ <notes>Welcome to the Linc Recommends extension for Magento.&#xD;
36
+ &#xD;
37
+ This extension requires the Linc Care extenstion. Please install that first or Linc Recommends will not function properly.&#xD;
38
+ &#xD;
39
+ Linc Recommends requires only a miminal installation and no configuration. Just install it has you would any extension.&#xD;
40
+ &#xD;
41
+ After installation you must enable cron if you it isn't already. Information about this can be found at http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#magento_and_crontab&#xD;
42
+ &#xD;
43
+ Send any issues or comments to linc-care-issues-magento@letslinc.com</notes>
44
+ <authors><author><name>Linc</name><user>letslincapp</user><email>apps@letslinc.com</email></author></authors>
45
+ <date>2014-12-12</date>
46
+ <time>11:43:12</time>
47
+ <contents><target name="mageetc"><dir name="modules"><file name="Linc_Recommends.xml" hash="0ce16336373f1491e8b2aa6a0a7cd349"/></dir></target><target name="magecommunity"><dir name="Linc"><dir name="Recommends"><dir name="Block"><file name="Recommends.php" hash="6722a5c8be65a18ba47bd6167e6705cf"/></dir><dir name="Helper"><file name="Data.php" hash="bc04b4d72523c54d50cbed5262c773a5"/></dir><dir name="Model"><file name="Orders.php" hash="6c40b4a403b818b5b20ced992b02539d"/><file name="Products.php" hash="e896c22f13975e38fa4b88aa22063f3f"/></dir><file name="common.php" hash="82b09b911018f12ce42efd9a32bbddf1"/><dir name="etc"><file name="config.xml" hash="cfe6b372b6bba0f3795a0509a9400eb3"/><file name="system.xml" hash="e04929738101399bf8310fdbeebb7698"/></dir><file name="readme" hash="ea055cf644f770cfa8456d808d5e0c60"/></dir></dir></target></contents>
48
+ <compatible/>
49
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Linc_Care</name><channel>community</channel><min>1.12</min><max/></package></required></dependencies>
50
+ </package>