1: <?php
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: class Mage_XmlConnect_CatalogController extends Mage_XmlConnect_Controller_Action
35: {
36: 37: 38: 39: 40:
41: public function categoryAction()
42: {
43: try {
44: $this->loadLayout(false);
45: $this->renderLayout();
46: } catch (Mage_Core_Exception $e) {
47: Mage::logException($e);
48: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
49: } catch (Exception $e) {
50: Mage::logException($e);
51: $this->_message(
52: $this->__('An error occurred while loading categories.'), self::MESSAGE_STATUS_ERROR
53: );
54: }
55: }
56:
57: 58: 59: 60: 61:
62: public function filtersAction()
63: {
64: try {
65: $this->loadLayout(false);
66: $this->renderLayout();
67: } catch (Mage_Core_Exception $e) {
68: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
69: } catch (Exception $e) {
70: Mage::logException($e);
71: $this->_message(
72: $this->__('An error occurred while loading category filters.'), self::MESSAGE_STATUS_ERROR
73: );
74: }
75: }
76:
77: 78: 79: 80: 81:
82: public function productAction()
83: {
84: try {
85: $this->loadLayout(false);
86: $this->renderLayout();
87: return;
88: } catch (Mage_Core_Exception $e) {
89: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
90: } catch (Exception $e) {
91: $this->_message($this->__('Unable to load product info.'), self::MESSAGE_STATUS_ERROR);
92: Mage::logException($e);
93: }
94: }
95:
96: 97: 98: 99: 100:
101: public function productOptionsAction()
102: {
103: try {
104: $this->loadLayout(false);
105: $this->renderLayout();
106: } catch (Mage_Core_Exception $e) {
107: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
108: } catch (Exception $e) {
109: $this->_message($this->__('Unable to load product options.'), self::MESSAGE_STATUS_ERROR);
110: Mage::logException($e);
111: }
112: }
113:
114: 115: 116: 117: 118:
119: public function productGalleryAction()
120: {
121: try {
122: $this->loadLayout(false);
123: $this->renderLayout();
124: } catch (Mage_Core_Exception $e) {
125: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
126: } catch (Exception $e) {
127: $this->_message($this->__('Unable to load product gallery.'), self::MESSAGE_STATUS_ERROR);
128: Mage::logException($e);
129: }
130: }
131:
132: 133: 134: 135: 136:
137: public function productReviewsAction()
138: {
139: try {
140: $this->loadLayout(false);
141: $this->renderLayout();
142: } catch (Mage_Core_Exception $e) {
143: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
144: } catch (Exception $e) {
145: $this->_message($this->__('Unable to load product reviews.'), self::MESSAGE_STATUS_ERROR);
146: Mage::logException($e);
147: }
148: }
149:
150: 151: 152: 153: 154:
155: public function productReviewAction()
156: {
157: try {
158: $this->loadLayout(false);
159: $this->renderLayout();
160: } catch (Mage_Core_Exception $e) {
161: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
162: } catch (Exception $e) {
163: $this->_message($this->__('Unable to load product review.'), self::MESSAGE_STATUS_ERROR);
164: Mage::logException($e);
165: }
166: }
167:
168: 169: 170: 171: 172:
173: public function searchAction()
174: {
175:
176: $_helper = Mage::helper('catalogsearch');
177: $queryParam = str_replace('%20', ' ', $this->getRequest()->getParam('query'));
178: $this->getRequest()->setParam($_helper->getQueryParamName(), $queryParam);
179:
180: $query = $_helper->getQuery();
181: $query->setStoreId(Mage::app()->getStore()->getId());
182:
183: if ($query->getQueryText()) {
184: if ($_helper->isMinQueryLength()) {
185: $query->setId(0)
186: ->setIsActive(1)
187: ->setIsProcessed(1);
188: } else {
189: if ($query->getId()) {
190: $query->setPopularity($query->getPopularity()+1);
191: } else {
192: $query->setPopularity(1);
193: }
194:
195: 196: 197: 198: 199:
200: if (false && $query->getRedirect()) {
201: $query->save();
202: $this->getResponse()->setRedirect($query->getRedirect());
203: return;
204: } else {
205: $query->prepare();
206: }
207: }
208:
209: $_helper->checkNotes();
210:
211: if (!$_helper->isMinQueryLength()) {
212: $query->save();
213: }
214: }
215:
216: try {
217: $this->loadLayout(false);
218: $this->renderLayout();
219: } catch (Mage_Core_Exception $e) {
220: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
221: } catch (Exception $e) {
222: $this->_message($this->__('Unable to load search.'), self::MESSAGE_STATUS_ERROR);
223: Mage::logException($e);
224: }
225: }
226:
227: 228: 229: 230: 231:
232: public function searchSuggestAction()
233: {
234: $this->getRequest()->setParam('q', $this->getRequest()->getParam('query'));
235: try {
236: $this->loadLayout(false);
237: $this->renderLayout();
238: } catch (Mage_Core_Exception $e) {
239: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
240: } catch (Exception $e) {
241: $this->_message($this->__('Unable to load search.'), self::MESSAGE_STATUS_ERROR);
242: Mage::logException($e);
243: }
244: }
245:
246: 247: 248: 249: 250:
251: public function sendEmailAction()
252: {
253:
254: $helper = Mage::helper('sendfriend');
255:
256: $session = Mage::getSingleton('customer/session');
257:
258: if (!$helper->isEnabled()) {
259: $this->_message($this->__('Tell a Friend is disabled.'), self::MESSAGE_STATUS_ERROR);
260: return $this;
261: }
262:
263: if (!$helper->isAllowForGuest() && !$session->isLoggedIn()) {
264: $this->_message(
265: $this->__('Customer not logged in.'),
266: self::MESSAGE_STATUS_ERROR,
267: array('logged_in' => '0')
268: );
269: return $this;
270: }
271:
272: 273: 274:
275: $productId = (int)$this->getRequest()->getParam('product_id');
276: if (!$productId) {
277: $this->_message($this->__('No product selected.'), self::MESSAGE_STATUS_ERROR);
278: return $this;
279: }
280: $product = Mage::getModel('catalog/product')
281: ->load($productId);
282: if (!$product->getId() || !$product->isVisibleInCatalog()) {
283: $this->_message($this->__('Selected product is unavailable.'), self::MESSAGE_STATUS_ERROR);
284: return $this;
285: }
286:
287: Mage::register('product', $product);
288:
289: 290: 291:
292: $model = Mage::getModel('sendfriend/sendfriend');
293: $model->setRemoteAddr(Mage::helper('core/http')->getRemoteAddr(true));
294: $model->setCookie(Mage::app()->getCookie());
295: $model->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
296:
297: Mage::register('send_to_friend_model', $model);
298:
299: $data = $this->getRequest()->getPost();
300:
301: if (!$data) {
302: $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR);
303: return $this;
304: }
305:
306: $sender = (array)$this->getRequest()->getPost('sender');
307: if ($session->isLoggedIn()) {
308: $sender['email'] = $session->getCustomer()->getEmail();
309: $sender['name'] = $session->getCustomer()->getFirstName() . ' ' . $session->getCustomer()->getLastName();
310: }
311:
312: 313: 314:
315: $categoryId = $this->getRequest()->getParam('category_id', null);
316: if ($categoryId) {
317: $category = Mage::getModel('catalog/category')->load($categoryId);
318: $product->setCategory($category);
319: Mage::register('current_category', $category);
320: }
321:
322: $model->setSender($sender);
323: $model->setRecipients($this->getRequest()->getPost('recipients'));
324: $model->setProduct($product);
325:
326: try {
327: $validate = $model->validate();
328: if ($validate === true) {
329: $model->send();
330: $this->_message($this->__('Tell a Friend link has been sent.'), self::MESSAGE_STATUS_SUCCESS);
331: return;
332: } else {
333: if (is_array($validate)) {
334: $this->_message(implode(' ', $validate), self::MESSAGE_STATUS_ERROR);
335: return;
336: } else {
337: $this->_message($this->__('There were some problems with the data.'), self::MESSAGE_STATUS_ERROR);
338: return;
339: }
340: }
341: } catch (Mage_Core_Exception $e) {
342: $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
343: } catch (Exception $e) {
344: $this->_message($this->__('Some emails were not sent.'), self::MESSAGE_STATUS_ERROR);
345: }
346: return $this;
347: }
348: }
349: