HardikAjaxCart - Version 1.1.1

Version Notes

added file upload functionality to support custom product option type file.

Download this release

Release Info

Developer Hardik Gajjar
Extension HardikAjaxCart
Version 1.1.1
Comparing to
See all releases


Code changes from version 1.1.0 to 1.1.1

app/code/local/Hardik/Ajaxcart/Model/Response.php CHANGED
@@ -7,7 +7,7 @@ class Hardik_Ajaxcart_Model_Response extends Varien_Object
7
  Zend_Json::$useBuiltinEncoderDecoder = true;
8
  if ($this->getError()) $this->setR('error');
9
  else $this->setR('success');
10
- Mage::app()->getFrontController()->getResponse()->setBody(Zend_Json::encode($this->getData()));
11
  }
12
 
13
  public function addUpdatedBlocks(&$_response) {
7
  Zend_Json::$useBuiltinEncoderDecoder = true;
8
  if ($this->getError()) $this->setR('error');
9
  else $this->setR('success');
10
+ Mage::app()->getFrontController()->getResponse()->setHeader('Content-Type', 'text/plain')->setBody(Zend_Json::encode($this->getData()));
11
  }
12
 
13
  public function addUpdatedBlocks(&$_response) {
app/code/local/Hardik/Ajaxcart/etc/config.xml CHANGED
@@ -7,7 +7,7 @@
7
  <config>
8
  <modules>
9
  <Hardik_Ajaxcart>
10
- <version>1.1.0</version>
11
  </Hardik_Ajaxcart>
12
  </modules>
13
  <global>
7
  <config>
8
  <modules>
9
  <Hardik_Ajaxcart>
10
+ <version>1.1.1</version>
11
  </Hardik_Ajaxcart>
12
  </modules>
13
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HardikAjaxCart</name>
4
- <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
@@ -14,11 +14,11 @@ If you want to add more blocks which should be updated, you can easily do so jus
14
  You can refer the default layout update entries in admin panel for further details.&#xD;
15
  &#xD;
16
  NOTE: Please confirm that the block which you are adding in layout update entries is under &lt;strong&gt;default&lt;/strong&gt; handle or under &lt;strong&gt;ajaxcart&lt;/strong&gt; handle. You can refer ajaxcart.xml frontend layout file for further details.</description>
17
- <notes>Provides only simple products ajax cart functionality.</notes>
18
  <authors><author><name>Hardik Gajjar</name><user>hardik_krishinc</user><email>hardik.gajjar@krishinc.com</email></author></authors>
19
- <date>2012-12-12</date>
20
- <time>05:28:14</time>
21
- <contents><target name="magelocal"><dir name="Hardik"><dir name="Ajaxcart"><dir name="Block"><dir name="Adminhtml"><file name="Info.php" hash="8fab3b7d0b1390dcc80a037c66b1ba7f"/><file name="Url.php" hash="ed7b1ff4b0f4ad33d45cfd301dba4227"/></dir></dir><dir name="Helper"><file name="Data.php" hash="773174c4f49cccc57be68acb1e0027e5"/></dir><dir name="Model"><file name="Observer.php" hash="25a046b451673ced3055f9dbd16cbc08"/><file name="Response.php" hash="3065d0ee53883dada0376c5ad5f3a0bb"/></dir><dir name="controllers"><dir name="Checkout"><file name="CartController.php" hash="1fbdb0b12a18522a9aaafc46fda4c7e3"/></dir></dir><dir name="etc"><file name="config.xml" hash="85e3ff4d94a0dd76fe540dfc655c1e22"/><file name="system.xml" hash="70e92e5d3c03d7b462e72ba3a8eaca1f"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="ajaxcart"><file name="ajaxcart.js" hash="d4239780d0b16b371a7f097267db8790"/><file name="growler.css" hash="c13a01e28cb4eb98b1fbc4a419d906cf"/><file name="growler.js" hash="816d275972bbe9c048033643755fb194"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="ajaxcart.xml" hash="c3ec794d08c15150d302bdfff95cec55"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Hardik_Ajaxcart.xml" hash="81451d4f81af3650b8151344bbc1e865"/></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HardikAjaxCart</name>
4
+ <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
14
  You can refer the default layout update entries in admin panel for further details.&#xD;
15
  &#xD;
16
  NOTE: Please confirm that the block which you are adding in layout update entries is under &lt;strong&gt;default&lt;/strong&gt; handle or under &lt;strong&gt;ajaxcart&lt;/strong&gt; handle. You can refer ajaxcart.xml frontend layout file for further details.</description>
17
+ <notes>added file upload functionality to support custom product option type file.</notes>
18
  <authors><author><name>Hardik Gajjar</name><user>hardik_krishinc</user><email>hardik.gajjar@krishinc.com</email></author></authors>
19
+ <date>2013-01-02</date>
20
+ <time>10:41:57</time>
21
+ <contents><target name="magelocal"><dir name="Hardik"><dir name="Ajaxcart"><dir name="Block"><dir name="Adminhtml"><file name="Info.php" hash="8fab3b7d0b1390dcc80a037c66b1ba7f"/><file name="Url.php" hash="ed7b1ff4b0f4ad33d45cfd301dba4227"/></dir></dir><dir name="Helper"><file name="Data.php" hash="773174c4f49cccc57be68acb1e0027e5"/></dir><dir name="Model"><file name="Observer.php" hash="25a046b451673ced3055f9dbd16cbc08"/><file name="Response.php" hash="c8032d2b23f6073be31f33dd47a2448e"/></dir><dir name="controllers"><dir name="Checkout"><file name="CartController.php" hash="1fbdb0b12a18522a9aaafc46fda4c7e3"/></dir></dir><dir name="etc"><file name="config.xml" hash="2e2fde0f031718730dfacfaaa6890328"/><file name="system.xml" hash="70e92e5d3c03d7b462e72ba3a8eaca1f"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="ajaxcart"><file name="ajaxcart.js" hash="879c93b05d725657cace5793ef31739a"/><file name="growler.css" hash="c13a01e28cb4eb98b1fbc4a419d906cf"/><file name="growler.js" hash="816d275972bbe9c048033643755fb194"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="ajaxcart.xml" hash="c3ec794d08c15150d302bdfff95cec55"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Hardik_Ajaxcart.xml" hash="81451d4f81af3650b8151344bbc1e865"/></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>
skin/frontend/base/default/ajaxcart/ajaxcart.js CHANGED
@@ -57,47 +57,99 @@ var ajaxcart = {
57
  }
58
  });
