-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexController.php
80 lines (70 loc) · 2.72 KB
/
IndexController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require_once "Mage/Catalog/controllers/ProductController.php";
class Magentothem_Ajaxcartsuper_IndexController extends Mage_Catalog_ProductController
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
protected function _initProduct()
{
$categoryId = Mage::getSingleton('catalog/layer')
->getCurrentCategory()
->getId();
$productId = $this->getRequest()->getParam('id');
$params = new Varien_Object();
$params->setCategoryId($categoryId);
return Mage::helper('catalog/product')->initProduct($productId, $this, $params);
}
public function productviewAction()
{
if ($product = $this->_initProduct()) {
if ($this->getRequest()->getParam('options')) {
$notice = $product->getTypeInstance(true)->getSpecifyOptionMessage();
Mage::getSingleton('catalog/session')->addNotice($notice);
}
Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId());
$this->_initProductLayout($product);
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('tag/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
}
else {
if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) {
$this->_redirect('');
} elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
}
}
public function cartdeleteAction() {
if($this->getRequest()->getParam('callback')) {
$id = $this->getRequest()->getParam('id');
$id = $this->getRequest()->getParam('id');
if ($id) {
try {
Mage::getSingleton('checkout/cart')->removeItem($id)
->save();
} catch (Exception $e) {
Mage::getSingleton('checkout/session')->addError($this->__('Cannot remove item'));
}
}
$this->loadLayout();
$ajaxData = array();
$content = "";
if($this->loadLayout()->getLayout()->getBlock('content')) {
$content = $this->loadLayout()->getLayout()->getBlock('content')->toHtml();
}
$mini_cart = "";
if($this->getLayout()->getBlock('cart_sidebar_mini')) {
$mini_cart = $this->getLayout()->getBlock('cart_sidebar_mini')->toHtml();
}
$formCart = $this->getLayout()->getBlockSingleton('checkout/cart')->setTemplate("checkout/cart.phtml")->toHtml();
$ajaxData['form_cart'] = $content;
$ajaxData['top_cart'] = $mini_cart;
$this->getResponse()->setBody($this->getRequest()->getParam('callback').'('.Mage::helper('core')->jsonEncode($ajaxData).')');
}
}
}