HusseyCoding_AjaxCartPopup - Version 1.2.1

Version Notes

Added cart page ajax quantity update and remove functionality

Download this release

Release Info

Developer Hussey Coding
Extension HusseyCoding_AjaxCartPopup
Version 1.2.1
Comparing to
See all releases


Version 1.2.1

app/code/community/HusseyCoding/AjaxCartPopup/Block/Cart.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_AjaxCartPopup_Block_Cart extends Mage_Core_Block_Template
3
+ {
4
+ public function isEnabled()
5
+ {
6
+ return Mage::getStoreConfig('ajaxcartpopup/ajax/cart_enabled');
7
+ }
8
+
9
+ public function getUpdateUrl()
10
+ {
11
+ return $this->helper('ajaxcartpopup')->getUpdateUrl();
12
+ }
13
+ }
app/code/community/HusseyCoding/AjaxCartPopup/Block/Popup.php ADDED
@@ -0,0 +1,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_AjaxCartPopup_Block_Popup extends Mage_Checkout_Block_Cart_Sidebar
3
+ {
4
+ private $_currentcategory;
5
+ private $_currentproduct;
6
+ private $_carthelper;
7
+ private $_checkouthelper;
8
+ private $_urlhelper;
9
+ private $_customersession;
10
+ private $_thisrequest;
11
+ private $_currenturl;
12
+ private $_extracount = 0;
13
+ private $_taxconfig;
14
+
15
+ public function _beforeToHtml()
16
+ {
17
+ if ($this->_getRequest()->getParam('ajaxcartpopup')):
18
+ $this->setTemplate('ajaxcartpopup/popupbody.phtml');
19
+ endif;
20
+ }
21
+
22
+ public function isEnabled()
23
+ {
24
+ return Mage::getStoreConfig('ajaxcartpopup/general/enabled');
25
+ }
26
+
27
+ private function _getCurrentCategory()
28
+ {
29
+ if (!isset($this->_currentcategory)):
30
+ $this->_currentcategory = false;
31
+ if ($category = Mage::registry('current_category')):
32
+ $this->_currentcategory = $category;
33
+ endif;
34
+ endif;
35
+
36
+ return $this->_currentcategory;
37
+ }
38
+
39
+ private function _getCurrentProduct()
40
+ {
41
+ if (!isset($this->_currentproduct)):
42
+ $this->_currentproduct = false;
43
+ if ($product = Mage::registry('current_product')):
44
+ $this->_currentproduct = $product;
45
+ endif;
46
+ endif;
47
+
48
+ return $this->_currentproduct;
49
+ }
50
+
51
+ public function isProductPage()
52
+ {
53
+ if ($this->_getCurrentProduct()):
54
+ return true;
55
+ endif;
56
+
57
+ return false;
58
+ }
59
+
60
+ public function getCategoryUrl()
61
+ {
62
+ if ($category = $this->_getCurrentCategory()):
63
+ return $category->getUrl();
64
+ endif;
65
+
66
+ return '';
67
+ }
68
+
69
+ public function getCategoryName()
70
+ {
71
+ if ($category = $this->_getCurrentCategory()):
72
+ $name = $category->getName();
73
+ return addslashes($name);
74
+ endif;
75
+
76
+ return '';
77
+ }
78
+
79
+ public function getProductImageUrl()
80
+ {
81
+ if ($product = $this->_getCurrentProduct()):
82
+ return $this->helper('catalog/image')->init($product, 'small_image')->resize(135);
83
+ endif;
84
+
85
+ return '';
86
+ }
87
+
88
+ public function getProductName()
89
+ {
90
+ if ($product = $this->_getCurrentProduct()):
91
+ $name = $product->getName();
92
+ return addslashes($name);
93
+ endif;
94
+
95
+ return '';
96
+ }
97
+
98
+ private function _getCartHelper()
99
+ {
100
+ if (!isset($this->_carthelper)):
101
+ $this->_carthelper = $this->helper('checkout/cart');
102
+ endif;
103
+
104
+ return $this->_carthelper;
105
+ }
106
+
107
+ private function _getCheckoutHelper()
108
+ {
109
+ if (!isset($this->_checkouthelper)):
110
+ $this->_checkouthelper = $this->helper('checkout');
111
+ endif;
112
+
113
+ return $this->_checkouthelper;
114
+ }
115
+
116
+ private function _getUrlHelper()
117
+ {
118
+ if (!isset($this->_urlhelper)):
119
+ $this->_urlhelper = $this->helper('core/url');
120
+ endif;
121
+
122
+ return $this->_urlhelper;
123
+ }
124
+
125
+ private function _getCurrentUrl()
126
+ {
127
+ if (!isset($this->_currenturl)):
128
+ if ($this->_getRequest()->isXmlHttpRequest() && $this->_getRequest()->getServer('HTTP_REFERER')):
129
+ $this->_currenturl = $this->_getRequest()->getServer('HTTP_REFERER');
130
+ else:
131
+ $this->_currenturl = $this->_getUrlHelper()->getCurrentUrl();
132
+ endif;
133
+
134
+ endif;
135
+
136
+ return $this->_currenturl;
137
+ }
138
+
139
+ public function showPopup()
140
+ {
141
+ if ($count = $this->_getCartCount()):
142
+ if ($count != $this->_getCustomerSession()->getCartCount()):
143
+ $this->_updateCartCount();
144
+ if ($this->_showPopupOnAdd()):
145
+ return 'true';
146
+ endif;
147
+ endif;
148
+ endif;
149
+
150
+ return 'false';
151
+ }
152
+
153
+ private function _getCartCount()
154
+ {
155
+ return $this->_getCartHelper()->getSummaryCount();
156
+ }
157
+
158
+ private function _getCustomerSession()
159
+ {
160
+ if (!isset($this->_customersession)):
161
+ $this->_customersession = Mage::getSingleton('customer/session');
162
+ endif;
163
+
164
+ return $this->_customersession;
165
+ }
166
+
167
+ public function showPopupOnAdd()
168
+ {
169
+ if ($this->_showPopupOnAdd()):
170
+ return 'true';
171
+ endif;
172
+
173
+ return 'false';
174
+ }
175
+
176
+ private function _showPopupOnAdd()
177
+ {
178
+ return Mage::getStoreConfig('ajaxcartpopup/popup/show_on_add');
179
+ }
180
+
181
+ private function _updateCartCount()
182
+ {
183
+ $this->_getCustomerSession()->setCartCount($this->_getCartCount());
184
+ }
185
+
186
+ private function _getRequest()
187
+ {
188
+ if (!isset($this->_thisrequest)):
189
+ $this->_thisrequest = Mage::app()->getRequest();
190
+ endif;
191
+
192
+ return $this->_thisrequest;
193
+ }
194
+
195
+ public function emptyCart()
196
+ {
197
+ if ($this->_getCartCount()):
198
+ return 'false';
199
+ endif;
200
+
201
+ return 'true';
202
+ }
203
+
204
+ public function getCheckoutUrl()
205
+ {
206
+ return $this->_getCheckoutUrl();
207
+ }
208
+
209
+ private function _getCheckoutUrl()
210
+ {
211
+ if (Mage::getStoreConfig('checkout/options/onepage_checkout_enabled')):
212
+ return Mage::getUrl('checkout/onepage', array('_secure' => true));
213
+ endif;
214
+
215
+ return Mage::getUrl('checkout/multishipping', array('_secure' => true));
216
+ }
217
+
218
+ public function displayCartButton()
219
+ {
220
+ return Mage::getStoreConfig('ajaxcartpopup/ajax/cart_button');
221
+ }
222
+
223
+ public function displayCheckoutButton()
224
+ {
225
+ return Mage::getStoreConfig('ajaxcartpopup/ajax/checkout_button');
226
+ }
227
+
228
+ public function getCartUrl()
229
+ {
230
+ return $this->_getCartUrl();
231
+ }
232
+
233
+ private function _getCartUrl()
234
+ {
235
+ return $this->_getCartHelper()->getCartUrl();
236
+ }
237
+
238
+ public function ajaxEnabled()
239
+ {
240
+ if (Mage::getStoreConfig('ajaxcartpopup/ajax/ajax_enabled')):
241
+ if (!$this->_isCartEditPage()):
242
+ return 'true';
243
+ endif;
244
+ endif;
245
+
246
+ return 'false';
247
+ }
248
+
249
+ private function _isCartEditPage()
250
+ {
251
+ $currenturl = $this->_getCurrentUrl();
252
+ $editpage = $this->_getCartUrl() . 'configure/';
253
+
254
+ return strpos($currenturl, $editpage) === 0 ? true : false;
255
+ }
256
+
257
+ public function getSlideSpeed()
258
+ {
259
+ $speed = (float) Mage::getStoreConfig('ajaxcartpopup/popup/slide_speed');
260
+
261
+ return !empty($speed) ? $speed : 0.3;
262
+ }
263
+
264
+ public function getUpdateUrl()
265
+ {
266
+ return $this->helper('ajaxcartpopup')->getUpdateUrl();
267
+ }
268
+
269
+ public function getAutoCloseTime()
270
+ {
271
+ $timer = (float) Mage::getStoreConfig('ajaxcartpopup/popup/popup_close_timer');
272
+
273
+ return !empty($timer) ? $timer : 'false';
274
+ }
275
+
276
+ private function _getProductLimit()
277
+ {
278
+ $limit = (int) Mage::getStoreConfig('ajaxcartpopup/popup/product_limit');
279
+ if ($limit <= 0):
280
+ $limit = 3;
281
+ elseif ($limit > 10):
282
+ $limit = 10;
283
+ endif;
284
+
285
+ return $limit;
286
+ }
287
+
288
+ public function getProductLimit()
289
+ {
290
+ return $this->_getProductLimit();
291
+ }
292
+
293
+ public function getDeleteUrl($itemid)
294
+ {
295
+ return Mage::getUrl('checkout/cart/delete', array('id' => $itemid, Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->_getUrlHelper()->getEncodedUrl()));
296
+ }
297
+
298
+ public function getPopupItems()
299
+ {
300
+ $items = $this->_getItems();
301
+ $limit = $this->getProductLimit();
302
+ $extra = count($items) - $limit;
303
+ $extra = $extra < 0 ? 0 : $extra;
304
+ $this->_extracount = $extra;
305
+ $items = array_slice($items, 0, $limit);
306
+
307
+ return $items;
308
+ }
309
+
310
+ private function _getItems()
311
+ {
312
+ $items = parent::getItems();
313
+
314
+ return array_reverse($items);
315
+ }
316
+
317
+ public function getExtraCount()
318
+ {
319
+ return $this->_extracount;
320
+ }
321
+
322
+ public function getProductUrl($item)
323
+ {
324
+ return $this->_getProductFromItem($item)->getProductUrl();
325
+ }
326
+
327
+ public function getShortDescription($item)
328
+ {
329
+ if (Mage::getStoreConfig('ajaxcartpopup/popup/short_description')):
330
+ if ($description = $this->_getProductFromItem($item)->getShortDescription()):
331
+ return $description;
332
+ endif;
333
+ endif;
334
+
335
+ return false;
336
+ }
337
+
338
+ private function _getProductFromItem($item)
339
+ {
340
+ $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
341
+
342
+ return $product;
343
+ }
344
+
345
+ public function getItemMessages($item)
346
+ {
347
+ $item->checkData();
348
+ $itemmessages = $item->getMessage(false);
349
+ $messages = array();
350
+ if (!empty($itemmessages)) {
351
+ foreach ($itemmessages as $message) {
352
+ $message = $this->escapeHtml($message);
353
+ $messages[] = array(
354
+ 'text' => $message,
355
+ 'type' => $item->getHasError() ? 'error' : 'notice'
356
+ );
357
+ }
358
+ }
359
+
360
+ return $messages;
361
+ }
362
+
363
+ public function getItemProductPrice($item)
364
+ {
365
+ if ($this->_getTaxConfig()):
366
+ $price = $item->getPriceInclTax();
367
+ else:
368
+ $price = $item->getPrice();
369
+ endif;
370
+
371
+ return $this->_formatPrice($price);
372
+ }
373
+
374
+ public function getItemRowPrice($item)
375
+ {
376
+ if ($this->_getTaxConfig()):
377
+ $price = $item->getRowTotalInclTax();
378
+ else:
379
+ $price = $item->getRowTotal();
380
+ endif;
381
+
382
+ return $this->_formatPrice($price);
383
+ }
384
+
385
+ private function _formatPrice($price)
386
+ {
387
+ return $this->_getCheckoutHelper()->formatPrice($price);
388
+ }
389
+
390
+ public function getRelatedProducts($item)
391
+ {
392
+ $limit = (int) Mage::getStoreConfig('ajaxcartpopup/popup/related_product_limit');
393
+ if ($limit < 0):
394
+ $limit = 0;
395
+ elseif ($limit > 10):
396
+ $limit = 10;
397
+ endif;
398
+
399
+ if (!empty($limit)):
400
+ $related = $this->_getProductFromItem($item)->getRelatedProductCollection()
401
+ ->addAttributeToSelect('name')
402
+ ->addAttributeToSelect('thumbnail')
403
+ ->setPositionOrder()
404
+ ->addStoreFilter();
405
+ $related->getSelect()->limit($limit);
406
+
407
+ if ($related->count()):
408
+ return $related;
409
+ endif;
410
+ endif;
411
+
412
+ return false;
413
+ }
414
+
415
+ public function getCartSubtotal()
416
+ {
417
+ if ($this->_getTaxConfig()):
418
+ return $this->_formatPrice($this->getSubtotal(false));
419
+ else:
420
+ return $this->_formatPrice($this->getSubtotal(true));
421
+ endif;
422
+ }
423
+
424
+ private function _getTaxConfig()
425
+ {
426
+ if (!isset($this->_taxconfig)):
427
+ $this->_taxconfig = Mage::getStoreConfig('ajaxcartpopup/popup/incl_tax');
428
+ endif;
429
+
430
+ return $this->_taxconfig;
431
+ }
432
+
433
+ public function getClickOpen()
434
+ {
435
+ if (Mage::getStoreConfig('ajaxcartpopup/popup/click_open')):
436
+ return 'true';
437
+ endif;
438
+
439
+ return 'false';
440
+ }
441
+ }
app/code/community/HusseyCoding/AjaxCartPopup/Helper/Data.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_AjaxCartPopup_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function updateCartCount()
5
+ {
6
+ $count = Mage::helper('checkout/cart')->getSummaryCount();
7
+ Mage::getSingleton('customer/session')->setCartCount($count);
8
+ }
9
+
10
+ public function getCartItemCount()
11
+ {
12
+ $allitems = Mage::getSingleton('checkout/cart')->getItems();
13
+ return count($allitems);
14
+ }
15
+
16
+ public function getDeleteUrl($itemid)
17
+ {
18
+ return Mage::getUrl('checkout/cart/delete', array('id' => $itemid, Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core/url')->getEncodedUrl()));
19
+ }
20
+
21
+ public function getCartCount()
22
+ {
23
+ return Mage::helper('checkout/cart')->getSummaryCount();
24
+ }
25
+
26
+ public function getUpdateUrl()
27
+ {
28
+ return Mage::getUrl('checkout/cart/updatePost');
29
+ }
30
+ }
app/code/community/HusseyCoding/AjaxCartPopup/controllers/CartController.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once("Mage/Checkout/controllers/CartController.php");
3
+ class HusseyCoding_AjaxCartPopup_CartController extends Mage_Checkout_CartController
4
+ {
5
+ public function addAction()
6
+ {
7
+ if (!Mage::getStoreConfig('ajaxcartpopup/general/enabled') || !Mage::getStoreConfig('ajaxcartpopup/ajax/ajax_enabled')):
8
+ return parent::addAction();
9
+ endif;
10
+
11
+ $items = Mage::getSingleton('checkout/cart')->init()->getItems();
12
+ $countbefore = count($items);
13
+
14
+ parent::addAction();
15
+
16
+ $this->getResponse()
17
+ ->clearHeaders()
18
+ ->clearBody();
19
+ $this->getResponse()->setHeader("Content-Type", "text/html; charset=UTF-8")
20
+ ->setHttpResponseCode(200)
21
+ ->isRedirect(0);
22
+
23
+ $lastmessage = Mage::getSingleton('checkout/session')->getMessages()->getLastAddedMessage();
24
+ $result = $lastmessage->getType() == 'success' ? 'success' : false;
25
+
26
+ $message = '';
27
+ $linktext = '';
28
+ $popuphtml = '';
29
+ $imageurl = '';
30
+ $productname = '';
31
+ $itemid = '';
32
+ $deleteurl = '';
33
+ $product = $this->_initProduct();
34
+ if ($result == 'success'):
35
+ $this->loadLayout()->_initLayoutMessages('checkout/session');
36
+ $message = Mage::app()->getLayout()->getMessagesBlock()->toHtml();
37
+ $message = strip_tags($message);
38
+ $linktext = $this->_getLinkText();
39
+ $popuphtml = $this->getLayout()->getBlock('ajaxcartpopup')->toHtml();
40
+ if (Mage::app()->getRequest()->getParam('imagedetail')):
41
+ $imageurl = (string) Mage::helper('catalog/image')->init($product, 'small_image')->resize(135);
42
+ $productname = addslashes($product->getName());
43
+ endif;
44
+ elseif ($this->getRequest()->getParam('isproductpage')):
45
+ $this->loadLayout()->_initLayoutMessages('checkout/session');
46
+ $message = Mage::app()->getLayout()->getMessagesBlock()->toHtml();
47
+ $message = strip_tags($message);
48
+ else:
49
+ $result = $product->getProductUrl();
50
+ endif;
51
+
52
+ Mage::helper('ajaxcartpopup')->updateCartCount();
53
+
54
+ if (Mage::helper('ajaxcartpopup')->getCartItemCount() > $countbefore):
55
+ $allitems = Mage::getSingleton('checkout/cart')->getItems()->getData();
56
+ $itemid = array_pop($allitems);
57
+ $itemid = $itemid['item_id'];
58
+ $deleteurl = Mage::helper('ajaxcartpopup')->getDeleteUrl($itemid);
59
+ endif;
60
+
61
+ $this->getResponse()->setBody(Zend_Json::encode(array(
62
+ 'result' => $result,
63
+ 'message' => $message,
64
+ 'linktext' => $linktext,
65
+ 'popuphtml' => $popuphtml,
66
+ 'imageurl' => $imageurl,
67
+ 'productname' => $productname,
68
+ 'itemid' => $itemid,
69
+ 'deleteurl' => $deleteurl
70
+ )));
71
+ }
72
+
73
+ public function deleteAction()
74
+ {
75
+ parent::deleteAction();
76
+
77
+ if ($this->getRequest()->getParam('ajaxcartpopup')):
78
+ $result = 'success';
79
+ foreach (Mage::getSingleton('checkout/session')->getMessages()->getItems() as $message):
80
+ if ($message->getType() == 'error'):
81
+ $result = Mage::helper('checkout/cart')->getCartUrl();
82
+ endif;
83
+ break;
84
+ endforeach;
85
+
86
+ $this->getResponse()
87
+ ->clearHeaders()
88
+ ->clearBody();
89
+ $this->getResponse()
90
+ ->setHeader("Content-Type", "text/html; charset=UTF-8")
91
+ ->setHttpResponseCode(200)
92
+ ->isRedirect(0);
93
+
94
+ if ($this->getRequest()->getParam('iscartpage')):
95
+ $totals = '';
96
+ if ($result == 'success'):
97
+ $totals = $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('checkout/cart/totals.phtml')->toHtml();
98
+ endif;
99
+
100
+ $this->getResponse()->setBody(Zend_Json::encode(array(
101
+ 'result' => $result,
102
+ 'totals' => $totals
103
+ )));
104
+ else:
105
+ $linktext = '';
106
+ $popuphtml = '';
107
+ $emptycart = '';
108
+ if ($result == 'success'):
109
+ $this->loadLayout()->_initLayoutMessages('checkout/session');
110
+ $linktext = $this->_getLinkText();
111
+ $popuphtml = $this->getLayout()->getBlock('ajaxcartpopup')->toHtml();
112
+ $emptycart = Mage::helper('ajaxcartpopup')->getCartCount() ? false : true;
113
+ endif;
114
+
115
+ $this->getResponse()->setBody(Zend_Json::encode(array(
116
+ 'result' => $result,
117
+ 'linktext' => $linktext,
118
+ 'popuphtml' => $popuphtml,
119
+ 'emptycart' => $emptycart
120
+ )));
121
+ endif;
122
+ endif;
123
+ }
124
+
125
+ public function updatePostAction()
126
+ {
127
+ parent::updatePostAction();
128
+
129
+ if ($this->getRequest()->getParam('ajaxcartpopup') && $this->getRequest()->getParam('ajaxupdatequantity')):
130
+ $result = 'success';
131
+ $this->loadLayout()->_initLayoutMessages('checkout/session');
132
+ foreach (Mage::getSingleton('checkout/session')->getMessages()->getItems() as $message):
133
+ if ($message->getType() == 'error' || $message->getType() == 'exception'):
134
+ $result = Mage::helper('checkout/cart')->getCartUrl();
135
+ endif;
136
+ break;
137
+ endforeach;
138
+
139
+ $this->getResponse()
140
+ ->clearHeaders()
141
+ ->clearBody();
142
+ $this->getResponse()
143
+ ->setHeader("Content-Type", "text/html; charset=UTF-8")
144
+ ->setHttpResponseCode(200)
145
+ ->isRedirect(0);
146
+
147
+ if ($this->getRequest()->getParam('iscartpage')):
148
+ $totals = '';
149
+ if ($result == 'success'):
150
+ $totals = $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('checkout/cart/totals.phtml')->toHtml();
151
+ endif;
152
+
153
+ $this->getResponse()->setBody(Zend_Json::encode(array(
154
+ 'result' => $result,
155
+ 'totals' => $totals
156
+ )));
157
+ else:
158
+ $linktext = '';
159
+ $popuphtml = '';
160
+ $emptycart = '';
161
+ if ($result == 'success'):
162
+ $this->loadLayout()->_initLayoutMessages('checkout/session');
163
+ $linktext = $this->_getLinkText();
164
+ $popuphtml = $this->getLayout()->getBlock('ajaxcartpopup')->toHtml();
165
+ $emptycart = Mage::helper('ajaxcartpopup')->getCartCount() ? false : true;
166
+ endif;
167
+
168
+ $this->getResponse()->setBody(Zend_Json::encode(array(
169
+ 'result' => $result,
170
+ 'linktext' => $linktext,
171
+ 'popuphtml' => $popuphtml,
172
+ 'emptycart' => $emptycart
173
+ )));
174
+ endif;
175
+ endif;
176
+ }
177
+
178
+ private function _getLinkText()
179
+ {
180
+ if ($block = $this->getLayout()->getBlock('minicart_head')):
181
+ $cartlink = $block->toHtml();
182
+ preg_match('/<a.+skip-cart.+>(.+)<\/a>/Us', $cartlink, $linktext);
183
+ else:
184
+ $toplinks = $this->getLayout()->getBlock('top.links')->toHtml();
185
+ preg_match('/<a.+top-link-cart.+>(.+)<\/a>/Us', $toplinks, $linktext);
186
+ endif;
187
+
188
+ return $linktext[1];
189
+ }
190
+ }
app/code/community/HusseyCoding/AjaxCartPopup/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <ajaxcartpopup module="ajaxcartpopup">
15
+ <title>Ajax Cart Popup</title>
16
+ </ajaxcartpopup>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/community/HusseyCoding/AjaxCartPopup/etc/config.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_AjaxCartPopup>
5
+ <version>1.2.1</version>
6
+ </HusseyCoding_AjaxCartPopup>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <ajaxcartpopup>
11
+ <class>HusseyCoding_AjaxCartPopup_Helper</class>
12
+ </ajaxcartpopup>
13
+ </helpers>
14
+ <blocks>
15
+ <ajaxcartpopup>
16
+ <class>HusseyCoding_AjaxCartPopup_Block</class>
17
+ </ajaxcartpopup>
18
+ </blocks>
19
+ </global>
20
+ <frontend>
21
+ <layout>
22
+ <updates>
23
+ <ajaxcartpopup>
24
+ <file>ajaxcartpopup.xml</file>
25
+ </ajaxcartpopup>
26
+ </updates>
27
+ </layout>
28
+ <routers>
29
+ <checkout>
30
+ <args>
31
+ <modules>
32
+ <HusseyCoding_AjaxCartPopup before="Mage_Checkout">HusseyCoding_AjaxCartPopup</HusseyCoding_AjaxCartPopup>
33
+ </modules>
34
+ </args>
35
+ </checkout>
36
+ </routers>
37
+ </frontend>
38
+ </config>
app/code/community/HusseyCoding/AjaxCartPopup/etc/system.xml ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <ajaxcartpopup translate="label" module="ajaxcartpopup">
5
+ <label>Ajax Cart Popup</label>
6
+ <tab>husseycoding</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>1</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <general translate="label">
14
+ <label>General</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <enabled>
22
+ <label>Enabled</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <comment>Enable or disable extension entirely.</comment>
30
+ </enabled>
31
+ </fields>
32
+ </general>
33
+ <ajax translate="label">
34
+ <label>Ajax Functionality</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>2</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <fields>
41
+ <ajax_enabled>
42
+ <label>Enable Ajax Add To Cart</label>
43
+ <frontend_type>select</frontend_type>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ <sort_order>1</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>Enable or disable just ajax add to cart functionality, keeps the mini cart popup.</comment>
50
+ </ajax_enabled>
51
+ <cart_button>
52
+ <label>Display Cart Button</label>
53
+ <frontend_type>select</frontend_type>
54
+ <source_model>adminhtml/system_config_source_yesno</source_model>
55
+ <sort_order>2</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ </cart_button>
60
+ <checkout_button>
61
+ <label>Display Checkout Button</label>
62
+ <frontend_type>select</frontend_type>
63
+ <source_model>adminhtml/system_config_source_yesno</source_model>
64
+ <sort_order>3</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>1</show_in_store>
68
+ </checkout_button>
69
+ <cart_enabled>
70
+ <label>Enable Ajax Cart Page</label>
71
+ <frontend_type>select</frontend_type>
72
+ <source_model>adminhtml/system_config_source_yesno</source_model>
73
+ <sort_order>4</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>1</show_in_website>
76
+ <show_in_store>1</show_in_store>
77
+ </cart_enabled>
78
+ </fields>
79
+ </ajax>
80
+ <popup translate="label">
81
+ <label>Cart Popup</label>
82
+ <frontend_type>text</frontend_type>
83
+ <sort_order>3</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ <fields>
88
+ <product_limit>
89
+ <label>Product Display Limit</label>
90
+ <frontend_type>text</frontend_type>
91
+ <sort_order>1</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ <comment>Limited to 10, defaults to 3.</comment>
96
+ </product_limit>
97
+ <slide_speed>
98
+ <label>Slide Out Speed</label>
99
+ <frontend_type>text</frontend_type>
100
+ <sort_order>2</sort_order>
101
+ <show_in_default>1</show_in_default>
102
+ <show_in_website>1</show_in_website>
103
+ <show_in_store>1</show_in_store>
104
+ <comment>Defaults to 0.3, higher is slower, 0 is instant.</comment>
105
+ </slide_speed>
106
+ <incl_tax>
107
+ <label>Prices Include Tax</label>
108
+ <frontend_type>select</frontend_type>
109
+ <source_model>adminhtml/system_config_source_yesno</source_model>
110
+ <sort_order>3</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>1</show_in_store>
114
+ </incl_tax>
115
+ <show_on_add>
116
+ <label>Show On Add To Cart</label>
117
+ <frontend_type>select</frontend_type>
118
+ <source_model>adminhtml/system_config_source_yesno</source_model>
119
+ <sort_order>4</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ <comment>Popup will show instead of the normal notice.</comment>
124
+ </show_on_add>
125
+ <popup_close_timer>
126
+ <label>Auto Close</label>
127
+ <frontend_type>text</frontend_type>
128
+ <sort_order>5</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>1</show_in_store>
132
+ <comment>Optional, value in seconds.</comment>
133
+ </popup_close_timer>
134
+ <short_description>
135
+ <label>Show Product Short Description</label>
136
+ <frontend_type>select</frontend_type>
137
+ <source_model>adminhtml/system_config_source_yesno</source_model>
138
+ <sort_order>6</sort_order>
139
+ <show_in_default>1</show_in_default>
140
+ <show_in_website>1</show_in_website>
141
+ <show_in_store>1</show_in_store>
142
+ <comment>Only shows for products with a short description.</comment>
143
+ </short_description>
144
+ <related_product_limit>
145
+ <label>Show Related Products</label>
146
+ <frontend_type>text</frontend_type>
147
+ <sort_order>7</sort_order>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ <comment>Optional, limited to 10</comment>
152
+ </related_product_limit>
153
+ <click_open>
154
+ <label>Show On Click</label>
155
+ <frontend_type>select</frontend_type>
156
+ <source_model>adminhtml/system_config_source_yesno</source_model>
157
+ <sort_order>8</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>1</show_in_store>
161
+ <comment>Show mini cart popup on click rather than mouseover.</comment>
162
+ </click_open>
163
+ </fields>
164
+ </popup>
165
+ </groups>
166
+ </ajaxcartpopup>
167
+ </sections>
168
+ </config>
app/code/community/HusseyCoding/Common/etc/system.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <husseycoding translate="label">
5
+ <label>Hussey Coding</label>
6
+ <sort_order>500</sort_order>
7
+ </husseycoding>
8
+ </tabs>
9
+ </config>
app/design/frontend/base/default/layout/ajaxcartpopup.xml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="before_body_end">
5
+ <block type="ajaxcartpopup/popup" name="ajaxcartpopup" template="ajaxcartpopup/popup.phtml" after="-">
6
+ <block type="ajaxcartpopup/popup" name="ajaxcartpopupbody" template="ajaxcartpopup/popupbody.phtml" />
7
+ </block>
8
+ <block type="core/template" name="ajaxnotice" template="ajaxcartpopup/notice.phtml" before="ajaxcartpopup" />
9
+ </reference>
10
+ <reference name="content">
11
+ <action method="unsetChild">
12
+ <name>cart_sidebar</name>
13
+ </action>
14
+ </reference>
15
+ <reference name="head">
16
+ <action method="addItem">
17
+ <type>skin_js</type>
18
+ <name>js/ajaxcartpopup.js</name>
19
+ </action>
20
+ <action method="addItem">
21
+ <type>skin_css</type>
22
+ <name>css/ajaxcartpopup.css</name>
23
+ </action>
24
+ </reference>
25
+ <reference name="right">
26
+ <action method="unsetChild">
27
+ <name>cart_sidebar</name>
28
+ </action>
29
+ </reference>
30
+ <reference name="left">
31
+ <action method="unsetChild">
32
+ <name>cart_sidebar</name>
33
+ </action>
34
+ </reference>
35
+ <reference name="minicart_head">
36
+ <action ifconfig="ajaxcartpopup/general/enabled" method="unsetChild">
37
+ <name>minicart_content</name>
38
+ </action>
39
+ </reference>
40
+ </default>
41
+ <disable_ajaxcartpopup>
42
+ <reference name="before_body_end">
43
+ <action method="unsetChild">
44
+ <name>ajaxcartpopup</name>
45
+ </action>
46
+ <action method="unsetChild">
47
+ <name>ajaxnotice</name>
48
+ </action>
49
+ </reference>
50
+ </disable_ajaxcartpopup>
51
+ <checkout_cart_index>
52
+ <update handle="disable_ajaxcartpopup" />
53
+ <reference name="head">
54
+ <action method="addItem">
55
+ <type>skin_js</type>
56
+ <name>js/ajaxcartpopup.js</name>
57
+ </action>
58
+ <action method="addItem">
59
+ <type>skin_css</type>
60
+ <name>css/ajaxcartpopup.css</name>
61
+ </action>
62
+ </reference>
63
+ <reference name="before_body_end">
64
+ <block type="ajaxcartpopup/cart" name="ajaxcartpage" template="ajaxcartpopup/cart.phtml" />
65
+ <block type="core/template" name="ajaxnotice" template="ajaxcartpopup/notice.phtml" />
66
+ </reference>
67
+ </checkout_cart_index>
68
+ <checkout_multishipping>
69
+ <update handle="disable_ajaxcartpopup" />
70
+ </checkout_multishipping>
71
+ <checkout_onepage_index>
72
+ <update handle="disable_ajaxcartpopup" />
73
+ </checkout_onepage_index>
74
+ </layout>
app/design/frontend/base/default/template/ajaxcartpopup/cart.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ thiscartpage = new cartpage();
5
+ thiscartpage.updateurl = "<?php echo $this->getUpdateUrl(); ?>";
6
+
7
+ thiscartpage.afterInit();
8
+ //]]>
9
+ </script>
10
+ <?php endif; ?>
app/design/frontend/base/default/template/ajaxcartpopup/notice.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <div id="ajaxnotice" style="display:none">
2
+ <div class="ajaxnotice_inner">
3
+ <div id="ajaxnotice_working">
4
+ <img src="<?php echo $this->getSkinUrl('images/ajaxcartpopup/loading.gif'); ?>" alt="" />
5
+ </div>
6
+ <div id="ajaxnotice_result"></div>
7
+ <div class="ajaxnotice_clearer"></div>
8
+ </div>
9
+ </div>
app/design/frontend/base/default/template/ajaxcartpopup/popup.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ thiscartpopup = new cartpopup();
5
+ <?php if ($this->isProductPage()): ?>
6
+ thiscartpopup.product = true;
7
+ thiscartpopup.backurl = "<?php echo $this->getCategoryUrl(); ?>";
8
+ thiscartpopup.backname = "<?php echo $this->getCategoryName(); ?>";
9
+ thiscartpopup.imageurl = "<?php echo $this->getProductImageUrl(); ?>";
10
+ thiscartpopup.productname = "<?php echo $this->getProductName(); ?>";
11
+ <?php endif; ?>
12
+ thiscartpopup.showpopup = <?php echo $this->showPopup(); ?>;
13
+ thiscartpopup.emptycart = <?php echo $this->emptyCart(); ?>;
14
+ <?php if ($this->displayCartButton()): ?>
15
+ thiscartpopup.cartbutton = "<?php echo $this->getSkinUrl('images/ajaxcartpopup/button.gif'); ?>";
16
+ thiscartpopup.carturl = "<?php echo $this->getCartUrl(); ?>";
17
+ thiscartpopup.carttext = "<?php echo $this->__('View Cart'); ?>";
18
+ <?php endif; ?>
19
+ <?php if ($this->displayCheckoutButton()): ?>
20
+ thiscartpopup.checkoutbutton = "<?php echo $this->getSkinUrl('images/ajaxcartpopup/button.gif'); ?>";
21
+ thiscartpopup.checkouturl = "<?php echo $this->getCheckoutUrl(); ?>";
22
+ thiscartpopup.checkouttext = "<?php echo $this->__('Checkout'); ?>";
23
+ <?php endif; ?>
24
+ thiscartpopup.ajaxenabled = <?php echo $this->ajaxEnabled(); ?>;
25
+ thiscartpopup.slidespeed = <?php echo $this->getSlideSpeed(); ?>;
26
+ thiscartpopup.deleteurls = [];
27
+ thiscartpopup.updateurl = "<?php echo $this->getUpdateUrl(); ?>";
28
+ thiscartpopup.showonadd = <?php echo $this->showPopupOnAdd(); ?>;
29
+ thiscartpopup.autoclose = false;
30
+ thiscartpopup.autoclosetime = <?php echo $this->getAutoCloseTime(); ?>;
31
+ thiscartpopup.clickopen = <?php echo $this->getClickOpen(); ?>;
32
+ //]]>
33
+ </script>
34
+ <div id="cartpopup" style="display:none">
35
+ <div id="cartpopup_slidecontainer">
36
+ <?php echo $this->getChildHtml('ajaxcartpopupbody'); ?>
37
+ </div>
38
+ </div>
39
+ <script type="text/javascript">
40
+ //<![CDATA[
41
+ thiscartpopup.afterInit();
42
+ Event.observe(window, "resize", function() {
43
+ thiscartpopup.positionAll();
44
+ });
45
+ //]]>
46
+ </script>
47
+ <?php endif; ?>
app/design/frontend/base/default/template/ajaxcartpopup/popupbody.phtml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="cartpopup_header">
2
+ <span><?php echo $this->__('Shopping Cart'); ?></span>
3
+ <a class="cartpopup_close" href="javascript:void(null)" onclick="thiscartpopup.hidePopup()"><?php echo $this->__('Close'); ?></a>
4
+ <div class="cartpopup_clear"></div>
5
+ </div>
6
+ <form id="cartpopup_form" action="javascript:thiscartpopup.updateQuantityAction()" method="post">
7
+ <table>
8
+ <thead>
9
+ <th class="lefttext" colspan="2"><?php echo $this->__('Product'); ?></th>
10
+ <th class="lefttext"><?php echo $this->__('Price'); ?></th>
11
+ <th class="centertext"><?php echo $this->__('Quantity'); ?></th>
12
+ <th class="centertext"><?php echo $this->__('Total'); ?></th>
13
+ </thead>
14
+ <tbody>
15
+ <?php foreach ($this->getPopupItems() as $item): ?>
16
+ <script type="text/javascript">
17
+ //<![CDATA[
18
+ thiscartpopup.deleteurls[<?php echo $item->getId(); ?>] = "<?php echo $this->getDeleteUrl($item->getId()); ?>";
19
+ //]]>
20
+ </script>
21
+ <?php $relatedproducts = $this->getRelatedProducts($item); ?>
22
+ <?php $borderclass = $relatedproducts ? ' noborder' : ''; ?>
23
+ <tr>
24
+ <?php $url = $this->getProductUrl($item); ?>
25
+ <td class="cartpopup_productimage<?php echo $borderclass; ?>">
26
+ <a href="<?php echo $url; ?>">
27
+ <img src="<?php echo Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail')->resize(60); ?>" alt="<?php echo $item->getName(); ?>" title="<?php echo $item->getName(); ?>" />
28
+ </a>
29
+ </td>
30
+ <td class="cartpopup_productname<?php echo $borderclass; ?>">
31
+ <a href="<?php echo $url; ?>"><?php echo $item->getName(); ?></a>
32
+ <?php if ($description = $this->getShortDescription($item)): ?>
33
+ <p class="short_description"><?php echo $description; ?></p>
34
+ <?php endif; ?>
35
+ <?php foreach ($this->getItemMessages($item) as $message): ?>
36
+ <p class="item-msg <?php echo $message['type']; ?>"><?php echo $message['text']; ?></p>
37
+ <?php endforeach; ?>
38
+ </td>
39
+ <td class="lefttext<?php echo $borderclass; ?>"><?php echo $this->getItemProductPrice($item); ?></td>
40
+ <td<?php echo $borderclass ? ' class="' . $borderclass . '"' : ''; ?>>
41
+ <input name="cart[<?php echo $item->getId(); ?>][qty]" value="<?php echo $item->getQty(); ?>" size="4" title="<?php echo $this->__('Quantity'); ?>" class="input-text qty" maxlength="12" />
42
+ <a class="cartpopup_remove" href="javascript:void(null)" onclick="thiscartpopup.removeFromCart(<?php echo $item->getId(); ?>)"><?php echo $this->__('Remove'); ?></a>
43
+ </td>
44
+ <td class="righttext<?php echo $borderclass; ?>"><?php echo $this->getItemRowPrice($item); ?></td>
45
+ </tr>
46
+ <?php if ($relatedproducts): ?>
47
+ <tr>
48
+ <td colspan="5" class="nopaddingtop">
49
+ <div class="lefttext"><?php echo $this->__('Related Products'); ?></div>
50
+ <?php foreach ($relatedproducts as $relatedproduct): ?>
51
+ <div class="cartpopup_related cartpopup_clear">
52
+ <div class="cartpopup_productimage">
53
+ <a href="<?php echo $relatedproduct->getProductUrl(); ?>" title="<?php echo $this->escapeHtml($relatedproduct->getName()); ?>">
54
+ <img src="<?php echo $this->helper('catalog/image')->init($relatedproduct, 'thumbnail')->resize(30); ?>" alt="<?php echo $this->escapeHtml($relatedproduct->getName()); ?>" />
55
+ </a>
56
+ </div>
57
+ <div class="cartpopup_productname">
58
+ <a href="<?php echo $relatedproduct->getProductUrl(); ?>"><?php echo $relatedproduct->getName(); ?></a>
59
+ </div>
60
+ </div>
61
+ <?php endforeach; ?>
62
+ </td>
63
+ </tr>
64
+ <?php endif; ?>
65
+ <?php endforeach; ?>
66
+ </tbody>
67
+ </table>
68
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
69
+ </form>
70
+ <div class="cartpopup_footer">
71
+ <?php if ($extracount = $this->getExtraCount()): ?>
72
+ <div class="cartpopup_cartlink">
73
+ <a href="<?php echo $this->getCartUrl(); ?>"><?php echo $this->__('View all products'); ?></a>
74
+ </div>
75
+ <?php endif; ?>
76
+ <div class="cartpopup_subtotal">
77
+ <div class="cartpopup_producttotal">
78
+ <?php echo $this->__('Total'); ?>: <?php echo $this->getCartSubtotal(); ?>
79
+ </div>
80
+ <a href="<?php echo $this->getCartUrl(); ?>">
81
+ <img src="<?php echo $this->getSkinUrl('images/ajaxcartpopup/button.gif'); ?>" alt="<?php echo $this->__('View Cart'); ?>" />
82
+ <div><?php echo $this->__('View Cart'); ?></div>
83
+ </a>
84
+ <a href="<?php echo $this->getCheckoutUrl(); ?>">
85
+ <img src="<?php echo $this->getSkinUrl('images/ajaxcartpopup/button.gif'); ?>" alt="<?php echo $this->__('Checkout'); ?>" />
86
+ <div><?php echo $this->__('Checkout'); ?></div>
87
+ </a>
88
+ <div class="cartpopup_clear"></div>
89
+ </div>
90
+ </div>
91
+ <div id="cartpopup_overlay">
92
+ <div class="cartpopup_overlay_center">
93
+ <img src="<?php echo $this->getSkinUrl('images/ajaxcartpopup/loading.gif'); ?>" alt="" />
94
+ </div>
95
+ </div>
app/etc/modules/HusseyCoding_AjaxCartPopup.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_AjaxCartPopup>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <HusseyCoding_Common />
9
+ </depends>
10
+ </HusseyCoding_AjaxCartPopup>
11
+ </modules>
12
+ </config>
app/etc/modules/HusseyCoding_Common.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_Common>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_Common>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>HusseyCoding_AjaxCartPopup</name>
4
+ <version>1.2.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Gives you both ajax add/remove cart functionality and a rollover mini cart popup.</summary>
10
+ <description>Remove page reloads when adding/removing and editing product quantities in the cart and add a mini cart popup to your 'My Cart' link with Ajax Cart Popup.&#xD;
11
+ &#xD;
12
+ This extension replaces the sidebar minicart and shows up to 10 products most recently added to the cart. There are also convenient links to the cart and checkout pages from the ajax and mini cart popups.&#xD;
13
+ &#xD;
14
+ Ajax Cart Popup will works all product types.</description>
15
+ <notes>Added cart page ajax quantity update and remove functionality</notes>
16
+ <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
17
+ <date>2015-06-08</date>
18
+ <time>12:02:19</time>
19
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="AjaxCartPopup"><dir name="Block"><file name="Cart.php" hash="1c2015b9082cf0418735e23d6063e8f4"/><file name="Popup.php" hash="6e0e2d567d3cab87382592d02f059a8e"/></dir><dir name="controllers"><file name="CartController.php" hash="452b1bc33e1aebd4778e835fbacdfb48"/></dir><dir name="etc"><file name="adminhtml.xml" hash="0e8cf41422012a721cefbb40a763b702"/><file name="config.xml" hash="23bae551d8fe2d124269d9e2f702085c"/><file name="system.xml" hash="f81637177507e6193ecb0a9a6f7f44a5"/></dir><dir name="Helper"><file name="Data.php" hash="c1f5cb33c97e2896335f2686e4a78c78"/></dir></dir><dir name="Common"><dir name="etc"><file name="system.xml" hash="6c9ba9f227b9adfc9abf97f17b46fdbf"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_AjaxCartPopup.xml" hash="112a71843351e85521ae9b66965b0112"/><file name="HusseyCoding_Common.xml" hash="31e82d3d9b3179c2fa9e002f9669da47"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="ajaxcartpopup.xml" hash="762a66cc9e1daa065202643b7e2f5356"/></dir><dir name="template"><dir name="ajaxcartpopup"><file name="cart.phtml" hash="e012b212b4a64b7a9416d2500209de86"/><file name="notice.phtml" hash="0dfcd36aac0783cfbb3331f2f7c2e3c3"/><file name="popupbody.phtml" hash="37fad39508776e3012ab4aad8579a22c"/><file name="popup.phtml" hash="008d78ec213185f5aa0dee99c4876c4a"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><file name="ajaxcartpopup.js" hash="b983e2f6ef214a2a196c26bb852ab25b"/></dir><dir name="css"><file name="ajaxcartpopup.css" hash="6dfa39936898305fbea01ce67c22be0d"/></dir><dir name="images"><dir name="ajaxcartpopup"><file name="button.gif" hash="ccafde0fa767eaf7faf20da4ea73c8bd"/><file name="loading.gif" hash="faa74e8c61fc64d5edb11613c7eead2c"/><file name="overlay.png" hash="0a949aa705c4792377b09bbd04668195"/></dir></dir></dir></dir></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
22
+ </package>
skin/frontend/base/default/css/ajaxcartpopup.css ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #cartpopup { position:absolute; top:-10000px; z-index:99998; }
2
+ #cartpopup .cartpopup_productimage img { display:block; border:1px solid #ccc; }
3
+ #cartpopup * { border-width:0; margin:0; padding:0; box-sizing:content-box; }
4
+ #cartpopup_slidecontainer { width:396px; border:1px solid #aaa; padding:10px; background-color:#fff; }
5
+ #cartpopup_slidecontainer .cartpopup_close { float:right; }
6
+ #cartpopup_slidecontainer .cartpopup_clear { clear:both; }
7
+ #cartpopup_slidecontainer .cartpopup_remove { margin-top:4px; }
8
+ #cartpopup_slidecontainer .cartpopup_header { position:relative; height:26px; }
9
+ #cartpopup_slidecontainer .cartpopup_header span { font-size:16px; line-height:22px; position:absolute; left:5px; bottom:5px; }
10
+ #cartpopup_slidecontainer .cartpopup_header a { font-size:12px; position:absolute; right:7px; bottom:5px; text-transform:uppercase; line-height:20px; }
11
+ #cartpopup_slidecontainer tbody input { margin:0 !important; border:1px solid #ccc; font-size:13px; height:15px; line-height:17px; text-align:center; }
12
+ #cartpopup_slidecontainer tbody a { display:block; font-size:13px; }
13
+ #cartpopup_slidecontainer tbody .cartpopup_productname a { font-size:11px; text-align:left; }
14
+ #cartpopup_slidecontainer tbody .cartpopup_productname p.short_description { font-size:10px; text-align:left; padding-top:5px; }
15
+ #cartpopup_slidecontainer tbody .cartpopup_productname .error,
16
+ #cartpopup_slidecontainer tbody .cartpopup_productname .notice { font-size:10px; text-align:left; }
17
+ #cartpopup_slidecontainer .cartpopup_cartlink { font-size:14px; line-height:17px; position:absolute; left:7px; bottom:2px; }
18
+ #cartpopup_slidecontainer td { padding:7px; border-bottom:1px dotted #ccc; text-align:center; }
19
+ #cartpopup_slidecontainer .righttext { text-align:right !important; }
20
+ #cartpopup_slidecontainer .lefttext { text-align:left !important; }
21
+ #cartpopup_slidecontainer .centertext { text-align:center !important; }
22
+ #cartpopup_slidecontainer td.cartpopup_productimage a { display:inline; }
23
+ #cartpopup_slidecontainer td.cartpopup_productimage { width:1%; }
24
+ #cartpopup_slidecontainer tbody .price { font-size:13px; text-align:right; }
25
+ #cartpopup_slidecontainer .cartpopup_footer { height:59px; position:relative; }
26
+ #cartpopup_slidecontainer .cartpopup_footer img { border-width:0; }
27
+ #cartpopup_slidecontainer .cartpopup_footer .cartpopup_subtotal { position:absolute; right:0; top:7px; }
28
+ #cartpopup_slidecontainer .cartpopup_footer .cartpopup_producttotal { font-size:13px; line-height:17px; float:right; border-bottom:1px solid #ccc; padding-right:7px; }
29
+ #cartpopup_slidecontainer .cartpopup_footer .cartpopup_subtotal a { float:left; clear:right; margin:7px 0 0 7px; }
30
+ #cartpopup_slidecontainer .cartpopup_footer .cartpopup_subtotal a { text-transform:uppercase; text-decoration:none; color:#000; font-size:12px; font-weight:bold; position:relative; }
31
+ #cartpopup_slidecontainer .cartpopup_footer .cartpopup_subtotal a div { position:absolute; top:0; left:0; width:87px; text-align:center; line-height:24px; }
32
+ #cartpopup_slidecontainer table { width:396px; }
33
+ #cartpopup_slidecontainer thead th { height:22px; padding:2px 7px 0; font-size:13px; color:#fff; background-color:#2f2f2f; vertical-align:middle; }
34
+ #cartpopup_slidecontainer #cartpopup_overlay { height:100%; width:100%; position:absolute; left:0; top:0; background:url(../images/ajaxcartpopup/overlay.png) center; }
35
+ #cartpopup_slidecontainer .cartpopup_overlay_center { height:50%; width:100%; position:relative; }
36
+ #cartpopup_slidecontainer .cartpopup_overlay_center img { position:absolute; bottom:-12px; left:197px; }
37
+ #cartpopup_slidecontainer .cartpopup_related div { float:left; padding:7px; }
38
+ #cartpopup_slidecontainer .noborder { border-width:0; }
39
+ #cartpopup_slidecontainer .nopaddingtop { padding-top:0; }
40
+
41
+ #ajaxnotice { position:fixed; padding:10px; border:1px solid #aaa; z-index:99999; background-color:#fff; font-size:13px; }
42
+ #ajaxnotice img { display:block; }
43
+ #ajaxnotice * { border-width:0; margin:0; padding:0; }
44
+ #ajaxnotice .ajaxnotice_inner { position:relative; width:100%; height:100%; }
45
+ #ajaxnotice .ajaxnotice_clearer { clear:both; }
46
+ #ajaxnotice .ajaxnotice_image { float:left; border:1px solid #ccc; margin-right:10px; }
47
+ #ajaxnotice .ajaxnotice_content { float:left; width:250px; }
48
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_buttons { position:absolute; right:0; bottom:0; }
49
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_cart { float:left; text-transform:uppercase; text-decoration:none; color:#000; font-size:11px; font-weight:bold; position:relative; }
50
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_cart div { position:absolute; top:0; left:0; width:87px; text-align:center; line-height:24px; }
51
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_checkout { float:left; margin-left:10px; text-transform:uppercase; text-decoration:none; color:#000; font-size:11px; font-weight:bold; position:relative; }
52
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_checkout div { position:absolute; top:0; left:0; width:87px; text-align:center; line-height:24px; }
53
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_message { margin-top:5px; text-align:left; }
54
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_close { float:right; font-size:11px; }
55
+ #ajaxnotice .ajaxnotice_content .ajaxnotice_back { float:left; font-size:12px; }
56
+ #ajaxnotice .ajaxnotice_content .ajaxaddfailed { color:#eb340a; font-weight:bold; }
skin/frontend/base/default/images/ajaxcartpopup/button.gif ADDED
Binary file
skin/frontend/base/default/images/ajaxcartpopup/loading.gif ADDED
Binary file
skin/frontend/base/default/images/ajaxcartpopup/overlay.png ADDED
Binary file
skin/frontend/base/default/js/ajaxcartpopup.js ADDED
@@ -0,0 +1,520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var cartpopup = Class.create({
2
+ afterInit: function() {
3
+ if (this.ajaxenabled) {
4
+ if (this.product) {
5
+ this.observeSubmit();
6
+ } else {
7
+ this.collectCategoryRequests();
8
+ }
9
+ }
10
+ if ($("header-cart")) {
11
+ $("header-cart").remove();
12
+ }
13
+ this.positionNoticeStart();
14
+ if (this.showpopup) {
15
+ this.mouseclose = false;
16
+ this.displayPopup();
17
+ this.addCloseListener.bind(this).delay(this.slidespeed);
18
+ this.addInputListener.bind(this).delay(this.slidespeed);
19
+ } else if (!this.emptycart) {
20
+ this.initPopup();
21
+ }
22
+ this.disableCartLink();
23
+ },
24
+ getCartElement: function() {
25
+ if ($$("a.skip-cart")[0]) {
26
+ return $$("a.skip-cart")[0];
27
+ } else if ($$("a.top-link-cart")[0]) {
28
+ return $$("a.top-link-cart")[0];
29
+ }
30
+ },
31
+ initPopup: function() {
32
+ $("cartpopup_overlay").hide();
33
+ this.mouseclose = true;
34
+ this.positionPopupStart();
35
+ this.mouseDisplayPopup();
36
+ this.addCancelAutoCloseListener();
37
+ this.addInputListener.bind(this).delay(this.slidespeed);
38
+ this.popupshowing = false;
39
+ },
40
+ disablePopup: function() {
41
+ this.emptycart = true;
42
+ this.mouseclose = false;
43
+ document.stopObserving("click", this.documenthandler);
44
+ $("cartpopup").stopObserving("mouseout", this.hidehandler);
45
+ this.getCartElement().stopObserving(this.getOpenMethod(), this.popuphandler);
46
+ if (this.popupshowing) {
47
+ Effect.SlideUp("cartpopup", {duration: this.slidespeed});
48
+ this.popupshowing = false;
49
+ }
50
+ },
51
+ observeSubmit: function() {
52
+ this.submiturl = $("product_addtocart_form").readAttribute("action");
53
+ $("product_addtocart_form").writeAttribute("action", "javascript:thiscartpopup.submitAction()");
54
+ },
55
+ submitAction: function() {
56
+ var formdata = $("product_addtocart_form").serialize(true);
57
+ var id = false;
58
+ this.addToCart(id, formdata, this.submiturl)
59
+ },
60
+ updateQuantityAction: function() {
61
+ var formdata = $("cartpopup_form").serialize(true);
62
+ this.updateQuantity(formdata, this.updateurl);
63
+ },
64
+ collectCategoryRequests: function() {
65
+ this.requests = {};
66
+ $$("button.btn-cart").each(function(e) {
67
+ if (!e.up("div.block-reorder")) {
68
+ var request = e.readAttribute("onclick");
69
+ if (request.indexOf("/product/") > 0) {
70
+ var id = request.substring(request.indexOf("/product/")).split("/");
71
+ id = id[2];
72
+ e.addClassName("ajaxprodid-" + id);
73
+ request = request.replace(/^setlocation\(['"]{1}/i, "").replace(/['"]{1}\)$/, "");
74
+ this.requests[id] = request;
75
+ e.writeAttribute("onclick", "");
76
+
77
+ e.observe("click", function(el) {
78
+ var target = el.target;
79
+ if (target.tagName.toLowerCase() != "button") {
80
+ target = target.up("button.btn-cart");
81
+ }
82
+ var id = target.className;
83
+ if (id.indexOf("ajaxprodid-")) {
84
+ id = id.substring(id.indexOf("ajaxprodid-"));
85
+ id = id.split(" ").shift();
86
+ id = id.split("-").pop();
87
+ this.addToCart(id);
88
+ }
89
+ }.bind(this));
90
+ }
91
+ }
92
+ }.bind(this));
93
+ },
94
+ addToCart: function(id, formdata, submiturl) {
95
+ $("ajaxnotice_working").show();
96
+ $("ajaxnotice_result").hide();
97
+ this.positionNotice();
98
+ $("ajaxnotice").show();
99
+ if (formdata) {
100
+ formdata.ajaxcartpopup = true;
101
+ formdata.isproductpage = true;
102
+ var parameters = formdata;
103
+ } else {
104
+ var parameters = {ajaxcartpopup : true, imagedetail : true};
105
+ }
106
+ if (submiturl) {
107
+ var url = submiturl;
108
+ } else {
109
+ var url = this.requests[id];
110
+ }
111
+ new Ajax.Request(url, {
112
+ parameters: parameters,
113
+ onSuccess: function(response) {
114
+ var contentarray = response.responseText.evalJSON();
115
+ var result = contentarray.result;
116
+ if (result == "success" || (!result && this.product)) {
117
+ var message = contentarray.message;
118
+ var linktext = contentarray.linktext;
119
+ var popuphtml = contentarray.popuphtml;
120
+ var itemid = contentarray.itemid;
121
+ var deleteurl = contentarray.deleteurl;
122
+ if (contentarray.imageurl) {
123
+ this.imageurl = contentarray.imageurl;
124
+ }
125
+ if (contentarray.productname) {
126
+ this.productname = contentarray.productname;
127
+ }
128
+ var image = this.getProductImage();
129
+ if (this.showonadd) {
130
+ $("ajaxnotice").hide();
131
+ this.displayPopup();
132
+ } else {
133
+ var notice = "";
134
+ if (image) {
135
+ notice += "<div class=\"ajaxnotice_image\">" + image + "</div>";
136
+ }
137
+ notice += "<div class=\"ajaxnotice_content\">";
138
+ if (this.backurl && this.backname) {
139
+ notice += "<a class=\"ajaxnotice_back\" href=\"" + this.backurl + "\">< Back to " + this.backname + "</a>";
140
+ }
141
+ notice += "<a class=\"ajaxnotice_close\" href=\"javascript:void(null)\" onclick=\"thiscartpopup.hideNotice()\">CLOSE</a>";
142
+ notice += "<div class=\"ajaxnotice_clearer\"></div>";
143
+ if (!result && this.product) {
144
+ var errorclass = " ajaxaddfailed";
145
+ } else {
146
+ var errorclass = "";
147
+ }
148
+ if (this.cartbutton || this.checkoutbutton) {
149
+ notice += "<div class=\"ajaxnotice_message" + errorclass + "\" style=\"margin-bottom:35px\">" + message + "</div>";
150
+ notice += "<div class=\"ajaxnotice_buttons\">";
151
+ if (this.cartbutton) {
152
+ notice += "<a href=\"" + this.carturl + "\">";
153
+ notice += "<div class=\"ajaxnotice_cart\"><img src=\"" + this.cartbutton + "\" alt=\"\" \\><div>" + this.carttext + "</div></div>";
154
+ notice += "</a>";
155
+ }
156
+ if (this.checkoutbutton) {
157
+ notice += "<a href=\"" + this.checkouturl + "\">";
158
+ notice += "<div class=\"ajaxnotice_checkout\"><img src=\"" + this.checkoutbutton + "\" alt=\"\" \\><div>" + this.checkouttext + "</div></div>";
159
+ notice += "</a>";
160
+ }
161
+ notice += "<div class=\"ajaxnotice_clearer\"></div>";
162
+ notice += "</div>";
163
+ } else {
164
+ notice += "<div class=\"ajaxnotice_message" + errorclass + "\">" + message + "</div>";
165
+ }
166
+ notice += "<div class=\"ajaxnotice_clearer\"></div>";
167
+ notice += "</div>";
168
+ $("ajaxnotice").hide();
169
+ $("ajaxnotice_working").hide();
170
+ $("ajaxnotice_result").update(notice);
171
+ $("ajaxnotice_result").show();
172
+ this.positionNotice();
173
+ $("ajaxnotice").show();
174
+ }
175
+
176
+ if (result == "success") {
177
+ this.updatePopup(linktext, popuphtml);
178
+ if (itemid && deleteurl) {
179
+ this.deleteurls[itemid] = deleteurl;
180
+ }
181
+ if (this.emptycart) {
182
+ this.emptycart = false;
183
+ this.initPopup();
184
+ }
185
+ }
186
+ } else {
187
+ setLocation(result);
188
+ }
189
+ if (this.product) {
190
+ $$("button.btn-cart").each(function(e) {
191
+ e.disabled = false;
192
+ });
193
+ }
194
+ }.bind(this)
195
+ });
196
+ },
197
+ removeFromCart: function(id) {
198
+ $("cartpopup_overlay").show();
199
+ var url = this.deleteurls[id];
200
+ var parameters = {ajaxcartpopup : true};
201
+ new Ajax.Request(url, {
202
+ parameters: parameters,
203
+ onSuccess: function(response) {
204
+ var contentarray = response.responseText.evalJSON();
205
+ var result = contentarray.result;
206
+ if (result == "success") {
207
+ var emptycart = contentarray.emptycart;
208
+ var linktext = contentarray.linktext;
209
+ var popuphtml = contentarray.popuphtml;
210
+ if (emptycart) {
211
+ this.disablePopup();
212
+ this.updatePopup.bind(this).delay(this.slidespeed, linktext, popuphtml, true);
213
+ } else {
214
+ this.updatePopup(linktext, popuphtml);
215
+ }
216
+ } else {
217
+ setLocation(result);
218
+ }
219
+ }.bind(this)
220
+ });
221
+ },
222
+ updateQuantity: function(formdata, updateurl) {
223
+ $("cartpopup_overlay").show();
224
+ if (formdata) {
225
+ formdata.ajaxcartpopup = true;
226
+ formdata.ajaxupdatequantity = true;
227
+ formdata.update_cart_action = "update_qty";
228
+ var parameters = formdata;
229
+ }
230
+ if (updateurl) {
231
+ var url = updateurl;
232
+ }
233
+ new Ajax.Request(url, {
234
+ parameters: parameters,
235
+ onSuccess: function(response) {
236
+ var contentarray = response.responseText.evalJSON();
237
+ var result = contentarray.result;
238
+ if (result == "success") {
239
+ var emptycart = contentarray.emptycart;
240
+ var linktext = contentarray.linktext;
241
+ var popuphtml = contentarray.popuphtml;
242
+ if (emptycart) {
243
+ this.disablePopup();
244
+ this.updatePopup.bind(this).delay(this.slidespeed, linktext, popuphtml, true);
245
+ } else {
246
+ this.updatePopup(linktext, popuphtml);
247
+ }
248
+ } else {
249
+ setLocation(result);
250
+ }
251
+ }.bind(this)
252
+ });
253
+ },
254
+ updatePopup: function(linktext, popuphtml, removecount) {
255
+ if (linktext) {
256
+ var link = this.getCartElement();
257
+ if (link.readAttribute("title")) {
258
+ link.writeAttribute("title", linktext.stripScripts().stripTags());
259
+ }
260
+ link.update(linktext);
261
+ if (removecount) {
262
+ this.removeCount();
263
+ }
264
+ }
265
+ if (popuphtml) {
266
+ $("cartpopup_slidecontainer").update(popuphtml);
267
+ }
268
+ $("cartpopup_overlay").hide();
269
+ this.addInputListener();
270
+ },
271
+ getProductImage: function() {
272
+ if (this.imageurl && this.productname) {
273
+ var tag = "<img src=\"" + this.imageurl + "\" alt=\"" + this.productname + "\" title=\"" + this.productname + "\" \\>";
274
+ return tag;
275
+ } else {
276
+ return false;
277
+ }
278
+ },
279
+ addCancelAutoCloseListener: function() {
280
+ this.autoclosehandler = this.autoCloseHandler.bind(this);
281
+ $("cartpopup").observe("mouseover", this.autoclosehandler);
282
+ },
283
+ autoCloseHandler: function(e) {
284
+ if (Position.within($("cartpopup"), Event.pointerX(e), Event.pointerY(e))) {
285
+ this.cancelPopupAutoClose();
286
+ }
287
+ },
288
+ startPopupAutoClose: function() {
289
+ if (this.autoclosetime) {
290
+ this.autoclose = this.hidePopup.bind(this).delay(this.autoclosetime);
291
+ }
292
+ },
293
+ cancelPopupAutoClose: function() {
294
+ if (this.autoclose) {
295
+ window.clearTimeout(this.autoclose);
296
+ this.autoclose = false;
297
+ }
298
+ },
299
+ displayPopup: function() {
300
+ this.startPopupAutoClose();
301
+ $("cartpopup_overlay").hide();
302
+ if (!this.mouseclose) {
303
+ this.positionPopupStart();
304
+ Effect.SlideDown("cartpopup", {duration: this.slidespeed});
305
+ } else {
306
+ this.getCartElement().stopObserving(this.getOpenMethod(), this.popuphandler);
307
+ Effect.SlideDown("cartpopup", {duration: this.slidespeed});
308
+ this.mouseHidePopup.bind(this).delay(this.slidespeed);
309
+ this.addCloseListener.bind(this).delay(this.slidespeed);
310
+ }
311
+ this.popupshowing = true;
312
+ },
313
+ positionPopupStart: function() {
314
+ $("cartpopup").hide();
315
+ this.positionPopup();
316
+ },
317
+ positionPopup: function() {
318
+ var position = this.getCartElement().viewportOffset();
319
+ var top = position.top;
320
+ var left = position.left
321
+ var size = this.getCartElement().getDimensions();
322
+ var height = size.height;
323
+ var width = size.width;
324
+ var posleft = left + (width / 2) - ($("cartpopup").getWidth() / 2);
325
+ var mainleft = $$("div.main")[0].viewportOffset();
326
+ mainleft = mainleft.left;
327
+ var mainright = mainleft + $$("div.main")[0].getWidth();
328
+ if (posleft < mainleft) {
329
+ posleft = mainleft;
330
+ } else if ((posleft + $("cartpopup").getWidth()) > mainright) {
331
+ var diff = (posleft + $("cartpopup").getWidth()) - mainright;
332
+ posleft = posleft - diff;
333
+ }
334
+ var scroll = document.viewport.getScrollOffsets();
335
+ var postop = top + height + scroll.top;
336
+ $("cartpopup").setStyle({
337
+ top: postop + "px",
338
+ left: posleft + "px"
339
+ });
340
+ },
341
+ positionNoticeStart: function() {
342
+ $("ajaxnotice").hide();
343
+ this.positionNotice();
344
+ },
345
+ positionNotice: function() {
346
+ var viewportdimensions = document.viewport.getDimensions();
347
+ var noticedimensions = $("ajaxnotice").getDimensions();
348
+ $("ajaxnotice").style.left = (viewportdimensions.width / 2) - (noticedimensions.width / 2) + "px";
349
+ $("ajaxnotice").style.top = (viewportdimensions.height / 2) - (noticedimensions.height / 2) + "px";
350
+ },
351
+ addCloseListener: function() {
352
+ this.documenthandler = this.documentHandler.bind(this);
353
+ document.observe("click", this.documenthandler);
354
+ },
355
+ documentHandler: function(e) {
356
+ if (!e.target.up("div#cartpopup")) {
357
+ this.cancelPopupAutoClose();
358
+ this.hidePopup();
359
+ }
360
+ },
361
+ addInputListener: function() {
362
+ $$("#cartpopup_slidecontainer input").each(function(e) {
363
+ e.observe("keypress", function(e) {
364
+ if (e.keyCode == Event.KEY_RETURN) {
365
+ $("cartpopup_form").submit();
366
+ Event.stop(e);
367
+ }
368
+ });
369
+ });
370
+ },
371
+ hidePopup: function() {
372
+ if (!this.mouseclose) {
373
+ this.mouseclose = true;
374
+ document.stopObserving("click", this.documenthandler);
375
+ Effect.SlideUp("cartpopup", {duration: this.slidespeed});
376
+ this.mouseDisplayPopup.bind(this).delay(this.slidespeed);
377
+ } else {
378
+ document.stopObserving("click", this.documenthandler);
379
+ $("cartpopup").stopObserving("mouseout", this.hidehandler);
380
+ Effect.SlideUp("cartpopup", {duration: this.slidespeed});
381
+ this.mouseDisplayPopup.bind(this).delay(this.slidespeed);
382
+ }
383
+ this.popupshowing = false;
384
+ },
385
+ hideNotice: function() {
386
+ $("ajaxnotice").hide();
387
+ },
388
+ mouseDisplayPopup: function() {
389
+ this.popuphandler = this.mousePopupHandler.bind(this);
390
+ this.getCartElement().observe(this.getOpenMethod(), this.popuphandler);
391
+ },
392
+ mousePopupHandler: function(e) {
393
+ this.displayPopup();
394
+ },
395
+ mouseHidePopup: function() {
396
+ this.hidehandler = this.mouseHideHandler.bind(this);
397
+ $("cartpopup").observe("mouseout", this.hidehandler);
398
+ },
399
+ mouseHideHandler: function(e) {
400
+ if (!Position.within($("cartpopup"), Event.pointerX(e), Event.pointerY(e))) {
401
+ this.hidePopup();
402
+ }
403
+ },
404
+ positionAll: function() {
405
+ this.positionNotice();
406
+ this.positionPopup();
407
+ },
408
+ getOpenMethod: function() {
409
+ if (this.clickopen) {
410
+ return "click";
411
+ }
412
+ return "mouseover";
413
+ },
414
+ disableCartLink: function() {
415
+ if (this.clickopen) {
416
+ this.linkhandler = this.cartLinkHandler.bind(this);
417
+ this.getCartElement().observe(this.getOpenMethod(), this.linkhandler);
418
+ }
419
+ },
420
+ cartLinkHandler: function(e) {
421
+ if (!this.emptycart) {
422
+ Event.stop(e);
423
+ }
424
+ },
425
+ removeCount: function(e) {
426
+ if (this.getCartElement().down("span.count")) {
427
+ this.getCartElement().down("span.count").remove();
428
+ }
429
+ }
430
+ });
431
+
432
+ var cartpage = Class.create({
433
+ afterInit: function() {
434
+ $$(".cart-table .btn-update")[0].remove();
435
+ $$(".cart-table .qty").each(function(e) {
436
+ e.observe("change", function(el) {
437
+ this.updateQuantity(el.target);
438
+ }.bind(this));
439
+ e.observe("keypress", function(el) {
440
+ if (el.keyCode == Event.KEY_RETURN) {
441
+ Event.stop(el);
442
+ this.updateQuantity(el.target);
443
+ }
444
+ }.bind(this));
445
+ }.bind(this));
446
+ $$(".cart-table .btn-remove").each(function(e) {
447
+ e.observe("click", function(el) {
448
+ Event.stop(el);
449
+ this.removeFromCart(el.target);
450
+ }.bind(this));
451
+ }.bind(this));
452
+ },
453
+ updateQuantity: function(e) {
454
+ this.showWorking();
455
+ var formdata = $$(".cart form")[0].serialize(true);
456
+ if (formdata) {
457
+ formdata.ajaxcartpopup = true;
458
+ formdata.ajaxupdatequantity = true;
459
+ formdata.update_cart_action = "update_qty";
460
+ formdata.iscartpage = true;
461
+ var parameters = formdata;
462
+ }
463
+ new Ajax.Request(this.updateurl, {
464
+ parameters: parameters,
465
+ onSuccess: function(response) {
466
+ var contentarray = response.responseText.evalJSON();
467
+ var result = contentarray.result;
468
+ if (result == "success") {
469
+ if (e.value == "0") {
470
+ this.removeAndStyle(e);
471
+ }
472
+ var totals = contentarray.totals;
473
+ $("shopping-cart-totals-table").replace(totals);
474
+ this.hideWorking();
475
+ }
476
+ }.bind(this)
477
+ });
478
+ },
479
+ removeFromCart: function(e) {
480
+ this.showWorking();
481
+ var parameters = { ajaxcartpopup:true, iscartpage:true };
482
+ new Ajax.Request(e.href, {
483
+ parameters: parameters,
484
+ onSuccess: function(response) {
485
+ var contentarray = response.responseText.evalJSON();
486
+ var result = contentarray.result;
487
+ if (result == "success") {
488
+ this.removeAndStyle(e);
489
+ var totals = contentarray.totals;
490
+ $("shopping-cart-totals-table").replace(totals);
491
+ this.hideWorking();
492
+ }
493
+ }.bind(this)
494
+ });
495
+ },
496
+ showWorking: function() {
497
+ $("ajaxnotice_result").hide();
498
+ this.positionNotice();
499
+ $("ajaxnotice_working").show();
500
+ $("ajaxnotice").show();
501
+ },
502
+ hideWorking: function() {
503
+ $("ajaxnotice_result").hide();
504
+ $("ajaxnotice").hide();
505
+ $("ajaxnotice_working").hide();
506
+ },
507
+ positionNotice: function() {
508
+ var viewportdimensions = document.viewport.getDimensions();
509
+ var noticedimensions = $("ajaxnotice").getDimensions();
510
+ $("ajaxnotice").style.left = (viewportdimensions.width / 2) - (noticedimensions.width / 2) + "px";
511
+ $("ajaxnotice").style.top = (viewportdimensions.height / 2) - (noticedimensions.height / 2) + "px";
512
+ },
513
+ removeAndStyle: function(e) {
514
+ e.up("tr").remove();
515
+ $$(".cart-table tbody tr").each(function(el) {
516
+ el.writeAttribute("class", "");
517
+ }.bind(this));
518
+ decorateTable("shopping-cart-table");
519
+ }
520
+ });