59
  } else {
60
- var url = obj.form.action,
61
- data = obj.form.serialize();
62
 
63
- new Ajax.Request(url, {
64
- method : 'post',
65
- postBody : data,
66
- onCreate : function() {
67
- _this.g.warn("Processing", {life: 5});
68
- },
69
- onSuccess : function(response) {
70
- // Handle the response content...
71
- try{
72
- var res = response.responseText.evalJSON();
73
-
74
- if(res) {
75
- if(res.r == 'success') {
76
- if(res.message) {
77
- _this.showSuccess(res.message);
78
- } else {
79
- _this.showSuccess('Item was added into cart.');
80
- }
81
 
82
  //update all blocks here
83
  _this.updateBlocks(res.update_blocks);
84
 
85
- } else {
86
- if(typeof res.messages != 'undefined') {
87
- _this.showError(res.messages);
88
- } else {
89
- _this.showError("Something bad happened");
90
- }
91
- }
92
- } else {
93
- _this.showError("Something bad happened");
94
- }
95
- } catch(e) {
96
- console.log(e);
97
- _this.showError("Something bad happened");
98
- }
99
- }
100
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  }
102
  } catch(e) {
103
  console.log(e);
57
  }
58
  });
59
  } else {
60
+ if(typeof obj.form.down('input[type=file]') != 'undefined') {
 
61
 
62
+ //use iframe
63
+
64
+ obj.form.insert('<iframe id="upload_target" name="upload_target" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>');
65
+
66
+ var iframe = $('upload_target');
67
+ iframe.observe('load', function(){
68
+ // Handle the response content...
69
+ try{
70
+ var res = iframe.contentWindow.document.body.innerText;
71
+ res = res.evalJSON();
72
+
73
+ if(res) {
74
+ if(res.r == 'success') {
75
+ if(res.message) {
76
+ _this.showSuccess(res.message);
77
+ } else {
78
+ _this.showSuccess('Item was added into cart.');
79
+ }
80
 
81
  //update all blocks here
82
  _this.updateBlocks(res.update_blocks);
83
 
84
+ } else {
85
+ if(typeof res.messages != 'undefined') {
86
+ _this.showError(res.messages);
87
+ } else {
88
+ _this.showError("Something bad happened");
89
+ }
90
+ }
91
+ } else {
92
+ _this.showError("Something bad happened");
93
+ }
94
+ } catch(e) {
95
+ console.log(e);
96
+ _this.showError("Something bad happened");
97
+ }
98
+ });
99
+
100
+ obj.form.target = 'upload_target';
101
+
102
+ //show loading
103
+ _this.g.warn("Processing", {life: 5});
104
+
105
+ obj.form.submit();
106
+ return true;
107
+
108
+ } else {
109
+ //use ajax
110
+
111
+ var url = obj.form.action,
112
+ data = obj.form.serialize();
113
+
114
+ new Ajax.Request(url, {
115
+ method : 'post',
116
+ postBody : data,
117
+ onCreate : function() {
118
+ _this.g.warn("Processing", {life: 5});
119
+ },
120
+ onSuccess : function(response) {
121
+ // Handle the response content...
122
+ try{
123
+ var res = response.responseText.evalJSON();
124
+
125
+ if(res) {
126
+ if(res.r == 'success') {
127
+ if(res.message) {
128
+ _this.showSuccess(res.message);
129
+ } else {
130
+ _this.showSuccess('Item was added into cart.');
131
+ }
132
+
133
+ //update all blocks here
134
+ _this.updateBlocks(res.update_blocks);
135
+
136
+ } else {
137
+ if(typeof res.messages != 'undefined') {
138
+ _this.showError(res.messages);
139
+ } else {
140
+ _this.showError("Something bad happened");
141
+ }
142
+ }
143
+ } else {
144
+ _this.showError("Something bad happened");
145
+ }
146
+ } catch(e) {
147
+ console.log(e);
148
+ _this.showError("Something bad happened");
149
+ }
150
+ }
151
+ });
152
+ }
153
  }
154
  } catch(e) {
155
  console.log(e);