Svitla_IBoughtIt - Version 0.1.3

Version Notes

sharing through emails

Download this release

Release Info

Developer Magento Core Team
Extension Svitla_IBoughtIt
Version 0.1.3
Comparing to
See all releases


Code changes from version 0.1.2 to 0.1.3

app/code/community/Svitla/Iboughtit/Block/Email.php CHANGED
@@ -3,14 +3,24 @@
3
  class Svitla_Iboughtit_Block_Email extends Mage_Core_Block_Template {
4
 
5
  protected function _toHtml(){
 
 
 
 
 
6
  $rez='';
 
7
  if(Mage::helper('iboughtit')->isActive()){
8
- $site=(Mage::helper('iboughtit')->isUseSandbox()?'go.furiouspro.com/IboughtIt':'furiouspro.com/IboughtIt');
9
- if(Mage::helper('iboughtit')->getEmail()==1){
10
- $rez.='<a target="_blank" href="http://'.$site.'/merchant/claim_discount?pid='.Mage::helper('iboughtit')->getAccountId().'"><span style="text-decoration: none;"><img border="0" src="http://'.$site.'/image/'.Mage::helper('iboughtit')->getAccountId().'/email" />&nbsp;</span></a>';
 
11
  }
12
- elseif(Mage::helper('iboughtit')->getEmail()==2){
13
- $rez.='<a target="_blank" href="http://'.$site.'/merchant/claim_discount?pid='.Mage::helper('iboughtit')->getAccountId().'">'.Mage::helper('iboughtit')->__('Share your purchase with friends and make them smile').'</a>';
 
 
 
14
  }
15
  }
16
  Mage::log($rez);
@@ -18,3 +28,4 @@ class Svitla_Iboughtit_Block_Email extends Mage_Core_Block_Template {
18
  }
19
 
20
  }
 
3
  class Svitla_Iboughtit_Block_Email extends Mage_Core_Block_Template {
4
 
5
  protected function _toHtml(){
6
+ $orderId = $this->getParentBlock()->getOrder()->getId();//Mage::getSingleton('checkout/session')->getLastOrderId();
7
+ //if(!$orderId) $orderId=Mage::getSingleton('checkout/session')->getLastSuccessQuoteId();
8
+ //$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
9
+ $customerEmail=$this->getParentBlock()->getOrder()->getCustomer()->getEmail();
10
+ $hash='';
11
  $rez='';
12
+
13
  if(Mage::helper('iboughtit')->isActive()){
14
+ $response=Mage::Helper('iboughtit')->getHash($orderId);
15
+ if($response && !$response->error){
16
+ $aResponse=json_decode($response);
17
+ $hash=$aResponse->hash;
18
  }
19
+ if(Mage::helper('iboughtit')->getEmail()==1 && isset($aResponse)){
20
+ $rez.='<a target="_blank" href="http://i-bought-it.com/award/coupon/'.Mage::helper('iboughtit')->getAccountId().'/'.$orderId.'/'.$hash.'/email">I bought it!</a>';
21
+ }
22
+ elseif(Mage::helper('iboughtit')->getEmail()==2 && isset($aResponse)){
23
+ $rez.='<a target="_blank" href="http://i-bought-it.com/award/coupon/'.Mage::helper('iboughtit')->getAccountId().'/'.$orderId.'/'.$hash.'/email">I bought it!</a>';
24
  }
25
  }
26
  Mage::log($rez);
28
  }
29
 
30
  }
31
+
app/code/community/Svitla/Iboughtit/Block/Script.php CHANGED
@@ -16,7 +16,7 @@ class Svitla_Iboughtit_Block_Script extends Mage_Core_Block_Template {
16
  }
17
 
18
  if (Mage::helper('iboughtit')->isActive()) {
19
- $aResult=array();
20
  $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
21
  $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
22
 
@@ -27,43 +27,13 @@ class Svitla_Iboughtit_Block_Script extends Mage_Core_Block_Template {
27
  </script>';
28
  }
29
 
30
- $aResult['partner_id']=$this->escapeHtml(Mage::helper('iboughtit')->getAccountId());
31
- $aResult['store_type']='Magento';
32
- $aResult['store_currency']=Mage::app()->getStore()->getCurrentCurrencyCode();
33
- $aResult['order_id']=$orderId;
34
- $aResult['ssFrame_width']=Mage::helper('iboughtit')->getWidth();
35
- $aResult['ssFrame_height']=Mage::helper('iboughtit')->getHeight();
36
- $aResult['auto_popup']=Mage::helper('iboughtit')->isPopup();
37
- $aResult['sandbox']=Mage::helper('iboughtit')->isUseSandbox();
38
- //$itemsQty = count($order->getAllVisibleItems());
39
- //$aResult['prod_count']=$itemsQty;
40
- foreach ($order->getAllVisibleItems() as $key=>$item) {
41
- $productId = $item->getProductId();
42
- $product = Mage::getModel('catalog/product')->load($productId);
43
- $categoryIds = $product->getCategoryIds();
44
- $productCategory = $this->fetchCategories($categoryIds);
45
-
46
- $aResult['items'][$key]['prod_id']=$productId;
47
- $aResult['items'][$key]['prod_category']=$productCategory;
48
 
49
- $aResult['items'][$key]['category_id']=(is_array($categoryIds) && count($categoryIds)>0) ? implode(',', $categoryIds) : '';
50
- $aResult['items'][$key]['category_title']=$productCategory;
51
- $aResult['items'][$key]['prod_count']=sprintf("%.0f", $item->getQtyOrdered());
52
- $aResult['items'][$key]['prod_price']=sprintf("%.2f", $product->getPrice());
53
- $aResult['items'][$key]['prod_currency']=Mage::app()->getStore()->getCurrentCurrencyCode();
54
- $aResult['items'][$key]['prod_title']=$this->escapeHtml($product->getName());
55
- $aResult['items'][$key]['prod_img_url']=$this->helper('catalog/image')->init($product, 'thumbnail')->__toString();
56
- $aResult['items'][$key]['prod_page_url']=$product->getProductUrl();
57
- }
58
  }
59
- if(is_array($aResult) && count($aResult)>0){
60
- $sParams=json_encode($aResult);
61
- //$sParams=Mage::getModel('core/url')->escape($sParams);
62
- $response=Mage::Helper('iboughtit')->getHash($sParams);
63
- if($response){
64
- $aResponse=json_decode($response);
65
- $res.='<iframe name="iboughtit" id="iboughtit" src="http://i-bought-it.com/widget/?id='.$aResponse->id.'&hash='.$aResponse->hash.'&partnerid='.$this->escapeHtml(Mage::helper('iboughtit')->getAccountId()).'"></iframe>';
66
- }
67
  }
68
  //Mage::log($sParams);
69
  Mage::log($res);
@@ -74,17 +44,5 @@ class Svitla_Iboughtit_Block_Script extends Mage_Core_Block_Template {
74
  return Mage::helper('iboughtit')->getAnchorClass();
75
  }
76
 
77
- private function fetchCategories($categories){
78
- $productCategory = '';
79
- if(count($categories) > 0){
80
- foreach($categories as $categoryId) {
81
- $catResource = Mage::getModel('catalog/category')->load($categoryId);
82
- $catNamesArray[] = $catResource->getName();
83
- }
84
- $productCategory = implode(',', $catNamesArray);
85
- }
86
- return $productCategory;
87
- }
88
-
89
 
90
  }
16
  }
17
 
18
  if (Mage::helper('iboughtit')->isActive()) {
19
+
20
  $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
21
  $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
22
 
27
  </script>';
28
  }
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
 
 
 
 
 
 
 
 
31
  }
32
+ //$sParams=Mage::getModel('core/url')->escape($sParams);
33
+ $response=Mage::Helper('iboughtit')->getHash($orderId);
34
+ if($response){
35
+ $aResponse=json_decode($response);
36
+ $res.='<iframe name="iboughtit" width="685" height="571" id="iboughtit" style="border: 0px; padding-top: 10px; background: transparent;" src="http://i-bought-it.com/widget/?id='.$aResponse->id.'&hash='.$aResponse->hash.'&partnerid='.$this->escapeHtml(Mage::helper('iboughtit')->getAccountId()).'"></iframe>';
 
 
 
37
  }
38
  //Mage::log($sParams);
39
  Mage::log($res);
44
  return Mage::helper('iboughtit')->getAnchorClass();
45
  }
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  }
app/code/community/Svitla/Iboughtit/Helper/Data.php CHANGED
@@ -5,6 +5,8 @@ class Svitla_Iboughtit_Helper_Data extends Mage_Catalog_Helper_Data {
5
  private $_config = null;
6
  private $_adv_config = null;
7
 
 
 
8
  const PATH_TO_CONFIG = 'iboughtit/general';
9
  const PATH_TO_CONFIG_ADVANCED = 'iboughtit/advanced';
10
 
@@ -64,42 +66,100 @@ class Svitla_Iboughtit_Helper_Data extends Mage_Catalog_Helper_Data {
64
  return $this->getConfig()->getAnchorCssClass();
65
  }
66
 
67
- public function getHash($sParams){
68
- if(!isset($sParams)){
69
- return false;
70
- }
71
- try{
72
- $request = "http://i-bought-it.com/widget/reg?";
73
- $sFields=http_build_query(array('data' => $sParams));
74
- $session = curl_init($request);
75
-
76
- curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
77
- //curl_setopt($session, CURLOPT_HEADER, 1);
78
- curl_setopt($session, CURLOPT_POST, 1);
79
- curl_setopt($session, CURLOPT_POSTFIELDS, $sFields);
80
- //curl_setopt($session, CURLOPT_POSTFIELDS, $sParams);
81
- //curl_setopt($session, CURLOPT_VERBOSE, 0);
82
- //curl_setopt($session, CURLINFO_HEADER_OUT, 0);
83
-
84
- $response = curl_exec($session);
85
- if($response === false){
86
- throw new Exception(curl_error($session));
87
- }
88
- curl_close($session);
89
-
90
- if(!json_decode($response)){
91
- throw new Exception("Wrong remote server response: " . ": " . $response);
92
- Mage::getSingleton('core/session')->addError("Wrong remote server response");
93
- return false;
94
  }
95
  else{
96
- return $response;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
  }
99
- catch(Exception $e){
100
- Mage::log($e->getMessage());
101
- return false;
 
 
 
 
 
 
 
102
  }
103
- }
104
-
105
  }
5
  private $_config = null;
6
  private $_adv_config = null;
7
 
8
+ private $_response=null;
9
+
10
  const PATH_TO_CONFIG = 'iboughtit/general';
11
  const PATH_TO_CONFIG_ADVANCED = 'iboughtit/advanced';
12
 
66
  return $this->getConfig()->getAnchorCssClass();
67
  }
