KRYD - Version 1.1.0

Version Notes

First release

Download this release

Release Info

Developer KRYD GmbH
Extension KRYD
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.0 to 1.1.0

app/code/community/KRYD/Observer/Model/Observer.php CHANGED
@@ -3,31 +3,266 @@ require_once(dirname(__FILE__)."/../../kryd_include.php");
3
 
4
  class KRYD_Observer_Model_Observer {
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  public function catalog_controller_product_view(Varien_Event_Observer $observer) {
 
7
  KRYD::event('itemview',Array("itemid"=>$observer->event->product->sku));
8
  }
9
 
10
  public function customer_register_success(Varien_Event_Observer $observer) {
 
11
  KRYD::event('register');
12
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer) {
15
- KRYD::event('complete');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
- public function checkout_cart_product_add_after(Varien_Event_Observer $observer) {
 
19
  $quote=Mage::getSingleton('checkout/session')->getQuote();
20
  $items=$quote->getAllVisibleItems();
21
- $itemids=Array();
22
- foreach ($items as $item) $itemids[]=$item->sku;
23
- $itemids=array_unique($itemids);
24
- KRYD::event("basket",Array("itemids"=>implode(";",$itemids)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
 
27
  public function customer_login(Varien_Event_Observer $observer) {
 
 
28
  $customer=$observer->event->customer;
29
- KRYD::event("identify",Array("email"=>$customer->email,"firstname"=>$customer->firstname,"lastname"=>$customer->lastname));
 
 
 
 
 
30
  KRYD::event('login');
 
31
  }
32
 
33
 
3
 
4
  class KRYD_Observer_Model_Observer {
5
 
6
+ private function init_api() {
7
+ $cookie=Mage::getSingleton('core/cookie');
8
+ KRYD::messageid($cookie->get("kryd_messageid"));
9
+ $sessionid=$cookie->get("kryd_sessionid");
10
+ if (!$sessionid) {
11
+ $sessionid=md5(uniqid("",true));
12
+ $cookie->set('kryd_sessionid',$sessionid,0,'/');
13
+ }
14
+ KRYD::sessionid($sessionid);
15
+ }
16
+
17
+ private function getBundleItemOptions($item) {
18
+ $product=$item->getProduct();
19
+ $options=$product->getTypeInstance(true)->getOrderOptions($product);
20
+ $optionIds=array_keys($options['info_buyRequest']['bundle_option']);
21
+ $types=Mage_Catalog_Model_Product_Type::getTypes();
22
+ $typemodel=Mage::getSingleton($types[Mage_Catalog_Model_Product_Type::TYPE_BUNDLE]['model']);
23
+ $typemodel->setConfig($types[Mage_Catalog_Model_Product_Type::TYPE_BUNDLE]);
24
+ $selections=$typemodel->getSelectionsCollection($optionIds,$item);
25
+ $selection_map=array();
26
+ foreach ($selections->getData() as $selection) {
27
+ $option_id=$selection['option_id'];
28
+ $selection_id=$selection['selection_id'];
29
+ if (!isset($selection_map[$option_id])) $selection_map[$option_id]=array();
30
+ $selection_map[$option_id][$selection_id]=$selection;
31
+ }
32
+
33
+ $result=array();
34
+
35
+ $req=$options['info_buyRequest'];
36
+
37
+ $qtys=$req['bundle_option_qty'];
38
+
39
+ foreach($req['bundle_option'] as $op => $sel) {
40
+ $sel=(array)$sel;
41
+ foreach ($sel as $itm) {
42
+ $sinfo=$selection_map[$op][$itm];
43
+ if (!isset($sinfo)) continue;
44
+ $amount=$qtys[$op];
45
+ if (!isset($amount)) $amount=1;
46
+ $sku=$sinfo['sku'];
47
+ $result[]=Array("amount"=>$amount,"id"=>$sku);
48
+ }
49
+ }
50
+
51
+ return $result;
52
+ }
53
+
54
+ public function controller_action_predispatch(Varien_Event_Observer $observer) {
55
+
56
+ if ($_GET["kryd_action"]=="basket_restore") {
57
+
58
+ $basket=KRYD::get_basket($_GET["kryd_messageid"]);
59
+
60
+ $cart=Mage::getModel('checkout/cart');
61
+ $cart->init();
62
+ $cart->truncate();
63
+
64
+ foreach ($basket as $bitem) {
65
+
66
+ $sku=$bitem["parentid"]?:$bitem["id"];
67
+
68
+ $params=Array();
69
+
70
+ $params['qty']=$bitem["amount"];
71
+
72
+ $products=Mage::getModel('catalog/product');
73
+ $itemid=$products->getIdBySku($sku);
74
+ $item=$products->load($itemid);
75
+
76
+ if ($item->getTypeId()==='configurable') {
77
+
78
+ $products2=Mage::getModel('catalog/product');
79
+
80
+ $subitemid=$products2->getIdBySku($bitem["id"]);
81
+ $subitem=$products2->load($subitemid);
82
+
83
+ $attrs=$item->getTypeInstance(true)->getConfigurableAttributesAsArray($item);
84
+
85
+ foreach ($attrs as $attr) {
86
+ $code=$attr["attribute_code"];
87
+ $attrid=$attr["attribute_id"];
88
+ $values=$attr["values"];
89
+ $avalue=$subitem->getAttributeText($code);
90
+ foreach ($values as $value) {
91
+ if ($value["label"]!=$avalue) continue;
92
+ $vindex=$value["value_index"];
93
+ //echo $attrid." (".$code."): ".$avalue." (".$vindex.")<br />";
94
+ $params['super_attribute'][$attrid]=$vindex;
95
+ }
96
+ }
97
+
98
+ }
99
+
100
+ if ($item->getTypeId()==='bundle') {
101
+
102
+ $params['bundle_option']=Array();
103
+ $params['bundle_option_qty']=Array();
104
+
105
+ $selection=$item->getTypeInstance()->getSelectionsCollection($item->getTypeInstance()->getOptionsIds());
106
+ foreach ($selection as $sel) {
107
+ foreach ($bitem["subitems"] as $subitem) {
108
+ if ($subitem["id"]==$sel->getSku()) {
109
+ $optid=$sel->getOptionId();
110
+ $selid=$sel->getSelectionId();
111
+ $params['bundle_option'][$optid]=$selid;
112
+ if ($subitem["amount"]>1) $params['bundle_option_qty'][$optid]=$subitem["amount"];
113
+ }
114
+ }
115
+ }
116
+
117
+ } //if bundle
118
+
119
+ $cart->addProduct($item, $params);
120
+
121
+ } //foreach basket
122
+
123
+ $cart->save();
124
+ }
125
+
126
+ if ($_GET["kryd_messageid"]) {
127
+ $cookie=Mage::getSingleton('core/cookie');
128
+
129
+ $cookie->set("kryd_messageid",$_GET["kryd_messageid"],0,"/");
130
+ $this->init_api();
131
+ KRYD::event("click");
132
+ parse_str($_SERVER["QUERY_STRING"],$query);
133
+ unset($query["kryd_messageid"]);
134
+ unset($query["kryd_action"]);
135
+ $query=http_build_query($query);
136
+ if ($query!=="") $query="?".$query;
137
+ $url=(isset($_SERVER['HTTPS'])=='on'?'https':'http').'://'.$_SERVER['HTTP_HOST'].strtok($_SERVER['REQUEST_URI'],'?').$query;
138
+ header("Location: ".$url);
139
+ exit;
140
+ }
141
+
142
+ }
143
+
144
  public function catalog_controller_product_view(Varien_Event_Observer $observer) {
145
+ $this->init_api();
146
  KRYD::event('itemview',Array("itemid"=>$observer->event->product->sku));
147
  }
148
 
149
  public function customer_register_success(Varien_Event_Observer $observer) {
150
+ $this->init_api();
151
  KRYD::event('register');
152
  }
153
+
154
+ protected function getTotalOrderInfo() {
155
+ $customerid=Mage::getSingleton('customer/session')->getCustomer()->getId();
156
+ $orders=Mage::getModel("sales/order")->getCollection();
157
+ $orders->addFieldToFilter('customer_id',$customerid);
158
+ $value=0;
159
+ $count=0;
160
+ foreach ($orders as $order) {
161
+ $count++;
162
+ $value+=$order->getGrandTotal();
163
+ }
164
+
165
+ $arr=Array();
166
+ $arr["count"]=$count;
167
+ $arr["value"]=$value;
168
+
169
+ return $arr;
170
+ }
171
 
172
  public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer) {
173
+ $this->init_api();
174
+ $order=$observer->getEvent()->getOrder();
175
+
176
+ $orderid=$order->getIncrementId();
177
+
178
+ $items=$order->getAllVisibleItems();
179
+
180
+ $price=0;
181
+ $arr=Array();
182
+
183
+ foreach ($items as $item) {
184
+ $sku=$item->getSku();
185
+
186
+ $product=Mage::getModel('catalog/product')->load($item->getProductId());
187
+ $parentsku=$product->getSku();
188
+
189
+ $row=Array();
190
+ $row["amount"]=$item->getQtyOrdered();
191
+ $row["price"]=$item->getPrice();
192
+ $row["id"]=$sku;
193
+
194
+ if ($parentsku!=$sku) $row["parentid"]=$parentsku;
195
+
196
+ $subitems=$this->getBundleItemOptions($item);
197
+ if ($subitems) $row["subitems"]=$subitems;
198
+
199
+ $arr[]=$row;
200
+
201
+ $price+=$item->getPrice();
202
+ }
203
+
204
+ $info=$this->getTotalOrderInfo();
205
+
206
+ if ($code=$order->getCouponCode()) KRYD::event('voucher',Array("voucherid"=>$code));
207
+
208
+ KRYD::event('complete',Array("orderid"=>$orderid,"order_count_total"=>$info["count"],"order_value_total"=>$info["value"],"order_value"=>$price,"items"=>$arr));
209
  }
210
 
211
+ public function checkout_cart_add_product_complete(Varien_Event_Observer $observer) {
212
+ $this->init_api();
213
  $quote=Mage::getSingleton('checkout/session')->getQuote();
214
  $items=$quote->getAllVisibleItems();
215
+
216
+ $price=0;
217
+ $arr=Array();
218
+
219
+ foreach ($items as $item) {
220
+ $sku=$item->getSku();
221
+
222
+ $product=Mage::getModel('catalog/product')->load($item->getProductId());
223
+ $parentsku=$product->getSku();
224
+
225
+ $row=Array();
226
+ $row["amount"]=$item->getQty();
227
+ $row["price"]=$item->getPrice();
228
+ $row["id"]=$sku;
229
+
230
+ if ($parentsku!=$sku) $row["parentid"]=$parentsku;
231
+
232
+ $subitems=$this->getBundleItemOptions($item);
233
+ if ($subitems) $row["subitems"]=$subitems;
234
+
235
+ $arr[]=$row;
236
+
237
+ $price+=$item->getPrice();
238
+ }
239
+
240
+ KRYD::event("basket",Array("items"=>$arr,"value"=>$price));
241
+ }
242
+
243
+ public function controller_action_postdispatch_checkout_onepage_saveBilling(Varien_Event_Observer $observer) {
244
+ $post=Mage::app()->getRequest()->getPost();
245
+ $billing=$post["billing"];
246
+ if (!isset($billing)) return;
247
+
248
+ if (!$billing["email"]) return;
249
+
250
+ $this->init_api();
251
+ KRYD::event("identify",Array("email"=>$billing["email"],"firstname"=>$billing["firstname"],"lastname"=>$billing["lastname"]));
252
  }
253
 
254
  public function customer_login(Varien_Event_Observer $observer) {
255
+ $this->init_api();
256
+
257
  $customer=$observer->event->customer;
258
+
259
+ $subscriber=Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
260
+ $optin=$subscriber->isSubscribed()?"yes":"no";
261
+
262
+ $this->init_api();
263
+ KRYD::event("identify",Array("email"=>$customer->email,"firstname"=>$customer->firstname,"lastname"=>$customer->lastname,"optin"=>$optin));
264
  KRYD::event('login');
265
+
266
  }
267
 
268
 
app/code/community/KRYD/Observer/controllers/ExportController.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class KRYD_Observer_ExportController extends Mage_Core_Controller_Front_Action {
4
+
5
+ private function xmlentities($string) {
6
+ return str_replace(array('&','"',"'",'<', '>'),array('&amp;','&quot;','&apos;','&lt;','&gt;'),$string);
7
+ }
8
+
9
+ public function createItem($args) {
10
+ $product=Mage::getModel('catalog/product');
11
+ $product->setData($args['row']);
12
+
13
+ unset($parentProduct);
14
+ unset($parentSku);
15
+
16
+ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
17
+ $parentSkus=Mage::getModel('catalog/product')->getResource()->getProductsSku($parentIds);
18
+
19
+ if (count($parentSkus)==1) {
20
+ $parentSku=$parentSkus[0]["sku"];
21
+ $parentProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $parentSku);
22
+ }
23
+
24
+
25
+ echo " <item>\n";
26
+ echo " <id>".$this->xmlentities($product->getSku())."</id>\n";
27
+
28
+ if ($parentProduct) {
29
+ $parentSku=$parentSkus[0]["sku"];
30
+ if ($parentSku) echo " <parentid>".$this->xmlentities($parentSku)."</parentid>\n";
31
+ }
32
+
33
+ echo " <name>".$this->xmlentities($product->getName())."</name>\n";
34
+ echo " <price>".$this->xmlentities($product->getPrice())."</price>\n";
35
+
36
+ $si=$product->getSmallImage();
37
+ if ($si && $si!="no_selection" && is_file("media/catalog/product".$si)) {
38
+ $imageurl=(string)Mage::helper('catalog/image')->init($product,'small_image')->resize(135);
39
+ echo " <thumb>".$this->xmlentities($imageurl)."</thumb>\n";
40
+ } else {
41
+ if ($parentSku) {
42
+ $parentProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $parentSku);
43
+ if ($parentProduct) {
44
+ $parentImageurl=(string)Mage::helper('catalog/image')->init($parentProduct,'small_image')->resize(135);
45
+ echo " <thumb>".$this->xmlentities($parentImageurl)."</thumb>\n";
46
+ }
47
+ }
48
+ }
49
+
50
+ if ($parentProduct) {
51
+ echo " <url>".$parentProduct->getProductURL(false)."</url>\n";
52
+ } else {
53
+ echo " <url>".$product->getProductURL(false)."</url>\n";
54
+ }
55
+
56
+ echo " </item>\n";
57
+ flush();
58
+ }
59
+
60
+ public function exportAction () {
61
+
62
+ header("Content-type:text/xml");
63
+ echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
64
+ echo "<items>\n";
65
+
66
+ $products=Mage::getModel('catalog/product')->getCollection();
67
+
68
+ $products->addAttributeToSelect(Array('sku','name','price','small_image'),'left');
69
+
70
+ $that=$this;
71
+
72
+ $func=function ($args) use($that) {
73
+ $that->createItem($args);
74
+ };
75
+
76
+ Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(),array($func));
77
+
78
+ echo '</items>';
79
+ exit;
80
+
81
+ }
82
+
83
+ }
app/code/community/KRYD/Observer/etc/config.xml CHANGED
@@ -10,6 +10,19 @@
10
  <class>KRYD_Observer_Model_Observer</class>
11
  </KRYD_Observer_Model_Observer>
12
  </models>
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  <global>
14
 
15
  <models>
@@ -25,6 +38,26 @@
25
  </helpers>
26
 
27
  <events>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  <catalog_controller_product_view>
30
  <observers>
@@ -56,15 +89,15 @@
56
  </observers>
57
  </customer_login>
58
 
59
- <checkout_cart_product_add_after>
60
  <observers>
61
  <kryd_observer>
62
  <type>singleton</type>
63
  <class>KRYD_Observer_Model_Observer</class>
64
- <method>checkout_cart_product_add_after</method>
65
  </kryd_observer>
66
  </observers>
67
- </checkout_cart_product_add_after>
68
 
69
  <checkout_type_onepage_save_order_after>
70
  <observers>
10
  <class>KRYD_Observer_Model_Observer</class>
11
  </KRYD_Observer_Model_Observer>
12
  </models>
13
+
14
+ <frontend>
15
+ <routers>
16
+ <productexport>
17
+ <use>standard</use>
18
+ <args>
19
+ <module>KRYD_Observer</module>
20
+ <frontName>kryd</frontName>
21
+ </args>
22
+ </productexport>
23
+ </routers>
24
+ </frontend>
25
+
26
  <global>
27
 
28
  <models>
38
  </helpers>
39
 
40
  <events>
41
+
42
+ <controller_action_postdispatch_checkout_onepage_saveBilling>
43
+ <observers>
44
+ <kryd_observer>
45
+ <type>singleton</type>
46
+ <class>KRYD_Observer_Model_Observer</class>
47
+ <method>controller_action_postdispatch_checkout_onepage_saveBilling</method>
48
+ </kryd_observer>
49
+ </observers>
50
+ </controller_action_postdispatch_checkout_onepage_saveBilling>
51
+
52
+ <controller_action_predispatch>
53
+ <observers>
54
+ <kryd_observer>
55
+ <type>singleton</type>
56
+ <class>KRYD_Observer_Model_Observer</class>
57
+ <method>controller_action_predispatch</method>
58
+ </kryd_observer>
59
+ </observers>
60
+ </controller_action_predispatch>
61
 
62
  <catalog_controller_product_view>
63
  <observers>
89
  </observers>
90
  </customer_login>
91
 
92
+ <checkout_cart_add_product_complete>
93
  <observers>
94
  <kryd_observer>
95
  <type>singleton</type>
96
  <class>KRYD_Observer_Model_Observer</class>
97
+ <method>checkout_cart_add_product_complete</method>
98
  </kryd_observer>
99
  </observers>
100
+ </checkout_cart_add_product_complete>
101
 
102
  <checkout_type_onepage_save_order_after>
103
  <observers>
app/code/community/KRYD/api.php CHANGED
@@ -1,34 +1,154 @@
1
  <?php
 
 
 
 
2
  class KRYD {
3
 
4
- private static $script_included=false;
5
  private static $id;
6
  private static $key;
 
 
7
  private static $last_error;
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  public static function last_error() {
10
  return self::$last_error;
11
  }
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  public static function id($id) {
14
  self::$id=$id;
 
15
  }
16
 
 
 
 
 
 
17
  public static function key($key) {
18
  self::$key=$key;
 
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  public static function has_settings() {
22
  return is_file(dirname(__FILE__)."/settings.php");
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
 
 
 
 
 
 
 
25
  public static function event($eventtype,$options=Array()) {
26
 
27
  if (!self::$id) {self::$last_error=Array('code'=>'accountid_missing','message'=>'KRYD account id missing.');return false;}
28
  if (!self::$key) {self::$key_missing=Array('code'=>'key_missing','message'=>'KRYD API key missing.');return false;}
29
 
30
- $sessionid=md5(session_id());
 
 
 
 
31
 
 
 
 
 
 
 
32
  $post=Array(
33
  'accountid'=>self::$id,
34
  'sessionid'=>$sessionid,
@@ -44,6 +164,7 @@ class KRYD {
44
  }
45
 
46
  $ch=curl_init('https://api.kryd.com/event.lua');
 
47
  curl_setopt($ch,CURLOPT_POST,true);
48
  curl_setopt($ch,CURLOPT_POSTFIELDS,$query);
49
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
@@ -60,5 +181,5 @@ class KRYD {
60
 
61
  }
62
 
63
- if (KRYD::has_settings()) include(dirname(__FILE__)."/settings.php");
64
  ?>
1
  <?php
2
+ /**
3
+ * PHP-API for KRYD. This class is responsible for sending events to the KRYD event server.
4
+ *
5
+ */
6
  class KRYD {
7
 
 
8
  private static $id;
9
  private static $key;
10
+ private static $sessionid;
11
+ private static $messageid;
12
  private static $last_error;
13
+ private static $ready=false;
14
 
15
+ /**
16
+ * Handles click-tracking. Saves the kryd_messageid in a cookie and reloads the page without the respective query string key
17
+ *
18
+ */
19
+ private static function handle_tracking() {
20
+ // Handled by Magento observer
21
+ }
22
+
23
+ /**
24
+ * Returns the last error that occured
25
+ *
26
+ * @return Array
27
+ */
28
  public static function last_error() {
29
  return self::$last_error;
30
  }
31
 
32
+ /**
33
+ * Checks whether credentials are ready yet, and if yes, starts tracking handling
34
+ *
35
+ */
36
+ private static function ready() {
37
+ if (self::$ready or !self::$id or !self::$key) return;
38
+ self::$ready=true;
39
+ self::handle_tracking();
40
+ }
41
+
42
+ /**
43
+ * Sets the KRYD account ID
44
+ *
45
+ * @param string $id
46
+ */
47
  public static function id($id) {
48
  self::$id=$id;
49
+ self::ready();
50
  }
51
 
52
+ /**
53
+ * Sets the KRYD API key
54
+ *
55
+ * @param string $key
56
+ */
57
  public static function key($key) {
58
  self::$key=$key;
59
+ self::ready();
60
  }
61
 
62
+ /**
63
+ * Sets a custom sessionid
64
+ *
65
+ * @param string $sessionid
66
+ */
67
+ public static function sessionid($sessionid) {
68
+ self::$sessionid=$sessionid;
69
+ }
70
+
71
+ /**
72
+ * Sets a custom messageid
73
+ *
74
+ * @param string $messageid
75
+ */
76
+ public static function messageid($messageid) {
77
+ self::$messageid=$messageid;
78
+ }
79
+
80
+ #$has_settings_start
81
+ /**
82
+ * Finds out whether a fixed settings file exists
83
+ *
84
+ * @return bool
85
+ */
86
  public static function has_settings() {
87
  return is_file(dirname(__FILE__)."/settings.php");
88
  }
89
+ #$has_settings_end
90
+
91
+ /**
92
+ * Loads settings
93
+ *
94
+ */
95
+ public static function load_settings() {
96
+ #$load_settings_start
97
+ if (KRYD::has_settings()) include(dirname(__FILE__)."/settings.php");
98
+ #$load_settings_end
99
+ }
100
+
101
+ /**
102
+ * Looks up a user's basket by a given message ID
103
+ *
104
+ * @param string $messageid
105
+ * @return array
106
+ */
107
+ public function get_basket($messageid) {
108
+
109
+ if (!self::$id) {self::$last_error=Array('code'=>'accountid_missing','message'=>'KRYD account id missing.');return false;}
110
+ if (!self::$key) {self::$key_missing=Array('code'=>'key_missing','message'=>'KRYD API key missing.');return false;}
111
+
112
+ $signature=md5(self::$id.$messageid.self::$key);
113
+
114
+ $url="http://feedback.kryd.com/basket.lua?accountid=".rawurlencode(self::$id)."&messageid=".rawurlencode($messageid).'&signature='.$signature;
115
+
116
+ $ch = curl_init();
117
+
118
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
119
+ curl_setopt($ch, CURLOPT_URL, $url);
120
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
121
+
122
+ $response = curl_exec($ch);
123
+
124
+ return json_decode($response,true);
125
+ }
126
 
127
+ /**
128
+ * Sends an event with associated options, return true on success and false on error.
129
+ * In case of an error you can receive the error message via last_error()
130
+ *
131
+ * @param string $eventtype
132
+ * @param array $options
133
+ * @return bool
134
+ */
135
  public static function event($eventtype,$options=Array()) {
136
 
137
  if (!self::$id) {self::$last_error=Array('code'=>'accountid_missing','message'=>'KRYD account id missing.');return false;}
138
  if (!self::$key) {self::$key_missing=Array('code'=>'key_missing','message'=>'KRYD API key missing.');return false;}
139
 
140
+ if (self::$sessionid) {
141
+ $sessionid=self::$sessionid;
142
+ } else {
143
+ $sessionid=md5(session_id());
144
+ }
145
 
146
+ if (self::$messageid) {
147
+ $options["messageid"]=self::$messageid;
148
+ } else {
149
+ if (isset($_COOKIE["kryd_messageid"])) $options["messageid"]=$_COOKIE["kryd_messageid"];
150
+ }
151
+
152
  $post=Array(
153
  'accountid'=>self::$id,
154
  'sessionid'=>$sessionid,
164
  }
165
 
166
  $ch=curl_init('https://api.kryd.com/event.lua');
167
+ curl_setopt($ch,CURLOPT_TIMEOUT,2);
168
  curl_setopt($ch,CURLOPT_POST,true);
169
  curl_setopt($ch,CURLOPT_POSTFIELDS,$query);
170
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
181
 
182
  }
183
 
184
+ KRYD::load_settings();
185
  ?>
app/code/community/KRYD/kryd_include.php CHANGED
@@ -1,4 +1,4 @@
1
- <?
2
  require_once(dirname(__FILE__)."/api.php");
3
 
4
  if (!KRYD::has_settings()) {
1
+ <?php
2
  require_once(dirname(__FILE__)."/api.php");
3
 
4
  if (!KRYD::has_settings()) {
kryd_export/items.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
- require('../app/Mage.php');
3
- @set_time_limit(0);
4
- Mage::app();
5
-
6
- function xmlentities($string) {
7
- return str_replace(array('&','"',"'",'<', '>'),array('&amp;','&quot;','&apos;','&lt;','&gt;'),$string);
8
- }
9
-
10
- function createItem($args) {
11
- $product=Mage::getModel('catalog/product');
12
- $product->setData($args['row']);
13
-
14
- echo " <item>\n";
15
- echo " <id>".xmlentities($product->getSku())."</id>\n";
16
- echo " <name>".xmlentities($product->getName())."</name>\n";
17
- echo " <price>".xmlentities($product->getPrice())."</price>\n";
18
-
19
- $imageurl=(string)Mage::helper('catalog/image')->init($product,'small_image')->resize(135);
20
-
21
- echo " <thumb>".xmlentities($imageurl)."</thumb>\n";
22
- echo " </item>\n";
23
- flush();
24
- }
25
-
26
- header("Content-type:text/xml");
27
- echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
28
- echo "<items>\n";
29
-
30
- $products=Mage::getModel('catalog/product')->getCollection();
31
- $products->addAttributeToSelect(Array('sku'),'inner');
32
- $products->addAttributeToSelect(Array('name'),'inner');
33
- $products->addAttributeToSelect(Array('price'),'inner');
34
- $products->addAttributeToSelect(Array('small_image'),'inner');
35
-
36
- Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(),array('createItem'));
37
-
38
- echo '</items>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KRYD</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.kryd.com/partner/license.php">Proprietary</license>
7
  <channel>community</channel>
@@ -27,25 +27,28 @@ With KRYD, you utilize it optimally. KRYD analyzes your customers' behavior and
27
  <email>info@kryd.com</email>
28
  </author>
29
  </authors>
30
- <date>2013-06-21</date>
31
- <time>12:03:18</time>
32
  <contents>
33
  <target name="magecommunity">
34
  <dir name="KRYD">
 
35
  <dir name="Observer">
36
- <dir name="Model">
37
- <file name="Observer.php" hash="f68f4953b1bdc263f41b7a6e95b87bca"/>
38
- </dir>
39
- <dir name="Helper">
40
- <file name="Data.php" hash="8cdfd25ace7de949d068d500d6dd730f"/>
41
  </dir>
42
  <dir name="etc">
43
- <file name="config.xml" hash="4764fa9d9c2fbd6f3dfc1d56048b988a"/>
44
  <file name="adminhtml.xml" hash="3bdbeb1348a24faf29710ed344f93a2b"/>
 
45
  <file name="system.xml" hash="47e63f155a100fe269038e9cc998e760"/>
46
  </dir>
 
 
 
 
 
 
47
  </dir>
48
- <file name="kryd_include.php" hash="423fd3f4590f09fbff09ec973dddb689"/>
49
  </dir>
50
  </target>
51
  </contents>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KRYD</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.kryd.com/partner/license.php">Proprietary</license>
7
  <channel>community</channel>
27
  <email>info@kryd.com</email>
28
  </author>
29
  </authors>
30
+ <date>2014-08-20</date>
31
+ <time>13:58:52</time>
32
  <contents>
33
  <target name="magecommunity">
34
  <dir name="KRYD">
35
+ <file name="kryd_include.php" hash="0d0a89622d7ea9c9e0f8ce6f50bc06c7"/>
36
  <dir name="Observer">
37
+ <dir name="controllers">
38
+ <file name="ExportController.php" hash="94f54a383b3632373b11a1c9d0b24574"/>
 
 
 
39
  </dir>
40
  <dir name="etc">
 
41
  <file name="adminhtml.xml" hash="3bdbeb1348a24faf29710ed344f93a2b"/>
42
+ <file name="config.xml" hash="063d8d27d02386079ec6c5396bcd6a4f"/>
43
  <file name="system.xml" hash="47e63f155a100fe269038e9cc998e760"/>
44
  </dir>
45
+ <dir name="Model">
46
+ <file name="Observer.php" hash="5cb82761c625708164bfa2371da2e859"/>
47
+ </dir>
48
+ <dir name="Helper">
49
+ <file name="Data.php" hash="fff38f9d8c87a7cfac6b259c8402d9c9"/>
50
+ </dir>
51
  </dir>
 
52
  </dir>
53
  </target>
54
  </contents>