freshdesk - Version 1.0.0

Version Notes

First release

Download this release

Release Info

Developer MagePlace
Extension freshdesk
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (130) hide show
  1. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Comment.php +25 -0
  2. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Feedbackwidget.php +25 -0
  3. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Link.php +50 -0
  4. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Customer/Edit/Tab/View/Tickets.php +31 -0
  5. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket.php +54 -0
  6. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit.php +95 -0
  7. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit/Form.php +58 -0
  8. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit/Form/Fields.php +68 -0
  9. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid.php +238 -0
  10. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Datetime.php +34 -0
  11. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Orderincrements.php +37 -0
  12. app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Orders.php +35 -0
  13. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Abstract.php +97 -0
  14. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Create.php +124 -0
  15. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Grid.php +44 -0
  16. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/List.php +74 -0
  17. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Recent.php +50 -0
  18. app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/View.php +150 -0
  19. app/code/local/Mageplace/Freshdesk/Block/Field/Abstract.php +165 -0
  20. app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Checkbox.php +34 -0
  21. app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Dropdown.php +16 -0
  22. app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Number.php +27 -0
  23. app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Paragraph.php +16 -0
  24. app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Text.php +16 -0
  25. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Agent.php +16 -0
  26. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Description.php +16 -0
  27. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Group.php +16 -0
  28. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Priority.php +16 -0
  29. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Requester.php +16 -0
  30. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Source.php +16 -0
  31. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Status.php +16 -0
  32. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Subject.php +16 -0
  33. app/code/local/Mageplace/Freshdesk/Block/Field/Default/Ticket/Type.php +16 -0
  34. app/code/local/Mageplace/Freshdesk/Block/Field/Dropdown.php +62 -0
  35. app/code/local/Mageplace/Freshdesk/Block/Field/Nested/Field.php +128 -0
  36. app/code/local/Mageplace/Freshdesk/Block/Field/Paragraph.php +57 -0
  37. app/code/local/Mageplace/Freshdesk/Block/Field/Row.php +77 -0
  38. app/code/local/Mageplace/Freshdesk/Block/Field/Text.php +31 -0
  39. app/code/local/Mageplace/Freshdesk/Block/Order/Info/Buttons.php +58 -0
  40. app/code/local/Mageplace/Freshdesk/Block/Page/Html/Head/Widget.php +34 -0
  41. app/code/local/Mageplace/Freshdesk/Exception.php +24 -0
  42. app/code/local/Mageplace/Freshdesk/Helper/Const.php +45 -0
  43. app/code/local/Mageplace/Freshdesk/Helper/Customer.php +33 -0
  44. app/code/local/Mageplace/Freshdesk/Helper/Data.php +161 -0
  45. app/code/local/Mageplace/Freshdesk/Model/Abstract.php +38 -0
  46. app/code/local/Mageplace/Freshdesk/Model/Cache.php +55 -0
  47. app/code/local/Mageplace/Freshdesk/Model/Field.php +201 -0
  48. app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Checkbox.php +16 -0
  49. app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Dropdown.php +16 -0
  50. app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Number.php +26 -0
  51. app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Paragraph.php +16 -0
  52. app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Text.php +16 -0
  53. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Agent.php +16 -0
  54. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Description.php +16 -0
  55. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Group.php +16 -0
  56. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Priority.php +16 -0
  57. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Requester.php +16 -0
  58. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Source.php +16 -0
  59. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Status.php +16 -0
  60. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Subject.php +16 -0
  61. app/code/local/Mageplace/Freshdesk/Model/Field/Default/Ticket/Type.php +16 -0
  62. app/code/local/Mageplace/Freshdesk/Model/Field/Dropdown.php +37 -0
  63. app/code/local/Mageplace/Freshdesk/Model/Field/Nested/Field.php +183 -0
  64. app/code/local/Mageplace/Freshdesk/Model/Freshdesk.php +270 -0
  65. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Abstract.php +267 -0
  66. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Fields.php +179 -0
  67. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Interface.php +19 -0
  68. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Notes.php +97 -0
  69. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Tickets.php +502 -0
  70. app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Users.php +223 -0
  71. app/code/local/Mageplace/Freshdesk/Model/Note.php +71 -0
  72. app/code/local/Mageplace/Freshdesk/Model/Observer.php +117 -0
  73. app/code/local/Mageplace/Freshdesk/Model/Resource/Collection/Abstract.php +223 -0
  74. app/code/local/Mageplace/Freshdesk/Model/Resource/Field.php +20 -0
  75. app/code/local/Mageplace/Freshdesk/Model/Resource/Field/Collection.php +64 -0
  76. app/code/local/Mageplace/Freshdesk/Model/Resource/Note.php +44 -0
  77. app/code/local/Mageplace/Freshdesk/Model/Resource/Ticket.php +64 -0
  78. app/code/local/Mageplace/Freshdesk/Model/Resource/Ticket/Collection.php +142 -0
  79. app/code/local/Mageplace/Freshdesk/Model/Resource/User.php +49 -0
  80. app/code/local/Mageplace/Freshdesk/Model/Source/Abstract.php +32 -0
  81. app/code/local/Mageplace/Freshdesk/Model/Source/Priority.php +29 -0
  82. app/code/local/Mageplace/Freshdesk/Model/Source/Status.php +29 -0
  83. app/code/local/Mageplace/Freshdesk/Model/Source/Ticketview.php +27 -0
  84. app/code/local/Mageplace/Freshdesk/Model/Source/Widgetposition.php +37 -0
  85. app/code/local/Mageplace/Freshdesk/Model/Ticket.php +92 -0
  86. app/code/local/Mageplace/Freshdesk/Model/User.php +51 -0
  87. app/code/local/Mageplace/Freshdesk/controllers/Adminhtml/Freshdesk/TicketController.php +150 -0
  88. app/code/local/Mageplace/Freshdesk/controllers/Adminhtml/FreshdeskController.php +102 -0
  89. app/code/local/Mageplace/Freshdesk/controllers/IndexController.php +37 -0
  90. app/code/local/Mageplace/Freshdesk/controllers/TicketController.php +370 -0
  91. app/code/local/Mageplace/Freshdesk/etc/config.xml +264 -0
  92. app/code/local/Mageplace/Freshdesk/etc/system.xml +294 -0
  93. app/design/adminhtml/default/default/layout/freshdesk.xml +45 -0
  94. app/design/adminhtml/default/default/template/freshdesk/field/checkbox.phtml +19 -0
  95. app/design/adminhtml/default/default/template/freshdesk/field/dropdown.phtml +22 -0
  96. app/design/adminhtml/default/default/template/freshdesk/field/nested_field.phtml +57 -0
  97. app/design/adminhtml/default/default/template/freshdesk/field/paragraph.phtml +21 -0
  98. app/design/adminhtml/default/default/template/freshdesk/field/row_1_column.phtml +26 -0
  99. app/design/adminhtml/default/default/template/freshdesk/field/row_2_column.phtml +28 -0
  100. app/design/adminhtml/default/default/template/freshdesk/field/text.phtml +19 -0
  101. app/design/adminhtml/default/default/template/freshdesk/ticket/edit/form.phtml +39 -0
  102. app/design/adminhtml/default/default/template/freshdesk/ticket/edit/form/fields.phtml +26 -0
  103. app/design/frontend/base/default/layout/freshdesk.xml +122 -0
  104. app/design/frontend/base/default/template/freshdesk/customer/account/navigation/js.phtml +18 -0
  105. app/design/frontend/base/default/template/freshdesk/field/checkbox.phtml +19 -0
  106. app/design/frontend/base/default/template/freshdesk/field/dropdown.phtml +22 -0
  107. app/design/frontend/base/default/template/freshdesk/field/nested_field.phtml +63 -0
  108. app/design/frontend/base/default/template/freshdesk/field/paragraph.phtml +21 -0
  109. app/design/frontend/base/default/template/freshdesk/field/row.phtml +30 -0
  110. app/design/frontend/base/default/template/freshdesk/field/row_inline.phtml +25 -0
  111. app/design/frontend/base/default/template/freshdesk/field/text.phtml +20 -0
  112. app/design/frontend/base/default/template/freshdesk/page/html/head/widget.phtml +15 -0
  113. app/design/frontend/base/default/template/freshdesk/sales/order/info/create_ticket_button.phtml +14 -0
  114. app/design/frontend/base/default/template/freshdesk/tickets/create.phtml +77 -0
  115. app/design/frontend/base/default/template/freshdesk/tickets/list.phtml +133 -0
  116. app/design/frontend/base/default/template/freshdesk/tickets/recent.phtml +132 -0
  117. app/design/frontend/base/default/template/freshdesk/tickets/view.phtml +151 -0
  118. app/etc/modules/Mageplace_Freshdesk.xml +20 -0
  119. app/locale/en_US/Mageplace_Freshdesk.csv +131 -0
  120. package.xml +18 -0
  121. skin/adminhtml/default/default/freshdesk/css/freshdesk.css +51 -0
  122. skin/adminhtml/default/default/freshdesk/images/admin-ticket-icon.gif +0 -0
  123. skin/adminhtml/default/default/freshdesk/images/fd-logo-header.png +0 -0
  124. skin/adminhtml/default/default/freshdesk/images/fd-logo-tab.png +0 -0
  125. skin/adminhtml/default/default/freshdesk/images/logo-big.png +0 -0
  126. skin/adminhtml/default/default/freshdesk/js/freshdesk.js +293 -0
  127. skin/frontend/base/default/freshdesk/css/freshdesk.css +122 -0
  128. skin/frontend/base/default/freshdesk/images/bkg_block-title.gif +0 -0
  129. skin/frontend/base/default/freshdesk/images/ticket-icon.gif +0 -0
  130. skin/frontend/base/default/freshdesk/js/freshdesk.js +316 -0
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Comment.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Config_Comment
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Config_Comment extends Mage_Adminhtml_Block_System_Config_Form_Field
15
+ {
16
+ public function render(Varien_Data_Form_Element_Abstract $element)
17
+ {
18
+ $html = '';
19
+ $html .= '<td class="" colspan="4">';
20
+ $html .= '<div class="comment">' . $element->getComment() . '</div>';
21
+ $html .= '</td>';
22
+
23
+ return $this->_decorateRowHtml($element, $html);
24
+ }
25
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Feedbackwidget.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Config_Feedbackwidget
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Config_Feedbackwidget extends Mage_Adminhtml_Block_System_Config_Form_Field
15
+ {
16
+ public function render(Varien_Data_Form_Element_Abstract $element)
17
+ {
18
+ $html = '';
19
+ $html .= '<td class="" colspan="4">';
20
+ $html .= '<div class="comment"><textarea>' . $element->getComment() . '</textarea></div>';
21
+ $html .= '</td>';
22
+
23
+ return $this->_decorateRowHtml($element, $html);
24
+ }
25
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Config/Link.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Zendesk.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ class Zendesk_Zendesk_Block_Adminhtml_Config_Link extends Mage_Adminhtml_Block_System_Config_Form_Field
19
+ {
20
+ protected function _prepareLayout()
21
+ {
22
+ parent::_prepareLayout();
23
+ if (!$this->getTemplate()) {
24
+ $this->setTemplate('zendesk/config/link.phtml');
25
+ }
26
+ return $this;
27
+ }
28
+
29
+ public function render(Varien_Data_Form_Element_Abstract $element)
30
+ {
31
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
32
+ return parent::render($element);
33
+ }
34
+
35
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
36
+ {
37
+ // TODO: Check if the translation used here is actually superfluous
38
+ $data = $element->getOriginalData();
39
+
40
+ $path = $data['destination'];
41
+ $label = $data['value'];
42
+
43
+ $url = Mage::helper('zendesk')->getUrl('raw', $path);
44
+
45
+ $this->addData(array('label' => $label, 'link_url' => $url));
46
+
47
+ return $this->_toHtml();
48
+ }
49
+
50
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Customer/Edit/Tab/View/Tickets.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Customer_Edit_Tab_View_Tickets
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Customer_Edit_Tab_View_Tickets extends Mage_Core_Block_Abstract
15
+ {
16
+ protected function _prepareLayout()
17
+ {
18
+ /** @var Mage_Adminhtml_Block_Customer_Edit_Tab_View_Accordion $accordion */
19
+ $accordion = $this->getLayout()->getBlock('accordion');
20
+ if ($accordion instanceof Mage_Adminhtml_Block_Customer_Edit_Tab_View_Accordion) {
21
+ $accordion->addItem('freshdesk_tickets', array(
22
+ 'title' => Mage::helper('freshdesk')->__('Recent Tickets'),
23
+ 'ajax' => true,
24
+ 'content_url' => $this->getUrl('*/freshdesk/customerView', array('_current' => true)),
25
+ ));
26
+ } else {
27
+ Mage::getSingleton('adminhtml/session')->addWarning("Can't get parent block for Recent Tickets");
28
+ Mage::logException(new Mageplace_Freshdesk_Exception("Can't get parent block for Recent Tickets"));
29
+ }
30
+ }
31
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket extends Mage_Adminhtml_Block_Widget_Grid_Container
15
+ {
16
+ protected $_blockGroup = 'freshdesk';
17
+ protected $_controller = 'adminhtml_ticket';
18
+
19
+ /**
20
+ * Constructor for Adminhtml Block
21
+ */
22
+ public function __construct()
23
+ {
24
+ $this->_addButtonLabel = $this->__('Create Ticket');
25
+
26
+ $this->_addButton('refresh', array(
27
+ 'label' => $this->__('Refresh'),
28
+ 'onclick' => 'setLocation(\'' . $this->getRefreshUrl() .'\')',
29
+ //'class' => 'add',
30
+ ));
31
+
32
+ parent::__construct();
33
+ }
34
+
35
+ public function getCreateUrl()
36
+ {
37
+ return $this->getUrl('*/freshdesk_ticket/create');
38
+ }
39
+
40
+ public function getRefreshUrl()
41
+ {
42
+ return $this->getUrl('*/freshdesk_ticket/refresh');
43
+ }
44
+
45
+ public function getHeaderText()
46
+ {
47
+ return $this->__('Tickets');
48
+ }
49
+
50
+ public function getHeaderCssClass()
51
+ {
52
+ return 'icon-head head-ticket-page';
53
+ }
54
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
15
+ {
16
+ protected $_objectId = 'ticket_id';
17
+ protected $_blockGroup = 'freshdesk';
18
+ protected $_controller = 'adminhtml_ticket';
19
+
20
+
21
+ /**
22
+ * Constructor for the category edit form
23
+ */
24
+ public function __construct()
25
+ {
26
+ parent::__construct();
27
+
28
+ $this->_removeButton('back');
29
+ $this->_removeButton('reset');
30
+ $this->_removeButton('delete');
31
+
32
+ $this->_addButton('save_and_new',
33
+ array(
34
+ 'label' => $this->__('Save and New'),
35
+ 'onclick' => 'editForm.submit(\'' . $this->getSaveAndNewUrl() . '\')',
36
+ 'class' => 'save'
37
+ ),
38
+ -110
39
+ );
40
+
41
+ /*$this->_addButton('save_and_close',
42
+ array(
43
+ 'label' => $this->__('Save and Close'),
44
+ 'onclick' => 'editForm.submit(\'' . $this->getSaveAndCloseUrl() . '\')',
45
+ 'class' => 'save'
46
+ ),
47
+ -100
48
+ );*/
49
+
50
+ $this->_addButton('cancel',
51
+ array(
52
+ 'label' => $this->__('Cancel'),
53
+ 'onclick' => 'setLocation(\'' . $this->getCancelUrl() . '\')',
54
+ 'class' => 'cancel'
55
+ ),
56
+ -90
57
+ );
58
+ }
59
+
60
+ public function getCancelUrl()
61
+ {
62
+ return $this->getUrl('*/freshdesk/ticket');
63
+ }
64
+
65
+ public function getSaveAndNewUrl()
66
+ {
67
+ return $this->getUrl('*/*/save', array(
68
+ '_current' => true,
69
+ 'back' => 'new',
70
+ ));
71
+ }
72
+
73
+ public function getSaveAndCloseUrl()
74
+ {
75
+ return $this->getUrl('*/*/save', array(
76
+ '_current' => true,
77
+ 'back' => 'no',
78
+ ));
79
+ }
80
+
81
+ public function addFormScripts($js)
82
+ {
83
+ $this->_formScripts[] = $js;
84
+ }
85
+
86
+ public function getHeaderText()
87
+ {
88
+ return $this->__('Create Ticket');
89
+ }
90
+
91
+ public function getHeaderCssClass()
92
+ {
93
+ return '';
94
+ }
95
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
15
+ {
16
+ protected function _prepareLayout()
17
+ {
18
+ parent::_prepareLayout();
19
+ if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
20
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
21
+ }
22
+ }
23
+
24
+ protected function _prepareForm()
25
+ {
26
+ $form = new Varien_Data_Form();
27
+
28
+ $fieldset = $form->addFieldset('create-ticket-fieldset',
29
+ array(
30
+ 'legend' => $this->__('Create Ticket'),
31
+ 'class' => 'fieldset-wide'
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('ticket_fields_area',
36
+ 'note',
37
+ array(
38
+ 'name' => 'ticket_fields_area',
39
+ 'text' => '<div style="width:50%;">' . $this->getLayout()->createBlock('freshdesk/adminhtml_ticket_edit_form_fields')->setForm($this)->toHtml() . '</div>',
40
+ )
41
+ );
42
+
43
+ $form->setUseContainer(true);
44
+ $form->setId('edit_form');
45
+ $form->setMethod('post');
46
+
47
+ $form->setAction($this->getSaveUrl());
48
+
49
+ $this->setForm($form);
50
+
51
+ return parent::_prepareForm();
52
+ }
53
+
54
+ public function getSaveUrl()
55
+ {
56
+ return $this->getUrl('*/*/save');
57
+ }
58
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Edit/Form/Fields.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form_Fields
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form_Fields extends Mage_Core_Block_Template
15
+ {
16
+ protected $_helper;
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ $this->_helper = $this->helper('freshdesk');
23
+
24
+ $this->setTemplate('freshdesk/ticket/edit/form/fields.phtml');
25
+ }
26
+
27
+ /**
28
+ * @return Mageplace_Freshdesk_Model_Resource_Field_Collection
29
+ */
30
+ public function getFields()
31
+ {
32
+ if ($this->_getData('fields') === null) {
33
+ $this->setData('fields', Mage::getResourceModel('freshdesk/field_collection'));
34
+
35
+ }
36
+
37
+ return $this->_getData('fields');
38
+ }
39
+
40
+ /**
41
+ * @param Mageplace_Freshdesk_Model_Field $field
42
+ *
43
+ * @return string
44
+ */
45
+ public function getFieldHtml($field)
46
+ {
47
+ $block = $this->getLayout()->createBlock(
48
+ 'freshdesk/field_row',
49
+ 'freshdesk_field_row',
50
+ array('field' => $field)
51
+ );
52
+ if ($block instanceof Mageplace_Freshdesk_Block_Field_Row) {
53
+ return $block->toHtml();
54
+ } else {
55
+ return '';
56
+ }
57
+ }
58
+
59
+ public function _helper()
60
+ {
61
+ return $this->_helper;
62
+ }
63
+
64
+ protected function _toHtml()
65
+ {
66
+ return parent::_toHtml();
67
+ }
68
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid extends Mage_Adminhtml_Block_Widget_Grid
15
+ {
16
+ protected $_customer;
17
+
18
+ /**
19
+ * Constructor of Grid
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+
26
+ $collection = Mage::getResourceModel('freshdesk/ticket_collection');
27
+
28
+ if (is_object(Mage::registry('current_customer'))) {
29
+ $this->setCustomer(Mage::registry('current_customer'));
30
+
31
+ $collection->setRequester($this->getCustomer()->getEmail());
32
+
33
+ $this->setId('customer_view_orders_grid');
34
+ $this->setDefaultSort('created_at', 'desc');
35
+ $this->setSortable(false);
36
+ $this->setPagerVisibility(false);
37
+ } else {
38
+ $this->setId('freshdesk_ticket_grid');
39
+ }
40
+
41
+ $this->setFilterVisibility(false);
42
+
43
+ $this->setUseAjax(false);
44
+ $this->setDefaultSort('display_id');
45
+ $this->setDefaultDir('DESC');
46
+
47
+ /* @var $collection Mageplace_Freshdesk_Model_Resource_Ticket_Collection */
48
+ $this->setCollection($collection);
49
+
50
+ // echo "<pre>"; var_dump($collection->getItems()); die;
51
+ }
52
+
53
+ /**
54
+ * @return Mage_Customer_Model_Customer|null
55
+ */
56
+ public function getCustomer()
57
+ {
58
+ return $this->_customer;
59
+ }
60
+
61
+ public function setCustomer($customer)
62
+ {
63
+ $this->_customer = $customer;
64
+
65
+ return $this;
66
+ }
67
+
68
+ public function getRowUrl($row)
69
+ {
70
+ return $this->getUrl('*/freshdesk_ticket/view', array('ticket_id' => $row->getDisplayId()));
71
+ }
72
+
73
+ public function getRowClickCallback()
74
+ {
75
+ $chooserJsObject = $this->getId();
76
+ $js = '
77
+ function (grid, event) {
78
+ var trElement = Event.findElement(event, "tr");
79
+ if(Object.isElement(trElement) && trElement.title != "" && trElement.title != "#") {
80
+ window.open(trElement.title, "_blank");
81
+ }
82
+ }
83
+ ';
84
+
85
+ return $js;
86
+ }
87
+
88
+ public function getGridUrl()
89
+ {
90
+ //return $this->getUrl('*/*/index', array('_current' => true));
91
+ }
92
+
93
+ protected function _preparePage()
94
+ {
95
+ if ($this->getCustomer() !== null) {
96
+ $this->getCollection()
97
+ ->setPageSize(5)
98
+ ->setCurPage(1);
99
+ } else {
100
+ parent::_preparePage();
101
+ }
102
+ }
103
+
104
+ protected function _prepareColumns()
105
+ {
106
+ $this->addColumn('subject',
107
+ array(
108
+ 'header' => $this->__('Subject'),
109
+ 'index' => 'subject',
110
+ 'filter' => false,
111
+ 'column_css_class' => $this->getCustomer() !== null ? 'grid-subject-column' : ''
112
+ )
113
+ );
114
+
115
+ $this->addColumn('display_id',
116
+ array(
117
+ 'header' => $this->__('Ticket#'),
118
+ 'index' => 'display_id',
119
+ 'type' => 'number',
120
+ 'width' => '80px',
121
+ 'filter' => false,
122
+ )
123
+ );
124
+
125
+ $this->addColumn('created_at',
126
+ array(
127
+ 'header' => $this->__('Date Created'),
128
+ 'index' => 'created_at',
129
+ 'type' => 'datetime',
130
+ 'gmtoffset' => true,
131
+ 'width' => '200px',
132
+ 'default' => ' ---- ',
133
+ 'filter' => false,
134
+ 'renderer' => 'freshdesk/adminhtml_ticket_grid_column_renderer_datetime',
135
+ )
136
+ );
137
+
138
+ $this->addColumn('requester_name',
139
+ array(
140
+ 'header' => $this->__('Request Name'),
141
+ 'index' => 'requester_name',
142
+ 'filter' => false,
143
+ )
144
+ );
145
+
146
+ $this->addColumn('due_by',
147
+ array(
148
+ 'header' => $this->__('Due By'),
149
+ 'index' => 'due_by',
150
+ 'type' => 'datetime',
151
+ 'gmtoffset' => true,
152
+ 'width' => '200px',
153
+ 'default' => ' ---- ',
154
+ 'filter' => false,
155
+ 'renderer' => 'freshdesk/adminhtml_ticket_grid_column_renderer_datetime',
156
+ )
157
+ );
158
+
159
+ $this->addColumn('priority',
160
+ array(
161
+ 'header' => $this->__('Priority'),
162
+ 'index' => 'priority',
163
+ 'type' => 'options',
164
+ 'options' => $this->_getPriority(),
165
+ )
166
+ );
167
+
168
+ $this->addColumn('status',
169
+ array(
170
+ 'header' => $this->__('Status'),
171
+ 'index' => 'status',
172
+ 'type' => 'options',
173
+ 'options' => $this->_getStatus(),
174
+ )
175
+ );
176
+
177
+ $this->addColumn('responder_name',
178
+ array(
179
+ 'header' => $this->__('Agent'),
180
+ 'index' => 'responder_name',
181
+ 'filter' => false,
182
+ 'column_css_class' => $this->getCustomer() !== null ? 'grid-agent-column' : ''
183
+ )
184
+ );
185
+
186
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
187
+ if (is_object($orderField)) {
188
+ $this->addColumn(Mageplace_Freshdesk_Model_Ticket::ORDER_INCREMENT_ID,
189
+ array(
190
+ 'header' => $this->__('Order ID'),
191
+ 'index' => Mageplace_Freshdesk_Model_Ticket::ORDER_INCREMENT_ID,
192
+ 'width' => '80px',
193
+ 'filter' => false,
194
+ 'renderer' => 'freshdesk/adminhtml_ticket_grid_column_renderer_orderincrements',
195
+ )
196
+ );
197
+ }
198
+
199
+
200
+ $this->addColumn('action',
201
+ array(
202
+ 'header' => $this->__('Action'),
203
+ 'index' => 'display_id',
204
+ 'width' => '100px',
205
+ 'type' => 'action',
206
+ 'filter' => false,
207
+ 'sortable' => false,
208
+ 'actions' => array(
209
+ array(
210
+ 'caption' => $this->__('View'),
211
+ 'target' => '_blank',
212
+ 'url' => $this->getUrl('*/freshdesk_ticket/view', array('ticket_id' => '$display_id')),
213
+ ),
214
+ /*array(
215
+ 'caption' => Mage::helper('adminhtml')->__('Close'),
216
+ 'url' => $this->getUrl('*freshdesk_ticket/close', array(
217
+ 'ticket_id' => '$display_id',
218
+ 'customer_id' => $this->getCustomer() !== null ? $this->getCustomer()->getId() : ''
219
+ )
220
+ ),
221
+ ),*/
222
+ ),
223
+ )
224
+ );
225
+
226
+ return parent::_prepareColumns();
227
+ }
228
+
229
+ protected function _getPriority()
230
+ {
231
+ return $this->getCollection()->getPriorities();
232
+ }
233
+
234
+ protected function _getStatus()
235
+ {
236
+ return $this->getCollection()->getStatuses();
237
+ }
238
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Datetime.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid_Column_Renderer_Datetime
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid_Column_Renderer_Datetime
15
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Datetime
16
+ {
17
+ protected function _getFormat()
18
+ {
19
+ $format = $this->getColumn()->getFormat();
20
+ if (!$format) {
21
+ if (is_null(self::$_format)) {
22
+ try {
23
+ self::$_format = Mage::app()->getLocale()->getDateFormat($this->getLocale()) . ' ' . Mage::app()->getLocale()->getTranslation(array('gregorian', 'short'), 'time');
24
+ } catch (Exception $e) {
25
+ Mage::logException($e);
26
+ }
27
+ }
28
+
29
+ $format = self::$_format;
30
+ }
31
+
32
+ return $format;
33
+ }
34
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Orderincrements.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid_Column_Renderer_Ordersincrements
13
+ */
14
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid_Column_Renderer_Orderincrements
15
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
16
+ {
17
+ /**
18
+ * Renders grid column
19
+ *
20
+ * @param Varien_Object $row
21
+ *
22
+ * @return string
23
+ */
24
+ public function render(Varien_Object $row)
25
+ {
26
+ if ($index = $row->getData($this->getColumn()->getIndex())) {
27
+ $orderId = $row->getData(Mageplace_Freshdesk_Model_Ticket::ORDER_ID);
28
+ if ($orderId) {
29
+ return '<a href="' . Mage::getUrl('*/sales_order/view/', array('order_id' => $orderId)) . '">#' . $index . '</strong>';
30
+ } else {
31
+ return $index;
32
+ }
33
+ }
34
+
35
+ return '---';
36
+ }
37
+ }
app/code/local/Mageplace/Freshdesk/Block/Adminhtml/Ticket/Grid/Column/Renderer/Orders.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category Mageplace_Freshdesk
7
+ * @package Mageplace_Freshdesk
8
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ class Mageplace_Freshdesk_Block_Adminhtml_Ticket_Grid_Column_Renderer_Orders
12
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
13
+ {
14
+ /**
15
+ * Renders grid column
16
+ *
17
+ * @param Varien_Object $row
18
+ *
19
+ * @return string
20
+ */
21
+ public function render(Varien_Object $row)
22
+ {
23
+
24
+
25
+ if ($index = (int)$row->getData($this->getColumn()->getIndex())) {
26
+ $order = Mage::getModel('sales/order')->load($index);
27
+
28
+ if ($orderId = $order->getId()) {
29
+ return '<a href="' . Mage::getUrl('*/sales_order/view/', array('order_id' => $orderId)) . '">#' . $order->getIncrementId() . '</strong>';
30
+ }
31
+ }
32
+
33
+ return '---';
34
+ }
35
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Abstract.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
13
+ */
14
+ class Mageplace_Freshdesk_Block_Customer_Ticket_Abstract extends Mage_Core_Block_Template
15
+ {
16
+ public function getCustomer()
17
+ {
18
+ return Mage::getSingleton('customer/session')->getCustomer();
19
+ }
20
+
21
+ public function getCustomerEmail()
22
+ {
23
+ if ($this->_getData('customer_email') === null) {
24
+ $this->setData('customer_email', $this->getCustomer()->getEmail());
25
+ }
26
+
27
+ return $this->_getData('customer_email');
28
+ }
29
+
30
+ public function isFieldVisible($fieldName)
31
+ {
32
+ if ($this->_getData('field_visible_' . $fieldName) === null) {
33
+ $field = Mage::getModel('freshdesk/field')->loadByName($fieldName);
34
+
35
+ $this->setData('field_visible_' . $fieldName, is_object($field) && $field->isVisible());
36
+ }
37
+
38
+ return $this->_getData('field_visible_' . $fieldName);
39
+ }
40
+
41
+ public function isSubjectVisible()
42
+ {
43
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_SUBJECT);
44
+ }
45
+
46
+ public function isStatusVisible()
47
+ {
48
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_STATUS);
49
+ }
50
+
51
+ public function isOrderColumnVisible()
52
+ {
53
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
54
+
55
+ return is_object($orderField) && $orderField->isVisible() && $orderField->isEditable();
56
+ }
57
+
58
+ public function canAction()
59
+ {
60
+ if ($this->_getData('can_action') === null) {
61
+ $this->setData('can_action', Mage::helper('freshdesk')->isTicketTabEnabled());
62
+ }
63
+
64
+ return $this->_getData('can_action');
65
+ }
66
+
67
+ /**
68
+ * @param Mageplace_Freshdesk_Model_Ticket $ticket
69
+ *
70
+ * @return bool
71
+ */
72
+ public function canClose($ticket)
73
+ {
74
+ if (!$this->canAction()) {
75
+ return false;
76
+ }
77
+
78
+ $statusField = Mage::getModel('freshdesk/field')->loadStatusField();
79
+
80
+ return is_object($statusField) && $statusField->isEditable() && $ticket->getStatus() != Mage::helper('freshdesk')->getStatusClose();
81
+ }
82
+
83
+ public function getCreateUrl()
84
+ {
85
+ return $this->getUrl('freshdesk/ticket/create');
86
+ }
87
+
88
+ public function getViewUrl($ticket)
89
+ {
90
+ return $this->getUrl('freshdesk/ticket/view', array('ticket_id' => $ticket->getDisplayId()));
91
+ }
92
+
93
+ public function getCloseUrl($ticket)
94
+ {
95
+ return $this->getUrl('freshdesk/ticket/close', array('ticket_id' => $ticket->getDisplayId()));
96
+ }
97
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Create.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_Create
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Resource_Field_Collection getFields
15
+ * @method Mageplace_Freshdesk_Model_User getUser
16
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_Create setFields
17
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_Create setUser
18
+ */
19
+ class Mageplace_Freshdesk_Block_Customer_Ticket_Create extends Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
20
+ {
21
+ static $HIDE_FIELDS = array(
22
+ Mageplace_Freshdesk_Model_Field::FIELD_REQUESTER,
23
+ Mageplace_Freshdesk_Model_Field::FIELD_STATUS
24
+ );
25
+
26
+ public function __construct()
27
+ {
28
+ parent::__construct();
29
+
30
+ if (Mage::helper('freshdesk')->isTicketTabEnabled()) {
31
+ $fields = Mage::getModel('freshdesk/field')
32
+ ->getCollection()
33
+ ->load();
34
+
35
+ if (!$fields->getSize()) {
36
+ throw new Mageplace_Freshdesk_Exception($this->helper('freshdesk')->__('Wrong ticket\'s fields object'));
37
+ }
38
+
39
+ $this->setFields($fields);
40
+ $this->setUser(Mage::helper('freshdesk')->getCurrentUser());
41
+ }
42
+ }
43
+
44
+ protected function _prepareLayout()
45
+ {
46
+ parent::_prepareLayout();
47
+
48
+ if ($headBlock = $this->getLayout()->getBlock('head')) {
49
+ $headBlock->setTitle($this->getTitle());
50
+ }
51
+
52
+ return $this;
53
+ }
54
+
55
+ public function getTitle()
56
+ {
57
+ return $this->__('New Ticket');
58
+ }
59
+
60
+ /**
61
+ * @param Mageplace_Freshdesk_Model_Field $field
62
+ *
63
+ * @return bool|mixed
64
+ */
65
+ public function isFieldVisible($field)
66
+ {
67
+ if (in_array($field->getName(), self::$HIDE_FIELDS)) {
68
+ return false;
69
+ } elseif (!$field->isVisible()) {
70
+ return false;
71
+ } elseif (!$field->isEditable()) {
72
+ return false;
73
+ }
74
+
75
+ return true;
76
+ }
77
+
78
+ public function getFieldHtml($field)
79
+ {
80
+ $block = $this->getLayout()->createBlock(
81
+ 'freshdesk/field_row',
82
+ 'freshdesk_field_row',
83
+ array(
84
+ 'field' => $field,
85
+ 'template' => 'freshdesk/field/row.phtml'
86
+ )
87
+ );
88
+
89
+ if ($block instanceof Mageplace_Freshdesk_Block_Field_Row) {
90
+ return $block->toHtml();
91
+ } else {
92
+ return '';
93
+ }
94
+ }
95
+
96
+ public function getCancelUrl()
97
+ {
98
+ return Mage::getUrl('*/*/list');
99
+ }
100
+
101
+ public function getSaveUrl()
102
+ {
103
+ return $this->getUrl('*/*/save', array('_current' => true));
104
+ }
105
+
106
+ public function getSaveNewUrl()
107
+ {
108
+ return $this->getUrl('*/*/save', array('_current' => true, 'back' => 'new'));
109
+ }
110
+
111
+ public function getSaveCloseUrl()
112
+ {
113
+ return $this->getUrl('*/*/save', array('_current' => true, 'back' => 'close'));
114
+ }
115
+
116
+ protected function _toHtml()
117
+ {
118
+ if (Mage::helper('freshdesk')->isTicketTabEnabled() && $this->getFields()->getSize() > 0) {
119
+ return parent::_toHtml();
120
+ }
121
+
122
+ return '';
123
+ }
124
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Grid.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_Grid
13
+ */
14
+ class Mageplace_Freshdesk_Block_Customer_Ticket_Grid extends Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
15
+ {
16
+ public function isSubjectColumnVisible() {
17
+ return $this->isSubjectVisible();
18
+ }
19
+
20
+ public function isIdColumnVisible() {
21
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_DISPLAY_ID);
22
+ }
23
+
24
+ public function isDateCreatedColumnVisible() {
25
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_CREATED_AT);
26
+ }
27
+
28
+ public function isAgentColumnVisible() {
29
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_AGENT);
30
+ }
31
+
32
+ public function isStatusColumnVisible() {
33
+ return $this->isStatusVisible();
34
+ }
35
+
36
+ public function isPriorityColumnVisible() {
37
+ return $this->isFieldVisible(Mageplace_Freshdesk_Model_Field::FIELD_PRIORITY);
38
+ }
39
+
40
+ public function getOrderUrl($orderId)
41
+ {
42
+ return $this->getUrl('sales/order/view', array('order_id' => $orderId));
43
+ }
44
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/List.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_List
13
+ *
14
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_List setTickets
15
+ * @method Mageplace_Freshdesk_Model_Resource_Ticket_Collection getTickets
16
+ */
17
+ class Mageplace_Freshdesk_Block_Customer_Ticket_List extends Mageplace_Freshdesk_Block_Customer_Ticket_Grid
18
+ {
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ if (Mage::helper('freshdesk')->isTicketTabEnabled()
24
+ && Zend_Validate::is($this->getCustomerEmail(), 'EmailAddress')
25
+ ) {
26
+ $tickets = Mage::getResourceModel('freshdesk/ticket_collection')
27
+ ->setRequester($this->getCustomerEmail())
28
+ ->setOrder('created_at', 'DESC');
29
+
30
+ $this->setTickets($tickets);
31
+ }
32
+ }
33
+
34
+ protected function _prepareLayout()
35
+ {
36
+ parent::_prepareLayout();
37
+
38
+ $pager = $this->getLayout()
39
+ ->createBlock('page/html_pager', 'freshdesk_tickets_pager')
40
+ ->setCollection($this->getTickets());
41
+ $this->setChild('pager', $pager);
42
+
43
+ $this->getTickets()->load();
44
+
45
+ return $this;
46
+ }
47
+
48
+ public function getPagerHtml()
49
+ {
50
+ return $this->getChildHtml('pager');
51
+ }
52
+
53
+ public function isRefreshButtonVisible()
54
+ {
55
+ return
56
+ Mage::app()->useCache(Mageplace_Freshdesk_Model_Cache::CACHE_TYPE)
57
+ && is_object($this->getTickets())
58
+ && $this->getTickets()->getSize() > 0;
59
+ }
60
+
61
+ public function getRefreshUrl()
62
+ {
63
+ return $this->getUrl('freshdesk/ticket/refresh');
64
+ }
65
+
66
+ protected function _toHtml()
67
+ {
68
+ if (Mage::helper('freshdesk')->isTicketTabEnabled()) {
69
+ return parent::_toHtml();
70
+ }
71
+
72
+ return '';
73
+ }
74
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/Recent.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_Recent
13
+ *
14
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_Recent setTickets
15
+ * @method array getTickets
16
+ */
17
+ class Mageplace_Freshdesk_Block_Customer_Ticket_Recent extends Mageplace_Freshdesk_Block_Customer_Ticket_Grid
18
+ {
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ if (Mage::helper('freshdesk')->isRecentTicketsGridEnabled()
24
+ && Zend_Validate::is($this->getCustomerEmail(), 'EmailAddress')
25
+ ) {
26
+ $tickets = Mage::getResourceModel('freshdesk/ticket_collection')
27
+ ->setRequester($this->getCustomerEmail())
28
+ ->setOrder('created_at', 'DESC')
29
+ ->setPageSize('5')
30
+ ->setCurPage(1)
31
+ ->load();
32
+
33
+ $this->setTickets($tickets);
34
+ }
35
+ }
36
+
37
+ public function getViewAllUrl()
38
+ {
39
+ return $this->getUrl('freshdesk/ticket/list');
40
+ }
41
+
42
+ protected function _toHtml()
43
+ {
44
+ if (Mage::helper('freshdesk')->isRecentTicketsGridEnabled() && is_object($this->getTickets()) && $this->getTickets()->getSize() > 0) {
45
+ return parent::_toHtml();
46
+ }
47
+
48
+ return '';
49
+ }
50
+ }
app/code/local/Mageplace/Freshdesk/Block/Customer/Ticket/View.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Customer_Ticket_View
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Ticket getTicket
15
+ * @method array getNotes
16
+ * @method Mageplace_Freshdesk_Model_User getUser
17
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_View setTicket
18
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_View setNotes
19
+ * @method Mageplace_Freshdesk_Block_Customer_Ticket_View setUser
20
+ */
21
+ class Mageplace_Freshdesk_Block_Customer_Ticket_View extends Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
22
+ {
23
+ const TAG_MESSAGE = '{{MESSAGE}}';
24
+
25
+ public function __construct()
26
+ {
27
+ parent::__construct();
28
+
29
+ if (Mage::helper('freshdesk')->isTicketTabEnabled()) {
30
+ $this->setTicket(Mage::helper('freshdesk')->getCurrentTicket());
31
+ $this->setNotes(Mage::helper('freshdesk')->getCurrentTicket()->getNoteItems());
32
+
33
+ $user = Mage::helper('freshdesk')->getCurrentUser();
34
+ if (!$user->getId()) {
35
+ $user = Mage::getModel('freshdesk/user')->load(Mage::helper('freshdesk')->getCurrentTicket()->getRequesterId());
36
+ }
37
+ $this->setUser($user);
38
+ }
39
+ }
40
+
41
+ protected function _prepareLayout()
42
+ {
43
+ parent::_prepareLayout();
44
+
45
+ if ($headBlock = $this->getLayout()->getBlock('head')) {
46
+ $headBlock->setTitle($this->getTitle());
47
+ }
48
+
49
+ return $this;
50
+ }
51
+
52
+ public function getTitle()
53
+ {
54
+ if (null === $this->_getData('title')) {
55
+ if (($ticket = $this->getTicket()) && is_object($ticket)) {
56
+ if ($this->isStatusVisible()) {
57
+ $this->setData('title', $this->__('Ticket #%1$d - %2$s', $ticket->getDisplayId(), $ticket->getStatusName()));
58
+ } else {
59
+ $this->setData('title', $this->__('Ticket #%d', $ticket->getDisplayId()));
60
+ }
61
+ } else {
62
+ $this->setData('title', '');
63
+ }
64
+ }
65
+
66
+ return $this->_getData('title');
67
+ }
68
+
69
+ public function getSubject()
70
+ {
71
+ if (null === $this->_getData('subject')) {
72
+ if (($ticket = $this->getTicket()) && is_object($ticket) && $this->isSubjectVisible()) {
73
+ $this->setData('subject', $ticket->getSubject());
74
+ } else {
75
+ $this->setData('subject', '');
76
+ }
77
+ }
78
+
79
+ return $this->_getData('subject');
80
+ }
81
+
82
+ public function getDateDiff($date, $word)
83
+ {
84
+ $curTime = gmdate('U');
85
+ $neededTime = strtotime($date);
86
+
87
+ $diff = $curTime - $neededTime;
88
+ if (($years = floor($diff / (365 * 24 * 60 * 60))) > 0) {
89
+ return $this->__('%1$s about %2$d year(s) ago', $word, $years);
90
+ } elseif (($month = floor($diff / (30 * 24 * 60 * 60))) > 0) {
91
+ return $this->__('%1$s about %2$d month(s) ago', $word, $month);
92
+ } elseif (($day = floor($diff / (24 * 60 * 60))) > 0) {
93
+ return $this->__('%1$s about %2$d day(s) ago', $word, $day);
94
+ } elseif (($hour = floor($diff / (60 * 60))) > 0) {
95
+ return $this->__('%1$s about %2$d hour(s) ago', $word, $hour);
96
+ } elseif (($minute = floor($diff / (60))) > 0) {
97
+ return $this->__('%1$s about %2$d minute(s) ago', $word, $minute);
98
+ } else {
99
+ return $this->__('%1$s about %2$d second(s) ago', $word, $diff);
100
+ }
101
+ }
102
+
103
+ public function isRefreshButtonVisible()
104
+ {
105
+ return Mage::app()->useCache(Mageplace_Freshdesk_Model_Cache::CACHE_TYPE);
106
+ }
107
+
108
+ public function getRefreshUrl()
109
+ {
110
+ return $this->getUrl('freshdesk/ticket/refresh', array('ticket_id' => $this->getTicket()->getId()));
111
+ }
112
+
113
+ public function getMessageTag()
114
+ {
115
+ return self::TAG_MESSAGE;
116
+ }
117
+
118
+ public function getSendReplyUrl()
119
+ {
120
+ return $this->getUrl('freshdesk/ticket/reply', array('ticket_id' => $this->getTicket()->getId(), 'message' => $this->getMessageTag()));
121
+ }
122
+
123
+ public function getBackUrl()
124
+ {
125
+ return Mage::getUrl('*/*/list');
126
+ }
127
+
128
+ public function getCloseUrl($ticket = null)
129
+ {
130
+ if (null === $ticket) {
131
+ $ticket = $this->getTicket();
132
+ }
133
+
134
+ return parent::getCloseUrl($ticket);
135
+ }
136
+
137
+ public function getBackTitle()
138
+ {
139
+ return Mage::helper('sales')->__('Back to My Tickets');
140
+ }
141
+
142
+ protected function _toHtml()
143
+ {
144
+ if (Mage::helper('freshdesk')->isTicketTabEnabled() && is_object($this->getTicket()) && $this->getTicket()->getId()) {
145
+ return parent::_toHtml();
146
+ }
147
+
148
+ return '';
149
+ }
150
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Abstract.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Abstract
13
+ *
14
+ * @method Mageplace_Freshdesk_Block_Field_Abstract setField
15
+ * @method Mageplace_Freshdesk_Block_Field_Abstract setRowTemplate
16
+ * @method string|null getRowTemplate
17
+ *
18
+ */
19
+ class Mageplace_Freshdesk_Block_Field_Abstract extends Mage_Core_Block_Template
20
+ {
21
+ CONST CLASS_NAME_REQUIRED_ENTRY = 'required-entry';
22
+
23
+ protected $_fieldRowTemplate;
24
+ protected $_fieldRowAdminTemplate;
25
+ protected $_helper;
26
+ protected $_classNames = array();
27
+
28
+ public function _construct()
29
+ {
30
+ parent::_construct();
31
+
32
+ $this->_helper = $this->helper('freshdesk');
33
+ }
34
+
35
+ public function getFieldRowTemplate()
36
+ {
37
+ if ($this->hasData('field_row_template')) {
38
+ return $this->getData('field_row_template');
39
+ }
40
+
41
+ if ($this->isAdminArea() && !empty($this->_fieldRowAdminTemplate)) {
42
+ return $this->_fieldRowAdminTemplate;
43
+ }
44
+
45
+ return $this->_fieldRowTemplate;
46
+ }
47
+
48
+ /**
49
+ * @return Mageplace_Freshdesk_Helper_Data
50
+ */
51
+ public function _helper()
52
+ {
53
+ return $this->_helper;
54
+ }
55
+
56
+ public function getField()
57
+ {
58
+ if ($this->_getData('field') === null) {
59
+ throw new Mageplace_Freshdesk_Exception($this->_helper()->__('Wrong field object'));
60
+ }
61
+
62
+ return $this->_getData('field');
63
+ }
64
+
65
+ public function getFieldId()
66
+ {
67
+ if ($this->_getData('field_id') === null) {
68
+ $this->setData('field_id', $this->getFieldName() . '_' . $this->getField()->getId());
69
+ }
70
+
71
+ return $this->_getData('field_id');
72
+ }
73
+
74
+ public function getFieldName()
75
+ {
76
+ if ($this->_getData('field_name') === null) {
77
+ $this->setData('field_name', $this->getField()->getName());
78
+ }
79
+
80
+ return $this->_getData('field_name');
81
+ }
82
+
83
+ public function getFieldLabel()
84
+ {
85
+ if ($this->_getData('field_label') === null) {
86
+ $this->setData('field_label', $this->getField()->getLabel());
87
+ }
88
+
89
+ return $this->_getData('field_label');
90
+ }
91
+
92
+ public function getOrderIdFieldName()
93
+ {
94
+ if (null === $this->_getData('order_id_field_name')) {
95
+ /** @var Mageplace_Freshdesk_Model_Field $orderField */
96
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
97
+ $this->setData('order_id_field_name', is_object($orderField) ? $orderField->getName() : '');
98
+ }
99
+
100
+ return $this->_getData('order_id_field_name');
101
+ }
102
+
103
+ public function isOrderField()
104
+ {
105
+ return $this->getOrderIdFieldName() == $this->getFieldName();
106
+ }
107
+
108
+ public function getOrderId()
109
+ {
110
+ if ($this->isOrderField() && ($orderId = $this->getRequest()->getParam('order_id'))) {
111
+ return $orderId;
112
+ }
113
+
114
+ return '';
115
+ }
116
+
117
+ public function isRequired()
118
+ {
119
+ if ($this->_getData('is_required') === null) {
120
+ $this->setData('is_required', $this->getField()->isRequired());
121
+ }
122
+
123
+ return $this->_getData('is_required');
124
+ }
125
+
126
+ public function isAdminArea()
127
+ {
128
+ if ($this->_getData('is_admin') === null) {
129
+ $this->setData('is_admin', $this->getField()->isAdmin());
130
+ }
131
+
132
+ return $this->_getData('is_admin');
133
+ }
134
+
135
+ public function addFieldClass($className)
136
+ {
137
+ if (is_array($className)) {
138
+ $this->_classNames = array_merge($this->_classNames, $className);
139
+ } else {
140
+ $this->_classNames[] = strval($className);
141
+ }
142
+
143
+ return $this;
144
+ }
145
+
146
+ public function getFieldClass()
147
+ {
148
+ $classNames = $this->_classNames;
149
+
150
+ if ($this->hasData('field_class')) {
151
+ $classNames[] = strval($this->getData('field_class'));
152
+ }
153
+
154
+ return implode(' ', array_reverse($classNames));
155
+ }
156
+
157
+ protected function _beforeToHtml()
158
+ {
159
+ if ($this->isRequired()) {
160
+ $this->addFieldClass(self::CLASS_NAME_REQUIRED_ENTRY);
161
+ }
162
+
163
+ return parent::_beforeToHtml();
164
+ }
165
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Checkbox.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Custom_Checkbox
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Custom_Checkbox extends Mageplace_Freshdesk_Block_Field_Abstract
15
+ {
16
+ const CLASS_NAME_CHECKBOX = 'checkbox';
17
+
18
+ protected $_fieldRowTemplate = 'freshdesk/field/row_inline.phtml';
19
+ protected $_fieldRowAdminTemplate = 'freshdesk/field/row_1_column.phtml';
20
+
21
+ public function _construct()
22
+ {
23
+ $this->setTemplate('freshdesk/field/checkbox.phtml');
24
+
25
+ parent::_construct();
26
+ }
27
+
28
+ protected function _beforeToHtml()
29
+ {
30
+ $this->addFieldClass(self::CLASS_NAME_CHECKBOX);
31
+
32
+ return parent::_beforeToHtml();
33
+ }
34
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Dropdown.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Custom_Dropdown
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Custom_Dropdown extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Number.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Custom_Text
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Custom_Number extends Mageplace_Freshdesk_Block_Field_Text
15
+ {
16
+ const CLASS_NAME_VALIDATE_NUMBER = 'validate-number';
17
+ const CLASS_NAME_QTY = 'qty';
18
+
19
+
20
+ protected function _beforeToHtml()
21
+ {
22
+ $this->addFieldClass(self::CLASS_NAME_QTY);
23
+ $this->addFieldClass(self::CLASS_NAME_VALIDATE_NUMBER);
24
+
25
+ return Mageplace_Freshdesk_Block_Field_Abstract::_beforeToHtml();
26
+ }
27
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Paragraph.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Custom_Paragraph
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Custom_Paragraph extends Mageplace_Freshdesk_Block_Field_Paragraph
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Custom/Text.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Custom_Text
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Custom_Text extends Mageplace_Freshdesk_Block_Field_Text
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Agent.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Agent
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Agent extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Description.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Description
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Description extends Mageplace_Freshdesk_Block_Field_Paragraph
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Group.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Group
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Group extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Priority.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Priority
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Priority extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Requester.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Requester
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Requester extends Mageplace_Freshdesk_Block_Field_Text
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Source.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Source
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Source extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Status.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Status
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Status extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Subject.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Subject
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Subject extends Mageplace_Freshdesk_Block_Field_Text
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Default/Ticket/Type.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Default_Requester
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Default_Ticket_Type extends Mageplace_Freshdesk_Block_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Dropdown.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Abstract
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Dropdown extends Mageplace_Freshdesk_Block_Field_Abstract
15
+ {
16
+ const CLASS_NAME_SELECT = 'select';
17
+
18
+ public function _construct()
19
+ {
20
+ $this->setTemplate('freshdesk/field/dropdown.phtml');
21
+
22
+ parent::_construct();
23
+ }
24
+
25
+ public function getOptions()
26
+ {
27
+ if ($this->_getData('choices') === null) {
28
+ $choices[] = array(
29
+ 'label' => $this->_helper()->__('...'),
30
+ 'value' => ''
31
+ );
32
+ foreach ($this->getField()->getChoices() as $choice) {
33
+ if (empty($choice)) {
34
+ continue;
35
+ }
36
+
37
+ if (!is_array($choice)) {
38
+ $choices[] = array(
39
+ 'label' => strval($choice),
40
+ 'value' => strval($choice)
41
+ );
42
+ } else {
43
+ $choices[] = array(
44
+ 'label' => strval($choice[0]),
45
+ 'value' => strval($choice[1])
46
+ );
47
+ }
48
+ }
49
+
50
+ $this->setData('choices', $choices);
51
+ }
52
+
53
+ return $this->_getData('choices');
54
+ }
55
+
56
+ protected function _beforeToHtml()
57
+ {
58
+ $this->addFieldClass(self::CLASS_NAME_SELECT);
59
+
60
+ return parent::_beforeToHtml();
61
+ }
62
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Nested/Field.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Nested_Field
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Nested_Field extends Mageplace_Freshdesk_Block_Field_Abstract
15
+ {
16
+ const CLASS_NAME_INPUT_TEXT = 'select';
17
+
18
+ public function _construct()
19
+ {
20
+ $this->setTemplate('freshdesk/field/nested_field.phtml');
21
+
22
+ parent::_construct();
23
+ }
24
+
25
+ public function getNestedFields()
26
+ {
27
+ if ($this->_getData('nested_ticket_fields') === null) {
28
+ $this->setData('nested_ticket_fields', $this->getField()->getNestedTicketFields());
29
+ }
30
+
31
+ return $this->_getData('nested_ticket_fields');
32
+ }
33
+
34
+ public function getFirstLevelNestedField()
35
+ {
36
+ return $this->getField()->getFirstLevelField();
37
+ }
38
+
39
+ public function getFirstLevelNestedFieldName()
40
+ {
41
+ return $this->getField()->getFirstLevelFieldName();
42
+ }
43
+
44
+ public function getFirstLevelNestedFieldId()
45
+ {
46
+ return $this->getFirstLevelNestedFieldName() . '_' . $this->getField()->getFirstLevelFieldId();
47
+ }
48
+
49
+ public function getFirstLevelNestedFieldLabel()
50
+ {
51
+ return $this->getField()->getFirstLevelFieldLabel();
52
+ }
53
+
54
+ public function hasSecondLevel()
55
+ {
56
+ return $this->getField()->hasSecondLevel();
57
+ }
58
+
59
+ public function getSecondLevelNestedField()
60
+ {
61
+ return $this->getField()->getSecondLevelField();
62
+ }
63
+
64
+ public function getSecondLevelNestedFieldName()
65
+ {
66
+ return $this->getField()->getSecondLevelFieldName();
67
+ }
68
+
69
+ public function getSecondLevelNestedFieldId()
70
+ {
71
+ return $this->getSecondLevelNestedFieldName() . '_' . $this->getField()->getSecondLevelFieldId();
72
+ }
73
+
74
+ public function getSecondLevelNestedFieldLabel()
75
+ {
76
+ return $this->getField()->getSecondLevelFieldLabel();
77
+ }
78
+
79
+
80
+ public function getNestedOptions()
81
+ {
82
+ if ($this->_getData('nested_choices') === null) {
83
+ $options = $this->getNestedOptionChilds($this->getField()->getNestedChoices());
84
+ $this->setData('nested_choices', $options);
85
+ }
86
+
87
+ return $this->_getData('nested_choices');
88
+ }
89
+
90
+ protected function getNestedOptionChilds(array $array)
91
+ {
92
+ $choices[] = array(
93
+ 'label' => $this->_helper()->__('...'),
94
+ 'value' => '',
95
+ 'children' => array()
96
+ );
97
+
98
+ foreach ($array as $choice) {
99
+ if (empty($choice)) {
100
+ continue;
101
+ }
102
+
103
+ if (!is_array($choice)) {
104
+ $choices[] = array(
105
+ 'label' => strval($choice),
106
+ 'value' => strval($choice),
107
+ 'children' => array()
108
+ );
109
+ } else {
110
+ $choices[] = array(
111
+ 'label' => strval($choice[0]),
112
+ 'value' => strval($choice[1]),
113
+ 'children' => empty($choice[2]) || !is_array($choice[2]) ? array() : $this->getNestedOptionChilds($choice[2])
114
+ );
115
+ }
116
+
117
+ }
118
+
119
+ return $choices;
120
+ }
121
+
122
+ protected function _beforeToHtml()
123
+ {
124
+ $this->addFieldClass(self::CLASS_NAME_INPUT_TEXT);
125
+
126
+ return parent::_beforeToHtml();
127
+ }
128
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Paragraph.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Abstract
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Paragraph extends Mageplace_Freshdesk_Block_Field_Abstract
15
+ {
16
+ const CLASS_NAME_TEXTAREA = 'textarea';
17
+
18
+ public function _construct()
19
+ {
20
+ $this->setTemplate('freshdesk/field/paragraph.phtml');
21
+
22
+ parent::_construct();
23
+ }
24
+
25
+ public function getEditor()
26
+ {
27
+ $config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array(
28
+ 'enabled' => $this->isAdminArea(),
29
+ 'add_variables' => 0,
30
+ 'add_widgets' => false,
31
+ 'add_images' => false,
32
+ ));
33
+
34
+ $editor = new Varien_Data_Form_Element_Editor(array(
35
+ 'config' => $config,
36
+ 'html_id' => $this->getFieldId(),
37
+ 'name' => $this->getFieldName(),
38
+ 'title' => $this->getFieldLabel(),
39
+ 'required' => $this->isRequired(),
40
+ 'add_widgets' => 0,
41
+ 'add_images' => 0,
42
+ 'plugins' => 0,
43
+
44
+ ));
45
+
46
+ $editor->setForm(new Varien_Data_Form());
47
+
48
+ return $editor;
49
+ }
50
+
51
+ protected function _beforeToHtml()
52
+ {
53
+ $this->addFieldClass(self::CLASS_NAME_TEXTAREA);
54
+
55
+ return parent::_beforeToHtml();
56
+ }
57
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Row.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Row
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Field getField
15
+ * @method Mageplace_Freshdesk_Block_Field_Abstract setField
16
+ */
17
+ class Mageplace_Freshdesk_Block_Field_Row extends Mageplace_Freshdesk_Block_Field_Abstract
18
+ {
19
+ const CHILD_BLOCK_NAME_INPUT_FIELD = 'edit_input_field';
20
+
21
+ public function _construct()
22
+ {
23
+ $this->setTemplate('freshdesk/field/row_2_column.phtml');
24
+
25
+ parent::_construct();
26
+ }
27
+
28
+ protected function _prepareLayout()
29
+ {
30
+ parent::_prepareLayout();
31
+
32
+ $blockType = $this->getField()->getFieldBlockType();
33
+ $block = $this->getLayout()->createBlock($blockType);
34
+ if (!$block instanceof Mageplace_Freshdesk_Block_Field_Abstract) {
35
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Invalid block "%s"', $blockType));
36
+ }
37
+
38
+ $block->setField($this->getField());
39
+
40
+ if ($block instanceof Mageplace_Freshdesk_Block_Field_Abstract) {
41
+ if($rowTemplate = $block->getFieldRowTemplate()) {
42
+ $this->setTemplate($rowTemplate);
43
+ }
44
+ $this->setChild(self::CHILD_BLOCK_NAME_INPUT_FIELD, $block);
45
+ }
46
+ }
47
+
48
+ public function getFieldName()
49
+ {
50
+ if($this->_getData('field_name') === null) {
51
+ if(!is_object($this->getChild(self::CHILD_BLOCK_NAME_INPUT_FIELD)) || !($fieldName = $this->getChild(self::CHILD_BLOCK_NAME_INPUT_FIELD)->getFieldName())) {
52
+ $fieldName = parent::getFieldName();
53
+ }
54
+ $this->setData('field_name', $fieldName);
55
+ }
56
+
57
+ return $this->_getData('field_name');
58
+ }
59
+
60
+ public function getFieldId()
61
+ {
62
+ if($this->_getData('field_id') === null) {
63
+ if(!is_object($this->getChild(self::CHILD_BLOCK_NAME_INPUT_FIELD)) || !($fieldId = $this->getChild(self::CHILD_BLOCK_NAME_INPUT_FIELD)->getFieldId())) {
64
+ $fieldId = parent::getFieldId();
65
+ }
66
+ $this->setData('field_id', $fieldId);
67
+ }
68
+
69
+ return $this->_getData('field_id');
70
+ }
71
+
72
+
73
+ public function getInputFieldHtml()
74
+ {
75
+ return $this->getChildHtml(self::CHILD_BLOCK_NAME_INPUT_FIELD);
76
+ }
77
+ }
app/code/local/Mageplace/Freshdesk/Block/Field/Text.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Field_Abstract
13
+ */
14
+ class Mageplace_Freshdesk_Block_Field_Text extends Mageplace_Freshdesk_Block_Field_Abstract
15
+ {
16
+ const CLASS_NAME_INPUT_TEXT = 'input-text';
17
+
18
+ public function _construct()
19
+ {
20
+ $this->setTemplate('freshdesk/field/text.phtml');
21
+
22
+ parent::_construct();
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->addFieldClass(self::CLASS_NAME_INPUT_TEXT);
28
+
29
+ return parent::_beforeToHtml();
30
+ }
31
+ }
app/code/local/Mageplace/Freshdesk/Block/Order/Info/Buttons.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Order_Info_Buttons
13
+ */
14
+ class Mageplace_Freshdesk_Block_Order_Info_Buttons extends Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
15
+ {
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ }
20
+
21
+ /**
22
+ * Retrieve current order model instance
23
+ *
24
+ * @return Mage_Sales_Model_Order
25
+ */
26
+ public function getOrder()
27
+ {
28
+ return Mage::registry('current_order');
29
+ }
30
+
31
+ /**
32
+ * Get url for printing order
33
+ *
34
+ * @param Mage_Sales_Model_Order|null $order
35
+ *
36
+ * @return string
37
+ */
38
+ public function getCreateTicketUrl($order = null)
39
+ {
40
+ if (null === $order) {
41
+ $order = $this->getOrder();
42
+ }
43
+
44
+ return Mage::helper('freshdesk')->getCreateOrderTicketUrl($order);
45
+ }
46
+
47
+ protected function _toHtml()
48
+ {
49
+ if (Mage::helper('freshdesk')->isTicketTabEnabled()) {
50
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
51
+ if (is_object($orderField) && $orderField->isEditable()) {
52
+ return parent::_toHtml();
53
+ }
54
+ }
55
+
56
+ return '';
57
+ }
58
+ }
app/code/local/Mageplace/Freshdesk/Block/Page/Html/Head/Widget.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Block_Page_Html_Head_Widget
13
+ */
14
+ class Mageplace_Freshdesk_Block_Page_Html_Head_Widget extends Mageplace_Freshdesk_Block_Customer_Ticket_Abstract
15
+ {
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ }
20
+
21
+ public function getFeedbackWidgetCode()
22
+ {
23
+ return Mage::helper('freshdesk')->getFeedbackWidgetCode();
24
+ }
25
+
26
+ protected function _toHtml()
27
+ {
28
+ if (Mage::helper('freshdesk')->isFeedbackWidgetEnabled()) {
29
+ return parent::_toHtml();
30
+ }
31
+
32
+ return '';
33
+ }
34
+ }
app/code/local/Mageplace/Freshdesk/Exception.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2013 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ class Mageplace_Freshdesk_Exception extends Mage_Core_Exception
12
+ {
13
+ const ERROR_FIELDS = 1;
14
+
15
+ public function isWrongConfig()
16
+ {
17
+ switch($this->getCode()) {
18
+ case self::ERROR_FIELDS:
19
+ return true;
20
+ }
21
+
22
+ return false;
23
+ }
24
+ }
app/code/local/Mageplace/Freshdesk/Helper/Const.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Helper_Const
13
+ */
14
+ class Mageplace_Freshdesk_Helper_Const
15
+ {
16
+ const NAME = 'freshdesk';
17
+
18
+ const XML_ACCOUNT_DOMAIN = 'freshdesk/account/domain';
19
+ const XML_ACCOUNT_EMAIL = 'freshdesk/account/email';
20
+ const XML_ACCOUNT_API_KEY = 'freshdesk/account/api_key';
21
+ const XML_ACCOUNT_PASSWORD = 'freshdesk/account/password';
22
+
23
+ const XML_SSO_ENABLED = 'freshdesk/sso/enable';
24
+ const XML_SSO_SECRET = 'freshdesk/sso/secret';
25
+ const XML_SSO_LOGIN_URL = 'freshdesk/sso/login_url';
26
+ const XML_SSO_LOGOUT_URL = 'freshdesk/sso/logout_url';
27
+
28
+ const XML_ORDERS_ORDER_ID = 'freshdesk/orders/order_id';
29
+
30
+ const XML_CHANNELS_CONTACT_US_ENABLED = 'freshdesk/channels/enable_contact_us';
31
+ const XML_CHANNELS_FEEDBACK_WIDGET_ENABLED = 'freshdesk/channels/enable_feedback_widget';
32
+ const XML_CHANNELS_FEEDBACK_WIDGET_CODE = 'freshdesk/channels/feedback_widget';
33
+ const XML_CHANNELS_ENABLE_SUPPORT_LINK = 'freshdesk/channels/enable_support_link';
34
+
35
+ const XML_CUSTOMER_VIEW_ENABLE_CUSTOMER_VIEW = 'freshdesk/customer_view/enable_customer_view';
36
+ const XML_CUSTOMER_VIEW_ENABLE_TICKET_TAB = 'freshdesk/customer_view/enable_ticket_tab';
37
+ const XML_CUSTOMER_VIEW_ENABLE_RECENT_TICKET = 'freshdesk/customer_view/enable_recent_ticket';
38
+
39
+ const XML_TICKETS_PRIORITY = 'freshdesk/tickets/priority';
40
+ const XML_TICKETS_STATUS = 'freshdesk/tickets/status';
41
+ const XML_TICKETS_STATUS_CLOSE = 'freshdesk/tickets/status_close';
42
+
43
+ const REGISTER_CURRENT_FRESHDESK_TICKET = 'current_freshdesk_ticket';
44
+ const REGISTER_CURRENT_FRESHDESK_USER = 'current_freshdesk_user';
45
+ }
app/code/local/Mageplace/Freshdesk/Helper/Customer.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Helper_Data
13
+ */
14
+ class Mageplace_Freshdesk_Helper_Customer extends Mage_Customer_Helper_Data
15
+ {
16
+ public function getLoginUrlParams()
17
+ {
18
+ $params = array();
19
+
20
+ $referer = $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME);
21
+
22
+ if (!$referer && !Mage::getSingleton('customer/session')->getNoReferer()) {
23
+ $referer = Mage::getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
24
+ $referer = Mage::helper('core')->urlEncode($referer);
25
+ }
26
+
27
+ if ($referer) {
28
+ $params = array(self::REFERER_QUERY_PARAM_NAME => $referer);
29
+ }
30
+
31
+ return $params;
32
+ }
33
+ }
app/code/local/Mageplace/Freshdesk/Helper/Data.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Helper_Data
13
+ */
14
+ class Mageplace_Freshdesk_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+ public function isConfigSet()
17
+ {
18
+ return $this->getDomain() !== '' && $this->getAdminEmail() !== '' && ($this->getPassword() !== '' || $this->getAdminApiKey() !== '');
19
+ }
20
+
21
+ public function getDomain()
22
+ {
23
+ return trim(Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_ACCOUNT_DOMAIN));
24
+ }
25
+
26
+ public function getAdminEmail()
27
+ {
28
+ return trim(Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_ACCOUNT_EMAIL));
29
+ }
30
+
31
+ public function getAdminApiKey()
32
+ {
33
+ return trim(Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_ACCOUNT_API_KEY));
34
+ }
35
+
36
+ public function getPassword()
37
+ {
38
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_ACCOUNT_PASSWORD);
39
+ }
40
+
41
+ public function isSSOEnabled()
42
+ {
43
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_SSO_ENABLED);
44
+ }
45
+
46
+ public function getSSOSecret()
47
+ {
48
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_SSO_SECRET);
49
+ }
50
+
51
+ public function getSSOLoginUrl()
52
+ {
53
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_SSO_LOGIN_URL);
54
+ }
55
+
56
+ public function getSSOLogoutUrl()
57
+ {
58
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_SSO_LOGOUT_URL);
59
+ }
60
+
61
+ public function getOrderIdField()
62
+ {
63
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_ORDERS_ORDER_ID);
64
+ }
65
+
66
+ public function isContactUsFormEnabled()
67
+ {
68
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CHANNELS_CONTACT_US_ENABLED) == 1;
69
+ }
70
+
71
+ public function isFeedbackWidgetEnabled()
72
+ {
73
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CHANNELS_FEEDBACK_WIDGET_ENABLED) == 1;
74
+ }
75
+
76
+ public function getFeedbackWidgetCode()
77
+ {
78
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CHANNELS_FEEDBACK_WIDGET_CODE);
79
+ }
80
+
81
+ public function isSupportLinkEnabled()
82
+ {
83
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CHANNELS_ENABLE_SUPPORT_LINK) == 1;
84
+ }
85
+
86
+ public function getSupportLink()
87
+ {
88
+ try {
89
+ return Mage::getSingleton('freshdesk/freshdesk')->getUrl();
90
+ } catch (Exception $e) {
91
+ Mage::logException($e);
92
+ }
93
+
94
+ return 'http://www.freshdesk.com';
95
+ }
96
+
97
+ public function isCustomerViewEnabled()
98
+ {
99
+ return Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CUSTOMER_VIEW_ENABLE_CUSTOMER_VIEW) == 1;
100
+ }
101
+
102
+ public function isTicketTabEnabled()
103
+ {
104
+ return $this->isCustomerViewEnabled();
105
+ /*&& Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CUSTOMER_VIEW_ENABLE_TICKET_TAB) == 1;*/
106
+ }
107
+
108
+ public function isRecentTicketsGridEnabled()
109
+ {
110
+ return $this->isCustomerViewEnabled()
111
+ && Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_CUSTOMER_VIEW_ENABLE_RECENT_TICKET) == 1;
112
+ }
113
+
114
+ public function getPriorityDefault()
115
+ {
116
+ return (int)Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_TICKETS_PRIORITY);
117
+ }
118
+
119
+ public function getStatusDefault()
120
+ {
121
+ return (int)Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_TICKETS_STATUS);
122
+ }
123
+
124
+ public function getStatusClose()
125
+ {
126
+ return (int)Mage::getStoreConfig(Mageplace_Freshdesk_Helper_Const::XML_TICKETS_STATUS_CLOSE);
127
+ }
128
+
129
+ public function getCreateOrderTicketUrl(Mage_Sales_Model_Order $order)
130
+ {
131
+ return $this->_getUrl('freshdesk/ticket/create', array('order_id' => $order->getId()));
132
+ }
133
+
134
+ public function setCurrentTicket($ticket)
135
+ {
136
+ Mage::unregister(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_TICKET);
137
+ Mage::register(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_TICKET, $ticket);
138
+ }
139
+
140
+ public function getCurrentTicket()
141
+ {
142
+ return Mage::registry(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_TICKET);
143
+ }
144
+
145
+ public function getCurrentUser()
146
+ {
147
+ if (null === ($user = Mage::registry(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_USER))) {
148
+ Mage::unregister(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_USER);
149
+
150
+ if (Mage::getSingleton('customer/session')->getCustomer()) {
151
+ $user = Mage::getModel('freshdesk/user')->load(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
152
+ } else {
153
+ $user = false;
154
+ }
155
+
156
+ Mage::register(Mageplace_Freshdesk_Helper_Const::REGISTER_CURRENT_FRESHDESK_USER, $user);
157
+ }
158
+
159
+ return $user;
160
+ }
161
+ }
app/code/local/Mageplace/Freshdesk/Model/Abstract.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Abstract
13
+ */
14
+ class Mageplace_Freshdesk_Model_Abstract extends Mage_Core_Model_Abstract
15
+ {
16
+ public function getFreshdeskModel()
17
+ {
18
+ return $this->getResource()->getFreshdeskModel();
19
+ }
20
+
21
+ public function save()
22
+ {
23
+ try {
24
+ $this->_beforeSave();
25
+ if ($this->_dataSaveAllowed) {
26
+ $this->_getResource()->save($this);
27
+ $this->_afterSave();
28
+ }
29
+ $this->_hasDataChanges = false;
30
+ } catch (Exception $e) {
31
+ $this->_hasDataChanges = true;
32
+ Mage::logException($e);
33
+ throw $e;
34
+ }
35
+
36
+ return $this;
37
+ }
38
+ }
app/code/local/Mageplace/Freshdesk/Model/Cache.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Cache
13
+ */
14
+ class Mageplace_Freshdesk_Model_Cache extends Mage_Core_Model_Abstract
15
+ {
16
+ const CACHE_TYPE = 'freshdesk';
17
+ const CACHE_ID = 'freshdesk';
18
+ const CACHE_TAG = 'FRESHDESK';
19
+
20
+ protected $_cacheId;
21
+ protected $_cacheTag;
22
+
23
+ protected function _construct()
24
+ {
25
+ $this->setCacheId(self::CACHE_ID);
26
+ $this->setCacheTags(array(self::CACHE_TAG));
27
+ }
28
+
29
+ public function setCacheId($cacheId)
30
+ {
31
+ $this->_cacheId = $cacheId;
32
+ }
33
+
34
+ public function getCacheId()
35
+ {
36
+ return $this->_cacheId;
37
+ }
38
+
39
+ public function setCacheTags($cacheTag)
40
+ {
41
+ $this->_cacheTag = $cacheTag;
42
+ }
43
+
44
+ public function getCacheIdTags()
45
+ {
46
+ return false;
47
+ }
48
+
49
+ public function clean()
50
+ {
51
+ Mage::app()->getCacheInstance()->cleanType(self::CACHE_TYPE);
52
+
53
+ return $this;
54
+ }
55
+ }
app/code/local/Mageplace/Freshdesk/Model/Field.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field
13
+ *
14
+ * @method string getLabelInPortal
15
+ * @method string getFieldType
16
+ * @method string getName
17
+ * @method array getChoices
18
+ * @method bool getRequired
19
+ * @method bool getRequiredInPortal
20
+ * @method bool getVisibleInPortal
21
+ * @method bool getEditableInPortal
22
+ * @method array getNestedChoices
23
+ * @method array getNestedTicketFields
24
+ * @method Mageplace_Freshdesk_Model_Field setLayout
25
+ */
26
+ class Mageplace_Freshdesk_Model_Field extends Mageplace_Freshdesk_Model_Abstract
27
+ {
28
+ const FIELD_DISPLAY_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_DISPLAY_ID;
29
+ const FIELD_SUBJECT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_SUBJECT;
30
+ const FIELD_CREATED_AT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_CREATED_AT;
31
+ const FIELD_DESCRIPTION = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_DESCRIPTION;
32
+ const FIELD_REQUESTER = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_REQUESTER;
33
+ const FIELD_REQUESTER_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_REQUESTER_ID;
34
+ const FIELD_REQUESTER_NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_REQUESTER_NAME;
35
+ const FIELD_EMAIL = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_EMAIL;
36
+ const FIELD_PRIORITY = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_PRIORITY;
37
+ const FIELD_PRIORITY_NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_PRIORITY_NAME;
38
+ const FIELD_STATUS = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_STATUS;
39
+ const FIELD_STATUS_NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_STATUS_NAME;
40
+ const FIELD_AGENT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_AGENT;
41
+ const FIELD_RESPONDER_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_RESPONDER_ID;
42
+ const FIELD_GROUP = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_GROUP;
43
+ const FIELD_GROUP_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_GROUP_ID;
44
+ const FIELD_CUSTOM_FIELD = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_CUSTOM_FIELD;
45
+
46
+ const NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::PARAM_NAME;
47
+ const FIELD_TYPE = Mageplace_Freshdesk_Model_Freshdesk_Fields::PARAM_FIELD_TYPE;
48
+
49
+ const REGISTER_ORDER_FIELD = 'freshdesk_order_field';
50
+
51
+ protected $_isAdmin;
52
+
53
+ protected function _construct()
54
+ {
55
+ parent::_construct();
56
+
57
+ $this->_init('freshdesk/field');
58
+ }
59
+
60
+ public function load($id, $field = null)
61
+ {
62
+ $model = null;
63
+ $fields = $this->getCollection();
64
+ if ($field === null) {
65
+ $fields = $fields->getItems();
66
+ $model = $fields[$id];
67
+ } else {
68
+ foreach ($fields as $objField) {
69
+ if ($objField->getData($field) == $id) {
70
+ $model = $objField;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+
76
+ return $model;
77
+ }
78
+
79
+ public function loadByName($name)
80
+ {
81
+ return $this->load($name, self::NAME);
82
+ }
83
+
84
+ public function loadStatusField()
85
+ {
86
+ return $this->load(self::FIELD_STATUS, self::NAME);
87
+ }
88
+
89
+ public function getFieldModel($fieldData)
90
+ {
91
+ if (is_array($fieldData) && !empty($fieldData[self::FIELD_TYPE])) {
92
+ $fieldType = $fieldData[self::FIELD_TYPE];
93
+ } elseif (is_string($fieldData)) {
94
+ $fieldType = $fieldData;
95
+ } else {
96
+ throw new Mageplace_Backup_Exception(Mage::helper('freshdesk')->__('Invalid field type'));
97
+ }
98
+
99
+ $fieldType = strtolower($fieldType);
100
+ $model = Mage::getModel('freshdesk/field_' . $fieldType);
101
+ if (!is_object($model)) {
102
+ $model = Mage::getModel('freshdesk/field');
103
+ }
104
+
105
+ if (is_array($fieldData)) {
106
+ $model->setData($fieldData);
107
+ }
108
+
109
+ return $model;
110
+ }
111
+
112
+ /**
113
+ * @param null $fieldType
114
+ *
115
+ * @return string
116
+ */
117
+ public function getFieldBlockType($fieldType = null)
118
+ {
119
+ if ($fieldType === null) {
120
+ $fieldType = $this->getFieldType();
121
+ }
122
+
123
+ return 'freshdesk/field_' . strtolower($fieldType);
124
+ }
125
+
126
+ public function checkFieldValue($value, &$allValues, &$skipValues)
127
+ {
128
+ if ($this->isRequired() && trim($value) === '') {
129
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is required', $this->getLabel()));
130
+ }
131
+
132
+ return true;
133
+ }
134
+
135
+ public function getOrderField()
136
+ {
137
+ if (($model = Mage::registry(self::REGISTER_ORDER_FIELD)) === null) {
138
+ Mage::unregister(self::REGISTER_ORDER_FIELD);
139
+
140
+ $model = false;
141
+ try {
142
+ if (trim(Mage::helper('freshdesk')->getOrderIdField()) != '') {
143
+ $field = $this->getFreshdeskModel()->getOrderField();
144
+ if (!empty($field) && is_array($field)) {
145
+ $model = $this->getFieldModel($field);
146
+ }
147
+ }
148
+ } catch (Exception $e) {
149
+ Mage::logException($e);
150
+ }
151
+
152
+ Mage::register(self::REGISTER_ORDER_FIELD, $model);
153
+ }
154
+
155
+ return $model;
156
+ }
157
+
158
+ public function getLabel()
159
+ {
160
+ if ($this->isAdmin()) {
161
+ return $this->getData('label');
162
+ } else {
163
+ return $this->getLabelInPortal();
164
+ }
165
+ }
166
+
167
+ public function isRequired()
168
+ {
169
+ if ($this->isAdmin()) {
170
+ return $this->getRequired();
171
+ } else {
172
+ return $this->getRequiredInPortal();
173
+ }
174
+ }
175
+
176
+ public function isVisible()
177
+ {
178
+ return $this->getVisibleInPortal();
179
+ }
180
+
181
+ public function isEditable()
182
+ {
183
+ return $this->getEditableInPortal();
184
+ }
185
+
186
+ public function setIsAdmin($isAdmin = true)
187
+ {
188
+ $this->_isAdmin = $isAdmin;
189
+
190
+ return $this;
191
+ }
192
+
193
+ public function isAdmin()
194
+ {
195
+ if ($this->_isAdmin === null) {
196
+ return Mage::app()->getStore()->isAdmin();
197
+ } else {
198
+ return $this->_isAdmin;
199
+ }
200
+ }
201
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Checkbox.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Checkbox
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Custom_Checkbox extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Dropdown.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Dropdown
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Custom_Dropdown extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Number.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Number
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Custom_Number extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ public function checkFieldValue($value, &$allValues, &$skipValues)
17
+ {
18
+ parent::checkFieldValue($value, $allValues, $skipValues);
19
+
20
+ if ($value && !is_numeric($value)) {
21
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $this->getLabel()));
22
+ }
23
+
24
+ return true;
25
+ }
26
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Paragraph.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Dropdown
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Custom_Paragraph extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Custom/Text.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Text
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Custom_Text extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Agent.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Agent
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Agent extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Description.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Description
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Description extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Group.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Group
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Group extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Priority.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Priority
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Priority extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Requester.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Requester
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Requester extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Source.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Source
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Source extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Status.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Status
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Status extends Mageplace_Freshdesk_Model_Field_Dropdown
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Subject.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Subject
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Subject extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Default/Ticket/Type.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Default_Ticket_Type
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Default_Ticket_Type extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Dropdown.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Custom_Dropdown
13
+ */
14
+ class Mageplace_Freshdesk_Model_Field_Dropdown extends Mageplace_Freshdesk_Model_Field
15
+ {
16
+ public function checkFieldValue($value, &$allValues, &$skipValues)
17
+ {
18
+ parent::checkFieldValue($value, $allValues, $skipValues);
19
+
20
+ if ($value !== '') {
21
+ $check = false;
22
+
23
+ foreach ($this->getChoices() as $choice) {
24
+ if ($value == $choice[1]) {
25
+ $check = true;
26
+ break;
27
+ }
28
+ }
29
+
30
+ if (!$check) {
31
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $this->getLabel()));
32
+ }
33
+ }
34
+
35
+ return true;
36
+ }
37
+ }
app/code/local/Mageplace/Freshdesk/Model/Field/Nested/Field.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Field_Nested_Field
13
+ *
14
+ * @method array getNestedTicketFields
15
+ * @method array getNestedChoices
16
+ */
17
+ class Mageplace_Freshdesk_Model_Field_Nested_Field extends Mageplace_Freshdesk_Model_Field
18
+ {
19
+ /**
20
+ * @return Varien_Object
21
+ * @throws Mageplace_Freshdesk_Exception
22
+ */
23
+ public function getFirstLevelField()
24
+ {
25
+ if ($this->_getData('nested_ticket_fields_level_1') === null) {
26
+ $fields = $this->getNestedTicketFields();
27
+ if (empty($fields[0])) {
28
+ throw new Mageplace_Freshdesk_Exception('Error nested ticket fields');
29
+ }
30
+
31
+ $this->setData('nested_ticket_fields_level_1', new Varien_Object($fields[0]));
32
+ }
33
+
34
+ return $this->_getData('nested_ticket_fields_level_1');
35
+ }
36
+
37
+ public function getFirstLevelFieldName()
38
+ {
39
+ return $this->getFirstLevelField()->getName();
40
+ }
41
+
42
+ public function getFirstLevelFieldId()
43
+ {
44
+ return $this->getFirstLevelField()->getId();
45
+ }
46
+
47
+ public function getFirstLevelFieldLabel()
48
+ {
49
+ if ($this->isAdmin()) {
50
+ return $this->getFirstLevelField()->getLabel();
51
+ } else {
52
+ return $this->getFirstLevelField()->getLabelInPortal();
53
+ }
54
+ }
55
+
56
+ public function getSecondLevelField()
57
+ {
58
+ if ($this->_getData('nested_ticket_fields_level_2') === null) {
59
+ $fields = $this->getNestedTicketFields();
60
+ if (empty($fields[1])) {
61
+ $this->setData('nested_ticket_fields_level_2', false);
62
+ } else {
63
+ $this->setData('nested_ticket_fields_level_2', new Varien_Object($fields[1]));
64
+ }
65
+ }
66
+
67
+ return $this->_getData('nested_ticket_fields_level_2');
68
+ }
69
+
70
+ public function hasSecondLevel()
71
+ {
72
+ return is_object($this->getSecondLevelField());
73
+ }
74
+
75
+ public function getSecondLevelFieldName()
76
+ {
77
+ if (!$this->hasSecondLevel()) {
78
+ return '';
79
+ }
80
+
81
+ return $this->getSecondLevelField()->getName();
82
+ }
83
+
84
+ public function getSecondLevelFieldId()
85
+ {
86
+ if (!$this->hasSecondLevel()) {
87
+ return '';
88
+ }
89
+
90
+ return $this->getSecondLevelField()->getId();
91
+ }
92
+
93
+ public function getSecondLevelFieldLabel()
94
+ {
95
+ if (!$this->hasSecondLevel()) {
96
+ return '';
97
+ }
98
+
99
+ if ($this->isAdmin()) {
100
+ return $this->getSecondLevelField()->getLabel();
101
+ } else {
102
+ return $this->getSecondLevelField()->getLabelInPortal();
103
+ }
104
+ }
105
+
106
+
107
+ public function checkFieldValue($value, &$allValues, &$skipValues)
108
+ {
109
+ parent::checkFieldValue($value, $allValues, $skipValues);
110
+
111
+ if ($value !== '') {
112
+ $check = false;
113
+ $approveSkipValues = array();
114
+ $choices = $this->getNestedChoices();
115
+ foreach ($choices as $level0) {
116
+ if ($level0[1] == $value) {
117
+ if (empty($level0[2])) {
118
+ $check = true;
119
+ } else {
120
+ if (empty($skipValues[$this->getFirstLevelFieldName()])) {
121
+ if (!$this->isRequired()) {
122
+ $check = true;
123
+ }
124
+
125
+ break;
126
+ }
127
+
128
+ $level1value = $skipValues[$this->getFirstLevelFieldName()];
129
+ if (trim($level1value) === '') {
130
+ break;
131
+ } else {
132
+ foreach ($level0[2] as $level1) {
133
+ if ($level1[1] == $level1value) {
134
+ $approveSkipValues[] = $this->getFirstLevelFieldName();
135
+
136
+ if (empty($level1[2])) {
137
+ $check = true;
138
+ } else {
139
+ if (empty($skipValues[$this->getSecondLevelFieldName()])) {
140
+ if (!$this->isRequired()) {
141
+ $check = true;
142
+ }
143
+
144
+ break 2;
145
+ }
146
+
147
+ $level2value = $skipValues[$this->getSecondLevelFieldName()];
148
+ if (trim($level2value) !== '') {
149
+ foreach ($level1[2] as $level2) {
150
+ if ($level2[1] == $level2value) {
151
+ $approveSkipValues[] = $this->getSecondLevelFieldName();
152
+
153
+ $check = true;
154
+
155
+ break 3;
156
+ }
157
+ }
158
+ }
159
+
160
+ }
161
+
162
+ break 2;
163
+ }
164
+ }
165
+ }
166
+ }
167
+
168
+ break;
169
+ }
170
+ }
171
+
172
+ if (!$check) {
173
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $this->getLabel()));
174
+ }
175
+ }
176
+
177
+ if(!empty($approveSkipValues)) {
178
+ return $approveSkipValues;
179
+ }
180
+
181
+ return true;
182
+ }
183
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk.php ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk
13
+ */
14
+ class Mageplace_Freshdesk_Model_Freshdesk
15
+ {
16
+ const DEFAULT_PASSWORD = 'X';
17
+
18
+ const URL_SUFFIX_DASHBOARD = 'helpdesk/dashboard';
19
+ const URL_SUFFIX_SSO = 'login/sso';
20
+ const URL_SUFFIX_TICKET_EDIT = 'helpdesk/tickets/%d/edit';
21
+ const URL_SUFFIX_TICKET_VIEW = 'helpdesk/tickets/%d';
22
+
23
+ /**
24
+ * @var Zend_Http_Client
25
+ */
26
+ protected $_httpClient;
27
+ protected $_url;
28
+ protected $_urlSuffix;
29
+ protected $_urlQueryParams;
30
+ protected $_rawData;
31
+
32
+ public function __construct()
33
+ {
34
+ if (!$domain = $this->getHelper()->getDomain()) {
35
+ Mage::exception('Mageplace_Freshdesk', $this->getHelper()->__('Error Freshdesk domain'));
36
+ }
37
+
38
+ if (strpos($domain, 'http://') === 0) {
39
+ $domain = str_replace('http://', 'https://', $domain);
40
+ } else {
41
+ if (strpos($domain, 'https://') === false) {
42
+ $domain = 'https://' . $domain;
43
+ }
44
+ }
45
+
46
+ if (substr($domain, -1) != '/') {
47
+ $domain = $domain . '/';
48
+ }
49
+
50
+ $this->setUrl($domain);
51
+ }
52
+
53
+ protected function _getAdapter()
54
+ {
55
+ $email = $this->getHelper()->getAdminEmail();
56
+ $apiKey = $this->getHelper()->getAdminApiKey();
57
+ if (!$email && !$apiKey) {
58
+ $this->throwException($this->getHelper()->__('Error Freshdesk email or API key'));
59
+ }
60
+
61
+ if ($apiKey) {
62
+ $username = $apiKey;
63
+ $password = self::DEFAULT_PASSWORD;
64
+ } else {
65
+ $username = $email;
66
+ $password = $this->getHelper()->getPassword();
67
+ if (!$password) {
68
+ $this->throwException($this->getHelper()->__('Error Freshdesk password'));
69
+ }
70
+ }
71
+
72
+ $adapter = new Zend_Http_Client_Adapter_Curl();
73
+ $adapter->setCurlOption(CURLOPT_POST, true);
74
+ $adapter->setCurlOption(CURLOPT_USERPWD, $username . ':' . $password);
75
+ $adapter->setCurlOption(CURLOPT_RETURNTRANSFER, true);
76
+ $adapter->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
77
+ $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
78
+ $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
79
+
80
+ return $adapter;
81
+ }
82
+
83
+ /**
84
+ * @return array
85
+ */
86
+ protected function _getHeaders()
87
+ {
88
+ $headers = array();
89
+ $headers['Content-Type'] = 'application/json';
90
+ $headers['accept-encoding'] = '';
91
+
92
+ return $headers;
93
+ }
94
+
95
+ /**
96
+ * @param string $url
97
+ *
98
+ * @return $this
99
+ */
100
+ public function setUrl($url)
101
+ {
102
+ $this->_url = strval($url);
103
+
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * @return mixed
109
+ */
110
+ public function getUrl()
111
+ {
112
+ return $this->_url;
113
+ }
114
+
115
+ /**
116
+ * @param string $urlSuffix
117
+ *
118
+ * @return $this
119
+ */
120
+ public function setUrlSuffix($urlSuffix)
121
+ {
122
+ $this->_urlSuffix = strval($urlSuffix);
123
+
124
+ return $this;
125
+ }
126
+
127
+ /**
128
+ * @return string
129
+ */
130
+ public function getUrlSuffix()
131
+ {
132
+ return $this->_urlSuffix;
133
+ }
134
+
135
+ /**
136
+ * @return string
137
+ */
138
+ public function getUrlQueryParams()
139
+ {
140
+ return empty($this->_urlQueryParams) || !is_array($this->_urlQueryParams) ? '' : '?' . http_build_query($this->_urlQueryParams);
141
+ }
142
+
143
+ /**
144
+ * @return string
145
+ */
146
+ public function resetUrlParams()
147
+ {
148
+ $this->_urlSuffix = null;
149
+ $this->_urlQueryParams = null;
150
+
151
+ return $this;
152
+ }
153
+
154
+ /**
155
+ * @param string|array $name
156
+ * @param string|null $value
157
+ *
158
+ * @return $this
159
+ */
160
+ public function addUrlQueryParams($name, $value = null)
161
+ {
162
+ if (is_array($name)) {
163
+ $this->_urlQueryParams = array_merge($this->_urlQueryParams, $name);
164
+ } else {
165
+ $this->_urlQueryParams[$name] = $value;
166
+ }
167
+
168
+ return $this;
169
+ }
170
+
171
+ /**
172
+ * @param $rawData
173
+ *
174
+ * @return $this
175
+ */
176
+ public function setRawData($rawData)
177
+ {
178
+ $this->_rawData = $rawData;
179
+
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * @return mixed
185
+ */
186
+ public function getRawData()
187
+ {
188
+ return $this->_rawData;
189
+ }
190
+
191
+ /**
192
+ * @return string
193
+ */
194
+ public function getUri()
195
+ {
196
+ return $this->getUrl() . $this->getUrlSuffix() . $this->getUrlQueryParams();
197
+ }
198
+
199
+ public function getSSOUrl($name, $email)
200
+ {
201
+ $timestamp = time();
202
+ $secret = $this->getHelper()->getSSOSecret();
203
+ $to_be_hashed = $name . $email . $timestamp;
204
+ $hash = hash_hmac('md5', $to_be_hashed, $secret);
205
+
206
+ $query = array(
207
+ 'name' => $name,
208
+ 'email' => $email,
209
+ 'timestamp' => $timestamp,
210
+ 'hash' => $hash
211
+ );
212
+
213
+ return $this->getUrl() . self::URL_SUFFIX_SSO . '?' . http_build_query($query);
214
+ }
215
+
216
+ public function getDashboardUrl()
217
+ {
218
+ return $this->getUrl() . self::URL_SUFFIX_DASHBOARD;
219
+ }
220
+
221
+ public function getTicketEditUrl($id)
222
+ {
223
+ return $this->getUrl() . sprintf(self::URL_SUFFIX_TICKET_EDIT, $id);
224
+ }
225
+
226
+ public function getTicketViewUrl($id)
227
+ {
228
+ return $this->getUrl() . sprintf(self::URL_SUFFIX_TICKET_VIEW, $id);
229
+ }
230
+
231
+ /**
232
+ * @return Zend_Http_Client
233
+ */
234
+ public function getClient()
235
+ {
236
+ if ($this->_httpClient === null) {
237
+ $this->_httpClient = new Zend_Http_Client();
238
+ $this->_httpClient->setAdapter($this->_getAdapter());
239
+ $this->_httpClient->setHeaders($this->_getHeaders());
240
+ }
241
+
242
+ return $this->_httpClient;
243
+ }
244
+
245
+ /**
246
+ * @param string $method
247
+ *
248
+ * @return Zend_Http_Response
249
+ */
250
+ public function request($method = Zend_Http_Client::POST)
251
+ {
252
+ return $this->getClient()
253
+ ->setUri($this->getUri())
254
+ ->setRawData($this->getRawData())
255
+ ->request($method);
256
+ }
257
+
258
+ public function throwException($message)
259
+ {
260
+ Mage::exception('Mageplace_Freshdesk', $message);
261
+ }
262
+
263
+ /**
264
+ * @return Mageplace_Freshdesk_Helper_Data
265
+ */
266
+ public function getHelper()
267
+ {
268
+ return Mage::helper('freshdesk');
269
+ }
270
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Abstract.php ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2013 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk_Abstract
13
+ *
14
+ * @method string getRequestMethod
15
+ */
16
+ class Mageplace_Freshdesk_Model_Freshdesk_Abstract
17
+ extends Mageplace_Freshdesk_Model_Cache
18
+ implements Mageplace_Freshdesk_Model_Freshdesk_Interface
19
+ {
20
+ const XML_ROOT = 'root';
21
+
22
+ const URL_PARAM_FORMAT = 'format';
23
+
24
+ const PARAM_ID = 'id';
25
+
26
+ protected $_freshdesk;
27
+ protected $_xmlRootNode;
28
+ protected $_xmlData;
29
+ protected $_requestData;
30
+ protected $_helper;
31
+ protected $_id;
32
+ protected $_skipData = array();
33
+ protected $_rawData = array();
34
+
35
+ protected function _construct()
36
+ {
37
+ parent::_construct();
38
+
39
+ $this->setFreshdesk(Mage::getSingleton('freshdesk/freshdesk'));
40
+ $this->_helper = Mage::helper('freshdesk');
41
+ }
42
+
43
+ public function setDataFromArray(array $data)
44
+ {
45
+ if (array_key_exists(self::PARAM_ID, $data)) {
46
+ $this->_id = $data[self::PARAM_ID];
47
+ }
48
+
49
+ $params = $this->getValidParams();
50
+ if (empty($fields) || !is_array($fields)) {
51
+ $this->_rawData = $data;
52
+
53
+ return $this;
54
+ }
55
+
56
+ foreach ($data as $key => $value) {
57
+ if ($key === self::PARAM_ID) {
58
+ continue;
59
+ }
60
+
61
+ if (!array_key_exists($key, $params)) {
62
+ $this->_rawData[$key] = $value;
63
+ } else {
64
+ $this->_skipData[$key] = $value;
65
+ }
66
+ }
67
+
68
+ return $this;
69
+ }
70
+
71
+
72
+ /**
73
+ * @param string $urlSuffix
74
+ *
75
+ * @return $this
76
+ */
77
+ public function setUrlSuffix($urlSuffix)
78
+ {
79
+ $this->getFreshdesk()->setUrlSuffix($urlSuffix);
80
+
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * @return string
86
+ */
87
+ public function getUrlSuffix()
88
+ {
89
+ return $this->getFreshdesk()->getUrlSuffix();
90
+ }
91
+
92
+ /**
93
+ * @return string
94
+ */
95
+ public function getUrlQueryParams()
96
+ {
97
+ return $this->getFreshdesk()->getUrlQueryParams();
98
+ }
99
+
100
+ /**
101
+ * @param string|array $name
102
+ * @param string|null $value
103
+ *
104
+ * @return $this
105
+ */
106
+ public function addUrlQueryParams($name, $value = null)
107
+ {
108
+ $this->getFreshdesk()->addUrlQueryParams($name, $value);
109
+
110
+ return $this;
111
+ }
112
+
113
+ public function getXmlRootNode()
114
+ {
115
+ if (is_null($this->_xmlRootNode)) {
116
+ $this->getXmlData();
117
+ }
118
+
119
+ return $this->_xmlRootNode;
120
+ }
121
+
122
+ /**
123
+ * @return DOMDocument
124
+ */
125
+ public function getXmlData()
126
+ {
127
+ return $this->_xmlData;
128
+ }
129
+
130
+ public function setXmlData($xmlData)
131
+ {
132
+ $this->_xmlData = $xmlData;
133
+
134
+ return $this;
135
+ }
136
+
137
+ public function resetXmlData()
138
+ {
139
+ $this->_xmlData = null;
140
+
141
+ return $this;
142
+ }
143
+
144
+ public function getRequestData()
145
+ {
146
+ return $this->_requestData;
147
+ }
148
+
149
+ public function setRequestData($requestData)
150
+ {
151
+ $this->_requestData = $requestData;
152
+
153
+ return $this;
154
+ }
155
+
156
+ public function resetRequestData()
157
+ {
158
+ $this->_requestData = null;
159
+
160
+ return $this;
161
+ }
162
+
163
+ public function resetUrlData()
164
+ {
165
+ $this->getFreshdesk()->resetUrlParams();
166
+
167
+ return $this;
168
+ }
169
+
170
+ /**
171
+ * @return $this
172
+ */
173
+ public function resetData()
174
+ {
175
+ return $this->resetXmlData()
176
+ ->resetRequestData()
177
+ ->resetUrlData();
178
+ }
179
+
180
+
181
+ /**
182
+ * @return string
183
+ */
184
+ public function getRawData()
185
+ {
186
+ $requestData = $this->getRequestData();
187
+ if (!empty($requestData) && is_array($requestData)) {
188
+ return Zend_Json::encode($requestData);
189
+ }
190
+
191
+ $xmlData = $this->getXmlData();
192
+ if (is_null($xmlData)) {
193
+ return '';
194
+ }
195
+
196
+ $rawData = $this->getXmlData($this->getXmlRootNode())->saveXML($this->getXmlRootNode());
197
+
198
+ return $rawData;
199
+ }
200
+
201
+ /**
202
+ * @param null $method
203
+ *
204
+ * @return null|Zend_Http_Response
205
+ */
206
+ public function request($method = null)
207
+ {
208
+ if (is_null($method)) {
209
+ $method = $this->getRequestMethod();
210
+ }
211
+
212
+ try {
213
+ $response = $this->getFreshdesk()
214
+ ->setRawData($this->getRawData())
215
+ ->request($method);
216
+ } catch (Exception $e) {
217
+ Mage::logException($e);
218
+ Mage::log($this);
219
+
220
+ return null;
221
+ }
222
+
223
+ return $response;
224
+ }
225
+
226
+ /**
227
+ * @param Mageplace_Freshdesk_Model_Freshdesk $freshdesk
228
+ */
229
+ public function setFreshdesk($freshdesk)
230
+ {
231
+ $this->_freshdesk = $freshdesk;
232
+ }
233
+
234
+ /**
235
+ * @return Mageplace_Freshdesk_Model_Freshdesk
236
+ */
237
+ public function getFreshdesk()
238
+ {
239
+ if (is_null($this->_freshdesk)) {
240
+ $this->setFreshdesk(Mage::getSingleton('freshdesk/freshdesk'));
241
+ }
242
+
243
+ if (is_null($this->_freshdesk)) {
244
+ $this->throwException('Error freshdesk model');
245
+ }
246
+
247
+ return $this->_freshdesk;
248
+ }
249
+
250
+ public function throwException($message)
251
+ {
252
+ Mage::exception('Mageplace_Freshdesk', $message);
253
+ }
254
+
255
+ protected function getValidParams()
256
+ {
257
+ return array();
258
+ }
259
+
260
+ /**
261
+ * @return Mageplace_Freshdesk_Helper_Data
262
+ */
263
+ protected function _getHelper()
264
+ {
265
+ return $this->_helper;
266
+ }
267
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Fields.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk_Fields
13
+ *
14
+ */
15
+ class Mageplace_Freshdesk_Model_Freshdesk_Fields extends Mageplace_Freshdesk_Model_Freshdesk_Abstract
16
+ {
17
+ const CACHE_ID_SUFFIX_TICKET_FIELDS = 'ticket_fields';
18
+ const CACHE_ID_SUFFIX_ORDER_FIELD = 'order_field';
19
+
20
+ const URL_TICKET_FIELDS = 'ticket_fields';
21
+ const URL_XML_TICKET_FIELDS = 'ticket_fields.xml';
22
+
23
+ const URL_PARAM_FORMAT = 'format';
24
+
25
+ const PARAM_ID = 'id';
26
+ const PARAM_LABEL = 'label';
27
+ const PARAM_NAME = 'name';
28
+ const PARAM_TICKET_FIELD = 'ticket_field';
29
+ const PARAM_ACTIVE = 'active';
30
+ const PARAM_FIELD_TYPE = 'field_type';
31
+
32
+ const FIELD_DISPLAY_ID = 'display_id';
33
+ const FIELD_SUBJECT = 'subject';
34
+ const FIELD_DESCRIPTION = 'description';
35
+ const FIELD_REQUESTER = 'requester';
36
+ const FIELD_REQUESTER_ID = 'requester_id';
37
+ const FIELD_EMAIL = 'email';
38
+ const FIELD_PRIORITY = 'priority';
39
+ const FIELD_PRIORITY_NAME = 'priority_name';
40
+ const FIELD_STATUS = 'status';
41
+ const FIELD_STATUS_NAME = 'status_name';
42
+ const FIELD_AGENT = 'agent';
43
+ const FIELD_RESPONDER_ID = 'responder_id';
44
+ const FIELD_GROUP = 'group';
45
+ const FIELD_GROUP_ID = 'group_id';
46
+ const FIELD_CUSTOM_FIELD = 'custom_field';
47
+ const FIELD_CREATED_AT = 'created_at';
48
+ const FIELD_REQUESTER_NAME = 'requester_name';
49
+
50
+ public function getFields()
51
+ {
52
+ if ($this->_getData('fields') === null) {
53
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
54
+ if ($ticketFieldsJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET_FIELDS)) {
55
+ try {
56
+ $ticketFields = Zend_Json::decode($ticketFieldsJson);
57
+ if (!empty($ticketFields) && is_array($ticketFields)) {
58
+ $this->setData('fields', $ticketFields);
59
+
60
+ return $ticketFields;
61
+ }
62
+ } catch (Exception $e) {
63
+ Mage::logException($e);
64
+ }
65
+ }
66
+ }
67
+
68
+ try {
69
+ /** @var Zend_Http_Response|null $response */
70
+ $response = $this->resetData()
71
+ ->setUrlSuffix(self::URL_TICKET_FIELDS)
72
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json')
73
+ ->request(Zend_Http_Client::GET);
74
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
75
+ Mage::log($response);
76
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
77
+ }
78
+
79
+ if ($response->getStatus() != 200) {
80
+ Mage::log($response);
81
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
82
+ }
83
+
84
+ $ticketFields = trim($response->getRawBody());
85
+ if (empty($ticketFields[2])) { /* if $allTicketFieldsJson == '[]' or empty */
86
+ Mage::log($ticketFields);
87
+ throw new Mageplace_Freshdesk_Exception('Wrong raw body');
88
+ }
89
+
90
+ if (($arrTicketFields = Zend_Json::decode($ticketFields)) && is_array($arrTicketFields)) {
91
+ $orderFieldMagento = $this->_getHelper()->getOrderIdField();
92
+ $orderField = null;
93
+ $ticketFields = array();
94
+ foreach ($arrTicketFields as $field) {
95
+ if (!empty($field[self::PARAM_TICKET_FIELD]) && !empty($field[self::PARAM_TICKET_FIELD]) && $field[self::PARAM_TICKET_FIELD][self::PARAM_ACTIVE]) {
96
+ $ticketFields[strval($field[self::PARAM_TICKET_FIELD][self::PARAM_ID])] = $field[self::PARAM_TICKET_FIELD];
97
+ if ($orderField === null && $field[self::PARAM_TICKET_FIELD][self::PARAM_LABEL] == $orderFieldMagento) {
98
+ $orderField = $field[self::PARAM_TICKET_FIELD];
99
+ }
100
+ }
101
+ }
102
+
103
+ if ($orderField === null) {
104
+ $orderField = array();
105
+ }
106
+
107
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
108
+ Mage::app()->saveCache(Zend_Json::encode($ticketFields), $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET_FIELDS, $this->getCacheTags());
109
+ Mage::app()->saveCache(Zend_Json::encode($orderField), $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_ORDER_FIELD, $this->getCacheTags());
110
+ }
111
+
112
+ $this->setData('fields', $ticketFields);
113
+ $this->setData('order_field', $orderField);
114
+
115
+ return $ticketFields;
116
+ }
117
+
118
+
119
+ } catch (Exception $e) {
120
+ Mage::getSingleton('core/session')->addError($e->getMessage());
121
+ Mage::logException($e);
122
+ }
123
+
124
+ $this->setData('fields', array());
125
+ $this->setData('order_field', array());
126
+ }
127
+
128
+ return $this->_getData('fields');
129
+ }
130
+
131
+ public function getOrderField()
132
+ {
133
+ if ($this->_getData('order_field') === null) {
134
+ if ($orderFieldJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_ORDER_FIELD)) {
135
+ try {
136
+ $orderField = Zend_Json::decode($orderFieldJson);
137
+ if (!empty($orderField) && is_array($orderField)) {
138
+ $this->setData('order_field', $orderField);
139
+
140
+ return $orderField;
141
+ }
142
+ } catch (Exception $e) {
143
+ Mage::logException($e);
144
+ }
145
+ }
146
+
147
+ try {
148
+ $orderFieldMagento = $this->_getHelper()->getOrderIdField();
149
+ $orderField = null;
150
+ foreach ($this->getFields() as $field) {
151
+ if ($field[self::PARAM_LABEL] == $orderFieldMagento) {
152
+ $orderField = $field;
153
+ break;
154
+ }
155
+ }
156
+
157
+ if ($orderField === null) {
158
+ $orderField = array();
159
+ }
160
+
161
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
162
+ Mage::app()->saveCache(Zend_Json::encode($orderField), $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_ORDER_FIELD, $this->getCacheTags());
163
+ }
164
+
165
+ $this->setData('order_field', $orderField);
166
+
167
+ return $orderField;
168
+
169
+ } catch (Exception $e) {
170
+ Mage::getSingleton('core/session')->addError($e->getMessage());
171
+ Mage::logException($e);
172
+ }
173
+
174
+ $this->setData('order_field', array());
175
+ }
176
+
177
+ return $this->_getData('order_field');
178
+ }
179
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Interface.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2013 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ interface Mageplace_Freshdesk_Model_Freshdesk_Interface
12
+ {
13
+ /**
14
+ * @return Mageplace_Freshdesk_Model_Freshdesk
15
+ */
16
+ public function getFreshdesk();
17
+
18
+ public function request($method = null);
19
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Notes.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk_Notes
13
+ *
14
+ */
15
+ class Mageplace_Freshdesk_Model_Freshdesk_Notes extends Mageplace_Freshdesk_Model_Freshdesk_Abstract
16
+ {
17
+ const CACHE_ID_SUFFIX_NOTE = 'note';
18
+
19
+ const URL_NOTE_ADD = 'helpdesk/tickets/%d/conversations/note';
20
+
21
+ const HELPDESK_NOTE = 'helpdesk_note';
22
+ const NOTE = 'note';
23
+
24
+ const PARAM_TICKET_ID = 'ticket_id';
25
+ const PARAM_BODY = 'body';
26
+ const PARAM_BODY_HTML = 'body_html';
27
+ const PARAM_CREATED_AT = 'created_at';
28
+ const PARAM_PRIVATE = 'private';
29
+ const PARAM_UPDATED_AT = 'updated_at';
30
+ const PARAM_USER_ID = 'user_id';
31
+
32
+ static $VALID_PARAMS = array(
33
+ self::PARAM_BODY,
34
+ self::PARAM_PRIVATE,
35
+ );
36
+
37
+ protected $_ticketId;
38
+
39
+ public function setDataFromArray(array $data)
40
+ {
41
+ if (array_key_exists(self::PARAM_TICKET_ID, $data)) {
42
+ $this->_ticketId = (int)$data[self::PARAM_TICKET_ID];
43
+ unset($data[self::PARAM_TICKET_ID]);
44
+ }
45
+
46
+ parent::setDataFromArray($data);
47
+
48
+ return $this;
49
+ }
50
+
51
+ /**
52
+ * @return $this
53
+ */
54
+ public function initData()
55
+ {
56
+ $requestData[self::HELPDESK_NOTE] = $this->_rawData;
57
+
58
+ return $this->setRequestData($requestData);
59
+ }
60
+
61
+ public function saveNote($id = null)
62
+ {
63
+ if (!is_int($this->_ticketId)) {
64
+ throw new Mageplace_Freshdesk_Exception('Wrong ticket id');
65
+ }
66
+
67
+ $method = Zend_Http_Client::POST;
68
+ $urlSuffix = sprintf(self::URL_NOTE_ADD, $this->_ticketId);
69
+
70
+ /** @var Zend_Http_Response|null $response */
71
+ $response = $this->resetData()
72
+ ->initData()
73
+ ->setUrlSuffix($urlSuffix)
74
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json')
75
+ ->request($method);
76
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
77
+ Mage::log($response);
78
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
79
+ }
80
+
81
+ switch ($response->getStatus()) {
82
+ case 200:
83
+ case 201:
84
+ return true;
85
+
86
+ default:
87
+ Mage::log($this);
88
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
89
+ }
90
+
91
+ }
92
+
93
+ protected function getValidParams()
94
+ {
95
+ return self::$VALID_PARAMS;
96
+ }
97
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Tickets.php ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk_Tickets
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Freshdesk_Tickets setSubject
15
+ * @method Mageplace_Freshdesk_Model_Freshdesk_Tickets setDescription
16
+ * @method Mageplace_Freshdesk_Model_Freshdesk_Tickets setEmail
17
+ * @method Mageplace_Freshdesk_Model_Freshdesk_Tickets setPriority
18
+ * @method Mageplace_Freshdesk_Model_Freshdesk_Tickets setStatus
19
+ * @method string getSubject
20
+ * @method string getDescription
21
+ * @method string getEmail
22
+ */
23
+ class Mageplace_Freshdesk_Model_Freshdesk_Tickets extends Mageplace_Freshdesk_Model_Freshdesk_Abstract
24
+ {
25
+ const CACHE_ID_SUFFIX_TICKETS = 'tickets';
26
+ const CACHE_ID_SUFFIX_TICKET = 'ticket';
27
+
28
+ const TICKETS_MAX_PAGES = 1000;
29
+
30
+ const URL_TICKETS = 'helpdesk/tickets/filter/all_tickets';
31
+ const URL_XML_TICKETS = 'helpdesk/tickets.xml';
32
+ const URL_JSON_TICKETS = 'helpdesk/tickets.json';
33
+ const URL_JSON_TICKET = 'helpdesk/tickets/%d';
34
+
35
+ const URL_PARAM_PAGE = 'page';
36
+ const URL_PARAM_EMAIL = 'email';
37
+ const URL_PARAM_REQUESTER = 'requester';
38
+
39
+ const FIELD_DISPLAY_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_DISPLAY_ID;
40
+ const FIELD_SUBJECT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_SUBJECT;
41
+ const FIELD_CREATED_AT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_CREATED_AT;
42
+ const FIELD_DESCRIPTION = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_DESCRIPTION;
43
+ const FIELD_REQUESTER = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_REQUESTER;
44
+ const FIELD_EMAIL = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_EMAIL;
45
+ const FIELD_PRIORITY = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_PRIORITY;
46
+ const FIELD_PRIORITY_NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_PRIORITY_NAME;
47
+ const FIELD_STATUS = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_STATUS;
48
+ const FIELD_STATUS_NAME = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_STATUS_NAME;
49
+ const FIELD_AGENT = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_AGENT;
50
+ const FIELD_RESPONDER_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_RESPONDER_ID;
51
+ const FIELD_GROUP = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_GROUP;
52
+ const FIELD_GROUP_ID = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_GROUP_ID;
53
+ const FIELD_CUSTOM_FIELD = Mageplace_Freshdesk_Model_Freshdesk_Fields::FIELD_CUSTOM_FIELD;
54
+
55
+ const FIELD_NESTED_NAME = 'name';
56
+
57
+ const HELPDESK_TICKET = 'helpdesk_ticket';
58
+
59
+ const XML_RESPONSE_HELPDESK_TICKET = 'helpdesk-ticket';
60
+ const XML_RESPONSE_HELPDESK_TICKETS = 'helpdesk-tickets';
61
+
62
+ const STATUS_CLOSE = 5;
63
+
64
+ static $VALID_FIELDS_NAMES = array(
65
+ self::FIELD_EMAIL,
66
+ self::FIELD_RESPONDER_ID
67
+ );
68
+
69
+ static $CHANGE_FIELDS_NAMES = array(
70
+ self::FIELD_AGENT => self::FIELD_RESPONDER_ID,
71
+ self::FIELD_GROUP => self::FIELD_GROUP_ID
72
+ );
73
+
74
+ static $FIELDS_TYPES = array(
75
+ 'default_requester' => '',
76
+ 'default_subject' => '',
77
+ 'default_ticket_type' => '',
78
+ 'default_source' => '',
79
+ 'default_status' => '',
80
+ 'default_priority' => '',
81
+ 'default_group' => '',
82
+ 'default_agent' => '',
83
+ 'default_description' => '',
84
+ 'custom_text' => '',
85
+ 'custom_dropdown' => '',
86
+ 'nested_field' => '',
87
+ 'custom_paragraph' => '',
88
+ 'custom_number' => '',
89
+ 'custom_checkbox' => '',
90
+ );
91
+
92
+ /**
93
+ * @var int
94
+ */
95
+ protected $_displayId;
96
+
97
+ /**
98
+ * @var array
99
+ */
100
+ protected $_rawData = array();
101
+
102
+ /**
103
+ * @var Mageplace_Freshdesk_Model_Resource_Field_Collection
104
+ */
105
+ protected $_fieldsCollection;
106
+
107
+ /**
108
+ * @var array
109
+ */
110
+ protected $_fields;
111
+
112
+ /**
113
+ * @var array
114
+ */
115
+ protected $_skipFields = array();
116
+
117
+ /**
118
+ * @var array
119
+ */
120
+ protected $_notSkipFields = array();
121
+
122
+
123
+ protected function _construct()
124
+ {
125
+ parent::_construct();
126
+
127
+ $this->_fieldsCollection = Mage::getResourceModel('freshdesk/field_collection');
128
+ if ($this->_fieldsCollection->getSize() < 1) {
129
+ throw new Mageplace_Freshdesk_Exception($this->_helper->__("Can't get ticket fields"), Mageplace_Freshdesk_Exception::ERROR_FIELDS);
130
+ }
131
+
132
+ $this->_fields = $this->_fieldsCollection->getItemsByNames();
133
+ }
134
+
135
+ public function getFieldsCollection()
136
+ {
137
+ return $this->_fieldsCollection;
138
+ }
139
+
140
+ public function getFields()
141
+ {
142
+ return $this->_fields;
143
+ }
144
+
145
+ /**
146
+ * @param array $data
147
+ *
148
+ * @return $this
149
+ */
150
+ public function setTicketFromArray(array $data)
151
+ {
152
+ $fields = $this->getFields();
153
+ foreach ($data as $key => $value) {
154
+ if ($key === self::FIELD_DISPLAY_ID) {
155
+ $this->_displayId = (int)$value;
156
+ continue;
157
+ }
158
+
159
+ if (!in_array($key, self::$VALID_FIELDS_NAMES) && !array_key_exists($key, $fields)) {
160
+ $this->_skipFields[$key] = $value;
161
+ continue;
162
+ }
163
+
164
+ if (in_array($key, self::$VALID_FIELDS_NAMES) || stripos($fields[$key]->getFieldType(), 'default_') !== false) {
165
+ $this->_rawData[$key] = $value;
166
+ } else {
167
+ $this->_rawData[self::FIELD_CUSTOM_FIELD][$key] = $value;
168
+ }
169
+ }
170
+
171
+ return $this;
172
+ }
173
+
174
+ public function getDefaultPriority()
175
+ {
176
+ return $this->_getHelper()->getPriorityDefault();
177
+ }
178
+
179
+ public function getDefaultStatus()
180
+ {
181
+ return $this->_getHelper()->getStatusDefault();
182
+ }
183
+
184
+ public function getStatusClose()
185
+ {
186
+ return $this->_getHelper()->getStatusClose();
187
+ }
188
+
189
+ public function getXmlRootNodeName()
190
+ {
191
+ return self::HELPDESK_TICKET;
192
+ }
193
+
194
+ public function checkData($key, $value)
195
+ {
196
+ if ($key == self::FIELD_EMAIL) {
197
+ if (!Zend_Validate::is($value, 'EmailAddress')) {
198
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $key));
199
+ }
200
+
201
+ return true;
202
+ }
203
+
204
+ if (empty($this->_fields[$key])) {
205
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $key));
206
+ }
207
+
208
+ /** @var Mageplace_Freshdesk_Model_Field|mixed $field */
209
+ $field = $this->_fields[$key];
210
+
211
+ $value = trim($value);
212
+ if ($field->isRequired() && $value === '') {
213
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is required', $field->getLabel()));
214
+ }
215
+
216
+ $checkedFieldValue = $field->checkFieldValue($value, $this->_rawData, $this->_skipFields);
217
+ if (is_array($checkedFieldValue)) {
218
+ $this->_notSkipFields = array_merge($this->_notSkipFields, $checkedFieldValue);
219
+ } elseif (!$checkedFieldValue) {
220
+ throw new Mageplace_Freshdesk_Exception(Mage::helper('freshdesk')->__('Field "%s" is not valid, please re-enter', $field->getLabel()));
221
+ }
222
+
223
+ return true;
224
+ }
225
+
226
+ public function prepareData()
227
+ {
228
+ foreach ($this->_rawData as $key => $value) {
229
+ if (is_array($value)) {
230
+ foreach ($this->_rawData[$key] as $aKey => $aValue) {
231
+ $this->checkData($aKey, $aValue);
232
+ if(trim($aValue) === '') {
233
+ unset($this->_rawData[$key][$aKey]);
234
+ }
235
+ }
236
+
237
+ if(empty($this->_rawData[$key])) {
238
+ unset($this->_rawData[$key]);
239
+ }
240
+ } else {
241
+ $this->checkData($key, $value);
242
+ if(trim($value) === '') {
243
+ unset($this->_rawData[$key]);
244
+ }
245
+ }
246
+ }
247
+
248
+ foreach ($this->_notSkipFields as $notSkipField) {
249
+ if (array_key_exists($notSkipField, $this->_skipFields)) {
250
+ $this->_rawData[self::FIELD_CUSTOM_FIELD][$notSkipField] = $this->_skipFields[$notSkipField];
251
+ unset($this->_skipFields[$notSkipField]);
252
+ }
253
+ }
254
+
255
+ foreach (self::$CHANGE_FIELDS_NAMES as $current => $change) {
256
+ if (array_key_exists($current, $this->_rawData)) {
257
+ $this->_rawData[$change] = $this->_rawData[$current];
258
+ unset($this->_rawData[$current]);
259
+ } elseif (!empty($this->_rawData[self::FIELD_CUSTOM_FIELD]) && array_key_exists($current, $this->_rawData[self::FIELD_CUSTOM_FIELD])) {
260
+ $this->_rawData[self::FIELD_CUSTOM_FIELD][$change] = $this->_rawData[self::FIELD_CUSTOM_FIELD][$current];
261
+ unset($this->_rawData[self::FIELD_CUSTOM_FIELD][$current]);
262
+ }
263
+ }
264
+
265
+ if (empty($this->_rawData[self::FIELD_EMAIL])
266
+ && !empty($this->_rawData[self::FIELD_REQUESTER])
267
+ && strpos($this->_rawData[self::FIELD_REQUESTER], '@') > 0
268
+
269
+ ) {
270
+ $this->_rawData[self::FIELD_EMAIL] = $this->_rawData[self::FIELD_REQUESTER];
271
+ unset($this->_rawData[self::FIELD_REQUESTER]);
272
+ }
273
+ }
274
+
275
+ /**
276
+ * @return $this
277
+ */
278
+ public function initTicketData()
279
+ {
280
+ $this->prepareData();
281
+
282
+ $requestData[self::HELPDESK_TICKET] = $this->_rawData;
283
+
284
+ return $this->setRequestData($requestData);
285
+ }
286
+
287
+ /**
288
+ * @return $this
289
+ */
290
+ public function initTicketXmlData()
291
+ {
292
+ $this->prepareData();
293
+
294
+ $this->_xmlData = new DOMDocument();
295
+
296
+ $this->_xmlRootNode = $this->_xmlData->createElement($this->getXmlRootNodeName());
297
+
298
+ foreach ($this->_rawData as $key => $value) {
299
+ $value = strval($value);
300
+ $paramNode = $this->_xmlData->createElement($key, $value);
301
+ $this->_xmlRootNode->appendChild($paramNode);
302
+ }
303
+
304
+ $this->_xmlData->appendChild($this->_xmlRootNode);
305
+
306
+ return $this;
307
+ }
308
+
309
+ public function createTicket($id = null)
310
+ {
311
+ if ($id > 0) {
312
+ $method = Zend_Http_Client::PUT;
313
+ $urlSuffix = sprintf(self::URL_JSON_TICKET, $id);
314
+ } elseif ($this->_displayId > 0) {
315
+ $method = Zend_Http_Client::PUT;
316
+ $urlSuffix = sprintf(self::URL_JSON_TICKET, $this->_displayId);
317
+ } else {
318
+ $method = Zend_Http_Client::POST;
319
+ $urlSuffix = self::URL_JSON_TICKETS;
320
+ }
321
+
322
+ /** @var Zend_Http_Response|null $response */
323
+ $response = $this->resetData()
324
+ ->initTicketData()
325
+ ->setUrlSuffix($urlSuffix)
326
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json')
327
+ ->request($method);
328
+
329
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
330
+ Mage::log($response);
331
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
332
+ }
333
+
334
+ switch ($response->getStatus()) {
335
+ case 200:
336
+ case 201:
337
+ return true;
338
+
339
+ default:
340
+ Mage::log($this);
341
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
342
+ }
343
+ }
344
+
345
+ public function getTickets($requester = null)
346
+ {
347
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
348
+ if ($ticketsJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKETS . (null !== $requester ? '_' . $requester : ''))) {
349
+ try {
350
+ $tickets = Zend_Json::decode($ticketsJson);
351
+ if (!empty($tickets) && is_array($tickets)) {
352
+ return $tickets;
353
+ }
354
+ } catch (Exception $e) {
355
+ Mage::logException($e);
356
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_TICKETS . (null !== $requester ? '_' . $requester : ''));
357
+ }
358
+ }
359
+ }
360
+
361
+ try {
362
+ $page = 1;
363
+ $allJson = array();
364
+ do {
365
+ $this->resetData()
366
+ ->setUrlSuffix(self::URL_TICKETS)
367
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json')
368
+ ->addUrlQueryParams(self::URL_PARAM_PAGE, $page++);
369
+
370
+ if ($requester !== null) {
371
+ if (is_int($requester)) {
372
+ $this->addUrlQueryParams(self::URL_PARAM_REQUESTER, $requester);
373
+ } else {
374
+ $this->addUrlQueryParams(self::URL_PARAM_EMAIL, $requester);
375
+ }
376
+ }
377
+
378
+ /** @var Zend_Http_Response|null $response */
379
+ $response = $this->request(Zend_Http_Client::GET);
380
+
381
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
382
+ Mage::log($response);
383
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
384
+ }
385
+
386
+ if ($response->getStatus() != 200) {
387
+ Mage::log($response);
388
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
389
+ }
390
+
391
+ $json = trim($response->getRawBody());
392
+ if(strpos($json, '"errors"') !== false) {
393
+ $error = Zend_Json::decode($json);
394
+ if(!empty($error['errors'])) {
395
+ Mage::logException(new Mageplace_Freshdesk_Exception($json));
396
+ break;
397
+ }
398
+ }
399
+
400
+ if (empty($json[2])) { /* For example if $json == '[]' */
401
+ break;
402
+ }
403
+
404
+ $allJson [] = substr($json, 1, -1); /* Cut first([) and last(]) characters */
405
+
406
+ } while ($json && $page <= self::TICKETS_MAX_PAGES);
407
+
408
+ $allTicketsJson = '[' . implode(',', $allJson) . ']';
409
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
410
+ Mage::app()->saveCache(
411
+ $allTicketsJson,
412
+ $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKETS . (null !== $requester ? '_' . $requester : ''),
413
+ $this->getCacheTags()
414
+ );
415
+ }
416
+
417
+ return Zend_Json::decode($allTicketsJson);
418
+
419
+ } catch (Exception $e) {
420
+ Mage::logException($e);
421
+ }
422
+
423
+ return array();
424
+ }
425
+
426
+ public function getTicket($id, $requester = null)
427
+ {
428
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
429
+ if ($ticketJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET . (null !== $requester ? '_' . $requester : ''))) {
430
+ try {
431
+ $ticket = Zend_Json::decode($ticketJson);
432
+ if (!empty($ticket[$id]) && is_array($ticket[$id])) {
433
+ if (!empty($ticket[$id][self::HELPDESK_TICKET])) {
434
+ return $ticket[$id][self::HELPDESK_TICKET];
435
+ }
436
+
437
+ return $ticket[$id];
438
+ }
439
+ } catch (Exception $e) {
440
+ Mage::logException($e);
441
+ Mage::log($ticketJson);
442
+ Mage::app()->removeCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET . (null !== $requester ? '_' . $requester : ''));
443
+ }
444
+ }
445
+ }
446
+
447
+ try {
448
+ $this->resetData()
449
+ ->setUrlSuffix(sprintf(self::URL_JSON_TICKET, $id))
450
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json');
451
+
452
+ /** @var Zend_Http_Response|null $response */
453
+ $response = $this->request(Zend_Http_Client::GET);
454
+
455
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
456
+ Mage::log($response);
457
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
458
+ }
459
+
460
+ if ($response->getStatus() != 200) {
461
+ Mage::log($response);
462
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
463
+ }
464
+
465
+ $json = trim($response->getRawBody());
466
+ $ticket = Zend_Json::decode($json);
467
+ $ticket = $ticket[self::HELPDESK_TICKET];
468
+
469
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
470
+ $json = Zend_Json::encode($ticket);
471
+
472
+ $ticketJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET . (null !== $requester ? '_' . $requester : ''));
473
+ if (empty($ticketJson[2])) { /* For example if $json == '{}' */
474
+ $ticketJson = '{"' . $id . '":' . $json . '}';
475
+ } else {
476
+ $ticketJson = substr($ticketJson, 0, -1); /* Cut last (}) characters */
477
+ $ticketJson .= ',' . '"' . $id . '":' . $json . '}';
478
+ }
479
+
480
+ Mage::app()->saveCache(
481
+ $ticketJson,
482
+ $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_TICKET . (null !== $requester ? '_' . $requester : ''),
483
+ $this->getCacheTags()
484
+ );
485
+ }
486
+
487
+ return $ticket;
488
+
489
+ } catch (Exception $e) {
490
+ Mage::getSingleton('core/session')->addError($e->getMessage());
491
+ Mage::logException($e);
492
+ }
493
+
494
+ return array();
495
+ }
496
+
497
+ static public function cleanCache($requester = null)
498
+ {
499
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_TICKET . (null !== $requester ? '_' . $requester : ''));
500
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_TICKETS . (null !== $requester ? '_' . $requester : ''));
501
+ }
502
+ }
app/code/local/Mageplace/Freshdesk/Model/Freshdesk/Users.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Freshdesk_Users
13
+ *
14
+ */
15
+ class Mageplace_Freshdesk_Model_Freshdesk_Users extends Mageplace_Freshdesk_Model_Freshdesk_Abstract
16
+ {
17
+ const CACHE_ID_SUFFIX_USER = 'user';
18
+ const CACHE_ID_SUFFIX_USER_BY_EMAIL = 'user_email';
19
+
20
+ const USER = 'user';
21
+
22
+ const URL_CONTACT = 'contacts/%d';
23
+ const URL_CONTACTS = 'contacts';
24
+ const URL_CONTACTS_JSON = 'contacts.json';
25
+
26
+ const URL_PARAM_QUERY = 'query';
27
+
28
+ const PARAM_EMAIL = 'email';
29
+ const PARAM_LANGUAGE = 'language';
30
+ const PARAM_MOBILE = 'mobile';
31
+ const PARAM_NAME = 'name';
32
+ const PARAM_PHONE = 'phone';
33
+ const PARAM_TIME_ZONE = 'time_zone';
34
+
35
+ static $VALID_PARAMS = array(
36
+ self::PARAM_EMAIL,
37
+ self::PARAM_LANGUAGE,
38
+ self::PARAM_MOBILE,
39
+ self::PARAM_NAME,
40
+ self::PARAM_PHONE,
41
+ self::PARAM_TIME_ZONE,
42
+ );
43
+
44
+ public function getUser($userId)
45
+ {
46
+ $userId = trim($userId);
47
+ if (!$userId) {
48
+ return array();
49
+ }
50
+
51
+ if (null === $this->_getData('user_' . $userId)) {
52
+ $isEmail = strpos($userId, '@') > 0;
53
+
54
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
55
+ if ($isEmail) {
56
+ $userJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER_BY_EMAIL);
57
+ } else {
58
+ $userJson = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER);
59
+ }
60
+
61
+ if ($userJson) {
62
+ try {
63
+ $user = Zend_Json::decode($userJson);
64
+ if (!empty($user[$userId]) && is_array($user[$userId])) {
65
+ $this->setData('user_' . $user[$userId][self::PARAM_ID], $user[$userId]);
66
+ $this->setData('user_' . $user[$userId][self::PARAM_EMAIL], $user[$userId]);
67
+
68
+ return $user[$userId];
69
+ }
70
+
71
+ unset($user);
72
+ } catch (Exception $e) {
73
+ Mage::logException($e);
74
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_USER);
75
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_USER_BY_EMAIL);
76
+ }
77
+ }
78
+
79
+ unset($userJson);
80
+ }
81
+
82
+ try {
83
+ /** @var Zend_Http_Response|null $response */
84
+ $this->resetData();
85
+
86
+ if ($isEmail) {
87
+ $this->setUrlSuffix(self::URL_CONTACTS);
88
+ $this->addUrlQueryParams(self::URL_PARAM_QUERY, 'email is ' . $userId);
89
+ } else {
90
+ $this->setUrlSuffix(sprintf(self::URL_CONTACT, $userId));
91
+ }
92
+
93
+ $this->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json');
94
+
95
+ $response = $this->request(Zend_Http_Client::GET);
96
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
97
+ Mage::log($response);
98
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
99
+ }
100
+
101
+ if ($response->getStatus() != 200) {
102
+ Mage::log($response);
103
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
104
+ }
105
+
106
+ $userJson = trim($response->getRawBody());
107
+ if (empty($userJson[2])) { /* if $allTicketFieldsJson == '{}' or empty */
108
+ $this->setData('user_' . $userId, array());
109
+
110
+ return array();
111
+ }
112
+
113
+ $user = Zend_Json::decode($userJson);
114
+ if (is_array($user) && empty($user[self::USER])) {
115
+ $user = array_shift($user);
116
+ }
117
+
118
+ if (!empty($user[self::USER])) {
119
+ $user = $user[self::USER];
120
+ }
121
+
122
+ if (!array_key_exists(self::PARAM_ID, $user) || !array_key_exists(self::PARAM_EMAIL, $user)) {
123
+ throw new Mageplace_Freshdesk_Exception('Wrong user data');
124
+ }
125
+
126
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
127
+ $userJson = Zend_Json::encode($user);
128
+
129
+ $userJsonCached = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER);
130
+ if (empty($userJsonCached[2])) { /* For example if $json == '{}' */
131
+ $userJsonCached = '{"' . $user[self::PARAM_ID] . '":' . $userJson . '}';
132
+ } else {
133
+ $userJsonCached = substr($userJsonCached, 0, -1); /* Cut last (}) characters */
134
+ $userJsonCached .= ',' . '"' . $user[self::PARAM_ID] . '":' . $userJson . '}';
135
+ }
136
+ Mage::app()->saveCache($userJsonCached, $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER, $this->getCacheTags());
137
+
138
+ $userJsonCached = Mage::app()->loadCache($this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER_BY_EMAIL);
139
+ if (empty($userJsonCached[2])) { /* For example if $json == '{}' */
140
+ $userJsonCached = '{"' . $user[self::PARAM_EMAIL] . '":' . $userJson . '}';
141
+ } else {
142
+ $userJsonCached = substr($userJsonCached, 0, -1); /* Cut last (}) characters */
143
+ $userJsonCached .= ',' . '"' . $user[self::PARAM_EMAIL] . '":' . $userJson . '}';
144
+ }
145
+ Mage::app()->saveCache($userJsonCached, $this->getCacheId() . '_' . self::CACHE_ID_SUFFIX_USER_BY_EMAIL, $this->getCacheTags());
146
+ }
147
+
148
+ $this->setData('user_' . $user[self::PARAM_ID], $user);
149
+ $this->setData('user_' . $user[self::PARAM_EMAIL], $user);
150
+
151
+ return $user;
152
+ } catch (Exception $e) {
153
+ # Mage::getSingleton('core/session')->addError($e->getMessage());
154
+ Mage::logException($e);
155
+ }
156
+
157
+ $this->setData('user_' . $userId, array());
158
+ }
159
+
160
+ return $this->_getData('user_' . $userId);
161
+ }
162
+
163
+ /**
164
+ * @return $this
165
+ */
166
+ public function initData()
167
+ {
168
+ $requestData[self::USER] = $this->_rawData;
169
+
170
+ return $this->setRequestData($requestData);
171
+ }
172
+
173
+ public function saveUser($id = null)
174
+ {
175
+ $this->resetData()
176
+ ->initData();
177
+
178
+ if ($id > 0) {
179
+ $method = Zend_Http_Client::PUT;
180
+
181
+ $this->setUrlSuffix(sprintf(self::URL_CONTACT, $id))
182
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json');
183
+
184
+ } elseif ($this->_id > 0) {
185
+ $method = Zend_Http_Client::PUT;
186
+
187
+ $this->setUrlSuffix(sprintf(self::URL_CONTACT, $this->_id))
188
+ ->addUrlQueryParams(self::URL_PARAM_FORMAT, 'json');
189
+ } else {
190
+ $method = Zend_Http_Client::POST;
191
+
192
+ $this->setUrlSuffix(self::URL_CONTACTS_JSON);
193
+ }
194
+
195
+ /** @var Zend_Http_Response|null $response */
196
+ $response = $this->request($method);
197
+ if (is_null($response) || !($response instanceof Zend_Http_Response)) {
198
+ Mage::log($response);
199
+ throw new Mageplace_Freshdesk_Exception('Wrong response object');
200
+ }
201
+
202
+ switch ($response->getStatus()) {
203
+ case 200:
204
+ case 201:
205
+ return true;
206
+
207
+ default:
208
+ Mage::log($this);
209
+ throw new Mageplace_Freshdesk_Exception($response->getMessage());
210
+ }
211
+ }
212
+
213
+ protected function getValidParams()
214
+ {
215
+ return self::$VALID_PARAMS;
216
+ }
217
+
218
+ static public function cleanCache()
219
+ {
220
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_USER);
221
+ Mage::app()->removeCache(self::CACHE_ID . '_' . self::CACHE_ID_SUFFIX_USER_BY_EMAIL);
222
+ }
223
+ }
app/code/local/Mageplace/Freshdesk/Model/Note.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Note
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Note setTicketId
15
+ * @method Mageplace_Freshdesk_Model_Note setBody
16
+ * @method Mageplace_Freshdesk_Model_Note setUserName
17
+ * @method int|null getTicketId
18
+ * @method int|null getUserId
19
+ * @method string getUserName
20
+ * @method Mageplace_Freshdesk_Model_User getUser
21
+ * @method Mageplace_Freshdesk_Model_Note setUser
22
+ */
23
+ class Mageplace_Freshdesk_Model_Note extends Mageplace_Freshdesk_Model_Abstract
24
+ {
25
+ const NOTE = Mageplace_Freshdesk_Model_Freshdesk_Notes::NOTE;
26
+
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+
31
+ $this->_init('freshdesk/note');
32
+ }
33
+
34
+ /**
35
+ * @param array $notes
36
+ * @param Mageplace_Freshdesk_Model_Ticket $ticket
37
+ *
38
+ * @return array
39
+ */
40
+ public function parseTicketNotes($ticket, $notes = null)
41
+ {
42
+ $this->setTicketId($ticket->getId());
43
+
44
+ $notesParsed = array();
45
+
46
+ if (null === $notes) {
47
+ $notes = $ticket->getNotes();
48
+ }
49
+
50
+ foreach ($notes as $note) {
51
+ $noteModel = clone $this;
52
+
53
+ if (!empty($note[self::NOTE])) {
54
+ $noteModel->addData($note[self::NOTE]);
55
+ } else {
56
+ $noteModel->addData($note);
57
+ }
58
+
59
+ if ($noteModel->getUserId() > 0) {
60
+ $user = Mage::getModel('freshdesk/user')->load($noteModel->getUserId());
61
+ $noteModel->setUser($user);
62
+ $noteModel->setUserName($user->getName());
63
+ unset($user);
64
+ }
65
+
66
+ $notesParsed[] = $noteModel;
67
+ }
68
+
69
+ return $notesParsed;
70
+ }
71
+ }
app/code/local/Mageplace/Freshdesk/Model/Observer.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Observer
13
+ */
14
+ class Mageplace_Freshdesk_Model_Observer
15
+ {
16
+ public function processCoreBlockAbstractToHtmlBefore($observer)
17
+ {
18
+ /*if ($this->isTicketTabEnabled() && ($observer->getBlock() instanceof Mage_Customer_Block_Account_Navigation)) {
19
+ $observer->getBlock()->addLink(
20
+ 'freshdesk_tickets',
21
+ 'freshdesk/ticket/list',
22
+ Mage::helper('freshdesk')->__('My Tickets')
23
+ );
24
+ }*/
25
+ }
26
+
27
+ public function processControllerActionPostdispatchContacts($event)
28
+ {
29
+ if (!Mage::helper('freshdesk')->isContactUsFormEnabled()) {
30
+ return;
31
+ }
32
+
33
+ try {
34
+ $post = $event->getControllerAction()->getRequest()->getPost();
35
+ if ($post) {
36
+ $messages = $this->_getCustomerSession()->getMessages();
37
+ if ($messages->getLastAddedMessage()->getType() == Mage_Core_Model_Message::SUCCESS) {
38
+ $check = Mage::getModel('freshdesk/ticket')
39
+ ->setSubject(Mage::helper('freshdesk')->__('Contact Us form ticket from %s', $post['name']))
40
+ ->setEmail($post['email'])
41
+ ->setDescription($post['comment'] . "\n" . Mage::helper('contacts')->__('Telephone') . ': ' . $post['telephone'])
42
+ ->save();
43
+
44
+ if ($check) {
45
+ $this->_getCustomerSession()->addSuccess(Mage::helper('freshdesk')->__('Ticket was created'));
46
+ } else {
47
+ $this->_getCustomerSession()->addError(Mage::helper('freshdesk')->__('Ticket wasn\'t created'));
48
+ }
49
+ }
50
+ }
51
+ } catch (Mageplace_Freshdesk_Exception $mfe) {
52
+ $this->_getCustomerSession()->addError(Mage::helper('freshdesk')->__('Ticket wasn\'t created'));
53
+ Mage::logException($mfe);
54
+ } catch (Exception $e) {
55
+ Mage::logException($e);
56
+ }
57
+ }
58
+
59
+ public function processSaveCustomer($observer)
60
+ {
61
+ if(!$this->isTicketTabEnabled()) {
62
+ return;
63
+ }
64
+
65
+ try {
66
+ $customer = $observer->getEvent()->getCustomer();
67
+ if ($customer instanceof Mage_Customer_Model_Customer) {
68
+ Mage::getModel('freshdesk/user')->syncCustomer($customer);
69
+ }
70
+ } catch (Exception $e) {
71
+ Mage::logException($e);
72
+ }
73
+
74
+ return $this;
75
+ }
76
+
77
+ protected function isTicketTabEnabled()
78
+ {
79
+ static $enabled;
80
+
81
+ if (null === $enabled) {
82
+ $enabled = Mage::helper('freshdesk')->isTicketTabEnabled();
83
+ }
84
+
85
+ return $enabled;
86
+ }
87
+
88
+ protected function isFeedbackWidgetEnabled()
89
+ {
90
+ static $enabled;
91
+
92
+ if (null === $enabled) {
93
+ $enabled = Mage::helper('freshdesk')->isFeedbackWidgetEnabled();
94
+ }
95
+
96
+ return $enabled;
97
+ }
98
+
99
+ protected function isSupportLinkEnabled()
100
+ {
101
+ static $enabled;
102
+
103
+ if (null === $enabled) {
104
+ $enabled = Mage::helper('freshdesk')->isSupportLinkEnabled();
105
+ }
106
+
107
+ return $enabled;
108
+ }
109
+
110
+ /**
111
+ * @return Mage_Customer_Model_Session
112
+ */
113
+ protected function _getCustomerSession()
114
+ {
115
+ return Mage::getSingleton('customer/session');
116
+ }
117
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Collection/Abstract.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Collection_Abstract
13
+ */
14
+ abstract class Mageplace_Freshdesk_Model_Resource_Collection_Abstract extends Varien_Data_Collection
15
+ {
16
+ protected $_freshdeskData;
17
+ protected $_rawData = array();
18
+ protected $_isOrdersRendered = false;
19
+ protected $_sortField;
20
+ protected $_sortDir;
21
+
22
+ abstract protected function loadFreshdeskData();
23
+
24
+ public function loadData($printQuery = false, $logQuery = false)
25
+ {
26
+ if ($this->isLoaded()) {
27
+ return $this;
28
+ }
29
+
30
+ $this->_rawData = $this->loadFreshdeskData();
31
+ $this->_renderFilters()
32
+ ->_renderOrders()
33
+ ->_renderLimit();
34
+
35
+ foreach ($this->_rawData as $data) {
36
+ $this->createItem($data);
37
+ }
38
+
39
+ $this->_setIsLoaded();
40
+
41
+ return $this;
42
+ }
43
+
44
+ public function createItem($data)
45
+ {
46
+ $item = $this->getNewEmptyItem();
47
+ $item->addData($data);
48
+ $this->addItem($item);
49
+ }
50
+
51
+ public function getSize()
52
+ {
53
+ $this->loadFreshdeskData();
54
+ if (is_null($this->_totalRecords)) {
55
+ foreach ($this->_freshdeskData as $id => $data) {
56
+ if ($this->_filter($data)) {
57
+ ++$this->_totalRecords;
58
+ }
59
+ }
60
+ }
61
+
62
+ return intval($this->_totalRecords);
63
+ }
64
+
65
+ public function addFilter($field, $value, $type = 'and')
66
+ {
67
+ $this->addFieldToFilter($field, $value);
68
+ $this->_isFiltersRendered = false;
69
+
70
+ return $this;
71
+ }
72
+
73
+ public function getFilter($field)
74
+ {
75
+ if (is_array($field)) {
76
+ if (empty($field)) {
77
+ return $this->_filters;
78
+ }
79
+
80
+ $result = array();
81
+ foreach ($field as $f) {
82
+ if (array_key_exists($f, $this->_filters)) {
83
+ $result[] = $this->_filters[$f];
84
+ }
85
+ }
86
+
87
+ return $result;
88
+ }
89
+
90
+ if (array_key_exists($field, $this->_filters)) {
91
+ return $this->_filters[$field];
92
+ }
93
+
94
+ return null;
95
+ }
96
+
97
+ public function addFieldToFilter($fields, $conditions = null)
98
+ {
99
+ if (!is_array($this->_filters)) {
100
+ $this->_filters = array();
101
+ }
102
+
103
+ if (is_array($fields)) {
104
+ foreach ($fields as $field) {
105
+ if (is_array($conditions)) {
106
+ foreach ($conditions as $name => $condition) {
107
+ $this->_filters[$field][$name][] = $condition;
108
+ }
109
+ } else {
110
+ $this->_filters[$field]['eq'][] = strval($conditions);
111
+ }
112
+ }
113
+ } else {
114
+ if (is_array($conditions)) {
115
+ foreach ($conditions as $name => $condition) {
116
+ $this->_filters[strval($fields)][$name][] = $condition;
117
+ }
118
+ } else {
119
+ $this->_filters[strval($fields)]['eq'][] = strval($conditions);
120
+ }
121
+ }
122
+
123
+ return $this;
124
+ }
125
+
126
+ protected function _renderFilters()
127
+ {
128
+ if ($this->_isFiltersRendered) {
129
+ return $this;
130
+ }
131
+
132
+ foreach ($this->_rawData as $k => $data) {
133
+ if (!$this->_filter($data)) {
134
+ unset($this->_rawData[$k]);
135
+ }
136
+ }
137
+
138
+ $this->_isFiltersRendered = true;
139
+
140
+ return $this;
141
+ }
142
+
143
+ protected function _filter(array $data)
144
+ {
145
+ foreach ($this->_filters as $column => $filters) {
146
+ if (!array_key_exists($column, $data)) {
147
+ return false;
148
+ }
149
+
150
+ foreach ($filters as $type => $values) {
151
+ if ($type == 'or') {
152
+ if (!in_array($data[$column], $values)) {
153
+ return false;
154
+ }
155
+ } else {
156
+ foreach ($values as $value) {
157
+ if ($data[$column] != $value) {
158
+ return false;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ return true;
166
+ }
167
+
168
+ protected function _renderOrders()
169
+ {
170
+ if (!$this->_isOrdersRendered) {
171
+ reset($this->_orders);
172
+
173
+ while (current($this->_orders)) {
174
+ uasort($this->_rawData, array($this, 'sortByOrder'));
175
+ next($this->_orders);
176
+ }
177
+
178
+ reset($this->_orders);
179
+
180
+ $this->_isOrdersRendered = true;
181
+ }
182
+
183
+ return $this;
184
+ }
185
+
186
+ protected function sortByOrder($a, $b)
187
+ {
188
+ $direction = current($this->_orders);
189
+ $field = key($this->_orders);
190
+ if (strpos($field, '/') > 0) {
191
+ list($col1, $col2) = explode('/', $field);
192
+ $aField = $a[$col1][$col2];
193
+ $bField = $b[$col1][$col2];
194
+ } else {
195
+ $aField = $a[$field];
196
+ $bField = $b[$field];
197
+ }
198
+ if (is_int($aField)) {
199
+ if ($aField == $bField) {
200
+ return 0;
201
+ } elseif (($direction == 'DESC' && $aField > $bField) || ($direction == 'ASC' && $aField < $bField)) {
202
+ return -1;
203
+ } else {
204
+ return 1;
205
+ }
206
+ } else {
207
+ if ($strnatcmp = strnatcmp(strval($aField), strval($bField))) {
208
+ return ($direction == 'DESC' ? -1 : 1) * $strnatcmp;
209
+ }
210
+
211
+ return 0;
212
+ }
213
+ }
214
+
215
+ protected function _renderLimit()
216
+ {
217
+ if ($this->_pageSize) {
218
+ $this->_rawData = array_slice($this->_rawData, ($this->getCurPage() - 1) * $this->_pageSize, $this->_pageSize, true);
219
+ }
220
+
221
+ return $this;
222
+ }
223
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Field.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Field
13
+ */
14
+ class Mageplace_Freshdesk_Model_Resource_Field extends Varien_Object
15
+ {
16
+ public function getFreshdeskModel()
17
+ {
18
+ return Mage::getSingleton('freshdesk/freshdesk_fields');
19
+ }
20
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Field/Collection.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Field_Collection
13
+ *
14
+ * @method Mageplace_Freshdesk_Model_Field getNewEmptyItem
15
+ */
16
+ class Mageplace_Freshdesk_Model_Resource_Field_Collection extends Mageplace_Freshdesk_Model_Resource_Collection_Abstract
17
+ {
18
+ protected $_filedsByNames;
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $this->setItemObjectClass('freshdesk/field');
25
+ }
26
+
27
+ public function createItem($data)
28
+ {
29
+ $item = $this->getNewEmptyItem()->getFieldModel($data);
30
+ $this->addItem($item);
31
+ }
32
+
33
+ public function getItemsByNames()
34
+ {
35
+ if(!is_array($this->_filedsByNames)) {
36
+ $fields = $this->getItems();
37
+ foreach($fields as $field) {
38
+ /** @var Mageplace_Freshdesk_Model_Field $field */
39
+ $this->_filedsByNames[$field->getName()] = $field;
40
+ }
41
+ }
42
+
43
+ return $this->_filedsByNames;
44
+ }
45
+
46
+ protected function loadFreshdeskData()
47
+ {
48
+ return $this->loadFields();
49
+ }
50
+
51
+ protected function loadFields()
52
+ {
53
+ if (!is_array($this->_freshdeskData)) {
54
+ $this->_freshdeskData = $this->getNewEmptyItem()
55
+ ->getFreshdeskModel()
56
+ ->getFields();
57
+ if (!is_array($this->_freshdeskData)) {
58
+ $this->_freshdeskData = array();
59
+ }
60
+ }
61
+
62
+ return $this->_freshdeskData;
63
+ }
64
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Note.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Note
13
+ */
14
+ class Mageplace_Freshdesk_Model_Resource_Note extends Varien_Object
15
+ {
16
+ public function getFreshdeskModel()
17
+ {
18
+ return Mage::getSingleton('freshdesk/freshdesk_notes');
19
+ }
20
+
21
+ /**
22
+ * @param Mageplace_Freshdesk_Model_Note $note
23
+ * @param int $id
24
+ * @param null $field
25
+ *
26
+ * @return array|null
27
+ */
28
+ public function load($note, $id, $field = null)
29
+ {
30
+ return $note->addData(
31
+ $this->getFreshdeskModel()
32
+ ->getNote($id)
33
+ );
34
+ }
35
+
36
+ public function save(Mageplace_Freshdesk_Model_Note $note)
37
+ {
38
+ $this->getFreshdeskModel()
39
+ ->setDataFromArray($note->getData())
40
+ ->saveNote();
41
+
42
+ return $this;
43
+ }
44
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Ticket.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Ticket
13
+ */
14
+ class Mageplace_Freshdesk_Model_Resource_Ticket extends Varien_Object
15
+ {
16
+ protected $_requester;
17
+
18
+ public function getFreshdeskModel()
19
+ {
20
+ return Mage::getSingleton('freshdesk/freshdesk_tickets');
21
+ }
22
+
23
+ public function setRequester($requester)
24
+ {
25
+ $this->_requester = $requester;
26
+
27
+ return $this;
28
+ }
29
+
30
+ public function getRequester()
31
+ {
32
+ return $this->_requester;
33
+ }
34
+
35
+ public function getIdFieldName()
36
+ {
37
+ return Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_DISPLAY_ID;
38
+ }
39
+
40
+ /**
41
+ * @param Mageplace_Freshdesk_Model_Ticket $ticket
42
+ * @param int $id
43
+ * @param null $field
44
+ *
45
+ * @return array|null
46
+ */
47
+ public function load($ticket, $id, $field = null)
48
+ {
49
+ $requester = $this->getRequester() ? $this->getRequester() : $ticket->getRequester();
50
+ return $ticket->addData(
51
+ $this->getFreshdeskModel()
52
+ ->getTicket($id, $requester)
53
+ );
54
+ }
55
+
56
+ public function save(Mageplace_Freshdesk_Model_Ticket $ticket)
57
+ {
58
+ $this->getFreshdeskModel()
59
+ ->setTicketFromArray($ticket->getData())
60
+ ->createTicket();
61
+
62
+ return $this;
63
+ }
64
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/Ticket/Collection.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_Ticket_Collection
13
+ */
14
+ class Mageplace_Freshdesk_Model_Resource_Ticket_Collection extends Mageplace_Freshdesk_Model_Resource_Collection_Abstract
15
+ {
16
+ protected $_priority = array();
17
+ protected $_status = array();
18
+ protected $_requester;
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $this->setItemObjectClass('freshdesk/ticket');
25
+ }
26
+
27
+ public function getPriorities()
28
+ {
29
+ $this->loadTickets();
30
+
31
+ return $this->_priority;
32
+ }
33
+
34
+ public function getStatuses()
35
+ {
36
+ $this->loadTickets();
37
+
38
+ return $this->_status;
39
+ }
40
+
41
+ public function setRequester($requester)
42
+ {
43
+ $this->_requester = $requester;
44
+
45
+ return $this;
46
+ }
47
+
48
+ public function getRequester()
49
+ {
50
+ return $this->_requester;
51
+ }
52
+
53
+ protected function loadFreshdeskData()
54
+ {
55
+ return $this->loadTickets();
56
+ }
57
+
58
+ protected function loadTickets()
59
+ {
60
+ if (!is_array($this->_freshdeskData)) {
61
+ $requster = $this->getRequester();
62
+ $email = strpos($requster, '@') > 0 ? $requster : null;
63
+ $this->_freshdeskData = Mage::getSingleton('freshdesk/freshdesk_tickets')
64
+ ->getTickets($requster);
65
+ if (!is_array($this->_freshdeskData)) {
66
+ $this->_freshdeskData = array();
67
+
68
+ return array();
69
+ }
70
+
71
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
72
+ foreach ($this->_freshdeskData as &$ticket) {
73
+ $orderId = $orderIncrementId = null;
74
+ if (is_object($orderField) && ($orderFieldName = $orderField->getName())) {
75
+ if (!array_key_exists($orderFieldName, $ticket)) {
76
+ if (!empty($ticket[Mageplace_Freshdesk_Model_Ticket::CUSTOM_FIELDS])
77
+ && array_key_exists($orderFieldName, $ticket[Mageplace_Freshdesk_Model_Ticket::CUSTOM_FIELDS])
78
+ ) {
79
+ $orderId = $ticket[Mageplace_Freshdesk_Model_Ticket::CUSTOM_FIELDS][$orderFieldName];
80
+ }
81
+ } else {
82
+ $orderId = $ticket[$orderFieldName];
83
+ }
84
+
85
+ if ($orderId) {
86
+ if (strpos($orderId, '#') === 0) {
87
+ $orderId = substr($orderId, 1);
88
+ }
89
+
90
+ $order = Mage::getModel('sales/order')->load($orderId);
91
+ if (!$order->getId()) {
92
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
93
+ }
94
+
95
+ if (is_object($order) && $order->getId() && (!isset($email) || $email == $order->getCustomerEmail())) {
96
+ $orderId = $order->getId();
97
+ $orderIncrementId = $order->getIncrementId();
98
+ } else {
99
+ $orderId = $orderIncrementId = null;
100
+ }
101
+ }
102
+ }
103
+ $ticket[Mageplace_Freshdesk_Model_Ticket::ORDER_ID] = $orderId;
104
+ $ticket[Mageplace_Freshdesk_Model_Ticket::ORDER_INCREMENT_ID] = $orderIncrementId;
105
+
106
+ $this->_addPriority(
107
+ $ticket[Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_PRIORITY],
108
+ $ticket[Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_PRIORITY_NAME]
109
+ );
110
+ $this->_addStatus(
111
+ $ticket[Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_STATUS],
112
+ $ticket[Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_STATUS_NAME]
113
+ );
114
+ }
115
+ unset($ticket);
116
+ }
117
+
118
+ return $this->_freshdeskData;
119
+ }
120
+
121
+ protected function _addPriority($value, $label)
122
+ {
123
+ if (empty($label) || array_key_exists($value, $this->_priority)) {
124
+ return $this;
125
+ }
126
+
127
+ $this->_priority[$value] = $label;
128
+
129
+ return $this;
130
+ }
131
+
132
+ protected function _addStatus($value, $label)
133
+ {
134
+ if (empty($label) || array_key_exists($value, $this->_status)) {
135
+ return $this;
136
+ }
137
+
138
+ $this->_status[$value] = $label;
139
+
140
+ return $this;
141
+ }
142
+ }
app/code/local/Mageplace/Freshdesk/Model/Resource/User.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Resource_User
13
+ */
14
+ class Mageplace_Freshdesk_Model_Resource_User extends Varien_Object
15
+ {
16
+ public function getFreshdeskModel()
17
+ {
18
+ return Mage::getSingleton('freshdesk/freshdesk_users');
19
+ }
20
+
21
+ public function getIdFieldName()
22
+ {
23
+ return Mageplace_Freshdesk_Model_Freshdesk_Users::PARAM_ID;
24
+ }
25
+
26
+ /**
27
+ * @param Mageplace_Freshdesk_Model_User $user
28
+ * @param int $id
29
+ * @param null $field
30
+ *
31
+ * @return array|null
32
+ */
33
+ public function load($user, $id, $field = null)
34
+ {
35
+ return $user->addData(
36
+ $this->getFreshdeskModel()
37
+ ->getUser($id)
38
+ );
39
+ }
40
+
41
+ public function save(Mageplace_Freshdesk_Model_User $user)
42
+ {
43
+ $this->getFreshdeskModel()
44
+ ->setDataFromArray($user->getData())
45
+ ->saveUser();
46
+
47
+ return $this;
48
+ }
49
+ }
app/code/local/Mageplace/Freshdesk/Model/Source/Abstract.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Source_Abstract
13
+ */
14
+ abstract class Mageplace_Freshdesk_Model_Source_Abstract
15
+ {
16
+ abstract public function toOptionArray();
17
+
18
+ protected function _getHelper()
19
+ {
20
+ return Mage::helper('freshdesk');
21
+ }
22
+
23
+ public function toOptionHash()
24
+ {
25
+ $hash = array();
26
+ foreach($this->toOptionArray() as $item) {
27
+ $hash[$item['value']] = $item['label'];
28
+ }
29
+
30
+ return $hash;
31
+ }
32
+ }
app/code/local/Mageplace/Freshdesk/Model/Source/Priority.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Source_Priority
13
+ */
14
+ class Mageplace_Freshdesk_Model_Source_Priority extends Mageplace_Freshdesk_Model_Source_Abstract
15
+ {
16
+ public function toOptionArray()
17
+ {
18
+ $priorities = Mage::getModel('freshdesk/ticket')
19
+ ->getCollection()
20
+ ->getPriorities();
21
+
22
+ $return = array();
23
+ foreach ($priorities as $value => $label) {
24
+ $return[] = array('value' => $value, 'label' => $label);
25
+ }
26
+
27
+ return $return;
28
+ }
29
+ }
app/code/local/Mageplace/Freshdesk/Model/Source/Status.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Source_Status
13
+ */
14
+ class Mageplace_Freshdesk_Model_Source_Status extends Mageplace_Freshdesk_Model_Source_Abstract
15
+ {
16
+ public function toOptionArray()
17
+ {
18
+ $statuses = Mage::getModel('freshdesk/ticket')
19
+ ->getCollection()
20
+ ->getStatuses();
21
+
22
+ $return = array();
23
+ foreach ($statuses as $value => $label) {
24
+ $return[] = array('value' => $value, 'label' => $label);
25
+ }
26
+
27
+ return $return;
28
+ }
29
+ }
app/code/local/Mageplace/Freshdesk/Model/Source/Ticketview.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Source_Ticketview
13
+ */
14
+ class Mageplace_Freshdesk_Model_Source_Ticketview extends Mageplace_Freshdesk_Model_Source_Abstract
15
+ {
16
+ const NO = 0;
17
+ const YES = 1;
18
+
19
+ public function toOptionArray()
20
+ {
21
+ $return = array();
22
+ $return[] = array('value' => self::NO, 'label' => $this->_getHelper()->__('No, they will have to use your Freshdesk portal'));
23
+ $return[] = array('value' => self::YES, 'label' => $this->_getHelper()->__('Yes, My Account will have My Tickets to view, reply and close tickets'));
24
+
25
+ return $return;
26
+ }
27
+ }
app/code/local/Mageplace/Freshdesk/Model/Source/Widgetposition.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Source_Widgetposition
13
+ */
14
+ class Mageplace_Freshdesk_Model_Source_Widgetposition extends Mageplace_Freshdesk_Model_Source_Abstract
15
+ {
16
+ const POSITION_TOP = 1;
17
+ const POSITION_RIGHT = 2;
18
+ const POSITION_BOTTOM = 3;
19
+ const POSITION_LEFT = 4;
20
+
21
+ static $POSITIONS = array(
22
+ self::POSITION_LEFT => 'Left',
23
+ self::POSITION_RIGHT => 'Right',
24
+ self::POSITION_TOP => 'Top',
25
+ self::POSITION_BOTTOM => 'Bottom',
26
+ );
27
+
28
+ public function toOptionArray()
29
+ {
30
+ $return = array();
31
+ foreach (self::$POSITIONS as $value => $label) {
32
+ $return[] = array('value' => $value, 'label' => $this->_getHelper()->__($label));
33
+ }
34
+
35
+ return $return;
36
+ }
37
+ }
app/code/local/Mageplace/Freshdesk/Model/Ticket.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_Ticket
13
+ *
14
+ * @method string getSubject
15
+ * @method int getDisplayId
16
+ * @method int getRequesterId
17
+ * @method int getPriority
18
+ * @method int getStatus
19
+ * @method datetime getCreatedAt
20
+ * @method string getPriorityName
21
+ * @method string getStatusName
22
+ * @method array getNotes
23
+ * @method Mageplace_Freshdesk_Model_Ticket setStatus
24
+ * @method Mageplace_Freshdesk_Model_Ticket setDisplayId
25
+ */
26
+ class Mageplace_Freshdesk_Model_Ticket extends Mageplace_Freshdesk_Model_Abstract
27
+ {
28
+ const ORDER_ID = 'order_id';
29
+ const ORDER_INCREMENT_ID = 'order_increment_id';
30
+ const CUSTOM_FIELDS = Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_CUSTOM_FIELD;
31
+ const FIELD_DISPLAY_ID = Mageplace_Freshdesk_Model_Freshdesk_Tickets::FIELD_DISPLAY_ID;
32
+
33
+ protected $_requester;
34
+
35
+ protected $_notes = array();
36
+
37
+ protected function _construct()
38
+ {
39
+ parent::_construct();
40
+
41
+ $this->_init('freshdesk/ticket');
42
+ }
43
+
44
+ public function loadFromCollection($id, $field = self::FIELD_DISPLAY_ID)
45
+ {
46
+ /** @var Mageplace_Freshdesk_Model_Resource_Ticket_Collection $tickets */
47
+ $tickets = $this->getCollection();
48
+ if ($this->getRequester()) {
49
+ $tickets->setRequester($this->getRequester());
50
+ }
51
+
52
+ $model = null;
53
+ if (null === $field) {
54
+ $tickets = $tickets->getItems();
55
+ $model = $tickets[$id];
56
+ } else {
57
+ $model = $tickets->addFilter($field, $id)
58
+ ->load()
59
+ ->getFirstItem();
60
+ }
61
+
62
+ return $model;
63
+ }
64
+
65
+ public function getNoteItems()
66
+ {
67
+ if(empty($this->_notes)) {
68
+ $this->_notes = Mage::getModel('freshdesk/note')->parseTicketNotes($this);
69
+ }
70
+
71
+ return $this->_notes;
72
+ }
73
+
74
+ public function setRequester($requester)
75
+ {
76
+ $this->_requester = $requester;
77
+
78
+ return $this;
79
+ }
80
+
81
+ public function getRequester()
82
+ {
83
+ return $this->_requester;
84
+ }
85
+
86
+ public function close($ticketId)
87
+ {
88
+ return $this->setDisplayId($ticketId)
89
+ ->setStatus(Mage::helper('freshdesk')->getStatusClose())
90
+ ->save();
91
+ }
92
+ }
app/code/local/Mageplace/Freshdesk/Model/User.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Model_User
13
+ *
14
+ * @method string|null getName
15
+ * @method string|null getEmail
16
+ * @method Mageplace_Freshdesk_Model_User setName
17
+ * @method Mageplace_Freshdesk_Model_User setEmail
18
+ */
19
+ class Mageplace_Freshdesk_Model_User extends Mageplace_Freshdesk_Model_Abstract
20
+ {
21
+ protected function _construct()
22
+ {
23
+ parent::_construct();
24
+
25
+ $this->_init('freshdesk/user');
26
+ }
27
+
28
+ public function syncCustomer(Mage_Customer_Model_Customer $customer)
29
+ {
30
+ if (!$email = $customer->getEmail()) {
31
+ return false;
32
+ }
33
+
34
+ $this->load($email);
35
+ if (!$this->getId()) {
36
+ $this->setEmail($email);
37
+ }
38
+ $this->setName($customer->getName());
39
+
40
+ $this->save();
41
+
42
+ $this->cleanCache();
43
+
44
+ return true;
45
+ }
46
+
47
+ public function cleanCache()
48
+ {
49
+ Mageplace_Freshdesk_Model_Freshdesk_Users::cleanCache();
50
+ }
51
+ }
app/code/local/Mageplace/Freshdesk/controllers/Adminhtml/Freshdesk/TicketController.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Adminhtml_Freshdesk_TicketController
13
+ */
14
+ class Mageplace_Freshdesk_Adminhtml_Freshdesk_TicketController extends Mage_Adminhtml_Controller_Action
15
+ {
16
+ public function preDispatch()
17
+ {
18
+ parent::preDispatch();
19
+
20
+ if (!Mage::helper('freshdesk')->isConfigSet()) {
21
+ $this->_getSession()->addError($this->__('Please fill in Freshdesk configuration options first'));
22
+ $this->_redirect('*/system_config/edit/section/freshdesk');
23
+ $this->getResponse()->sendResponse();
24
+ exit;
25
+ }
26
+
27
+ return $this;
28
+ }
29
+
30
+ /**
31
+ * Displays the tickets overview grid.
32
+ */
33
+ public function indexAction()
34
+ {
35
+ return $this->_redirect('*/freshdesk/ticket');
36
+ }
37
+
38
+ /**
39
+ * Displays the tickets overview grid.
40
+ */
41
+ public function refreshAction()
42
+ {
43
+ $this->_refreshCache();
44
+
45
+ return $this->_redirect('*/freshdesk/ticket');
46
+ }
47
+
48
+ /**
49
+ * Displays the tickets overview grid.
50
+ */
51
+ public function createAction()
52
+ {
53
+ try {
54
+ return $this->loadLayout()
55
+ ->_setActiveMenu('freshdesk/ticket')
56
+ ->_title($this->__('Freshdesk'))
57
+ ->_title($this->__('Create Ticket'))
58
+ ->_addContent($this->getLayout()->createBlock('freshdesk/adminhtml_ticket_edit'))
59
+ ->renderLayout();
60
+
61
+ } catch (Exception $e) {
62
+ $this->_getSession()->addError($e->getMessage());
63
+ }
64
+
65
+ return $this->_redirect('*/freshdesk/ticket');
66
+ }
67
+
68
+ public function saveAction()
69
+ {
70
+ try {
71
+ $post = $this->getRequest()->getPost();
72
+ if (empty($post)) {
73
+ throw new Mageplace_Freshdesk_Exception($this->__('Wrong request data'));
74
+ }
75
+
76
+ Mage::getModel('freshdesk/ticket')
77
+ ->setData($post)
78
+ ->save();
79
+
80
+ $this->_getSession()->addSuccess($this->__('Ticket was successfully created'));
81
+
82
+ $this->_refreshCache(false);
83
+
84
+ if (!$this->getRequest()->getParam('back')) {
85
+ return $this->_redirect('*/freshdesk/ticket');
86
+ }
87
+
88
+ } catch (Exception $e) {
89
+ $this->_getSession()->addError($e->getMessage());
90
+ }
91
+
92
+ return $this->_redirect('*/freshdesk_ticket/create');
93
+ }
94
+
95
+ public function editAction()
96
+ {
97
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
98
+ $this->_redirectUrl(Mage::getSingleton('freshdesk/freshdesk')->getTicketEditUrl($ticketId));
99
+ Mage::app()->getResponse()->sendResponse();
100
+ exit;
101
+ }
102
+
103
+ public function viewAction()
104
+ {
105
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
106
+ $this->_redirectUrl(Mage::getSingleton('freshdesk/freshdesk')->getTicketViewUrl($ticketId));
107
+ Mage::app()->getResponse()->sendResponse();
108
+ exit;
109
+ }
110
+
111
+
112
+ public function closeAction()
113
+ {
114
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
115
+ $customerId = (int)$this->getRequest()->getParam('customer_id');
116
+
117
+ try {
118
+ if (Mage::getModel('freshdesk/ticket')->close($ticketId)) {
119
+ $this->_getSession()->addSuccess($this->__('Ticket was successfully closed'));
120
+ $this->_refreshCache(false);
121
+ } else {
122
+ $this->_getSession()->addError($this->__('Ticket wasn\'t closed'));
123
+ }
124
+
125
+ } catch (Exception $e) {
126
+ $this->_getSession()->addError($e->getMessage());
127
+ }
128
+
129
+ if ($customerId) {
130
+ return $this->_redirect('*/customer/edit', array('id' => $customerId));
131
+ } else {
132
+ return $this->_redirect('*/freshdesk/ticket');
133
+ }
134
+ }
135
+
136
+ protected function _refreshCache($message = true)
137
+ {
138
+ Mage::getModel('freshdesk/cache')->clean();
139
+ Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => Mageplace_Freshdesk_Model_Cache::CACHE_TYPE));
140
+
141
+ if ($message) {
142
+ $this->_getSession()->addSuccess($this->__('Cache was successfully refreshed'));
143
+ }
144
+ }
145
+
146
+ protected function _isAllowed()
147
+ {
148
+ return Mage::getSingleton('admin/session')->isAllowed('admin/freshdesk/tickets');
149
+ }
150
+ }
app/code/local/Mageplace/Freshdesk/controllers/Adminhtml/FreshdeskController.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_Adminhtml_FreshdeskController
13
+ */
14
+ class Mageplace_Freshdesk_Adminhtml_FreshdeskController extends Mage_Adminhtml_Controller_Action
15
+ {
16
+ public function preDispatch()
17
+ {
18
+ parent::preDispatch();
19
+
20
+ if (!Mage::helper('freshdesk')->isConfigSet()) {
21
+ $message = $this->__('Please fill in Freshdesk configuration options first');
22
+ if ($this->getRequest()->getActionName() == 'customerView') {
23
+ echo $message;
24
+ } else {
25
+ $this->_getSession()->addError($message);
26
+ $this->_redirect('*/system_config/edit/section/freshdesk');
27
+ $this->getResponse()->sendResponse();
28
+ }
29
+ exit;
30
+ }
31
+
32
+ return $this;
33
+ }
34
+
35
+ /**
36
+ * Displays the tickets overview grid.
37
+ */
38
+ public function ticketAction()
39
+ {
40
+ try {
41
+ return $this->loadLayout()
42
+ ->_setActiveMenu('freshdesk/ticket')
43
+ ->_title($this->__('Freshdesk'))
44
+ ->_title($this->__('Manage Tickets'))
45
+ ->_addContent($this->getLayout()->createBlock('freshdesk/adminhtml_ticket'))
46
+ ->renderLayout();
47
+ } catch (Mageplace_Freshdesk_Exception $mfe) {
48
+ $this->_getSession()->addError($mfe->getMessage());
49
+ $this->_getSession()->addError($this->__('Please check Freshdesk configuration options'));
50
+ if ($mfe->isWrongConfig()) {
51
+ $this->_redirect('*/system_config/edit/section/freshdesk');
52
+ } else {
53
+ $this->_redirect('*');
54
+ }
55
+ } catch (Exception $e) {
56
+ $this->_getSession()->addError($e->getMessage());
57
+ $this->_redirect('*');
58
+ }
59
+ }
60
+
61
+ public function portalAction()
62
+ {
63
+ $this->_redirectUrl(Mage::getSingleton('freshdesk/freshdesk')->getDashboardUrl());
64
+ Mage::app()->getResponse()->sendResponse();
65
+ exit;
66
+ }
67
+
68
+ public function customerViewAction()
69
+ {
70
+ if (!is_object(Mage::registry('current_customer'))) {
71
+ $customerId = $this->getRequest()->getParam('id');
72
+ $customer = Mage::getModel('customer/customer')->load($customerId);
73
+ Mage::unregister('current_customer');
74
+ Mage::register('current_customer', $customer);
75
+ }
76
+
77
+ $content = '';
78
+ try {
79
+ $content = $this->getLayout()
80
+ ->createBlock('freshdesk/adminhtml_ticket_grid')
81
+ ->toHtml();
82
+ } catch (Mageplace_Freshdesk_Exception $mfe) {
83
+ $content .= $mfe->getMessage();
84
+ $content .= $this->__('Please check Freshdesk configuration options');
85
+ } catch (Exception $e) {
86
+ $content .= $e->getMessage();
87
+ }
88
+
89
+ $this->getResponse()->setBody($content);
90
+ }
91
+
92
+ protected function _isAllowed()
93
+ {
94
+ $action = $this->getRequest()->getActionName();
95
+
96
+ if (in_array($action, array('portal'))) {
97
+ return Mage::getSingleton('admin/session')->isAllowed('admin/freshdesk/portal');
98
+ }
99
+
100
+ return Mage::getSingleton('admin/session')->isAllowed('admin/freshdesk/tickets');
101
+ }
102
+ }
app/code/local/Mageplace/Freshdesk/controllers/IndexController.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_IndexController
13
+ */
14
+ class Mageplace_Freshdesk_IndexController extends Mage_Core_Controller_Front_Action
15
+ {
16
+ public function indexAction()
17
+ {
18
+ if (!Mage::helper('freshdesk')->isSSOEnabled()) {
19
+ return $this->_redirect('*/ticket/list');
20
+ }
21
+
22
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
23
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
24
+ $name = $customer->getName();
25
+ $email = $customer->getEmail();
26
+ $ssoUrl = Mage::getSingleton('freshdesk/freshdesk')->getSSOUrl($name, $email);
27
+ Mage::log($ssoUrl);
28
+ $this->_redirectUrl($ssoUrl);
29
+ $this->getResponse()->sendResponse();
30
+ exit;
31
+ } else {
32
+ $this->_redirectUrl(Mage::helper('freshdesk/customer')->getLoginUrl());
33
+ }
34
+
35
+ return;
36
+ }
37
+ }
app/code/local/Mageplace/Freshdesk/controllers/TicketController.php ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * Class Mageplace_Freshdesk_TicketController
13
+ */
14
+ class Mageplace_Freshdesk_TicketController extends Mage_Core_Controller_Front_Action
15
+ {
16
+ public function preDispatch()
17
+ {
18
+ parent::preDispatch();
19
+
20
+ $loginUrl = Mage::helper('customer')->getLoginUrl();
21
+
22
+ if (!Mage::helper('freshdesk')->isTicketTabEnabled() || !Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) {
23
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
24
+ }
25
+ }
26
+
27
+ public function indexAction()
28
+ {
29
+ return $this->_redirect('*/*/list');
30
+ }
31
+
32
+ public function listAction()
33
+ {
34
+ try {
35
+ $this->loadLayout();
36
+ $this->_initLayoutMessages('catalog/session');
37
+
38
+ $this->getLayout()->getBlock('head')->setTitle($this->__('My Tickets'));
39
+
40
+ if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
41
+ $block->setRefererUrl($this->_getRefererUrl());
42
+ }
43
+
44
+ return $this->renderLayout();
45
+
46
+ } catch (Exception $e) {
47
+ $this->_getSession()->addError($e->getMessage());
48
+ }
49
+
50
+ $this->_redirectUrl(Mage::helper('customer')->getAccountUrl());
51
+ }
52
+
53
+ public function viewAction()
54
+ {
55
+ try {
56
+ if ($this->getRequest()->getParam('after_reply')) {
57
+ /*sleep(3); //Needed for status was changed on freshdesk server*/
58
+ $this->_refreshCache();
59
+ }
60
+
61
+ if (!$this->_loadValidTicket()) {
62
+ return;
63
+ }
64
+
65
+ $this->loadLayout();
66
+ $this->_initLayoutMessages('catalog/session');
67
+
68
+ if ($navigationBlock = $this->getLayout()->getBlock('customer_account_navigation')) {
69
+ $navigationBlock->setActive('freshdesk/ticket/list');
70
+ }
71
+
72
+ return $this->renderLayout();
73
+
74
+ } catch (Exception $e) {
75
+ $this->_getSession()->addError($e->getMessage());
76
+ }
77
+
78
+ $this->_redirectUrl('*/*/list');
79
+ }
80
+
81
+ public function editAction()
82
+ {
83
+ return $this->_redirect('*/*/create');
84
+ }
85
+
86
+ public function createAction()
87
+ {
88
+ try {
89
+ $this->loadLayout();
90
+ $this->_initLayoutMessages('catalog/session');
91
+
92
+ if ($navigationBlock = $this->getLayout()->getBlock('customer_account_navigation')) {
93
+ $navigationBlock->setActive('freshdesk/ticket/list');
94
+ }
95
+
96
+ if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
97
+ $block->setRefererUrl($this->_getRefererUrl());
98
+ }
99
+
100
+ return $this->renderLayout();
101
+
102
+ } catch (Exception $e) {
103
+ $this->_getSession()->addError($e->getMessage());
104
+ }
105
+
106
+ $this->_redirectUrl('*/*/list');
107
+ }
108
+
109
+ public function saveAction()
110
+ {
111
+ try {
112
+ $post = $this->getRequest()->getPost();
113
+ if (empty($post)) {
114
+ throw new Mageplace_Freshdesk_Exception($this->__('Wrong request data'));
115
+ }
116
+
117
+ if (array_key_exists(Mageplace_Freshdesk_Model_Field::FIELD_DISPLAY_ID, $post)) {
118
+ unset($post[Mageplace_Freshdesk_Model_Field::FIELD_DISPLAY_ID]);
119
+ }
120
+
121
+ $fields = Mage::getModel('freshdesk/field')->getCollection();
122
+ foreach ($fields as $field) {
123
+ if (!$field->isVisible() || !$field->isEditable()) {
124
+ if (array_key_exists($field->getName(), $post)) {
125
+ unset($post[$field->getName()]);
126
+ } elseif ($field->getFirstLevelFieldName() && array_key_exists($field->getFirstLevelFieldName(), $post)) {
127
+ unset($post[$field->getFirstLevelFieldName()]);
128
+ } elseif ($field->getSecondLevelFieldName() && array_key_exists($field->getSecondLevelFieldName(), $post)) {
129
+ unset($post[$field->getSecondLevelFieldName()]);
130
+ }
131
+ }
132
+ }
133
+
134
+ /*if($this->_getFreshdeskUser()->getId()) {
135
+ $post[Mageplace_Freshdesk_Model_Field::FIELD_REQUESTER_ID] = $this->_getFreshdeskUser()->getId();
136
+ }*/
137
+ $post[Mageplace_Freshdesk_Model_Field::FIELD_EMAIL] = $this->_getCustomer()->getEmail();
138
+ $post[Mageplace_Freshdesk_Model_Field::FIELD_REQUESTER_NAME] = $this->_getCustomer()->getName();
139
+ $post[Mageplace_Freshdesk_Model_Field::FIELD_STATUS] = Mage::helper('freshdesk')->getStatusDefault();
140
+
141
+ $orderId = (int)$this->getRequest()->getPost('order_id');
142
+ if (!$orderId) {
143
+ $orderId = (int)$this->getRequest()->getParam('order_id');
144
+ }
145
+ if ($orderId && $this->_canViewOrder($orderId)) {
146
+ $orderField = Mage::getModel('freshdesk/field')->getOrderField();
147
+ if (is_object($orderField) && $orderField->isEditable()) {
148
+ $post[$orderField->getName()] = $orderId;
149
+ }
150
+ }
151
+
152
+ Mage::getModel('freshdesk/ticket')
153
+ ->setData($post)
154
+ ->save();
155
+
156
+ $this->_getSession()->addSuccess($this->__('Ticket was successfully created'));
157
+
158
+ $this->_refreshCache();
159
+
160
+ $back = $this->getRequest()->getParam('back');
161
+ if (!$back) {
162
+ $lastTicket = Mage::getModel('freshdesk/ticket')->getCollection()
163
+ ->setRequester($this->_getCustomer()->getEmail())
164
+ ->setOrder(Mageplace_Freshdesk_Model_Field::FIELD_DISPLAY_ID, Varien_Data_Collection::SORT_ORDER_DESC)
165
+ ->load()
166
+ ->getFirstItem();
167
+
168
+ if ($lastTicket->getId()) {
169
+ return $this->_redirect('*/*/view', array('ticket_id' => $lastTicket->getId()));
170
+ } else {
171
+ return $this->_redirect('*/*/list');
172
+ }
173
+ } elseif ($back == 'new') {
174
+ return $this->_redirect('*/*/create');
175
+ }
176
+
177
+ return $this->_redirect('*/*/list');
178
+
179
+ } catch (Exception $e) {
180
+ $this->_getSession()->addError($e->getMessage());
181
+ }
182
+
183
+ return $this->_redirect('*/*/create');
184
+ }
185
+
186
+ public function replyAction()
187
+ {
188
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
189
+ if (!$this->_loadValidTicket($ticketId)) {
190
+ return;
191
+ }
192
+
193
+ $message = trim($this->getRequest()->getParam('message'));
194
+ if (!$message) {
195
+ return $this->_redirect('*/*/view', array('ticket_id' => $ticketId));
196
+ }
197
+
198
+ try {
199
+ $userId = $this->_getFreshdeskUser()->getId();
200
+ if (!$userId) {
201
+ if (is_object(Mage::helper('freshdesk')->getCurrentTicket())) {
202
+ $userId = Mage::helper('freshdesk')
203
+ ->getCurrentTicket()
204
+ ->getRequesterId();
205
+ }
206
+ }
207
+
208
+ if (!$userId) {
209
+ $this->_getSession()->addError($this->__('Wrong freshdesk user information'));
210
+
211
+ return $this->_redirect('*/*/view', array('ticket_id' => $ticketId));
212
+ }
213
+
214
+ Mage::getModel('freshdesk/note')
215
+ ->setTicketId($ticketId)
216
+ ->setUserId($userId)
217
+ ->setBody($message)
218
+ ->save();
219
+
220
+ $this->_refreshCache();
221
+
222
+ $this->_loadValidTicket();
223
+
224
+ return $this->_redirect('*/*/view', array('ticket_id' => $ticketId, 'after_reply' => 1));
225
+
226
+ } catch (Exception $e) {
227
+ $this->_getSession()->addError($e->getMessage());
228
+ }
229
+
230
+ return $this->_redirect('*/*/list');
231
+ }
232
+
233
+ public function closeAction()
234
+ {
235
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
236
+ if (!$this->_loadValidTicket($ticketId)) {
237
+ return;
238
+ }
239
+
240
+ try {
241
+ $statusField = Mage::getModel('freshdesk/field')->loadStatusField();
242
+ if (!$statusField->isEditable()) {
243
+ $this->_getSession()->addError($this->__('Permissions denied'));
244
+ $this->_redirect('*/*/list');
245
+
246
+ return;
247
+ }
248
+
249
+ if (Mage::getModel('freshdesk/ticket')->close($ticketId)) {
250
+ $this->_getSession()->addSuccess($this->__('Ticket was successfully closed'));
251
+ $this->_refreshCache();
252
+ } else {
253
+ $this->_getSession()->addError($this->__('Ticket wasn\'t closed'));
254
+ }
255
+ } catch (Exception $e) {
256
+ $this->_getSession()->addError($e->getMessage());
257
+ }
258
+
259
+ $this->_redirect('*/*/list');
260
+ }
261
+
262
+ public function refreshAction()
263
+ {
264
+ try {
265
+ $this->_refreshCache();
266
+ $this->_getSession()->addSuccess($this->__('Cache was successfully refreshed'));
267
+ } catch (Exception $e) {
268
+ $this->_getSession()->addError($e->getMessage());
269
+ }
270
+
271
+ if ($ticketId = $this->getRequest()->getParam('ticket_id')) {
272
+ $this->_redirect('*/*/view', array('ticket_id' => $ticketId));
273
+ } else {
274
+ $this->_redirect('*/*/list');
275
+ }
276
+ }
277
+
278
+ protected function _loadValidTicket($ticketId = null)
279
+ {
280
+ if (null === $ticketId) {
281
+ $ticketId = (int)$this->getRequest()->getParam('ticket_id');
282
+ }
283
+
284
+ if (!$ticketId) {
285
+ $this->_forward('noRoute');
286
+
287
+ return false;
288
+ }
289
+
290
+ try {
291
+ /** @var Mageplace_Freshdesk_Model_Ticket $ticket */
292
+ $ticket = Mage::getModel('freshdesk/ticket')
293
+ ->setRequester($this->_getCustomer()->getEmail())
294
+ ->load($ticketId);
295
+ if ($ticketId = $ticket->getId()) {
296
+ $id = $this->_getFreshdeskUser()->getId();
297
+ if (!$id || $ticket->getRequesterId() != $id) {
298
+ $collTicket = Mage::getModel('freshdesk/ticket')
299
+ ->getCollection()
300
+ ->setRequester($this->_getCustomer()->getEmail())
301
+ ->addFilter('display_id', $ticketId)
302
+ ->load()
303
+ ->getFirstItem();
304
+
305
+ if ($collTicket->getId() != $ticketId) {
306
+ $this->_forward('noRoute');
307
+
308
+ return false;
309
+ }
310
+ }
311
+
312
+ Mage::helper('freshdesk')->setCurrentTicket($ticket);
313
+
314
+ return true;
315
+ }
316
+ } catch (Exception $e) {
317
+ $this->_getSession()->addError($e->getMessage());
318
+ }
319
+
320
+ $this->_redirect('*/*/list');
321
+
322
+ return false;
323
+ }
324
+
325
+ protected function _refreshCache()
326
+ {
327
+ Mageplace_Freshdesk_Model_Freshdesk_Tickets::cleanCache($this->_getCustomer()->getEmail());
328
+ Mageplace_Freshdesk_Model_Freshdesk_Users::cleanCache();
329
+ }
330
+
331
+ /**
332
+ * @return Mage_Catalog_Model_Session
333
+ */
334
+ protected function _getSession()
335
+ {
336
+ return Mage::getSingleton('catalog/session');
337
+ }
338
+
339
+ /**
340
+ * @return Mage_Customer_Model_Customer
341
+ */
342
+ protected function _getCustomer()
343
+ {
344
+ return Mage::getSingleton('customer/session')->getCustomer();
345
+ }
346
+
347
+ protected function _getFreshdeskUser()
348
+ {
349
+ return Mage::helper('freshdesk')->getCurrentUser();
350
+ }
351
+
352
+ /**
353
+ * @param Mage_Sales_Model_Order $order
354
+ *
355
+ * @return bool
356
+ */
357
+ protected function _canViewOrder($orderId)
358
+ {
359
+ $order = Mage::getModel('sales/order')->load($orderId);
360
+ $customerId = Mage::getSingleton('customer/session')->getCustomerId();
361
+ $availableStates = Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates();
362
+ if ($order->getId() && $order->getCustomerId() && ($order->getCustomerId() == $customerId)
363
+ && in_array($order->getState(), $availableStates, $strict = true)
364
+ ) {
365
+ return true;
366
+ }
367
+
368
+ return false;
369
+ }
370
+ }
app/code/local/Mageplace/Freshdesk/etc/config.xml ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category Mageplace_Freshdesk
7
+ * @package Mageplace_Freshdesk
8
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Mageplace_Freshdesk>
15
+ <version>1.0.0</version>
16
+ </Mageplace_Freshdesk>
17
+ </modules>
18
+
19
+ <global>
20
+ <resources>
21
+ <freshdesk_setup>
22
+ <setup>
23
+ <module>Mageplace_Freshdesk</module>
24
+ </setup>
25
+ <connection>
26
+ <use>core_setup</use>
27
+ </connection>
28
+ </freshdesk_setup>
29
+ <freshdesk_write>
30
+ <connection>
31
+ <use>core_write</use>
32
+ </connection>
33
+ </freshdesk_write>
34
+ <freshdesk_read>
35
+ <connection>
36
+ <use>core_read</use>
37
+ </connection>
38
+ </freshdesk_read>
39
+ </resources>
40
+
41
+ <cache>
42
+ <types>
43
+ <freshdesk>
44
+ <label>Freshdesk</label>
45
+ <description>Freshdesk tickets, ticket fields, user tickets and etc</description>
46
+ <tags>FRESHDESK</tags>
47
+ </freshdesk>
48
+ </types>
49
+ </cache>
50
+
51
+ <blocks>
52
+ <freshdesk>
53
+ <class>Mageplace_Freshdesk_Block</class>
54
+ </freshdesk>
55
+ </blocks>
56
+
57
+ <helpers>
58
+ <freshdesk>
59
+ <class>Mageplace_Freshdesk_Helper</class>
60
+ </freshdesk>
61
+ </helpers>
62
+
63
+ <models>
64
+ <freshdesk>
65
+ <class>Mageplace_Freshdesk_Model</class>
66
+ <resourceModel>freshdesk_resource</resourceModel>
67
+ </freshdesk>
68
+ <freshdesk_resource>
69
+ <class>Mageplace_Freshdesk_Model_Resource</class>
70
+ <entities>
71
+ <ticket />
72
+ <field />
73
+ </entities>
74
+ </freshdesk_resource>
75
+ </models>
76
+
77
+ <events>
78
+ <customer_save_after>
79
+ <observers>
80
+ <freshdesk>
81
+ <class>freshdesk/observer</class>
82
+ <method>processSaveCustomer</method>
83
+ </freshdesk>
84
+ </observers>
85
+ </customer_save_after>
86
+ </events>
87
+ </global>
88
+
89
+ <admin>
90
+ <routers>
91
+ <adminhtml>
92
+ <args>
93
+ <modules>
94
+ <Mageplace_Freshdesk before="Mage_Adminhtml">Mageplace_Freshdesk_Adminhtml</Mageplace_Freshdesk>
95
+ </modules>
96
+ </args>
97
+ </adminhtml>
98
+ </routers>
99
+ </admin>
100
+
101
+ <adminhtml>
102
+ <translate>
103
+ <modules>
104
+ <Mageplace_Freshdesk>
105
+ <files>
106
+ <default>Mageplace_Freshdesk.csv</default>
107
+ </files>
108
+ </Mageplace_Freshdesk>
109
+ </modules>
110
+ </translate>
111
+
112
+ <layout>
113
+ <updates>
114
+ <freshdesk>
115
+ <file>freshdesk.xml</file>
116
+ </freshdesk>
117
+ </updates>
118
+ </layout>
119
+
120
+ <menu>
121
+ <freshdesk translate="title" module="freshdesk">
122
+ <title>Freshdesk</title>
123
+ <sort_order>71</sort_order>
124
+ <children>
125
+ <ticket translate="title" module="freshdesk">
126
+ <title>Tickets</title>
127
+ <action>adminhtml/freshdesk/ticket</action>
128
+ <sort_order>10</sort_order>
129
+ </ticket>
130
+ <portal translate="title" module="freshdesk">
131
+ <title>Go to Freshdesk</title>
132
+ <action>adminhtml/freshdesk/portal</action>
133
+ <sort_order>20</sort_order>
134
+ </portal>
135
+ <config translate="title" module="freshdesk">
136
+ <title>Settings</title>
137
+ <action>adminhtml/system_config/edit/section/freshdesk</action>
138
+ <sort_order>1000</sort_order>
139
+ </config>
140
+ </children>
141
+ </freshdesk>
142
+ </menu>
143
+
144
+ <acl>
145
+ <resources>
146
+ <admin>
147
+ <children>
148
+ <freshdesk>
149
+ <title>Freshdesk</title>
150
+ <sort_order>10</sort_order>
151
+ <children>
152
+ <tickets translate="title" module="freshdesk">
153
+ <title>Tickets</title>
154
+ <sort_order>10</sort_order>
155
+ <!--children>
156
+ <actions translate="title">
157
+ <title>Actions</title>
158
+ <children>
159
+ <create translate="title">
160
+ <title>Create ticket</title>
161
+ </create>
162
+ <close translate="title">
163
+ <title>Close ticket</title>
164
+ </close>
165
+ </children>
166
+ </actions>
167
+ </children-->
168
+ </tickets>
169
+ <portal translate="title" module="freshdesk">
170
+ <title>Go to Freshdesk</title>
171
+ <sort_order>20</sort_order>
172
+ </portal>
173
+ </children>
174
+ </freshdesk>
175
+
176
+ <system>
177
+ <children>
178
+ <config>
179
+ <children>
180
+ <freshdesk translate="title" module="freshdesk">
181
+ <title>Freshdesk</title>
182
+ <sort_order>100</sort_order>
183
+ </freshdesk>
184
+ </children>
185
+ </config>
186
+ </children>
187
+ </system>
188
+ </children>
189
+ </admin>
190
+ </resources>
191
+ </acl>
192
+ </adminhtml>
193
+
194
+ <frontend>
195
+ <routers>
196
+ <freshdesk>
197
+ <use>standard</use>
198
+ <args>
199
+ <module>Mageplace_Freshdesk</module>
200
+ <frontName>freshdesk</frontName>
201
+ </args>
202
+ </freshdesk>
203
+ </routers>
204
+
205
+ <translate>
206
+ <modules>
207
+ <Mageplace_Freshdesk>
208
+ <files>
209
+ <default>Mageplace_Freshdesk.csv</default>
210
+ </files>
211
+ </Mageplace_Freshdesk>
212
+ </modules>
213
+ </translate>
214
+
215
+ <layout>
216
+ <updates>
217
+ <freshdesk>
218
+ <file>freshdesk.xml</file>
219
+ </freshdesk>
220
+ </updates>
221
+ </layout>
222
+
223
+ <events>
224
+ <controller_action_postdispatch_contacts>
225
+ <observers>
226
+ <freshdesk>
227
+ <class>freshdesk/observer</class>
228
+ <method>processControllerActionPostdispatchContacts</method>
229
+ </freshdesk>
230
+ </observers>
231
+ </controller_action_postdispatch_contacts>
232
+
233
+ <!--core_block_abstract_to_html_before>
234
+ <observers>
235
+ <freshdesk>
236
+ <class>freshdesk/observer</class>
237
+ <method>processCoreBlockAbstractToHtmlBefore</method>
238
+ </freshdesk>
239
+ </observers>
240
+ </core_block_abstract_to_html_before-->
241
+ </events>
242
+ </frontend>
243
+
244
+ <default>
245
+ <freshdesk>
246
+ <tickets>
247
+ <priority>1</priority>
248
+ <status>2</status>
249
+ <status_close>5</status_close>
250
+ </tickets>
251
+ <!--channels>
252
+ <feedback_widget_label>Support</feedback_widget_label>
253
+ <feedback_widget_bgcolor>#006063</feedback_widget_bgcolor>
254
+ <feedback_widget_position>4</feedback_widget_position>
255
+ <feedback_widget><![CDATA[
256
+ <script type="text/javascript" src="http://assets.freshdesk.com/widget/freshwidget.js"></script>
257
+ <script type="text/javascript">
258
+ FreshWidget.init("", {"queryString": "&widgetType=popup", "widgetType": "popup", "buttonType": "text", "buttonText": "{{buttonText}}", "buttonColor": "white", "buttonBg": "{{buttonBg}}", "alignment": "{{alignment}}", "offset": "235px", "formHeight": "500px", "url": "{{URL}}"} );
259
+ </script>]]></feedback_widget>
260
+ </channels-->
261
+ </freshdesk>
262
+ </default>
263
+
264
+ </config>
app/code/local/Mageplace/Freshdesk/etc/system.xml ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category Mageplace_Freshdesk
7
+ * @package Mageplace_Freshdesk
8
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ -->
12
+ <config>
13
+ <tabs>
14
+ <freshdesk translate="label" module="freshdesk">
15
+ <label>Freshdesk</label>
16
+ <sort_order>500</sort_order>
17
+ </freshdesk>
18
+ </tabs>
19
+ <sections>
20
+ <freshdesk translate="label" module="freshdesk">
21
+ <label>Freshdesk</label>
22
+ <tab>freshdesk</tab>
23
+ <class>freshdesk-section</class>
24
+ <header_css>freshdesk-header</header_css>
25
+ <sort_order>100</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
+ <groups>
30
+ <account translate="label">
31
+ <label>Account</label>
32
+ <sort_order>10</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ <comment>Account details required to integrate Freshdesk with Magento</comment>
37
+ <fields>
38
+ <domain translate="label">
39
+ <label>Freshdesk domain:</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>10</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </domain>
46
+ <email translate="label">
47
+ <label>Admin email:</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <comment>Agent should have admin permissions in Freshdesk to access all ticket information</comment>
54
+ </email>
55
+ <!--password translate="label">
56
+ <label>Password:</label>
57
+ <frontend_type>password</frontend_type>
58
+ <sort_order>30</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </password-->
63
+ <api_key translate="label">
64
+ <label>Admin API key:</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>40</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ <comment>To get your token, inside Freshdesk portal, click profile settings and copy "Your API key"</comment>
71
+ </api_key>
72
+ <account_bottom_comment>
73
+ <frontend_model>freshdesk/adminhtml_config_comment</frontend_model>
74
+ <comment>Global view of all Freshdesk tickets will be shown</comment>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ <sort_order>50</sort_order>
79
+ </account_bottom_comment>
80
+ </fields>
81
+ </account>
82
+
83
+ <!--sso>
84
+ <label>Single Sign On</label>
85
+ <sort_order>20</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ <comment>Allow users and agents to login your Freshdesk portal through Magento authentication</comment>
90
+ <fields>
91
+ <enable translate="label">
92
+ <label>Enable Single Sign On:</label>
93
+ <frontend_type>select</frontend_type>
94
+ <source_model>adminhtml/system_config_source_yesno</source_model>
95
+ <sort_order>10</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ <comment>Enable SSO in Freshdesk and obtain your Shared Secret</comment>
100
+ </enable>
101
+ <secret translate="label">
102
+ <label>Shared Secret:</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>20</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ <comment>To get your shared secret, inside Freshdesk portal, go to Admin->Security</comment>
109
+ </secret>
110
+ <login_url translate="label">
111
+ <label>Login URL:</label>
112
+ <frontend_type>text</frontend_type>
113
+ <sort_order>30</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>1</show_in_store>
117
+ <comment>Url should be accessible to both agents and customers</comment>
118
+ </login_url>
119
+ <logout_url translate="label">
120
+ <label>Logout URL:</label>
121
+ <frontend_type>text</frontend_type>
122
+ <sort_order>30</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>1</show_in_website>
125
+ <show_in_store>1</show_in_store>
126
+ <comment>Url should be accessible to both agents and customers</comment>
127
+ </logout_url>
128
+ <sso_bottom_comment>
129
+ <frontend_model>freshdesk/adminhtml_config_comment</frontend_model>
130
+ <comment>Paste both the URLs into your Freshdesk SSO for the process to be complete</comment>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>1</show_in_store>
134
+ <sort_order>40</sort_order>
135
+ </sso_bottom_comment>
136
+ </fields>
137
+ </sso-->
138
+
139
+ <orders>
140
+ <label>Order Id Linking</label>
141
+ <sort_order>40</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <show_in_store>1</show_in_store>
145
+ <fields>
146
+ <order_id translate="label">
147
+ <label>Magento Order id linked to:</label>
148
+ <frontend_type>text</frontend_type>
149
+ <sort_order>10</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>1</show_in_store>
153
+ <comment>Obtain your custom field name (Agent Label) in Freshdesk that you want to correspond with your Magento order id and paste it here</comment>
154
+ </order_id>
155
+ <order_id_comment>
156
+ <frontend_model>freshdesk/adminhtml_config_comment</frontend_model>
157
+ <comment>If you haven't created an Order field yet, go to Freshdesk &lt;a id="fd_order_id_ticket_fields_link" href="" target="_blank"&gt;Ticket Fields&lt;/a&gt; to create one</comment>
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
+ <sort_order>40</sort_order>
162
+ </order_id_comment>
163
+ </fields>
164
+ </orders>
165
+
166
+ <channels>
167
+ <label>Channels</label>
168
+ <sort_order>50</sort_order>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <show_in_store>1</show_in_store>
172
+ <fields>
173
+ <enable_contact_us translate="label">
174
+ <label>Contact Us form:</label>
175
+ <!--label>Create tickets from Contact Us form:</label-->
176
+ <frontend_type>select</frontend_type>
177
+ <source_model>adminhtml/system_config_source_yesno</source_model>
178
+ <sort_order>10</sort_order>
179
+ <show_in_default>1</show_in_default>
180
+ <show_in_website>1</show_in_website>
181
+ <show_in_store>1</show_in_store>
182
+ <comment>Enabling this will automatically create a ticket when a form is submitted</comment>
183
+ </enable_contact_us>
184
+ <enable_feedback_widget translate="label">
185
+ <label>Feedback Widget:</label>
186
+ <!--label>Have a feedback widget on your website:</label-->
187
+ <frontend_type>select</frontend_type>
188
+ <source_model>adminhtml/system_config_source_yesno</source_model>
189
+ <sort_order>20</sort_order>
190
+ <show_in_default>1</show_in_default>
191
+ <show_in_website>1</show_in_website>
192
+ <show_in_store>1</show_in_store>
193
+ </enable_feedback_widget>
194
+ <feedback_widget translate="label">
195
+ <frontend_type>textarea</frontend_type>
196
+ <sort_order>40</sort_order>
197
+ <show_in_default>1</show_in_default>
198
+ <show_in_website>1</show_in_website>
199
+ <show_in_store>1</show_in_store>
200
+ <comment>Code will be pasted to all your store pages. To customize your feedback widget, go to Freshdesk &lt;a id="fd_channels_feedback_widget_link" href="" target="_blank"&gt;Feedback Widget&lt;/a&gt; and paste the final code above</comment>
201
+ </feedback_widget>
202
+ <!--feedback_widget_label translate="label">
203
+ <label>Feedback widget label:</label>
204
+ <frontend_type>text</frontend_type>
205
+ <sort_order>25</sort_order>
206
+ <show_in_default>1</show_in_default>
207
+ <show_in_website>1</show_in_website>
208
+ <show_in_store>1</show_in_store>
209
+ </feedback_widget_label>
210
+ <feedback_widget_bgcolor translate="label">
211
+ <label>Feedback widget background color:</label>
212
+ <frontend_type>text</frontend_type>
213
+ <sort_order>30</sort_order>
214
+ <show_in_default>1</show_in_default>
215
+ <show_in_website>1</show_in_website>
216
+ <show_in_store>1</show_in_store>
217
+ <comment>Example: #006063 or 006063</comment>
218
+ </feedback_widget_bgcolor>
219
+ <feedback_widget_position translate="label">
220
+ <label>Feedback widget position:</label>
221
+ <frontend_type>select</frontend_type>
222
+ <source_model>freshdesk/source_widgetposition</source_model>
223
+ <sort_order>35</sort_order>
224
+ <show_in_default>1</show_in_default>
225
+ <show_in_website>1</show_in_website>
226
+ <show_in_store>1</show_in_store>
227
+ </feedback_widget_position>
228
+ <feedback_widget_code translate="label">
229
+ <frontend_type>textarea</frontend_type>
230
+ <sort_order>45</sort_order>
231
+ <show_in_default>1</show_in_default>
232
+ <show_in_website>1</show_in_website>
233
+ <show_in_store>1</show_in_store>
234
+ <comment>Paste this code on each of the pages where you want it to appear. To customize your feedback widget, go to Freshdesk widget</comment>
235
+ </feedback_widget_code-->
236
+ <enable_support_link translate="label">
237
+ <label>Support link in Magento footer:</label>
238
+ <!--label>Show Support Link in Magento footer:</label-->
239
+ <frontend_type>select</frontend_type>
240
+ <source_model>adminhtml/system_config_source_yesno</source_model>
241
+ <sort_order>50</sort_order>
242
+ <show_in_default>1</show_in_default>
243
+ <show_in_website>1</show_in_website>
244
+ <show_in_store>1</show_in_store>
245
+ <comment>This link will take users to your freshdesk support portal</comment>
246
+ </enable_support_link>
247
+ </fields>
248
+ </channels>
249
+
250
+ <customer_view>
251
+ <label>Customer View</label>
252
+ <sort_order>60</sort_order>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_website>1</show_in_website>
255
+ <show_in_store>1</show_in_store>
256
+ <fields>
257
+ <enable_customer_view translate="label">
258
+ <!--label>Allow your customers to view their tickets:</label-->
259
+ <label>Ticket View for Customers:</label>
260
+ <frontend_type>select</frontend_type>
261
+ <source_model>freshdesk/source_ticketview</source_model>
262
+ <sort_order>10</sort_order>
263
+ <show_in_default>1</show_in_default>
264
+ <show_in_website>1</show_in_website>
265
+ <show_in_store>1</show_in_store>
266
+ <!--comment>If this is not selected, customers will only be able to create tickets through the Contact Us form of Feedback widget. To view their existing tickets, they will have to go to your freshdesk portal</comment-->
267
+ </enable_customer_view>
268
+
269
+ <!--enable_ticket_tab translate="label">
270
+ <label>My Tickets tab will be shown inside customer's My Account. Tickets can be viewed, replied and closed here:</label>
271
+ <frontend_type>select</frontend_type>
272
+ <source_model>adminhtml/system_config_source_yesno</source_model>
273
+ <sort_order>20</sort_order>
274
+ <show_in_default>1</show_in_default>
275
+ <show_in_website>1</show_in_website>
276
+ <show_in_store>1</show_in_store>
277
+ </enable_ticket_tab-->
278
+
279
+ <enable_recent_ticket translate="label">
280
+ <label>Show recent tickets in Account Dashboard:</label>
281
+ <!--label>Show customer's most recent tickets and their status in Account Dashboard:</label-->
282
+ <frontend_type>select</frontend_type>
283
+ <source_model>adminhtml/system_config_source_yesno</source_model>
284
+ <sort_order>30</sort_order>
285
+ <show_in_default>1</show_in_default>
286
+ <show_in_website>1</show_in_website>
287
+ <show_in_store>1</show_in_store>
288
+ </enable_recent_ticket>
289
+ </fields>
290
+ </customer_view>
291
+ </groups>
292
+ </freshdesk>
293
+ </sections>
294
+ </config>
app/design/adminhtml/default/default/layout/freshdesk.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category Mageplace_Freshdesk
7
+ * @package Mageplace_Freshdesk
8
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ -->
12
+ <layout>
13
+ <default>
14
+ <reference name="head">
15
+ <action method="addItem">
16
+ <type>skin_js</type>
17
+ <name>freshdesk/js/freshdesk.js</name>
18
+ </action>
19
+ </reference>
20
+ </default>
21
+
22
+ <adminhtml_freshdesk_ticket>
23
+ <reference name="head">
24
+ <action method="addCss">
25
+ <stylesheet>freshdesk/css/freshdesk.css</stylesheet>
26
+ </action>
27
+ </reference>
28
+ </adminhtml_freshdesk_ticket>
29
+
30
+ <adminhtml_freshdesk_ticket_create>
31
+ <update handle="editor" />
32
+ <update handle="adminhtml_freshdesk_ticket" />
33
+ </adminhtml_freshdesk_ticket_create>
34
+
35
+ <adminhtml_customer_edit>
36
+ <update handle="adminhtml_freshdesk_ticket_create" />
37
+ <reference name="accordion">
38
+ <block type="freshdesk/adminhtml_customer_edit_tab_view_tickets" name="freshdesk_customer_tickets" />
39
+ </reference>
40
+ </adminhtml_customer_edit>
41
+
42
+ <adminhtml_system_config_edit>
43
+ <update handle="adminhtml_freshdesk_ticket_create" />
44
+ </adminhtml_system_config_edit>
45
+ </layout>
app/design/adminhtml/default/default/template/freshdesk/field/checkbox.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Custom_Checkbox
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Custom_Checkbox $this
15
+ */
16
+
17
+ ?>
18
+ <input type="checkbox" id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>" value="1"/>
app/design/adminhtml/default/default/template/freshdesk/field/dropdown.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Dropdown
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Dropdown $this
15
+ */
16
+ ?>
17
+ <select id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
18
+ class="<?php echo $this->getFieldClass(); ?>">
19
+ <?php foreach ($this->getOptions() as $option) : ?>
20
+ <option value="<?php echo $option['value']; ?>"><?php echo $option['label']; ?></option>
21
+ <?php endforeach; ?>
22
+ </select>
app/design/adminhtml/default/default/template/freshdesk/field/nested_field.phtml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Nested_Field
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Nested_Field $this
15
+ */
16
+
17
+ ?>
18
+ <select id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>"
20
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
21
+ <?php foreach ($this->getNestedOptions() as $option) : ?>
22
+ <option value="<?php echo $option['value']; ?>"><?php echo $option['label']; ?></option>
23
+ <?php endforeach; ?>
24
+ </select>
25
+
26
+ <div id="<?php echo $this->getFieldId(); ?>_level1_block" style="display: none;">
27
+ <label for="<?php echo $this->getFirstLevelNestedFieldId(); ?>">
28
+ <?php echo $this->getFirstLevelNestedFieldLabel(); ?>
29
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
30
+ </label>
31
+ <select id="<?php echo $this->getFirstLevelNestedFieldId(); ?>"
32
+ name="<?php echo $this->getFirstLevelNestedFieldName(); ?>"
33
+ class=""
34
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
35
+ </select>
36
+ </div>
37
+
38
+ <?php if ($this->hasSecondLevel()) : ?>
39
+ <div id="<?php echo $this->getFieldId(); ?>_level2_block" style="display: none;">
40
+ <label for="<?php echo $this->getSecondLevelNestedFieldId(); ?>">
41
+ <?php echo $this->getSecondLevelNestedFieldLabel(); ?>
42
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
43
+ </label>
44
+ <select id="<?php echo $this->getSecondLevelNestedFieldId(); ?>"
45
+ name="<?php echo $this->getSecondLevelNestedFieldName(); ?>"
46
+ class=""
47
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
48
+ </select>
49
+ </div>
50
+ <?php endif; ?>
51
+
52
+ <script>
53
+ if (Object.isUndefined(fdNestedOptions)) {
54
+ var fdNestedOptions = [];
55
+ }
56
+ fdNestedOptions["<?php echo $this->getFieldId(); ?>"] = new Freshdesk.Fields.Nested('<?php echo $this->getFieldId(); ?>', <?php echo Zend_Json::encode($this->getNestedOptions()); ?>);
57
+ </script>
app/design/adminhtml/default/default/template/freshdesk/field/paragraph.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Paragraph
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Paragraph $this
15
+ */
16
+
17
+ echo $this->getEditor()->toHtml();
18
+ /*?>
19
+ <textarea id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
20
+ class="<?php echo $this->getFieldClass(); ?>" rows="2" cols="15"></textarea>
21
+ <?php */
app/design/adminhtml/default/default/template/freshdesk/field/row_1_column.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Row
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Row $this
15
+ */
16
+
17
+ ?>
18
+ <tr>
19
+ <td colspan="2" class="value">
20
+ <?php echo $this->getInputFieldHtml(); ?>
21
+ <label for="<?php echo $this->getFieldId(); ?>">
22
+ <?php echo $this->getFieldLabel(); ?>
23
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
24
+ </label>
25
+ </td>
26
+ </tr>
app/design/adminhtml/default/default/template/freshdesk/field/row_2_column.phtml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Row
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Row $this
15
+ */
16
+
17
+ ?>
18
+ <tr>
19
+ <td class="label">
20
+ <label for="<?php echo $this->getFieldId(); ?>">
21
+ <?php echo $this->getFieldLabel(); ?>
22
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
23
+ </label>
24
+ </td>
25
+ <td class="value">
26
+ <?php echo $this->getInputFieldHtml(); ?>
27
+ </td>
28
+ </tr>
app/design/adminhtml/default/default/template/freshdesk/field/text.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Text
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Text $this
15
+ */
16
+
17
+ ?>
18
+ <input type="text" id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>" value=""/>
app/design/adminhtml/default/default/template/freshdesk/ticket/edit/form.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+ ?>
11
+
12
+ <?php
13
+ /**
14
+ * @see Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form
15
+ *
16
+ * @var Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form $this
17
+ * @var Mageplace_Freshdesk_Model_Field $field
18
+ */
19
+
20
+ $_fields = $this->getFields();
21
+ ?>
22
+ <div class="entry-edit">
23
+ <div class="entry-edit-head">
24
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->getLabel(); ?></h4>
25
+ </div>
26
+
27
+ <div class="fieldset fieldset-wide" id="freshdesk_ticket_edit_fields">
28
+ <div class="hor-scroll">
29
+ <table cellspacing="0" class="form-list" style="width: 50%">
30
+ <?php $counter=0;foreach ($_fields as $field) : ?>
31
+ <?php echo $this->getFieldHtml($field); ?>
32
+ <?php if ($counter ++ == 7) {
33
+ break;
34
+ } ?>
35
+ <?php endforeach; ?>
36
+ </table>
37
+ </div>
38
+ </div>
39
+ </div>
app/design/adminhtml/default/default/template/freshdesk/ticket/edit/form/fields.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+ ?>
11
+
12
+ <?php
13
+ /**
14
+ * @see Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form_Fields
15
+ *
16
+ * @var Mageplace_Freshdesk_Block_Adminhtml_Ticket_Edit_Form_Fields $this
17
+ * @var Mageplace_Freshdesk_Model_Field $field
18
+ */
19
+
20
+ $_fields = $this->getFields();
21
+ ?>
22
+ <table cellspacing="0" class="form-list">
23
+ <?php foreach ($_fields as $field) : ?>
24
+ <?php echo $this->getFieldHtml($field); ?>
25
+ <?php endforeach; ?>
26
+ </table>
app/design/frontend/base/default/layout/freshdesk.xml ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category design
7
+ * @package base_default
8
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ -->
12
+ <layout version="1.0.0">
13
+ <default>
14
+ <reference name="head">
15
+ <block type="freshdesk/page_html_head_widget" name="freshdesk_widget"
16
+ template="freshdesk/page/html/head/widget.phtml" />
17
+ </reference>
18
+
19
+ <reference name="footer_links">
20
+ <action method="addLink" translate="label title" module="catalog"
21
+ ifconfig="freshdesk/channels/enable_support_link">
22
+ <label>Support</label>
23
+ <url helper="freshdesk/getSupportLink" />
24
+ <title>Support</title>
25
+ <prepare>0</prepare>
26
+ <url_params></url_params>
27
+ <position></position>
28
+ <li_params></li_params>
29
+ <a_params>target="_blank"</a_params>
30
+ </action>
31
+ </reference>
32
+ </default>
33
+
34
+ <customer_account>
35
+ <reference name="head">
36
+ <action method="addCss">
37
+ <stylesheet>freshdesk/css/freshdesk.css</stylesheet>
38
+ </action>
39
+
40
+ <action method="addItem">
41
+ <type>skin_js</type>
42
+ <name>freshdesk/js/freshdesk.js</name>
43
+ </action>
44
+ </reference>
45
+
46
+ <reference name="customer_account_navigation">
47
+ <action method="addLink" translate="label" module="freshdesk"
48
+ ifconfig="freshdesk/customer_view/enable_customer_view">
49
+ <name>freshdesk_tickets</name>
50
+ <path>freshdesk/ticket/list</path>
51
+ <label>My Tickets</label>
52
+ </action>
53
+ </reference>
54
+
55
+ <reference name="left">
56
+ <block type="core/template" name="js.move.navigation.link"
57
+ template="freshdesk/customer/account/navigation/js.phtml" after="customer_account_navigation">
58
+ <action method="setLabel" translate="label" module="freshdesk">
59
+ <label>My Tickets</label>
60
+ </action>
61
+ <action method="setPath">
62
+ <path>freshdesk/ticket/list</path>
63
+ </action>
64
+ <action method="setPosition">
65
+ <position>4</position>
66
+ </action>
67
+ </block>
68
+ </reference>
69
+ </customer_account>
70
+
71
+ <customer_account_index>
72
+ <reference name="my.account.wrapper">
73
+ <block type="freshdesk/customer_ticket_recent" name="customer_account_dashboard_freshdesk_tickets_recent"
74
+ as="freshdesk_tickets_recent" template="freshdesk/tickets/recent.phtml" after="-" />
75
+ </reference>
76
+ </customer_account_index>
77
+
78
+ <sales_order_view>
79
+ <reference name="sales.order.info.buttons">
80
+ <block type="freshdesk/order_info_buttons" name="order_info_create_ticket_button"
81
+ template="freshdesk/sales/order/info/create_ticket_button.phtml" />
82
+ </reference>
83
+ </sales_order_view>
84
+
85
+ <freshdesk_ticket_list>
86
+ <update handle="customer_account" />
87
+
88
+ <reference name="my.account.wrapper">
89
+ <block type="freshdesk/customer_ticket_list" name="freshdesk_customer_tickets"
90
+ template="freshdesk/tickets/list.phtml">
91
+ <block type="core/text_list" name="customer_freshdesk_tickets_info" as="freshdesk_tickets_info"
92
+ translate="label">
93
+ <label>My Tickets Info</label>
94
+ </block>
95
+ </block>
96
+ <block type="customer/account_dashboard" name="customer.account.link.back"
97
+ template="customer/account/link/back.phtml" />
98
+ </reference>
99
+ </freshdesk_ticket_list>
100
+
101
+ <freshdesk_ticket_create>
102
+ <update handle="customer_account" />
103
+
104
+ <reference name="my.account.wrapper">
105
+ <block type="freshdesk/customer_ticket_create" name="freshdesk_customer_ticket_create"
106
+ template="freshdesk/tickets/create.phtml">
107
+ </block>
108
+ <!--block type="customer/account_dashboard" name="customer.account.link.back"
109
+ template="customer/account/link/back.phtml"/-->
110
+ </reference>
111
+ </freshdesk_ticket_create>
112
+
113
+ <freshdesk_ticket_view>
114
+ <update handle="customer_account" />
115
+
116
+ <reference name="my.account.wrapper">
117
+ <block type="freshdesk/customer_ticket_view" name="freshdesk_customer_ticket_view"
118
+ template="freshdesk/tickets/view.phtml">
119
+ </block>
120
+ </reference>
121
+ </freshdesk_ticket_view>
122
+ </layout>
app/design/frontend/base/default/template/freshdesk/customer/account/navigation/js.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+ ?>
11
+ <script type="text/javascript">
12
+ //<![CDATA[
13
+ var label = "<?php echo $this->getLabel(); ?>";
14
+ var path = "<?php echo $this->getPath(); ?>";
15
+ var position = <?php echo intval($this->getPosition()); ?>;
16
+ new Freshdesk.Account(label, path, position).process();
17
+ //]]>
18
+ </script>
app/design/frontend/base/default/template/freshdesk/field/checkbox.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Custom_Checkbox
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Custom_Checkbox $this
15
+ */
16
+
17
+ ?>
18
+ <input type="checkbox" id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>" value="1"/>
app/design/frontend/base/default/template/freshdesk/field/dropdown.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Dropdown
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Dropdown $this
15
+ */
16
+ ?>
17
+ <select id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
18
+ class="<?php echo $this->getFieldClass(); ?>">
19
+ <?php foreach ($this->getOptions() as $option) : ?>
20
+ <option value="<?php echo $option['value']; ?>"><?php echo $option['label']; ?></option>
21
+ <?php endforeach; ?>
22
+ </select>
app/design/frontend/base/default/template/freshdesk/field/nested_field.phtml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Nested_Field
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Nested_Field $this
15
+ */
16
+
17
+ ?>
18
+ <select id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>"
20
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
21
+ <?php foreach ($this->getNestedOptions() as $option) : ?>
22
+ <option value="<?php echo $option['value']; ?>"><?php echo $option['label']; ?></option>
23
+ <?php endforeach; ?>
24
+ </select>
25
+
26
+ <div id="<?php echo $this->getFieldId(); ?>_level1_block" style="display: none;">
27
+ <label for="<?php echo $this->getFirstLevelNestedFieldId(); ?>">
28
+ <?php echo $this->getFirstLevelNestedFieldLabel(); ?>
29
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
30
+ </label>
31
+
32
+ <div class="input-box">
33
+ <select id="<?php echo $this->getFirstLevelNestedFieldId(); ?>"
34
+ name="<?php echo $this->getFirstLevelNestedFieldName(); ?>"
35
+ class=""
36
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
37
+ </select>
38
+ </div>
39
+ </div>
40
+
41
+ <?php if ($this->hasSecondLevel()) : ?>
42
+ <div id="<?php echo $this->getFieldId(); ?>_level2_block" style="display: none;">
43
+ <label for="<?php echo $this->getSecondLevelNestedFieldId(); ?>">
44
+ <?php echo $this->getSecondLevelNestedFieldLabel(); ?>
45
+ <?php if ($this->isRequired()): ?> <span class="required">*</span><?php endif; ?>
46
+ </label>
47
+
48
+ <div class="input-box">
49
+ <select id="<?php echo $this->getSecondLevelNestedFieldId(); ?>"
50
+ name="<?php echo $this->getSecondLevelNestedFieldName(); ?>"
51
+ class=""
52
+ onchange="fdNestedOptions['<?php echo $this->getFieldId(); ?>'].optionChanged(this)">
53
+ </select>
54
+ </div>
55
+ </div>
56
+ <?php endif; ?>
57
+
58
+ <script>
59
+ if (Object.isUndefined(fdNestedOptions)) {
60
+ var fdNestedOptions = [];
61
+ }
62
+ fdNestedOptions["<?php echo $this->getFieldId(); ?>"] = new Freshdesk.Fields.Nested('<?php echo $this->getFieldId(); ?>', <?php echo Zend_Json::encode($this->getNestedOptions()); ?>);
63
+ </script>
app/design/frontend/base/default/template/freshdesk/field/paragraph.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Paragraph
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Paragraph $this
15
+ */
16
+
17
+ echo $this->getEditor()->toHtml();
18
+ /*?>
19
+ <textarea id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
20
+ class="<?php echo $this->getFieldClass(); ?>" rows="2" cols="15"></textarea>
21
+ <?php */
app/design/frontend/base/default/template/freshdesk/field/row.phtml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Row
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Row $this
15
+ */
16
+
17
+ ?>
18
+ <li class="wide">
19
+ <div class="field">
20
+ <label for="<?php echo $this->getFieldId(); ?>"
21
+ class="<?php if ($this->isRequired()): ?>required<?php endif; ?>">
22
+ <?php if ($this->isRequired()): ?> <em class="required">*</em><?php endif; ?>
23
+ <?php echo $this->getFieldLabel(); ?>
24
+ </label>
25
+
26
+ <div class="input-box">
27
+ <?php echo $this->getInputFieldHtml(); ?>
28
+ </div>
29
+ </div>
30
+ </li>
app/design/frontend/base/default/template/freshdesk/field/row_inline.phtml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Row
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Row $this
15
+ */
16
+
17
+ ?>
18
+ <li class="control">
19
+ <?php echo $this->getInputFieldHtml(); ?>
20
+ <label for="<?php echo $this->getFieldId(); ?>"
21
+ class="<?php if ($this->isRequired()): ?>required<?php endif; ?>">
22
+ <?php if ($this->isRequired()): ?> <em class="required">*</em><?php endif; ?>
23
+ <?php echo $this->getFieldLabel(); ?>
24
+ </label>
25
+ </li>
app/design/frontend/base/default/template/freshdesk/field/text.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category Mageplace_Freshdesk
6
+ * @package Mageplace_Freshdesk
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Field_Text
13
+ *
14
+ * @var Mageplace_Freshdesk_Block_Field_Text $this
15
+ */
16
+
17
+ ?>
18
+ <input type="text" id="<?php echo $this->getFieldId(); ?>" name="<?php echo $this->getFieldName(); ?>"
19
+ class="<?php echo $this->getFieldClass(); ?>"
20
+ value="<?php echo $this->getOrderId(); ?>" <?php if ($this->getOrderId()) : ?>readonly="true"<?php endif; ?>/>
app/design/frontend/base/default/template/freshdesk/page/html/head/widget.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @var Mageplace_Freshdesk_Block_Page_Html_Head_Widget $this
13
+ */
14
+ ?>
15
+ <?php echo $this->getFeedbackWidgetCode();?>
app/design/frontend/base/default/template/freshdesk/sales/order/info/create_ticket_button.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+ ?>
11
+ <span class="separator">|</span>
12
+ <a href="<?php echo $this->getCreateTicketUrl() ?>" class="link-create-order">
13
+ <?php echo Mage::helper('freshdesk')->__('Create a Ticket') ?>
14
+ </a>
app/design/frontend/base/default/template/freshdesk/tickets/create.phtml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Customer_Ticket_Create
13
+ * @var Mageplace_Freshdesk_Block_Customer_Ticket_Create $this
14
+ */
15
+ ?>
16
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
17
+
18
+ <div class="freshdesk-ticket-create">
19
+ <div class="page-title">
20
+ <h1><?php echo $this->getTitle(); ?></h1>
21
+ </div>
22
+
23
+ <!--dl class="ticket-info">
24
+ <dt><?php echo $this->__('Submit Ticket'); ?></dt>
25
+ </dl-->
26
+
27
+ <form action="<?php echo $this->getSaveUrl(); ?>" method="post" id="createTicketForm">
28
+ <div class="col2-set ticket-create-box">
29
+ <ul class="form-list">
30
+ <?php foreach ($this->getFields() as $field) : ?>
31
+ <?php if ($this->isFieldVisible($field)) : ?>
32
+ <?php echo $this->getFieldHtml($field); ?>
33
+ <?php endif; ?>
34
+ <?php endforeach; ?>
35
+ </ul>
36
+ </div>
37
+
38
+ <div class="actions">
39
+ <button type="submit" title="<?php echo $this->__('Save') ?>"
40
+ class="button btn-save-ticket">
41
+ <span><span><?php echo $this->__('Save') ?></span></span>
42
+ </button>
43
+ <!--button type="button" title="<?php echo $this->__('Save and New') ?>"
44
+ class="button btn-save-new-ticket"
45
+ onclick="ticketForm.submit('<?php echo $this->getSaveNewUrl(); ?>')">
46
+ <span><span><?php echo $this->__('Save and New') ?></span></span>
47
+ </button>
48
+ <button type="button" title="<?php echo $this->__('Save and Close') ?>"
49
+ class="button btn-save-close-ticket"
50
+ onclick="ticketForm.submit('<?php echo $this->getSaveCloseUrl(); ?>')">
51
+ <span><span><?php echo $this->__('Save and Close') ?></span></span>
52
+ </button-->
53
+ <button type="button" title="<?php echo $this->__('Cancel') ?>"
54
+ class="button btn-close-ticket"
55
+ onclick="location.href='<?php echo $this->getCancelUrl(); ?>'">
56
+ <span><span><?php echo $this->__('Cancel') ?></span></span>
57
+ </button>
58
+ </div>
59
+ </form>
60
+ <script>
61
+ //<![CDATA[
62
+ VarienForm.addMethods({
63
+ submit: function (url) {
64
+ if (this.validator && this.validator.validate()) {
65
+ if (url) {
66
+ this.form.action = url;
67
+ }
68
+
69
+ this.form.submit();
70
+ }
71
+ return false;
72
+ }
73
+ });
74
+ var ticketForm = new VarienForm('createTicketForm', true);
75
+ //]]>
76
+ </script>
77
+ </div>
app/design/frontend/base/default/template/freshdesk/tickets/list.phtml ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Customer_Ticket_List
13
+ * @var Mageplace_Freshdesk_Block_Customer_Ticket_List $this
14
+ */
15
+ ?>
16
+ <div class="fd-tickets-list">
17
+ <?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
18
+ <?php $_tickets = $this->getTickets(); ?>
19
+ <div class="page-title title-buttons">
20
+ <h1><?php echo $this->__('My Tickets') ?></h1>
21
+
22
+ <div class="actions">
23
+ <?php if ($this->isRefreshButtonVisible()): ?>
24
+ <button type="button" title="<?php echo $this->__('Refresh') ?>" class="button btn-refresh-ticket"
25
+ onclick="location.href='<?php echo $this->getRefreshUrl(); ?>'">
26
+ <span><span><?php echo $this->__('Refresh') ?></span></span>
27
+ </button>
28
+ <?php endif; ?>
29
+ <button type="button" title="<?php echo $this->__('Create a Ticket') ?>" class="button btn-create-ticket"
30
+ onclick="location.href='<?php echo $this->getCreateUrl(); ?>'">
31
+ <span><span><?php echo $this->__('Create a Ticket') ?></span></span>
32
+ </button>
33
+ </div>
34
+ </div>
35
+
36
+ <?php echo $this->getPagerHtml(); ?>
37
+
38
+ <?php if (sizeof($_tickets->getItems()) > 0): ?>
39
+ <table class="data-table" id="my-tickets-table">
40
+ <?php if ($this->isSubjectColumnVisible()) : ?>
41
+ <col/>
42
+ <?php endif; ?>
43
+ <col width="1"/>
44
+ <col width="1"/>
45
+ <?php if ($this->isAgentColumnVisible()) : ?>
46
+ <col width="1"/>
47
+ <?php endif; ?>
48
+ <?php if ($this->isStatusColumnVisible()) : ?>
49
+ <col width="1"/>
50
+ <?php endif; ?>
51
+ <?php if ($this->isOrderColumnVisible()) : ?>
52
+ <col width="1"/>
53
+ <?php endif; ?>
54
+ <?php if ($this->isPriorityColumnVisible()) : ?>
55
+ <col width="1"/>
56
+ <?php endif; ?>
57
+ <col width="1"/>
58
+ <thead>
59
+ <tr>
60
+ <?php if ($this->isSubjectColumnVisible()) : ?>
61
+ <th><?php echo $this->__('Subject') ?></th>
62
+ <?php endif; ?>
63
+ <th><?php echo $this->__('Ticket #') ?></th>
64
+ <th><?php echo $this->__('Date Created') ?></th>
65
+ <?php if ($this->isAgentColumnVisible()) : ?>
66
+ <th><?php echo $this->__('Agent') ?></th>
67
+ <?php endif; ?>
68
+ <?php if ($this->isStatusColumnVisible()) : ?>
69
+ <th><?php echo $this->__('Status') ?></th>
70
+ <?php endif; ?>
71
+ <?php if ($this->isOrderColumnVisible()) : ?>
72
+ <th><?php echo $this->__('Order #') ?></th>
73
+ <?php endif; ?>
74
+ <?php if ($this->isPriorityColumnVisible()) : ?>
75
+ <th><?php echo $this->__('Priority') ?></th>
76
+ <?php endif; ?>
77
+ <th>&nbsp;</th>
78
+ </tr>
79
+ </thead>
80
+ <tbody>
81
+ <?php foreach ($_tickets as $_ticket): ?>
82
+ <tr>
83
+ <?php if ($this->isSubjectColumnVisible()) : ?>
84
+ <td><?php echo $_ticket->getSubject() ?></td>
85
+ <?php endif; ?>
86
+ <td class="right-cell-content"><?php echo $_ticket->getDisplayId() ?></td>
87
+ <td class="right-cell-content"><span
88
+ class="nobr"><?php echo $this->formatDate($_ticket->getCreatedAt()) ?></span></td>
89
+ <?php if ($this->isAgentColumnVisible()) : ?>
90
+ <td><?php echo $_ticket->getResponderName() ?></td>
91
+ <?php endif; ?>
92
+ <?php if ($this->isStatusColumnVisible()) : ?>
93
+ <td><em><?php echo $_ticket->getStatusName() ?></em></td>
94
+ <?php endif; ?>
95
+ <?php if ($this->isOrderColumnVisible()) : ?>
96
+ <td>
97
+ <?php if ($orderId = $_ticket->getOrderId()) : ?>
98
+ <a href="<?php echo $this->getOrderUrl($orderId); ?>">
99
+ <?php endif; ?>
100
+ <?php echo $_ticket->getOrderIncrementId() ? $_ticket->getOrderIncrementId() : '&nbsp;' ?>
101
+ <?php if ($orderId) : ?>
102
+ </a>
103
+ <?php endif; ?>
104
+ </td>
105
+ <?php endif; ?>
106
+ <?php if ($this->isPriorityColumnVisible()) : ?>
107
+ <td><em><?php echo $_ticket->getPriorityName() ?></em></td>
108
+ <?php endif; ?>
109
+ <td class="a-center">
110
+ <span class="nobr">
111
+ <a href="<?php echo $this->getViewUrl($_ticket) ?>"><?php echo $this->__('View'); ?></a>
112
+ <?php if ($this->canClose($_ticket)): ?>
113
+ <span class="separator">|</span>
114
+ <a href="<?php echo $this->getCloseUrl($_ticket) ?>"
115
+ onclick="return confirm('<?php echo $this->__('Are you sure you want to close ticket?'); ?>');"
116
+ class="link-reorder"><?php echo $this->__('Close'); ?></a>
117
+ <?php endif; ?>
118
+ </span>
119
+ </td>
120
+ </tr>
121
+ <?php endforeach; ?>
122
+ </tbody>
123
+ </table>
124
+
125
+ <?php echo $this->getPagerHtml(); ?>
126
+
127
+ <script type="text/javascript">
128
+ decorateTable('my-tickets-table');
129
+ </script>
130
+ <?php else: ?>
131
+ <p><?php echo $this->__('There are no tickets to display.'); ?></p>
132
+ <?php endif; ?>
133
+ </div>
app/design/frontend/base/default/template/freshdesk/tickets/recent.phtml ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Customer_Ticket_Recent
13
+ * @var Mageplace_Freshdesk_Block_Customer_Ticket_Recent $this
14
+ */
15
+ ?>
16
+ <div class="box-account box-fd-recent-tickets">
17
+ <?php $_tickets = $this->getTickets(); ?>
18
+ <div class="box-head">
19
+ <h2><?php echo $this->__('Recent Tickets') ?></h2>
20
+ <?php if ($this->canAction()): ?>
21
+ <div class="actions">
22
+ <span class="separator">|</span>
23
+ <a href="<?php echo $this->getCreateUrl(); ?>"><?php echo $this->__('Create a Ticket') ?></a>
24
+ </div>
25
+
26
+ <?php if (sizeof($_tickets->getItems()) > 0): ?>
27
+ <a href="<?php echo $this->getViewAllUrl(); ?>"><?php echo $this->__('View All') ?></a>
28
+ <?php endif; ?>
29
+ <?php endif; ?>
30
+ </div>
31
+ <?php if (sizeof($_tickets->getItems()) > 0): ?>
32
+ <table class="data-table" id="my-tickets-table">
33
+ <?php if ($this->isSubjectColumnVisible()) : ?>
34
+ <col/>
35
+ <?php endif; ?>
36
+ <col width="1"/>
37
+ <col width="1"/>
38
+ <?php if ($this->isAgentColumnVisible()) : ?>
39
+ <col width="1"/>
40
+ <?php endif; ?>
41
+ <?php if ($this->isStatusColumnVisible()) : ?>
42
+ <col width="1"/>
43
+ <?php endif; ?>
44
+ <?php if ($this->isOrderColumnVisible()) : ?>
45
+ <col width="1"/>
46
+ <?php endif; ?>
47
+ <?php if ($this->isPriorityColumnVisible()) : ?>
48
+ <col width="1"/>
49
+ <?php endif; ?>
50
+ <?php if ($this->canAction()): ?>
51
+ <col width="1"/>
52
+ <?php endif; ?>
53
+ <thead>
54
+ <tr>
55
+ <?php if ($this->isSubjectColumnVisible()) : ?>
56
+ <th><?php echo $this->__('Subject') ?></th>
57
+ <?php endif; ?>
58
+ <th><?php echo $this->__('Ticket #') ?></th>
59
+ <th><?php echo $this->__('Date Created') ?></th>
60
+ <?php if ($this->isAgentColumnVisible()) : ?>
61
+ <th><?php echo $this->__('Agent') ?></th>
62
+ <?php endif; ?>
63
+ <?php if ($this->isStatusColumnVisible()) : ?>
64
+ <th><?php echo $this->__('Status') ?></th>
65
+ <?php endif; ?>
66
+ <?php if ($this->isOrderColumnVisible()) : ?>
67
+ <th><?php echo $this->__('Order #') ?></th>
68
+ <?php endif; ?>
69
+ <?php if ($this->isPriorityColumnVisible()) : ?>
70
+ <th><?php echo $this->__('Priority') ?></th>
71
+ <?php endif; ?>
72
+ <?php if ($this->canAction()): ?>
73
+ <th>&nbsp;</th>
74
+ <?php endif; ?>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <?php foreach ($_tickets as $_ticket): ?>
79
+ <tr>
80
+ <?php if ($this->isSubjectColumnVisible()) : ?>
81
+ <td><?php echo $_ticket->getSubject() ?></td>
82
+ <?php endif; ?>
83
+ <td class="right-cell-content"><?php echo $_ticket->getDisplayId() ?></td>
84
+ <td class="right-cell-content"><span
85
+ class="nobr"><?php echo $this->formatDate($_ticket->getCreatedAt()) ?></span></td>
86
+ <?php if ($this->isAgentColumnVisible()) : ?>
87
+ <td><?php echo $_ticket->getResponderName() ?></td>
88
+ <?php endif; ?>
89
+ <?php if ($this->isStatusColumnVisible()) : ?>
90
+ <td><em><?php echo $_ticket->getStatusName() ?></em></td>
91
+ <?php endif; ?>
92
+ <?php if ($this->isOrderColumnVisible()) : ?>
93
+ <td>
94
+ <?php if ($orderId = $_ticket->getOrderId()) : ?>
95
+ <a href="<?php echo $this->getOrderUrl($orderId); ?>">
96
+ <?php endif; ?>
97
+ <?php echo $_ticket->getOrderIncrementId() ? $_ticket->getOrderIncrementId() : '&nbsp;' ?>
98
+ <?php if ($orderId) : ?>
99
+ </a>
100
+ <?php endif; ?>
101
+ </td>
102
+ <?php endif; ?>
103
+ <?php if ($this->isPriorityColumnVisible()) : ?>
104
+ <td><em><?php echo $_ticket->getPriorityName() ?></em></td>
105
+ <?php endif; ?>
106
+ <?php if ($this->canAction()): ?>
107
+ <td class="a-center">
108
+ <span class="nobr">
109
+ <a href="<?php echo $this->getViewUrl($_ticket) ?>"><?php echo $this->__('View') ?></a>
110
+ <?php if ($this->canClose($_ticket)): ?>
111
+ <span class="separator">|</span>
112
+ <a href="<?php echo $this->getCloseUrl($_ticket) ?>"
113
+ onclick="return confirm('<?php echo $this->__('Are you sure you want to close ticket?'); ?>');"
114
+ class="link-reorder"><?php echo $this->__('Close') ?></a>
115
+ <?php endif; ?>
116
+ </span>
117
+ </td>
118
+ <?php endif; ?>
119
+ </tr>
120
+ <?php endforeach; ?>
121
+ </tbody>
122
+ </table>
123
+ <script type="text/javascript">
124
+ if (!Object.isUndefined(fdAccountTicketRecent)) {
125
+ fdAccountTicketRecent.add('.box-recent', '.box-fd-recent-tickets', '.my-account .welcome-msg').process();
126
+ }
127
+ decorateTable('my-tickets-table');
128
+ </script>
129
+ <?php else: ?>
130
+ <p><?php echo $this->__('There are no tickets to display.'); ?></p>
131
+ <?php endif; ?>
132
+ </div>
app/design/frontend/base/default/template/freshdesk/tickets/view.phtml ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mageplace Freshdesk extension
4
+ *
5
+ * @category design
6
+ * @package base_default
7
+ * @copyright Copyright (c) 2014 Mageplace. (http://www.mageplace.com)
8
+ * @license http://www.mageplace.com/disclaimer.html
9
+ */
10
+
11
+ /**
12
+ * @see Mageplace_Freshdesk_Block_Customer_Ticket_View
13
+ * @var Mageplace_Freshdesk_Block_Customer_Ticket_View $this
14
+ */
15
+ ?>
16
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
17
+ <div class="freshdesk-ticket">
18
+ <div class="page-title title-buttons">
19
+ <h1><?php echo $this->getTitle(); ?></h1>
20
+
21
+ <div class="actions">
22
+ <?php if ($this->isRefreshButtonVisible()): ?>
23
+ <button type="button" title="<?php echo $this->__('Refresh') ?>" class="button btn-refresh-ticket"
24
+ onclick="location.href='<?php echo $this->getRefreshUrl(); ?>'">
25
+ <span><span><?php echo $this->__('Refresh') ?></span></span>
26
+ </button>
27
+ <?php endif; ?>
28
+ <button type="button" title="<?php echo $this->__('Create a New Ticket') ?>"
29
+ class="button btn-create-ticket"
30
+ onclick="location.href='<?php echo $this->getCreateUrl(); ?>'">
31
+ <span><span><?php echo $this->__('Create a New Ticket') ?></span></span>
32
+ </button>
33
+ </div>
34
+ </div>
35
+
36
+ <dl class="ticket-info">
37
+ <dt><?php echo $this->__('About This Ticket:'); ?></dt>
38
+ <dd>
39
+ <ul id="ticket-info-tabs">
40
+ <li class="current"><?php echo $this->__('Ticket Information'); ?></li>
41
+ </ul>
42
+ <script
43
+ type="text/javascript">decorateGeneric($('ticket-info-tabs').select('LI'), ['first', 'last']);</script>
44
+ </dd>
45
+ </dl>
46
+
47
+ <?php $_ticket = $this->getTicket(); ?>
48
+
49
+ <p class="order-date"><?php echo $this->__('Date Created: %s', $this->formatDate($_ticket->getCreatedAt(), 'long')) ?></p>
50
+
51
+ <div class="col2-set ticket-info-box">
52
+ <div class="page-title title-buttons notes-box">
53
+ <h1><?php echo $this->getSubject(); ?></h1>
54
+
55
+ <div class="actions">
56
+ <button type="button" title="<?php echo $this->__('Reply') ?>"
57
+ id="ticket_reply_button" class="button btn-close-ticket">
58
+ <span><span><?php echo $this->__('Reply') ?></span></span>
59
+ </button>
60
+ <?php if ($this->canClose($_ticket)): ?>
61
+ <button type="button" title="<?php echo $this->__('Close Ticket') ?>"
62
+ id="ticket_reply_button" class="button btn-close-ticket"
63
+ onclick="if(confirm('<?php echo $this->__('Are you sure you want to close ticket?'); ?>')) location.href='<?php echo $this->getCloseUrl(); ?>'">
64
+ <span><span><?php echo $this->__('Close Ticket') ?></span></span>
65
+ </button>
66
+ <?php endif; ?>
67
+ </div>
68
+ </div>
69
+
70
+ <div class="note-row">
71
+ <div class="col-1">
72
+ <div class="box">
73
+ <div class="box-title">
74
+ <strong><?php echo $this->getUser()->getName(); ?></strong>
75
+ </div>
76
+ <div class="box-date">
77
+ <?php echo $this->getDateDiff($_ticket->getCreatedAt(), $this->__('reported')); ?>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ <div class="col-2">
82
+ <div class="box-note">
83
+ <?php echo $_ticket->getDescriptionHtml(); ?>
84
+ </div>
85
+ </div>
86
+ </div>
87
+
88
+ <?php foreach ($this->getNotes() as $note) : ?>
89
+ <div class="note-row">
90
+ <div class="col-1">
91
+ <div class="box">
92
+ <div class="box-title">
93
+ <strong><?php echo $note->getUserName(); ?></strong>
94
+ </div>
95
+ <div class="box-date">
96
+ <?php echo $this->getDateDiff($note->getCreatedAt(), $this->__('said')); ?>
97
+ </div>
98
+ </div>
99
+ </div>
100
+ <div class="col-2">
101
+ <div class="box-note">
102
+ <?php echo $note->getBodyHtml(); ?>
103
+ </div>
104
+ </div>
105
+ </div>
106
+ <?php endforeach; ?>
107
+
108
+ <div class="note-row">
109
+ <div class="col-1 last">
110
+ <div class="box">
111
+ <div class="box-title">
112
+ <strong><?php echo $this->getUser()->getName(); ?></strong>
113
+ </div>
114
+ <div class="box-date">
115
+ <?php /*echo $this->getDateDiff($_ticket->getCreatedAt(), $this->__('reported'));*/ ?>
116
+ </div>
117
+ </div>
118
+ </div>
119
+ <div class="col-2 last">
120
+ <div class="box-note">
121
+ <input type="text" id="ticket_reply_message" class="reply not-active" name="reply"
122
+ value="<?php echo $this->__('Click here to reply to this ticket'); ?>"/>
123
+ <button type="button" title="<?php echo $this->__('Send') ?>"
124
+ id="ticket_send_button" class="button btn-send-ticket">
125
+ <span><span><?php echo $this->__('Send') ?></span></span>
126
+ </button>
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+
132
+ <div class="buttons-set">
133
+ <p class="back-link">
134
+ <a href="<?php echo $this->escapeUrl($this->getBackUrl()); ?>">
135
+ <small>&laquo; </small><?php echo $this->getBackTitle(); ?>
136
+ </a>
137
+ </p>
138
+ </div>
139
+ </div>
140
+ <script type="text/javascript">
141
+ new Freshdesk.Account.Ticket.View.Reply(
142
+ 'ticket_reply_message',
143
+ 'ticket_reply_button',
144
+ 'ticket_send_button',
145
+ '<?php echo $this->__('Click here to reply to this ticket'); ?>',
146
+ 'not-active',
147
+ '<?php echo $this->getSendReplyUrl(); ?>',
148
+ '<?php echo $this->getMessageTag(); ?>'
149
+
150
+ );
151
+ </script>
app/etc/modules/Mageplace_Freshdesk.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mageplace Freshdesk extension
5
+ *
6
+ * @category Mageplace_Freshdesk
7
+ * @package Mageplace_Freshdesk
8
+ * @copyright Copyright (c) 2013 Mageplace. (http://www.mageplace.com)
9
+ * @license http://www.mageplace.com/disclaimer.html
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Mageplace_Freshdesk>
15
+ <active>true</active>
16
+ <codePool>local</codePool>
17
+ <depends />
18
+ </Mageplace_Freshdesk>
19
+ </modules>
20
+ </config>
app/locale/en_US/Mageplace_Freshdesk.csv ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Freshdesk","Freshdesk"
2
+ "Tickets","Tickets"
3
+ "Portal","Portal"
4
+ "Settings","Settings"
5
+ "Enabled","Enabled"
6
+ "Freshdesk domain:","Freshdesk domain:"
7
+ "Admin email:","Admin email:"
8
+ "Admin API Key:","Admin API Key:"
9
+ "Password:","Password:"
10
+ "Error Freshdesk domain","Error Freshdesk domain"
11
+ "Error Freshdesk username","Error Freshdesk username"
12
+ "Error Freshdesk password","Error Freshdesk password"
13
+ "Ticket was created","Ticket was created"
14
+ "Ticket wasn't created","Ticket wasn't created"
15
+ "Contact Us form ticket from %s","Contact Us form ticket from %s"
16
+ "Account","Account"
17
+ "Order Id Linking","Order Id Linking"
18
+ "Magento Order id linked to:","Magento Order id linked to:"
19
+ "Obtain your custom field name in Freshdesk that you want to correspond with your Magento order id and paste it here","Obtain your custom field name in Freshdesk that you want to correspond with your Magento order id and paste it here"
20
+ "If you haven't created an Order field yet, go to Freshdesk Ticket Fields to create one","If you haven't created an Order field yet, go to Freshdesk Ticket Fields to create one"
21
+ "Channels","Channels"
22
+ "Create tickets from Contact Us form:","Create tickets from Contact Us form:"
23
+ "Enabling this will automatically create a ticket when a form is submitted","Enabling this will automatically create a ticket when a form is submitted"
24
+ "Have a feedback widget on your website:","Have a feedback widget on your website:"
25
+ "Feedback widget label:","Feedback widget label:"
26
+ "Feedback widget background color:","Feedback widget background color:"
27
+ "Feedback widget position:","Feedback widget position:"
28
+ "Paste this code on each of the pages where you want it to appear. To customize your feedback widget, go to Freshdesk widget","Paste this code on each of the pages where you want it to appear. To customize your feedback widget, go to Freshdesk widget"
29
+ "Show Support Link in Magento footer:","Show Support Link in Magento footer:"
30
+ "This link will take users to your freshdesk support portal","This link will take users to your freshdesk support portal"
31
+ "Customer View","Customer View"
32
+ "Allow your customers to view their tickets:","Allow your customers to view their tickets:"
33
+ "If this is not selected, customers will only be able to create tickets through the Contact Us form of Feedback widget. To view their existing tickets, they will have to go to your freshdesk portal","If this is not selected, customers will only be able to create tickets through the Contact Us form of Feedback widget. To view their existing tickets, they will have to go to your freshdesk portal"
34
+ "My Tickets tab will be shown inside customer's My Account. Tickets can be viewed, replied and closed here:","My Tickets tab will be shown inside customer's My Account. Tickets can be viewed, replied and closed here:"
35
+ "Show customer's most recent tickets and their status in Account Dashboard:","Show customer's most recent tickets and their status in Account Dashboard:"
36
+ "Agent should have admin permissions in Freshdesk to access all ticket information","Agent should have admin permissions in Freshdesk to access all ticket information"
37
+ "To get your token, inside Freshdesk portal, click profile settings and copy ""Your API key""","To get your token, inside Freshdesk portal, click profile settings and copy ""Your API key"""
38
+ "Single Sign On","Single Sign On"
39
+ "Enable Single Sign On:","Enable Single Sign On:"
40
+ "Allow users and agents to login your Freshdesk portal through Magento authentication","Allow users and agents to login your Freshdesk portal through Magento authentication"
41
+ "Enable SSO in Freshdesk and obtain your Shared Secret","Enable SSO in Freshdesk and obtain your Shared Secret"
42
+ "Shared Secret:","Shared Secret:"
43
+ "To get your shared secret, inside Freshdesk portal, go to Admin->Security","To get your shared secret, inside Freshdesk portal, go to Admin->Security"
44
+ "Global view of all Freshdesk tickets will be shown","Global view of all Freshdesk tickets will be shown"
45
+ "Login URL:","Login URL:"
46
+ "Logout URL:","Logout URL:"
47
+ "Url should be accessible to both agents and customers","Url should be accessible to both agents and customers"
48
+ "Error Freshdesk email or API key","Error Freshdesk email or API key"
49
+ "Create Ticket","Create Ticket"
50
+ "Freshdesk tickets, ticket fields, user tickets and etc","Freshdesk tickets, ticket fields, user tickets and etc"
51
+ "Create Ticket","Create Ticket"
52
+ "Close ticket","Close ticket"
53
+ "Invalid model ""%s""","Invalid model ""%s"""
54
+ "Invalid block ""%s""","Invalid block ""%s"""
55
+ "Save","Save"
56
+ "Save and New","Save and New"
57
+ "Save and Close","Save and Close"
58
+ "Cancel","Cancel"
59
+ "Wrong field object","Wrong field object"
60
+ "...","..."
61
+ "Can't get ticket fields","Can't get ticket fields"
62
+ "Field ""%s"" is required","Field ""%s"" is required"
63
+ "Wrong request data","Wrong request data"
64
+ "Field ""%s"" is not valid, please re-enter","Field ""%s"" is not valid, please re-enter"
65
+ "Ticket was successfully created","Ticket was successfully created"
66
+ "Refresh","Refresh"
67
+ "Cache was successfully refreshed","Cache was successfully refreshed"
68
+ "Please fill in Freshdesk configuration options first","Please fill in Freshdesk configuration options first"
69
+ "Please check Freshdesk configuration options","Please check Freshdesk configuration options"
70
+ "Freshdesk error: %s","Freshdesk error: %s"
71
+ "Ticket was successfully closed","Ticket was successfully closed"
72
+ "Ticket wasn't closed","Ticket wasn't closed"
73
+ "Left","Left"
74
+ "Right","Right"
75
+ "Top","Top"
76
+ "Bottom","Bottom"
77
+ "Manage Freshdesk Tickets","Manage Freshdesk Tickets"
78
+ "Recent Tickets","Recent Tickets"
79
+ "Create a Ticket","Create a Ticket"
80
+ "Create a New Ticket","Create a New Ticket"
81
+ "View All","View All"
82
+ "Subject","Subject"
83
+ "Ticket #","Ticket #"
84
+ "Ticket#","Ticket#"
85
+ "Date Created","Date Created"
86
+ "Request Name","Request Name"
87
+ "Status","Status"
88
+ "Priority","Priority"
89
+ "Due By","Due By"
90
+ "Agent","Agent"
91
+ "Order ID","Order ID"
92
+ "Order #","Order #"
93
+ "There are no tickets to display.","There are no tickets to display."
94
+ "View","View"
95
+ "Close","Close"
96
+ "My Tickets","My Tickets"
97
+ "My Tickets Info","My Tickets Info"
98
+ "Permissions denied","Permissions denied"
99
+ "Ticket #%d","Ticket #%d"
100
+ "Ticket #%1$d - %2$s","Ticket #%1$d - %2$s"
101
+ "About This Ticket:", "About This Ticket:"
102
+ "Ticket Information","Ticket Information"
103
+ "Date Created: %s","Date Created: %s"
104
+ "Back to My Tickets","Back to My Tickets"
105
+ "reported","reported"
106
+ "said","said"
107
+ "%1$s about %2$d year(s) ago","%1$s about %2$d year(s) ago"
108
+ "%1$s about %2$d month(s) ago","%1$s about %2$d month(s) ago"
109
+ "%1$s about %2$d day(s) ago","%1$s about %2$d day(s) ago"
110
+ "%1$s about %2$d hour(s) ago","%1$s about %2$d hour(s) ago"
111
+ "%1$s about %2$d minute(s) ago","%1$s about %2$d minute(s) ago"
112
+ "%1$s about %2$d second(s) ago","%1$s about %2$d second(s) ago"
113
+ "Are you sure you want to close ticket?","Are you sure you want to close ticket?"
114
+ "Click here to reply to this ticket","Click here to reply to this ticket"
115
+ "Send","Send"
116
+ "New Ticket","New Ticket"
117
+ "Submit Ticket","Submit Ticket"
118
+ "Wrong freshdesk user information","Wrong freshdesk user information"
119
+ "Contact Us form:","Contact Us form:"
120
+ "Feedback Widget:","Feedback Widget:"
121
+ "Support link in Magento footer:","Support link in Magento footer:"
122
+ "If you haven't created an Order field yet, go to Freshdesk &lt;a id="fd_order_id_ticket_fields_link" href="" target="_blank"&gt;Ticket Fields&lt;/a&gt; to create one","If you haven't created an Order field yet, go to Freshdesk &lt;a id="fd_order_id_ticket_fields_link" href="" target="_blank"&gt;Ticket Fields&lt;/a&gt; to create one"
123
+ "Code will be pasted to all your store pages. To customize your feedback widget, go to Freshdesk &lt;a id="fd_channels_feedback_widget_link" href="" target="_blank"&gt;Feedback Widget&lt;/a&gt; and paste the final code above","Code will be pasted to all your store pages. To customize your feedback widget, go to Freshdesk &lt;a id="fd_channels_feedback_widget_link" href="" target="_blank"&gt;Feedback Widget&lt;/a&gt; and paste the final code above"
124
+ "Ticket View for Customers:","Ticket View for Customers:"
125
+ "No, they will have to use your Freshdesk portal","No, they will have to use your Freshdesk portal"
126
+ "Yes, My Account will have My Tickets to view, reply and close tickets","Yes, My Account will have My Tickets to view, reply and close tickets"
127
+ "Show recent tickets in Account Dashboard:","Show recent tickets in Account Dashboard:"
128
+ "Wrong ticket's fields object","Wrong ticket's fields object"
129
+ "View","View"
130
+ "Go to Freshdesk","Go to Freshdesk"
131
+ "Obtain your custom field name (Agent Label) in Freshdesk that you want to correspond with your Magento order id and paste it here","Obtain your custom field name (Agent Label) in Freshdesk that you want to correspond with your Magento order id and paste it here"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>freshdesk</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>community</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Freshdesk Extension</summary>
10
+ <description>Freshdesk allows you to deliver exceptional customer support to your customers across multiple channels.</description>
11
+ <notes>First release</notes>
12
+ <authors><author><name>MagePlace</name><user>MagePlace</user><email>info@mageplace.com</email></author><author><name>Freshdesk</name><user>Freshdesk</user><email>smrithi@freshdesk.com</email></author></authors>
13
+ <date>2014-05-08</date>
14
+ <time>10:36:17</time>
15
+ <contents><target name="magelocal"><dir name="Mageplace"><dir name="Freshdesk"><dir name="Block"><dir name="Adminhtml"><dir name="Config"><file name="Comment.php" hash="3bf130cfd26e53a5c639bf03f9d7e626"/><file name="Feedbackwidget.php" hash="dc05ea95754073c93a680ae410efe1c9"/><file name="Link.php" hash="779827427e11db311b6e1de9d42818f2"/></dir><dir name="Customer"><dir name="Edit"><dir name="Tab"><dir name="View"><file name="Tickets.php" hash="7c5b4dbbda473089763cb56850d86747"/></dir></dir></dir></dir><dir name="Ticket"><dir name="Edit"><dir name="Form"><file name="Fields.php" hash="cf72365450d6b2c186a3c3308d9210ca"/></dir><file name="Form.php" hash="7afe4ec0d7d066da9231b8d5875937c6"/></dir><file name="Edit.php" hash="7df00e9bf69affc443c1ff5e1cfbbdb4"/><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Datetime.php" hash="d5b395e5d7bcb474c19885905184ff77"/><file name="Orderincrements.php" hash="196b1700f4d50623c7207d67de5e22c8"/><file name="Orders.php" hash="7022fcd97b7eaccbac884111f693b75f"/></dir></dir></dir><file name="Grid.php" hash="e1e25bfa6779206bb20fed9445c20fa9"/></dir><file name="Ticket.php" hash="051506b3081ea17ad3930aba26617e02"/></dir><dir name="Customer"><dir name="Ticket"><file name="Abstract.php" hash="1546bd9f7621486e86606f86d02820f8"/><file name="Create.php" hash="2708c18f6d0daaedfa5e93b7e8fa0959"/><file name="Grid.php" hash="df6cf04f8e13ba80001386f54ae4a721"/><file name="List.php" hash="f3c396ae1303011a9c9f5310bf42bf0a"/><file name="Recent.php" hash="852fc3bec6424fcd3fa0eb6b0c5e229a"/><file name="View.php" hash="051e3c0b9f3d95be51f74b339344b1c9"/></dir></dir><dir name="Field"><file name="Abstract.php" hash="1727f9e761d24c4e48ca535f79773c0f"/><dir name="Custom"><file name="Checkbox.php" hash="5345383d5e86bd4c5752973c487fe15b"/><file name="Dropdown.php" hash="b42e6e9f95ff08db541fe3b92c04184a"/><file name="Number.php" hash="64e9c0a453c28df6e4b4095d93e1028e"/><file name="Paragraph.php" hash="a825b309d2e20e923df978354231b278"/><file name="Text.php" hash="8041b6ab0e66b5dc1daff9cfc81904b5"/></dir><dir name="Default"><file name="Agent.php" hash="3026ec085ff1b9a911709e1ff1d9c6a9"/><file name="Description.php" hash="3753cd6e4fa79b7999bb2c41794455d3"/><file name="Group.php" hash="d0b391d83b983564993c1bc32a5a6f1f"/><file name="Priority.php" hash="f5ed49455155789b7765439373c3531e"/><file name="Requester.php" hash="3814505f4813787488fb8d548093cb73"/><file name="Source.php" hash="867ce023dd9ecab3ed169f02db4e8162"/><file name="Status.php" hash="0c7317369a35d36047cc55388731bb41"/><file name="Subject.php" hash="aee6e0a7850098bd4c336e70dfab54a1"/><dir name="Ticket"><file name="Type.php" hash="82911704932b0750c4ba393b5abb6aea"/></dir></dir><file name="Dropdown.php" hash="554d2b541026819d74e9ea3a6deb73f6"/><dir name="Nested"><file name="Field.php" hash="8cd5b59302920f2fafb55db38b9e4ff1"/></dir><file name="Paragraph.php" hash="82ad00eed75ec4d60128016584a70f8f"/><file name="Row.php" hash="fe082e138d2bc67a16072427bca6508d"/><file name="Text.php" hash="f596517b6e32ed04d94a974e33daf42a"/></dir><dir name="Order"><dir name="Info"><file name="Buttons.php" hash="246225d9fb3de91f1f6e6492d097b055"/></dir></dir><dir name="Page"><dir name="Html"><dir name="Head"><file name="Widget.php" hash="5809cf0b96676f703999030126b8ad50"/></dir></dir></dir></dir><file name="Exception.php" hash="0aaf4bb7f20354ddc817a6fcb34d3594"/><dir name="Helper"><file name="Const.php" hash="d86bb3a8760b2a3c25aae3d6f33c4282"/><file name="Customer.php" hash="5110ae8c83c15e6445f45dd0f91e3083"/><file name="Data.php" hash="5a8037618e0613f406f5010b40a4fa72"/></dir><dir name="Model"><file name="Abstract.php" hash="160dbb8dcadcd6891f4f1a82af989409"/><file name="Cache.php" hash="41fb801e89e6769ece8150091714269b"/><dir name="Field"><dir name="Custom"><file name="Checkbox.php" hash="d8ecf87571b692ba7dd79ff71448e271"/><file name="Dropdown.php" hash="e9a848e1e793d23b5badc49ad27e63d0"/><file name="Number.php" hash="5b0a285e44092c2668d9270fe7446f69"/><file name="Paragraph.php" hash="9ea7c3136bf92b7f86fb8cb155f2511f"/><file name="Text.php" hash="db42748d4b10ae64d8eabb2529959962"/></dir><dir name="Default"><file name="Agent.php" hash="b9fcce767d5ee25f8bf0e97ac770315e"/><file name="Description.php" hash="779a50c6a07bb0162e14e9346bec9361"/><file name="Group.php" hash="e9fe63549ff6c2151b95e1f440c62526"/><file name="Priority.php" hash="21d690931a175edd1dcd10851e1995e9"/><file name="Requester.php" hash="ae5e3e89d880c6703f2346cb70670a51"/><file name="Source.php" hash="84aa9406c769c28daf201eca364eb3f0"/><file name="Status.php" hash="ab0e8b13e956c77e5790f25176151dbf"/><file name="Subject.php" hash="6bc99e5809b57a788e0dd358546b3f77"/><dir name="Ticket"><file name="Type.php" hash="385377791b6b1d4eddf9a24eff046fd2"/></dir></dir><file name="Dropdown.php" hash="fa5045e5332d10b1df2a6e438e73310c"/><dir name="Nested"><file name="Field.php" hash="58113931b55fed4d13a3b480783c3c9b"/></dir></dir><file name="Field.php" hash="91aa5882bb6cae9bea69e31661486fa3"/><dir name="Freshdesk"><file name="Abstract.php" hash="223d4cc05191b33666c99405d33a2658"/><file name="Fields.php" hash="fe76548a666e6a5502eef1b3ef08d77f"/><file name="Interface.php" hash="ffd31403ea2352c57088708748958703"/><file name="Notes.php" hash="1dbe02a84dfc64f7ce97b60c78569baf"/><file name="Tickets.php" hash="e3e2975bf85e2d33647c8602c5601d19"/><file name="Users.php" hash="d79d8ef386955c13d8a9a094ac1a3122"/></dir><file name="Freshdesk.php" hash="543b7e2322870940a1c9299fbd556059"/><file name="Note.php" hash="c50bd2abc328ff8ba486703b2508b669"/><file name="Observer.php" hash="8a67670373d39bf23836f328c730f8f2"/><dir name="Resource"><dir name="Collection"><file name="Abstract.php" hash="3bff49eb263691965caaf7b5c768371c"/></dir><dir name="Field"><file name="Collection.php" hash="456f8ae715981f67358dc17953c6d71b"/></dir><file name="Field.php" hash="bddf096c9dbb4bca8febf1f7c54ff5e7"/><file name="Note.php" hash="dc45fc78502747f7be86797320e9a313"/><dir name="Ticket"><file name="Collection.php" hash="f01324e9616919bdbde8618c1e715bbb"/></dir><file name="Ticket.php" hash="3ac7a3461a7a058352ca9e4d0af2a988"/><file name="User.php" hash="cabab7636c275a6da9066e0fa6c77dbc"/></dir><dir name="Source"><file name="Abstract.php" hash="a45256e97b741c02b862085b47ef8327"/><file name="Priority.php" hash="569a32f526a4cb69f3eda6bb0550298c"/><file name="Status.php" hash="30ed953692f708371a4f415f6129809b"/><file name="Ticketview.php" hash="3d7aa4dbef996c0740465b2d135890eb"/><file name="Widgetposition.php" hash="6bb9adcb2e3ae1d29c0b667956bf628f"/></dir><file name="Ticket.php" hash="4479ee9e2e83d8eb2f03cef0decee5c4"/><file name="User.php" hash="5b7daff6c7f36e01dad7f38ffb0dab2b"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Freshdesk"><file name="TicketController.php" hash="472d3fee1addf44170b9e5cc2619518b"/></dir><file name="FreshdeskController.php" hash="7fb1e80f65f7a468c20965d41d2e2381"/></dir><file name="IndexController.php" hash="4e0e4e15191547674e778af5fb21965a"/><file name="TicketController.php" hash="4b50adf0ec8e7db15fadd414dc8a90b8"/></dir><dir name="etc"><file name="config.xml" hash="7ff229a37d5155094cc861ee05310146"/><file name="system.xml" hash="2c00dc9d9f1233047ecc30a05a5ddc16"/></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="freshdesk.xml" hash="a2bbddbe1a080e8b5065bc1e6b96cc83"/></dir><dir name="template"><dir name="freshdesk"><dir name="field"><file name="checkbox.phtml" hash="f48375f1fbec96fcd9f2a40ccce9dbba"/><file name="dropdown.phtml" hash="91fc7078dcceaabdcddb7944cf9959ee"/><file name="nested_field.phtml" hash="969dd91648e9ea65b9887757b03f3b68"/><file name="paragraph.phtml" hash="60b794e0155bedfc8938025640828bb1"/><file name="row_1_column.phtml" hash="8f5c91de5d1a0513ce859bbc9e4645aa"/><file name="row_2_column.phtml" hash="af63fbb71cb73591f5700c5bce3b6fd7"/><file name="text.phtml" hash="3d9db89aa436c98ce7be68bfdf18545d"/></dir><dir name="ticket"><dir name="edit"><dir name="form"><file name="fields.phtml" hash="81fba14c749ad98f0928f3004e240648"/></dir><file name="form.phtml" hash="d57d1276fd2286383a4c35639c51cd26"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="freshdesk.xml" hash="e81d50ed6407a5a005aee9c4453fb9b8"/></dir><dir name="template"><dir name="freshdesk"><dir name="customer"><dir name="account"><dir name="navigation"><file name="js.phtml" hash="843aebb615759503c897bff32ca4a4c4"/></dir></dir></dir><dir name="field"><file name="checkbox.phtml" hash="f48375f1fbec96fcd9f2a40ccce9dbba"/><file name="dropdown.phtml" hash="91fc7078dcceaabdcddb7944cf9959ee"/><file name="nested_field.phtml" hash="8864fb249a407cecfc9d62361ca5406d"/><file name="paragraph.phtml" hash="60b794e0155bedfc8938025640828bb1"/><file name="row.phtml" hash="efff502a2c72d61065567b42d994c43f"/><file name="row_inline.phtml" hash="6dcf5c27f398004f1ae1b3eb717e053a"/><file name="text.phtml" hash="25f8e55fea10a18630e10d0fa7504151"/></dir><dir name="page"><dir name="html"><dir name="head"><file name="widget.phtml" hash="a0a1f4ad744aac2792e46bcd3398a6b6"/></dir></dir></dir><dir name="sales"><dir name="order"><dir name="info"><file name="create_ticket_button.phtml" hash="49af07b84827a57d9f68bb67b0b589f7"/></dir></dir></dir><dir name="tickets"><file name="create.phtml" hash="adec793ca275a0a525e24edbdba71c25"/><file name="list.phtml" hash="b0e75d836b28f42b278846b02e2e630c"/><file name="recent.phtml" hash="23d4bdb9772545bcf283c5f951812c05"/><file name="view.phtml" hash="24cac09ab162c6e6d2a86e065aa70c3e"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mageplace_Freshdesk.xml" hash="994e7e18a70c605427de103feb689e7f"/></dir></target><target name="magelocale"><dir><dir name="en_US"><file name="Mageplace_Freshdesk.csv" hash="a25b24aefc7a5dd3250dbf86cfbbe8f3"/></dir></dir></target><target name="mageskin"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="freshdesk"><dir name="css"><file name="freshdesk.css" hash="b4272015df282fe00c92e170afaa4e40"/></dir><dir name="images"><file name="admin-ticket-icon.gif" hash="77144431392345a39048c6ed073359c5"/><file name="fd-logo-header.png" hash="23e9a082c2f1f853f616763b879df7a5"/><file name="fd-logo-tab.png" hash="ef19b8c504556844dd81005ec84f2106"/><file name="logo-big.png" hash="b030cae210c4776060fe073984e3abcf"/></dir><dir name="js"><file name="freshdesk.js" hash="aba545c35745e213cf9fc26da9b035e6"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="freshdesk"><dir name="css"><file name="freshdesk.css" hash="868f6a6806a3234901e60f97bb179922"/></dir><dir name="images"><file name="bkg_block-title.gif" hash="f8c1f130ad69464fe7aff2f589b2ec75"/><file name="ticket-icon.gif" hash="77144431392345a39048c6ed073359c5"/></dir><dir name="js"><file name="freshdesk.js" hash="5f4055078ed3b50cbf79f38e3725cf3e"/></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/default/default/freshdesk/css/freshdesk.css ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .head-ticket-page {
2
+ background-image: url(../images/admin-ticket-icon.gif);
3
+ }
4
+
5
+ #create-ticket-fieldset table tr td.label {
6
+ width: 0px;
7
+ padding: 0px !important;
8
+ }
9
+
10
+ #ticket_fields_area .label {
11
+ width: 200px !important;
12
+ padding: 5px 0px 5px 5px !important;
13
+ }
14
+
15
+ ul.tabs a.freshdesk-section,
16
+ ul.tabs a.freshdesk-section:hover {
17
+ border-bottom: 1px solid #BEBEBE;
18
+ padding: 0 0 0 1.3em;
19
+ text-indent: -9999px;
20
+ }
21
+
22
+ ul.tabs a.freshdesk-section.active,
23
+ ul.tabs a.freshdesk-section.active:hover {
24
+ background: none repeat scroll 0 0 white;
25
+ }
26
+
27
+ ul.tabs a.freshdesk-section span,
28
+ ul.tabs a.freshdesk-section:hover span {
29
+ background: url(../images/fd-logo-tab.png) no-repeat 0 3px;
30
+ width: 120px;
31
+ height: 25px;
32
+ padding: 0;
33
+ overflow: hidden;
34
+ }
35
+
36
+ h3.freshdesk-header {
37
+ background: url(../images/fd-logo-header.png) no-repeat scroll 0 0 transparent;
38
+ width: 200px;
39
+ height: 50px;
40
+ padding: 0;
41
+ text-indent: -9999px;
42
+ overflow: hidden;
43
+ }
44
+
45
+ .grid-subject-column {
46
+ width: 30%;
47
+ }
48
+
49
+ .grid-agent-column {
50
+ width: 20%;
51
+ }
skin/adminhtml/default/default/freshdesk/images/admin-ticket-icon.gif ADDED
Binary file
skin/adminhtml/default/default/freshdesk/images/fd-logo-header.png ADDED
Binary file
skin/adminhtml/default/default/freshdesk/images/fd-logo-tab.png ADDED
Binary file
skin/adminhtml/default/default/freshdesk/images/logo-big.png ADDED
Binary file
skin/adminhtml/default/default/freshdesk/js/freshdesk.js ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freshdesk = Class.create();
2
+ Freshdesk.prototype = {
3
+ portalLinkSearchTemplate: 'freshdesk/portal',
4
+
5
+ initialize: function () {
6
+ },
7
+
8
+ processLinks: function () {
9
+ $$('a[href*="' + this.portalLinkSearchTemplate + '"]').each(function (el) {
10
+ el.target = '_blank';
11
+ });
12
+ }
13
+ }
14
+
15
+ Freshdesk.Fields = {};
16
+ Freshdesk.Fields.Nested = Class.create();
17
+ Freshdesk.Fields.Nested.prototype = {
18
+ id: '',
19
+ mainSelect: null,
20
+ level1Select: null,
21
+ level2Select: null,
22
+ level1block: null,
23
+ level2block: null,
24
+ options: [],
25
+
26
+ initialize: function (id, options) {
27
+ this.id = id;
28
+ this.mainSelect = $(this.id);
29
+
30
+ this.level1block = $(this.id + '_level1_block');
31
+ this.level1Select = $(this.id + '_level1_block').select('select').first();
32
+
33
+ this.level2block = $(this.id + '_level2_block');
34
+ if (this.hasLevel2()) {
35
+ this.level2Select = $(this.id + '_level2_block').select('select').first();
36
+ }
37
+
38
+ this.options = options;
39
+ },
40
+
41
+ optionChanged: function (el) {
42
+ if (Object.isUndefined(el)) {
43
+ return;
44
+ }
45
+
46
+ var mainValue = this.mainSelect.options[this.mainSelect.selectedIndex].value;
47
+
48
+ if (this.isLevel2(el)) {
49
+ return;
50
+ } else if (this.isLevel1(el)) {
51
+ if (!this.hasLevel2()) {
52
+ return;
53
+ }
54
+
55
+ this.hideLevel2();
56
+
57
+ var level1Value = this.level1Select.options[this.level1Select.selectedIndex].value;
58
+ if (level1Value == '') {
59
+ return;
60
+ }
61
+
62
+ var level2Options = [];
63
+ for (var i = 0; i < this.options.length; i++) {
64
+ if (this.options[i].value == mainValue) {
65
+ var level1Options = this.options[i].children;
66
+ for (var j = 0; j < level1Options.length; j++) {
67
+ if (level1Options[j].value == level1Value) {
68
+ level2Options = level1Options[j].children;
69
+ break;
70
+ }
71
+ }
72
+ break;
73
+ }
74
+ }
75
+
76
+ if (level2Options.length > 0) {
77
+ this.showLevel2(level2Options);
78
+ }
79
+
80
+
81
+ } else {
82
+ this.hideLevel1();
83
+ this.hideLevel2();
84
+
85
+ if (mainValue == '') {
86
+ return;
87
+ }
88
+
89
+ var level1Options = [];
90
+ for (var i = 0; i < this.options.length; i++) {
91
+ if (this.options[i].value == mainValue) {
92
+ level1Options = this.options[i].children;
93
+ break;
94
+ }
95
+ }
96
+
97
+ if (level1Options.length > 0) {
98
+ this.showLevel1(level1Options);
99
+ }
100
+ }
101
+ },
102
+
103
+ isMain: function (el) {
104
+ return el.id == this.id;
105
+ },
106
+
107
+ isLevel1: function (el) {
108
+ return el.id == this.level1Select.id;
109
+ },
110
+
111
+ isLevel2: function (el) {
112
+ return this.hasLevel2() && el.id == this.level2Select.id;
113
+ },
114
+
115
+ hasLevel2: function () {
116
+ return Object.isElement(this.level2block);
117
+ },
118
+
119
+ showLevel1: function (level1options) {
120
+ for (var i = 0; i < level1options.length; i++) {
121
+ this.level1Select.insert('<option value="' + level1options[i].value + '">' + level1options[i].label + '</option>');
122
+ }
123
+
124
+ this.level1Select.selectedIndex = 0;
125
+ this.level1Select.className = this.mainSelect.className;
126
+
127
+ this.level1block.show();
128
+ },
129
+
130
+ hideLevel1: function () {
131
+ this.level1block.hide();
132
+
133
+ this.level1Select.select('option').each(Element.remove);
134
+ this.level1Select.className = '';
135
+ },
136
+
137
+ showLevel2: function (level2options) {
138
+ if (!this.hasLevel2()) {
139
+ return;
140
+ }
141
+
142
+ for (var i = 0; i < level2options.length; i++) {
143
+ this.level2Select.insert('<option value="' + level2options[i].value + '">' + level2options[i].label + '</option>');
144
+ }
145
+
146
+ this.level2Select.selectedIndex = 0;
147
+ this.level2Select.className = this.mainSelect.className;
148
+
149
+ this.level2block.show();
150
+ },
151
+
152
+ hideLevel2: function () {
153
+ if (!this.hasLevel2()) {
154
+ return;
155
+ }
156
+
157
+ this.level2block.hide();
158
+
159
+ this.level2Select.select('option').each(Element.remove);
160
+ this.level2Select.className = '';
161
+ }
162
+ };
163
+
164
+ Freshdesk.Customer = {};
165
+ Freshdesk.Customer.View = {};
166
+ Freshdesk.Customer.View.Tickets = Class.create();
167
+ Freshdesk.Customer.View.Tickets.prototype = {
168
+ elLastOrdersId: 'dd-lastOrders',
169
+ elTicketsDDId: 'dd-freshdesk_tickets',
170
+ elTicketsDTId: 'dt-freshdesk_tickets',
171
+
172
+ initialize: function () {
173
+ },
174
+
175
+ process: function () {
176
+ if (!Object.isElement($(this.elLastOrdersId)) || !Object.isElement($(this.elTicketsDDId)) || !Object.isElement($(this.elTicketsDTId))) {
177
+ return;
178
+ }
179
+
180
+ $(this.elLastOrdersId).insert({after: $(this.elTicketsDDId)}).insert({after: $(this.elTicketsDTId)});
181
+ }
182
+ };
183
+
184
+ Freshdesk.System = {};
185
+ Freshdesk.System.Config = Class.create();
186
+ Freshdesk.System.Config.prototype = {
187
+ elDomainId: 'freshdesk_account_domain',
188
+
189
+ elTicketFieldLinkId: 'fd_order_id_ticket_fields_link',
190
+ linkTicketField: 'ticket_fields',
191
+
192
+ elFeedbackWidgetLinkId: 'fd_channels_feedback_widget_link',
193
+ linkFeedbackWidget: 'admin/widget_config',
194
+
195
+ initialize: function () {
196
+ },
197
+
198
+ processLinks: function () {
199
+ if (!Object.isElement($(this.elDomainId))) {
200
+ return;
201
+ }
202
+
203
+ $(this.elDomainId).observe('change', this.changeLinks.bind(this));
204
+ $(this.elDomainId).observe('keyup', this.changeLinks.bind(this));
205
+ $(this.elDomainId).observe('mouseup', this.changeLinks.bind(this));
206
+
207
+ this.changeLinks();
208
+ },
209
+
210
+ changeLinks: function () {
211
+ if (!Object.isElement($(this.elDomainId)) || !Object.isElement($(this.elTicketFieldLinkId))) {
212
+ return;
213
+ }
214
+
215
+ var fdUrl = ($(this.elDomainId).value.indexOf("://") > 0 ? '' : 'http://') + $(this.elDomainId).value + '/';
216
+
217
+ $(this.elTicketFieldLinkId).href = fdUrl + this.linkTicketField;
218
+ $(this.elFeedbackWidgetLinkId).href = fdUrl + this.linkFeedbackWidget;
219
+ }
220
+ }
221
+
222
+ Freshdesk.System.Config.Widget = Class.create();
223
+ Freshdesk.System.Config.Widget.prototype = {
224
+ elEnableId: 'freshdesk_channels_enable_feedback_widget',
225
+ elCodeId: 'freshdesk_channels_feedback_widget',
226
+
227
+ initialize: function () {
228
+ },
229
+
230
+ process: function () {
231
+ if (!Object.isElement($(this.elEnableId))) {
232
+ return;
233
+ }
234
+
235
+ $(this.elEnableId).observe('change', this.toggle.bind(this));
236
+
237
+ this.toggle();
238
+ },
239
+
240
+ toggle: function () {
241
+ if (this.isEnable()) {
242
+ $(this.elCodeId).up().up().show();
243
+ } else {
244
+ $(this.elCodeId).up().up().hide();
245
+ }
246
+ },
247
+
248
+ isEnable: function () {
249
+ return $(this.elEnableId).value == 1;
250
+ }
251
+ }
252
+
253
+ Freshdesk.System.Config.CustomerView = Class.create();
254
+ Freshdesk.System.Config.CustomerView.prototype = {
255
+ elEnableId: 'freshdesk_customer_view_enable_customer_view',
256
+ elChild1Id: 'freshdesk_customer_view_enable_ticket_tab',
257
+ elChild2Id: 'freshdesk_customer_view_enable_recent_ticket',
258
+
259
+ initialize: function () {
260
+ },
261
+
262
+ process: function () {
263
+ if (!Object.isElement($(this.elEnableId))) {
264
+ return;
265
+ }
266
+
267
+ $(this.elEnableId).observe('change', this.toggle.bind(this));
268
+
269
+ this.toggle();
270
+ },
271
+
272
+ toggle: function () {
273
+ if (this.isEnable()) {
274
+ /*$(this.elChild1Id).up().up().show();*/
275
+ $(this.elChild2Id).up().up().show();
276
+ } else {
277
+ /*$(this.elChild1Id).up().up().hide();*/
278
+ $(this.elChild2Id).up().up().hide();
279
+ }
280
+ },
281
+
282
+ isEnable: function () {
283
+ return $(this.elEnableId).value == 1;
284
+ }
285
+ }
286
+
287
+ Event.observe(window, 'load', function () {
288
+ new Freshdesk().processLinks();
289
+ new Freshdesk.Customer.View.Tickets().process();
290
+ new Freshdesk.System.Config().processLinks();
291
+ new Freshdesk.System.Config.Widget().process();
292
+ new Freshdesk.System.Config.CustomerView().process();
293
+ });
skin/frontend/base/default/freshdesk/css/freshdesk.css ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #my-tickets-table td {
2
+ vertical-align: middle;
3
+ }
4
+
5
+ .box-fd-recent-tickets .box-head h2 {
6
+ background-image: url(../images/ticket-icon.gif);
7
+ }
8
+
9
+ .box-fd-recent-tickets .box-head .actions {
10
+ float: left;
11
+ margin-left: 5px;
12
+ line-height: 1.35;
13
+ }
14
+
15
+ .box-fd-recent-tickets .box-head .actions .separator {
16
+ color: #cccccc;
17
+ }
18
+
19
+ .box-fd-recent-tickets .right-cell-content {
20
+ text-align: right;
21
+ }
22
+
23
+ .ticket-info {
24
+ background: #DEE5E8;
25
+ border: 1px solid #D0CBC1;
26
+ padding: 4px 8px;
27
+ margin: 0 0 8px;
28
+ }
29
+
30
+ .ticket-info dt, .ticket-info dd, .ticket-info ul, .ticket-info li {
31
+ display: inline;
32
+ }
33
+
34
+ .ticket-info .current {
35
+ font-weight: bold;
36
+ }
37
+
38
+ .ticket-info li {
39
+ margin: 0 3px;
40
+ }
41
+
42
+ .ticket-info-box {
43
+ background: #fff url(../images/bkg_block-title.gif) 0 0 repeat-x;
44
+ border: 1px solid #D0CBC1;
45
+ padding: 12px 15px;
46
+ margin: 0 0 15px;
47
+ }
48
+
49
+ .notes-box {
50
+ border: 0px none;
51
+ }
52
+
53
+ .note-row {
54
+ float: left;
55
+ width: 100%;
56
+ margin-bottom: 40px;
57
+ }
58
+
59
+ .note-row .col-1 {
60
+ width: 17%;
61
+ text-align: center;
62
+ padding-top: 10px;
63
+ }
64
+
65
+ .note-row .col-1 .box-date {
66
+ font-size: 10px;
67
+ color: #AAAAAA;
68
+ }
69
+
70
+ .note-row .col-2 {
71
+ width: 78.5%;
72
+ height: 100%;
73
+ border: 1px solid #DDDCCC;
74
+ padding: 15px 10px;
75
+ }
76
+
77
+ .note-row .col-2 .box-note {
78
+ min-height: 20px;
79
+ }
80
+
81
+ .note-row .col-2.last {
82
+ background-color: #F7F7F7;
83
+ }
84
+
85
+ .freshdesk-ticket .reply {
86
+ border: 1px solid #CCCCCC;
87
+ width: 85%;
88
+ padding: 8px;
89
+ }
90
+
91
+ .freshdesk-ticket .not-active {
92
+ color: #CCCCCC;
93
+ font-weight: bold;
94
+ }
95
+
96
+ .freshdesk-ticket-create .page-title {
97
+ margin-bottom: 15px;
98
+ }
99
+
100
+ .freshdesk-ticket-create .actions {
101
+ text-align: right;
102
+ }
103
+
104
+ .freshdesk-ticket-create .ticket-create-box {
105
+ border: 1px solid #bbafa0;
106
+ background: #F2F2F2;
107
+ padding: 22px 25px 12px 33px;
108
+ margin: 15px 0;
109
+ }
110
+
111
+ .freshdesk-ticket-create .form-list li.wide select {
112
+ width: 260px;
113
+ }
114
+
115
+ .fd-tickets-list button.button, .freshdesk-ticket button.button, .freshdesk-ticket-create button.button {
116
+ margin-left: 7px;
117
+ }
118
+
119
+ .link-create-order {
120
+ font-weight: bold;
121
+ color: #dc6809;
122
+ }
skin/frontend/base/default/freshdesk/images/bkg_block-title.gif ADDED
Binary file
skin/frontend/base/default/freshdesk/images/ticket-icon.gif ADDED
Binary file
skin/frontend/base/default/freshdesk/js/freshdesk.js ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freshdesk = {};
2
+
3
+ Freshdesk.Fields = {};
4
+ Freshdesk.Fields.Nested = Class.create();
5
+ Freshdesk.Fields.Nested.prototype = {
6
+ id: '',
7
+ mainSelect: null,
8
+ level1Select: null,
9
+ level2Select: null,
10
+ level1block: null,
11
+ level2block: null,
12
+ options: [],
13
+
14
+ initialize: function (id, options) {
15
+ this.id = id;
16
+ this.mainSelect = $(this.id);
17
+
18
+ this.level1block = $(this.id + '_level1_block');
19
+ this.level1Select = $(this.id + '_level1_block').select('select').first();
20
+
21
+ this.level2block = $(this.id + '_level2_block');
22
+ if (this.hasLevel2()) {
23
+ this.level2Select = $(this.id + '_level2_block').select('select').first();
24
+ }
25
+
26
+ this.options = options;
27
+ },
28
+
29
+ optionChanged: function (el) {
30
+ if (Object.isUndefined(el)) {
31
+ return;
32
+ }
33
+
34
+ var mainValue = this.mainSelect.options[this.mainSelect.selectedIndex].value;
35
+
36
+ if (this.isLevel2(el)) {
37
+ return;
38
+ } else if (this.isLevel1(el)) {
39
+ if (!this.hasLevel2()) {
40
+ return;
41
+ }
42
+
43
+ this.hideLevel2();
44
+
45
+ var level1Value = this.level1Select.options[this.level1Select.selectedIndex].value;
46
+ if (level1Value == '') {
47
+ return;
48
+ }
49
+
50
+ var level2Options = [];
51
+ for (var i = 0; i < this.options.length; i++) {
52
+ if (this.options[i].value == mainValue) {
53
+ var level1Options = this.options[i].children;
54
+ for (var j = 0; j < level1Options.length; j++) {
55
+ if (level1Options[j].value == level1Value) {
56
+ level2Options = level1Options[j].children;
57
+ break;
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ }
63
+
64
+ if (level2Options.length > 0) {
65
+ this.showLevel2(level2Options);
66
+ }
67
+
68
+
69
+ } else {
70
+ this.hideLevel1();
71
+ this.hideLevel2();
72
+
73
+ if (mainValue == '') {
74
+ return;
75
+ }
76
+
77
+ var level1Options = [];
78
+ for (var i = 0; i < this.options.length; i++) {
79
+ if (this.options[i].value == mainValue) {
80
+ level1Options = this.options[i].children;
81
+ break;
82
+ }
83
+ }
84
+
85
+ if (level1Options.length > 0) {
86
+ this.showLevel1(level1Options);
87
+ }
88
+ }
89
+ },
90
+
91
+ isMain: function (el) {
92
+ return el.id == this.id;
93
+ },
94
+
95
+ isLevel1: function (el) {
96
+ return el.id == this.level1Select.id;
97
+ },
98
+
99
+ isLevel2: function (el) {
100
+ return this.hasLevel2() && el.id == this.level2Select.id;
101
+ },
102
+
103
+ hasLevel2: function () {
104
+ return Object.isElement(this.level2block);
105
+ },
106
+
107
+ showLevel1: function (level1options) {
108
+ for (var i = 0; i < level1options.length; i++) {
109
+ this.level1Select.insert('<option value="' + level1options[i].value + '">' + level1options[i].label + '</option>');
110
+ }
111
+
112
+ this.level1Select.selectedIndex = 0;
113
+ this.level1Select.className = this.mainSelect.className;
114
+
115
+ this.level1block.show();
116
+ },
117
+
118
+ hideLevel1: function () {
119
+ this.level1block.hide();
120
+
121
+ this.level1Select.select('option').each(Element.remove);
122
+ this.level1Select.className = '';
123
+ },
124
+
125
+ showLevel2: function (level2options) {
126
+ if (!this.hasLevel2()) {
127
+ return;
128
+ }
129
+
130
+ for (var i = 0; i < level2options.length; i++) {
131
+ this.level2Select.insert('<option value="' + level2options[i].value + '">' + level2options[i].label + '</option>');
132
+ }
133
+
134
+ this.level2Select.selectedIndex = 0;
135
+ this.level2Select.className = this.mainSelect.className;
136
+
137
+ this.level2block.show();
138
+ },
139
+
140
+ hideLevel2: function () {
141
+ if (!this.hasLevel2()) {
142
+ return;
143
+ }
144
+
145
+ this.level2block.hide();
146
+
147
+ this.level2Select.select('option').each(Element.remove);
148
+ this.level2Select.className = '';
149
+ }
150
+ };
151
+
152
+ Freshdesk.Account = Class.create();
153
+ Freshdesk.Account.prototype = {
154
+ label: '',
155
+ path: '',
156
+ position: 0,
157
+
158
+ initialize: function (label, path, position) {
159
+ this.label = label;
160
+ this.path = path;
161
+ this.position = position;
162
+ },
163
+
164
+ process: function () {
165
+ if (!this.label && !this.path) {
166
+ return;
167
+ }
168
+
169
+ var removed = false;
170
+ var arrMenuLi = $$('.sidebar .block-account ul li');
171
+ if (Object.isArray(arrMenuLi) && arrMenuLi.length > 0 && this.position <= arrMenuLi.length) {
172
+ var freshdeskLink = $$('.sidebar ul a[href*="' + this.path + '"]').first();
173
+ if (Object.isElement(freshdeskLink)) {
174
+ freshdeskLink.up().removeClassName('last');
175
+ arrMenuLi[this.position].insert({before: freshdeskLink.up()});
176
+ removed = true;
177
+ } else {
178
+ arrMenuLi.each(function (el, index) {
179
+ el.childElements().each(function (chEl, index) {
180
+ if (chEl.innerHTML == this.label) {
181
+ el.removeClassName('last');
182
+ arrMenuLi[this.position].insert({before: el});
183
+ removed = true;
184
+ throw $break;
185
+ }
186
+ }.bind(this));
187
+
188
+ if (removed) {
189
+ throw $break;
190
+ }
191
+ }.bind(this));
192
+ }
193
+ }
194
+
195
+ if(removed) {
196
+ $$('.sidebar .block-account ul li').last().addClassName('last');
197
+ }
198
+ }
199
+ };
200
+
201
+ Freshdesk.Account.Ticket = {};
202
+ Freshdesk.Account.Ticket.Recent = Class.create();
203
+ Freshdesk.Account.Ticket.Recent.prototype = {
204
+ pairs: [],
205
+
206
+ initialize: function () {
207
+ },
208
+
209
+ add: function (parentClass, childClass, altParentClass) {
210
+ if ((!Object.isString(parentClass) && !Object.isString(altParentClass)) || !Object.isString(childClass)) {
211
+ return this;
212
+ }
213
+
214
+ this.pairs.push({'parent': parentClass, 'child': childClass, 'altParent': altParentClass, 'skip': false});
215
+
216
+ return this;
217
+ },
218
+
219
+ process: function () {
220
+ if (this.pairs.length < 1) {
221
+ return;
222
+ }
223
+
224
+ var parent, child, altParent;
225
+ for (var i = 0; i < this.pairs.length; i++) {
226
+ if (this.pairs[i].skip) {
227
+ continue;
228
+ }
229
+
230
+ parent = $$(this.pairs[i].parent).first();
231
+ child = $$(this.pairs[i].child).first();
232
+ altParent = $$(this.pairs[i].altParent).first();
233
+ if ((Object.isElement(parent) || Object.isElement(altParent)) && Object.isElement(child)) {
234
+ if (Object.isElement(parent)) {
235
+ parent.insert({after: child});
236
+ } else {
237
+ altParent.insert({after: child});
238
+ }
239
+
240
+ this.pairs[i].skip = true;
241
+ }
242
+ }
243
+ }
244
+ };
245
+
246
+ Freshdesk.Account.Ticket.View = {};
247
+ Freshdesk.Account.Ticket.View.Reply = Class.create();
248
+ Freshdesk.Account.Ticket.View.Reply.prototype = {
249
+ id: undefined,
250
+ replyButtonId: undefined,
251
+ sendButtonId: undefined,
252
+ sendButtonDisabled: false,
253
+ text: '',
254
+ className: '',
255
+ sendUrl: undefined,
256
+ tag: undefined,
257
+
258
+
259
+ initialize: function (id, replyId, sendId, text, className, url, messageTag) {
260
+ this.id = id;
261
+ this.replyButtonId = replyId;
262
+ this.sendButtonId = sendId;
263
+ this.sendUrl = url;
264
+ this.text = text;
265
+ this.className = className;
266
+ this.tag = messageTag;
267
+
268
+ $(this.replyButtonId).observe('click', this.reply.bind(this));
269
+ $(this.sendButtonId).observe('click', this.send.bind(this));
270
+ $(this.id).observe('focus', this.focus.bind(this));
271
+ $(this.id).observe('blur', this.blur.bind(this));
272
+ },
273
+
274
+ reply: function () {
275
+ $(this.id).scrollTo();
276
+ $(this.id).focus();
277
+ },
278
+
279
+ send: function () {
280
+ if (this.sendButtonDisabled) {
281
+ return;
282
+ }
283
+
284
+ var message = $(this.id).value;
285
+ if ('' == message || message == this.text) {
286
+ this.reply();
287
+ return;
288
+ }
289
+
290
+ this.sendButtonDisabled = true;
291
+ $(this.id).disabled = true;
292
+ $(this.sendButtonId).addClassName('disabled');
293
+ location.href = this.sendUrl.replace(this.tag, message);
294
+ },
295
+
296
+ focus: function () {
297
+ if ($(this.id).value == this.text) {
298
+ $(this.id).value = '';
299
+ }
300
+
301
+ $(this.id).removeClassName(this.className);
302
+ },
303
+
304
+ blur: function () {
305
+ if ($(this.id).value == '') {
306
+ $(this.id).value = this.text;
307
+ }
308
+
309
+ $(this.id).addClassName(this.className);
310
+ }
311
+ };
312
+
313
+ var fdAccountTicketRecent = new Freshdesk.Account.Ticket.Recent();
314
+ Event.observe(window, 'load', function () {
315
+ fdAccountTicketRecent.process();
316
+ });