68
 
69
+ public function getHash($orderId=null){
70
+ $storedOrder=Mage::getSingleton('core/session')->getStoredOrder();
71
+ if(isset($storedOrder) && is_array($storedOrder) && count($storedOrder)>0 && isset($storedOrder[$orderId])){
72
+ return $storedOrder[$orderId];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  }
74
  else{
75
+ try{
76
+ if(!$orderId){
77
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
78
+ if(!$orderId) $orderId=Mage::getSingleton('checkout/session')->getLastSuccessQuoteId();
79
+ }
80
+ $order = Mage::getModel('sales/order')->load($orderId);
81
+
82
+ $aResult=array();
83
+ $aResult['partner_id']=$this->escapeHtml(Mage::helper('iboughtit')->getAccountId());
84
+ $aResult['store_type']='Magento';
85
+ $aResult['store_currency']=Mage::app()->getStore()->getCurrentCurrencyCode();
86
+ $aResult['order_id']=$orderId;
87
+ $aResult['ssFrame_width']=Mage::helper('iboughtit')->getWidth();
88
+ $aResult['ssFrame_height']=Mage::helper('iboughtit')->getHeight();
89
+ $aResult['auto_popup']=Mage::helper('iboughtit')->isPopup();
90
+ $aResult['sandbox']=Mage::helper('iboughtit')->isUseSandbox();
91
+
92
+ //$itemsQty = count($order->getAllVisibleItems());
93
+ //$aResult['prod_count']=$itemsQty;
94
+ foreach ($order->getAllVisibleItems() as $key=>$item) {
95
+ $productId = $item->getProductId();
96
+ $product = Mage::getModel('catalog/product')->load($productId);
97
+ $categoryIds = $product->getCategoryIds();
98
+ $productCategory = $this->fetchCategories($categoryIds);
99
+
100
+ $aResult['items'][$key]['prod_id']=$productId;
101
+ $aResult['items'][$key]['prod_category']=$productCategory;
102
+
103
+ $aResult['items'][$key]['category_id']=(is_array($categoryIds) && count($categoryIds)>0) ? implode(',', $categoryIds) : '';
104
+ $aResult['items'][$key]['category_title']=$productCategory;
105
+ $aResult['items'][$key]['prod_count']=sprintf("%.0f", $item->getQtyOrdered());
106
+ $aResult['items'][$key]['prod_price']=sprintf("%.2f", $product->getPrice());
107
+ $aResult['items'][$key]['prod_currency']=Mage::app()->getStore()->getCurrentCurrencyCode();
108
+ $aResult['items'][$key]['prod_title']=$this->escapeHtml($product->getName());
109
+ $aResult['items'][$key]['prod_img_url']=Mage::helper('catalog/image')->init($product, 'thumbnail')->__toString();
110
+ $aResult['items'][$key]['prod_page_url']=$product->getProductUrl();
111
+ }
112
+
113
+ if(is_array($aResult) && count($aResult)>0){
114
+ $sParams=json_encode($aResult);
115
+ //$sParams=Mage::getModel('core/url')->escape($sParams);
116
+ //$response=Mage::Helper('iboughtit')->getHash($sParams);
117
+
118
+ $request = "http://i-bought-it.com/widget/reg?";
119
+ $sFields=http_build_query(array('data' => $sParams));
120
+ $session = curl_init($request);
121
+
122
+ curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
123
+ //curl_setopt($session, CURLOPT_HEADER, 1);
124
+ curl_setopt($session, CURLOPT_POST, 1);
125
+ curl_setopt($session, CURLOPT_POSTFIELDS, $sFields);
126
+ //curl_setopt($session, CURLOPT_POSTFIELDS, $sParams);
127
+ //curl_setopt($session, CURLOPT_VERBOSE, 0);
128
+ //curl_setopt($session, CURLINFO_HEADER_OUT, 0);
129
+
130
+ $response = curl_exec($session);
131
+ if($response === false){
132
+ throw new Exception(curl_error($session));
133
+ }
134
+ curl_close($session);
135
+ }
136
+ if(!json_decode($response)){
137
+ throw new Exception("Wrong remote server response: " . ": " . $response);
138
+ Mage::getSingleton('core/session')->addError("Wrong remote server response");
139
+ return false;
140
+ }
141
+ else{
142
+ Mage::getSingleton('core/session')->setStoredOrder(array($orderId=>$response));
143
+ //$this->_response=$response;
144
+ return $response;
145
+ }
146
+ }
147
+ catch(Exception $e){
148
+ Mage::log($e->getMessage());
149
+ return false;
150
+ }
151
  }
152
  }
153
+ private function fetchCategories($categories){
154
+ $productCategory = '';
155
+ if(count($categories) > 0){
156
+ foreach($categories as $categoryId) {
157
+ $catResource = Mage::getModel('catalog/category')->load($categoryId);
158
+ $catNamesArray[] = $catResource->getName();
159
+ }
160
+ $productCategory = implode(',', $catNamesArray);
161
+ }
162
+ return $productCategory;
163
  }
164
+
 
165
  }
app/code/community/Svitla/Iboughtit/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Svitla_Iboughtit>
6
- <version>0.1.2</version>
7
  </Svitla_Iboughtit>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Svitla_Iboughtit>
6
+ <version>0.1.3</version>
7
  </Svitla_Iboughtit>
8
  </modules>
9
  <global>
app/design/frontend/base/default/template/iboughtit/items.phtml CHANGED
@@ -23,7 +23,7 @@
23
  </table>
24
 
25
  <br />
26
- <p><?php echo $this->getChildHtml('iboughtit_email') ?></p>
27
  <br />
28
  <br />
29
  <table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
23
  </table>
24
 
25
  <br />
26
+ <p>*<?php echo $this->getChildHtml('iboughtit_email') ?>*</p>
27
  <br />
28
  <br />
29
  <table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
app/design/frontend/base/default/template/iboughtit/social.phtml CHANGED
@@ -1,5 +1,7 @@
1
 
2
- <?php $anchorClass = $this->getAnchorClass(); ?>
 
 
3
 
4
  <div class="<?php echo $anchorClass ?>" style ="clear: both; margin: 4em 0 0;padding: 8px 0 0; text-align: right;"></div>
5
 
1
 
2
+ <?php
3
+ $anchorClass = $this->getAnchorClass();
4
+ ?>
5
 
6
  <div class="<?php echo $anchorClass ?>" style ="clear: both; margin: 4em 0 0;padding: 8px 0 0; text-align: right;"></div>
7
 
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Svitla_IBoughtIt</name>
4
- <version>0.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Extension to recommend goods over social networks</summary>
10
  <description>Extension to recommend goods over social networks</description>
11
- <notes>security fix, extended functionality</notes>
12
  <authors><author><name>Svitla</name><user>auto-converted</user><email>okhokhliuk@svitla.com</email></author></authors>
13
- <date>2012-07-16</date>
14
- <time>12:14:00</time>
15
- <contents><target name="magecommunity"><dir name="Svitla"><dir name="Iboughtit"><dir name="Block"><file name="Email.php" hash="e7e795b17873abea52b0c6156cb593d5"/><file name="Iboughtit.php" hash="bb8f4f72f0e88546f961230ddc8c385b"/><file name="Script.php" hash="8c876592d9d32cc24afbfae6e8a92569"/><file name="Social.php" hash="fb546910c18fc4f808b6c0cb24157d23"/></dir><dir name="Helper"><file name="Data.php" hash="5e207bdd390bb6739b091ae967a91cd5"/></dir><dir name="Model"><file name="Iboughtit.php" hash="88ca3383b67908168a717ebc3781f635"/><file name="Status.php" hash="7f7e065cb80e95c5344731957f160d10"/></dir><dir name="etc"><file name="config.xml" hash="f3fa1b40b1edc8321481b76cbeb3684b"/><file name="system.xml" hash="dc77118758c06e679586fab81947e6ec"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Svitla_Iboughtit.xml" hash="cb2ee7f8f58fb73c60f85ddf977a5f41"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="iboughtit"><file name="items.phtml" hash="9cb99903e94603bb162fcdcbab09af84"/><file name="social.phtml" hash="6ee40c4b5d1a41b98a0a1f8e9bad67d1"/></dir></dir><dir name="layout"><file name="iboughtit.xml" hash="04ae3aa0fe3bd8a4421006ca7b2b0a98"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Svitla_IBoughtIt</name>
4
+ <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Extension to recommend goods over social networks</summary>
10
  <description>Extension to recommend goods over social networks</description>
11
+ <notes>sharing through emails</notes>
12
  <authors><author><name>Svitla</name><user>auto-converted</user><email>okhokhliuk@svitla.com</email></author></authors>
13
+ <date>2012-07-18</date>
14
+ <time>10:37:59</time>
15
+ <contents><target name="magecommunity"><dir name="Svitla"><dir name="Iboughtit"><dir name="Block"><file name="Email.php" hash="b13dff4f97744b48bb6c24cde270d45a"/><file name="Iboughtit.php" hash="bb8f4f72f0e88546f961230ddc8c385b"/><file name="Script.php" hash="7f45b3cfd4471a399048b3f027c47a06"/><file name="Social.php" hash="fb546910c18fc4f808b6c0cb24157d23"/></dir><dir name="Helper"><file name="Data.php" hash="d3a6210d9d789fee118328d4cafef3ee"/></dir><dir name="Model"><file name="Iboughtit.php" hash="88ca3383b67908168a717ebc3781f635"/><file name="Status.php" hash="7f7e065cb80e95c5344731957f160d10"/></dir><dir name="etc"><file name="config.xml" hash="229b9cdbda82e20821c797467b0b10f8"/><file name="system.xml" hash="dc77118758c06e679586fab81947e6ec"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Svitla_Iboughtit.xml" hash="cb2ee7f8f58fb73c60f85ddf977a5f41"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="iboughtit"><file name="items.phtml" hash="92dcc460d264d6d5cbca634dcdd0b1f6"/><file name="social.phtml" hash="8d35064f3312f8f3cd224ef8f555d7bd"/></dir></dir><dir name="layout"><file name="iboughtit.xml" hash="04ae3aa0fe3bd8a4421006ca7b2b0a98"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>