Celebros_Salesperson_Site_Search - Version 2.0.0

Version Notes

Operation of this extension requires subscription to Celebros SaS search solution.

Download this release

Release Info

Developer Magento Core Team
Extension Celebros_Salesperson_Site_Search
Version 2.0.0
Comparing to
See all releases


Version 2.0.0

Files changed (80) hide show
  1. app/code/local/Celebros/Salesperson/Block/Adminhtml/Mapping.php +30 -0
  2. app/code/local/Celebros/Salesperson/Block/Layer.php +58 -0
  3. app/code/local/Celebros/Salesperson/Block/Layer/State.php +107 -0
  4. app/code/local/Celebros/Salesperson/Block/Layer/View.php +183 -0
  5. app/code/local/Celebros/Salesperson/Block/Product/Abstract.php +440 -0
  6. app/code/local/Celebros/Salesperson/Block/Product/List.php +137 -0
  7. app/code/local/Celebros/Salesperson/Block/Product/List/Toolbar.php +909 -0
  8. app/code/local/Celebros/Salesperson/Block/Product/List/Toolbar/Pager.php +559 -0
  9. app/code/local/Celebros/Salesperson/Block/Result.php +265 -0
  10. app/code/local/Celebros/Salesperson/Block/Review/Helper.php +52 -0
  11. app/code/local/Celebros/Salesperson/Block/System/Convert/Profile/Edit/Tab/Run.php +59 -0
  12. app/code/local/Celebros/Salesperson/Helper/Checkout/Cart.php +46 -0
  13. app/code/local/Celebros/Salesperson/Helper/Data.php +380 -0
  14. app/code/local/Celebros/Salesperson/Helper/Mapping.php +29 -0
  15. app/code/local/Celebros/Salesperson/Helper/Product/Compare.php +40 -0
  16. app/code/local/Celebros/Salesperson/Helper/Wishlist/Data.php +58 -0
  17. app/code/local/Celebros/Salesperson/Model/Api/Anlx/AnalyticsFunctions.php +355 -0
  18. app/code/local/Celebros/Salesperson/Model/Api/Anlx/DataStructure.php +58 -0
  19. app/code/local/Celebros/Salesperson/Model/Api/Anlx/DynamicProperty.php +179 -0
  20. app/code/local/Celebros/Salesperson/Model/Api/Anlx/Holders.php +225 -0
  21. app/code/local/Celebros/Salesperson/Model/Api/Anlx/LogRequest.php +637 -0
  22. app/code/local/Celebros/Salesperson/Model/Api/Anlx/RunLogReq.php +28 -0
  23. app/code/local/Celebros/Salesperson/Model/Api/Anlx/StringEncoder.php +42 -0
  24. app/code/local/Celebros/Salesperson/Model/Api/Anlx/ValidateResult.php +69 -0
  25. app/code/local/Celebros/Salesperson/Model/Api/Anlx/packetizer.php +53 -0
  26. app/code/local/Celebros/Salesperson/Model/Api/QwiserAnswer.php +30 -0
  27. app/code/local/Celebros/Salesperson/Model/Api/QwiserAnswers.php +92 -0
  28. app/code/local/Celebros/Salesperson/Model/Api/QwiserConcept.php +22 -0
  29. app/code/local/Celebros/Salesperson/Model/Api/QwiserConcepts.php +24 -0
  30. app/code/local/Celebros/Salesperson/Model/Api/QwiserProduct.php +44 -0
  31. app/code/local/Celebros/Salesperson/Model/Api/QwiserProductAnswer.php +21 -0
  32. app/code/local/Celebros/Salesperson/Model/Api/QwiserProductAnswers.php +22 -0
  33. app/code/local/Celebros/Salesperson/Model/Api/QwiserProductField.php +17 -0
  34. app/code/local/Celebros/Salesperson/Model/Api/QwiserProductFields.php +23 -0
  35. app/code/local/Celebros/Salesperson/Model/Api/QwiserProducts.php +27 -0
  36. app/code/local/Celebros/Salesperson/Model/Api/QwiserQuestion.php +30 -0
  37. app/code/local/Celebros/Salesperson/Model/Api/QwiserQuestions.php +91 -0
  38. app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchPath.php +23 -0
  39. app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchPathEntry.php +18 -0
  40. app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchResults.php +111 -0
  41. app/code/local/Celebros/Salesperson/Model/Api/QwiserSpellerInformation.php +18 -0
  42. app/code/local/Celebros/Salesperson/Model/Api/SearchInformation.php +44 -0
  43. app/code/local/Celebros/Salesperson/Model/Api/SortingOptions.php +20 -0
  44. app/code/local/Celebros/Salesperson/Model/Api/domxml-php4-to-php5.php +316 -0
  45. app/code/local/Celebros/Salesperson/Model/Convert/Adapter/Io.php +157 -0
  46. app/code/local/Celebros/Salesperson/Model/Convert/Mapper/Column.php +175 -0
  47. app/code/local/Celebros/Salesperson/Model/Convert/Parser/Csv.php +287 -0
  48. app/code/local/Celebros/Salesperson/Model/Convert/Parser/Product.php +218 -0
  49. app/code/local/Celebros/Salesperson/Model/Layer.php +65 -0
  50. app/code/local/Celebros/Salesperson/Model/Layer/State.php +66 -0
  51. app/code/local/Celebros/Salesperson/Model/Layout.php +129 -0
  52. app/code/local/Celebros/Salesperson/Model/Mapping.php +32 -0
  53. app/code/local/Celebros/Salesperson/Model/Mysql4/Mapping.php +7 -0
  54. app/code/local/Celebros/Salesperson/Model/Mysql4/Mapping/Collection.php +8 -0
  55. app/code/local/Celebros/Salesperson/Model/Mysql4/Qwiser.php +31 -0
  56. app/code/local/Celebros/Salesperson/Model/Observer.php +1065 -0
  57. app/code/local/Celebros/Salesperson/Model/Product.php +216 -0
  58. app/code/local/Celebros/Salesperson/Model/SalespersonAnalyticsApi.php +118 -0
  59. app/code/local/Celebros/Salesperson/Model/SalespersonSearchApi.php +567 -0
  60. app/code/local/Celebros/Salesperson/Model/Session.php +22 -0
  61. app/code/local/Celebros/Salesperson/Model/System/Config/Backend/Export/Cron.php +42 -0
  62. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Fileftp.php +19 -0
  63. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Layouts.php +26 -0
  64. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Lead.php +19 -0
  65. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Nonlead.php +20 -0
  66. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Pagenavtype.php +19 -0
  67. app/code/local/Celebros/Salesperson/Model/System/Config/Source/Selectortype.php +19 -0
  68. app/code/local/Celebros/Salesperson/Model/createZip.php +181 -0
  69. app/code/local/Celebros/Salesperson/controllers/Adminhtml/MappingController.php +40 -0
  70. app/code/local/Celebros/Salesperson/controllers/ExportController.php +426 -0
  71. app/code/local/Celebros/Salesperson/controllers/IndexController.php +11 -0
  72. app/code/local/Celebros/Salesperson/controllers/ResultController.php +376 -0
  73. app/code/local/Celebros/Salesperson/etc/config.xml +258 -0
  74. app/code/local/Celebros/Salesperson/etc/system.xml +389 -0
  75. app/code/local/Celebros/Salesperson/sql/salesperson_setup/mysql4-install-0.1.0.php +74 -0
  76. app/code/local/Celebros/Salesperson/sql/salesperson_setup/mysql4-upgrade-0.1.0-0.1.1.php +45 -0
  77. app/design/adminhtml/default/default/layout/salesperson.xml +9 -0
  78. app/design/adminhtml/default/default/template/salesperson/mapping.phtml +31 -0
  79. app/etc/modules/Celebros_Salesperson.xml +19 -0
  80. package.xml +18 -0
app/code/local/Celebros/Salesperson/Block/Adminhtml/Mapping.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Celebros_Salesperson_Block_Adminhtml_Mapping extends Mage_Core_Block_Template{
4
+
5
+ private $_fieldsCollection;
6
+
7
+ /**
8
+ * Load fields collection
9
+ *
10
+ * @return Celebros_Salesperson_Model_Mysql4_Mapping_Collection
11
+ */
12
+ protected function _loadFieldsCollection(){
13
+ if(!$this->_fieldsCollection){
14
+ $this->_fieldsCollection = Mage::getSingleton("salesperson/mapping")->getCollection();
15
+ }
16
+ return $this->_fieldsCollection;
17
+ }
18
+
19
+ /**
20
+ * Get fields collection
21
+ *
22
+ * @return Celebros_Salesperson_Model_Mysql4_Mapping_Collection
23
+ *
24
+ */
25
+ public function getFields(){
26
+ $this->_loadFieldsCollection();
27
+
28
+ return $this->_fieldsCollection;
29
+ }
30
+ }
app/code/local/Celebros/Salesperson/Block/Layer.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Layer extends Mage_Catalog_Block_Layer_View
11
+ {
12
+ /**
13
+ * Retrieve salesperson search results object
14
+ *
15
+ * @return Celebros_Salesperson_Model_Api_QwiserSearchResults
16
+ */
17
+ protected function getQwiserSearchResults(){
18
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
19
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
20
+ }
21
+
22
+ /**
23
+ * Retrieve relevant products count
24
+ *
25
+ * @return string
26
+ */
27
+ public function getResultCount()
28
+ {
29
+ return $this->getQwiserSearchResults()->GetRelevantProductsCount();
30
+ }
31
+
32
+ /**
33
+ * Get layer object
34
+ *
35
+ * @return Mage_Catalog_Model_Layer
36
+ */
37
+ public function getLayer()
38
+ {
39
+ return Mage::getModel('salesperson/layer');
40
+ }
41
+
42
+ /**
43
+ * Check availability display layer block
44
+ *
45
+ * @return bool
46
+ */
47
+ public function canShowBlock()
48
+ {
49
+ $availableResCount = (int) Mage::app()->getStore()
50
+ ->getConfig(Mage_CatalogSearch_Model_Layer::XML_PATH_DISPLAY_LAYER_COUNT );
51
+
52
+ if (!$availableResCount
53
+ || ($availableResCount>=$this->getResultCount())) {
54
+ return parent::canShowBlock();
55
+ }
56
+ return false;
57
+ }
58
+ }
app/code/local/Celebros/Salesperson/Block/Layer/State.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Celebros Qwiser - Magento Extension
5
+ *
6
+ * @category Celebros
7
+ * @package Celebros_Salesperson
8
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
9
+ *
10
+ */
11
+
12
+ class Celebros_Salesperson_Block_Layer_State extends Mage_Core_Block_Template
13
+ {
14
+ protected function getQwiserSearchResults(){
15
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
16
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
17
+ }
18
+ /**
19
+ * Initialize Layer State template
20
+ *
21
+ */
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+ $this->setTemplate('salesperson/layer/state.phtml');
26
+ }
27
+
28
+ /**
29
+ * Retrieve active filters
30
+ *
31
+ * @return array
32
+ */
33
+ public function getActiveFilters()
34
+ {
35
+ $filters = $this->getLayer()->getState()->getFilters();
36
+ if (!is_array($filters)) {
37
+ $filters = array();
38
+ }
39
+ return $filters;
40
+ }
41
+
42
+ /**
43
+ * Retrieve Layer object
44
+ *
45
+ * @return Celebros_Salesperson_Model_Layer
46
+ */
47
+ public function getLayer()
48
+ {
49
+ if (!$this->hasData('layer')) {
50
+ $this->setLayer(Mage::getSingleton('salesperson/layer'));
51
+ }
52
+ return $this->_getData('layer');
53
+ }
54
+
55
+ public function getStateRemoveUrl($answerId){
56
+ $params['_current'] = true;
57
+ $params['_use_rewrite'] = true;
58
+ $params['_escape'] = true;
59
+ $params['_query'] = array(
60
+ 'salespersonaction' => 'removeAnswer',
61
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
62
+ 'answerId' => $answerId,
63
+ );
64
+ $url = Mage::getUrl('*/*/change', $params);
65
+ $page = (int)$this->getQwiserSearchResults()->SearchInformation->CurrentPage+1;
66
+ $url = preg_replace("/p=*\d/",'p='.$page, $url);
67
+ return $url;
68
+ }
69
+ public function getClearAllFiltersUrl(){
70
+ $filters = $this->getLayer()->getState()->getFilters();
71
+ $answersIds = array();
72
+ if(!empty($filters)){
73
+ foreach($filters as $filter){
74
+ $answersIds[] = $filter['answers']->Items[0]->Id;
75
+ }
76
+ }
77
+ $answersIds = join(',', $answersIds);
78
+ $params['_current'] = true;
79
+ $params['_use_rewrite'] = true;
80
+ $params['_escape'] = true;
81
+ $params['_query'] = array(
82
+ 'salespersonaction' => 'removeAllAnswers',
83
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
84
+ 'answerIds' => $answersIds,
85
+ );
86
+ $url = Mage::getUrl('*/*/change', $params);
87
+ $page = (int)$this->getQwiserSearchResults()->SearchInformation->CurrentPage+1;
88
+ $url = preg_replace("/p=*\d/",'p='.$page, $url);
89
+ return $url;
90
+ }
91
+
92
+ public function getRemoveAnswersFromBredcrumbsUrl($answersIds){
93
+ $answersIds = join(',', $answersIds);
94
+ $params['_current'] = true;
95
+ $params['_use_rewrite'] = true;
96
+ $params['_escape'] = true;
97
+ $params['_query'] = array(
98
+ 'salespersonaction' => 'removeAllAnswers',
99
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
100
+ 'answerIds' => $answersIds,
101
+ );
102
+ $url = Mage::getUrl('*/*/change', $params);
103
+ $page = (int)$this->getQwiserSearchResults()->SearchInformation->CurrentPage+1;
104
+ $url = preg_replace("/p=*\d/",'p='.$page, $url);
105
+ return $url;
106
+ }
107
+ }
app/code/local/Celebros/Salesperson/Block/Layer/View.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_salesperson_Block_Layer_View extends Mage_Core_Block_Template
11
+ {
12
+ protected function getQwiserSearchResults(){
13
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
14
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
15
+ }
16
+ /**
17
+
18
+ /**
19
+ * Prepare child blocks
20
+ *
21
+ * @return Celebros_Salesperson_Block_Layer_View
22
+ */
23
+ protected function _prepareLayout()
24
+ {
25
+ $stateBlock = $this->getLayout()->createBlock('salesperson/layer_state')
26
+ ->setLayer($this->getLayer());
27
+ $this->setChild('layer_state', $stateBlock);
28
+
29
+ return parent::_prepareLayout();
30
+ }
31
+
32
+ /**
33
+ * Get layer object
34
+ *
35
+ * @return Celebros_Salesperson_Model_Layer
36
+ */
37
+ public function getLayer()
38
+ {
39
+ return Mage::getSingleton('salesperson/layer');
40
+ }
41
+
42
+ /**
43
+ * Get layered navigation state html
44
+ *
45
+ * @return string
46
+ */
47
+ public function getStateHtml()
48
+ {
49
+ return $this->getChildHtml('layer_state');
50
+ }
51
+
52
+ /**
53
+ * Get all layer filters
54
+ *
55
+ * @return array
56
+ */
57
+ public function getFilters()
58
+ {
59
+ $questions = $this->getQwiserSearchResults()->Questions->GetAllQuestions();
60
+
61
+ $filters = array();
62
+ if ($questions){
63
+ foreach($questions as $question){
64
+ $filters[] = $question;
65
+ }
66
+ }
67
+
68
+ return $filters;
69
+ }
70
+
71
+ public function answerQuestionUrl($answerId){
72
+ $urlParams = array();
73
+ $urlParams['_current'] = true;
74
+ $urlParams['_escape'] = true;
75
+ $urlParams['_use_rewrite'] = true;
76
+ $urlParams['_query'] = array(
77
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
78
+ 'salespersonaction' => 'answerQuestion',
79
+ 'answerId' => $answerId,
80
+ );
81
+ $url = Mage::getUrl('*/*/change', $urlParams);
82
+ if (preg_match("/p=*\d/", $url)){
83
+ $url = preg_replace("/p=*\d/",'p=1', $url);
84
+ }
85
+ else {
86
+ $url .= "&p=1";
87
+ }
88
+ return $url;
89
+ }
90
+
91
+ public function getFilterText($filter,$type){
92
+ if ($type == "nonlead" && Mage::Helper('salesperson')->getNonLeadQuestionsPosition() != 'top'){
93
+ return $filter->SideText;
94
+ }
95
+ elseif ($type == "lead"){
96
+ return $filter->SideText;
97
+ }
98
+ return $filter->Text;
99
+ }
100
+
101
+ public function getMaxLeadAnswers(){
102
+ return Mage::getStoreConfig('salesperson/display_settings/max_lead_answers');
103
+ }
104
+
105
+ public function getMaxNonLeadAnswers(){
106
+ if (Mage::Helper('salesperson')->getNonLeadQuestionsPosition() == 'left' || Mage::Helper('salesperson')->getNonLeadQuestionsPosition() == 'right'){
107
+ return Mage::getStoreConfig('salesperson/display_settings/max_non_lead_answers_side_nav');
108
+ }
109
+ return Mage::getStoreConfig('salesperson/display_settings/max_non_lead_answers');
110
+ }
111
+
112
+ public function getMaxNonLeadQuestions(){
113
+ return Mage::getStoreConfig('salesperson/display_settings/max_non_lead_questions');
114
+ }
115
+
116
+ public function showProductCountInLeadAnswers(){
117
+ return Mage::getStoreConfigFlag('salesperson/display_settings/show_product_count_in_lead_answers');
118
+ }
119
+
120
+ public function showProductCountInNonLeadAnswers(){
121
+ return Mage::getStoreConfigFlag('salesperson/display_settings/show_product_count_in_non_lead_answers');
122
+ }
123
+
124
+
125
+
126
+ /**
127
+ * Check availability display layer block
128
+ *
129
+ * @return bool
130
+ */
131
+ public function canShowNoneLeadSideBlock()
132
+ {
133
+ return Mage::Helper('salesperson')->getNonLeadQuestionsPosition() == 'left' || Mage::Helper('salesperson')->getNonLeadQuestionsPosition() == 'right';
134
+ }
135
+
136
+ public function canShowLeadQuestion(){
137
+ return Mage::getStoreConfigFlag('salesperson/display_settings/display_lead');
138
+ }
139
+
140
+ public function forceLeadQuestion($questionId){
141
+ $urlParams = array();
142
+ $urlParams['_current'] = true;
143
+ $urlParams['_escape'] = true;
144
+ $urlParams['_use_rewrite'] = true;
145
+ $urlParams['_query'] = array(
146
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
147
+ 'salespersonaction' => 'forceQuestion',
148
+ 'questionId' => $questionId,
149
+ );
150
+ return Mage::getUrl('*/*/change', $urlParams);
151
+ }
152
+
153
+ public function stateHasFilters(){
154
+ return count($this->getLayer()->getState()->getFilters()) > 0;
155
+ }
156
+
157
+ public function getCustomPriceAnswerUrl(){
158
+ $urlParams = array();
159
+ $urlParams['_current'] = true;
160
+ $urlParams['_escape'] = false;
161
+ $urlParams['_use_rewrite'] = true;
162
+ $urlParams['_query'] = array(
163
+ 'searchHandle' => $this->getQwiserSearchResults()->GetSearchHandle(),
164
+ 'salespersonaction' => 'answerQuestion',
165
+ );
166
+ $url = Mage::getUrl('*/*/change', $urlParams);
167
+ if(strpos($url, "answerId=")){
168
+ $replace_string = substr($url,strpos($url, "answerId="),strpos($url, '&',strpos($url, "answerId=")) - strpos($url, "answerId="));
169
+ $url = str_replace($replace_string, '', $url);
170
+ }
171
+ if (preg_match("/p=*\d/", $url)){
172
+ $url = preg_replace("/p=*\d/",'p=1', $url);
173
+ }
174
+ else {
175
+ $url .= "&p=1";
176
+ }
177
+ return $url;
178
+ }
179
+
180
+ public function getDisplayImageInLeadQuestion(){
181
+ return Mage::getStoreConfigFlag('salesperson/display_settings/display_image_lead_question');
182
+ }
183
+ }
app/code/local/Celebros/Salesperson/Block/Product/Abstract.php ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ abstract class Celebros_Salesperson_Block_Product_Abstract extends Mage_Core_Block_Template
11
+ {
12
+ protected $_priceBlock = array();
13
+ protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
14
+ protected $_tierPriceDefaultTemplate = 'catalog/product/view/tierprices.phtml';
15
+ protected $_priceBlockTypes = array();
16
+ /**
17
+ * Flag which allow/disallow to use link for as low as price
18
+ *
19
+ * @var bool
20
+ */
21
+ protected $_useLinkForAsLowAs = true;
22
+
23
+ protected $_reviewsHelperBlock;
24
+
25
+ /**
26
+ * Default product amount per row
27
+ *
28
+ * @var int
29
+ */
30
+ protected $_defaultColumnCount = 3;
31
+
32
+ /**
33
+ * Product amount per row depending on custom page layout of category
34
+ *
35
+ * @var array
36
+ */
37
+ protected $_columnCountLayoutDepend = array();
38
+
39
+
40
+ /**
41
+ * Retrieve url for add product to cart
42
+ * Will return product view page URL if product has required options
43
+ *
44
+ * @param Celebros_Salesperson_Model_Product $product
45
+ * @param array $additional
46
+ * @return string
47
+ */
48
+ public function getAddToCartUrl($product, $additional = array())
49
+ {
50
+ return $this->helper('salesperson/checkout_cart')->getAddUrl($product, $additional);
51
+ }
52
+
53
+ /**
54
+ * Retrieve url for add product to wishlist
55
+ *
56
+ * @param Celebros_Salesperson_Model_Product $product
57
+ * @return string
58
+ */
59
+ public function getAddToWishlistUrl($product)
60
+ {
61
+ return $this->helper('salesperson/wishlist')->getAddUrl($product);
62
+ }
63
+
64
+ /**
65
+ * Retrieve Add Product to Compare Products List URL
66
+ *
67
+ * @param Celebros_Salesperson_Model_Product $product
68
+ * @return string
69
+ */
70
+ public function getAddToCompareUrl($product)
71
+ {
72
+ return $this->helper('salesperson/product_compare')->getAddUrl($product);
73
+ }
74
+
75
+
76
+ protected function _getPriceBlock($productTypeId)
77
+ {
78
+ if (!isset($this->_priceBlock[$productTypeId])) {
79
+ $block = 'catalog/product_price';
80
+ if (isset($this->_priceBlockTypes[$productTypeId])) {
81
+ if ($this->_priceBlockTypes[$productTypeId]['block'] != '') {
82
+ $block = $this->_priceBlockTypes[$productTypeId]['block'];
83
+ }
84
+ }
85
+ $this->_priceBlock[$productTypeId] = $this->getLayout()->createBlock($block);
86
+ }
87
+ return $this->_priceBlock[$productTypeId];
88
+ }
89
+
90
+ protected function _getPriceBlockTemplate($productTypeId)
91
+ {
92
+ if (isset($this->_priceBlockTypes[$productTypeId])) {
93
+ if ($this->_priceBlockTypes[$productTypeId]['template'] != '') {
94
+ return $this->_priceBlockTypes[$productTypeId]['template'];
95
+ }
96
+ }
97
+ return $this->_priceBlockDefaultTemplate;
98
+ }
99
+
100
+ /**
101
+ * Returns product price block html
102
+ *
103
+ * @param Mage_Catalog_Model_Product $product
104
+ * @param boolean $displayMinimalPrice
105
+ */
106
+ public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix='')
107
+ {
108
+ if(key_exists($this->getMapping('id'), $product->Field)){
109
+ //Load the product from magento database in order to get the correct price block
110
+ $realProduct = Mage::getModel('catalog/product')->load($product->Field[$this->getMapping('id')]);
111
+
112
+ return $this->_getPriceBlock($realProduct->getTypeId())
113
+ ->setTemplate($this->_getPriceBlockTemplate($realProduct->getTypeId()))
114
+ ->setProduct($realProduct)
115
+ ->setDisplayMinimalPrice($displayMinimalPrice)
116
+ ->setIdSuffix($idSuffix)
117
+ ->setUseLinkForAsLowAs($this->_useLinkForAsLowAs)
118
+ ->toHtml();
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Adding customized price template for product type
124
+ *
125
+ * @param string $type
126
+ * @param string $block
127
+ * @param string $template
128
+ */
129
+ public function addPriceBlockType($type, $block = '', $template = '')
130
+ {
131
+ if ($type) {
132
+ $this->_priceBlockTypes[$type] = array(
133
+ 'block' => $block,
134
+ 'template' => $template
135
+ );
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Get product reviews summary
141
+ *
142
+ * @param Mage_Catalog_Model_Product $product
143
+ * @param bool $templateType
144
+ * @param bool $displayIfNoReviews
145
+ * @return string
146
+ */
147
+ public function getReviewsSummaryHtml($product, $templateType = false, $displayIfNoReviews = false)
148
+ {
149
+ $this->_initReviewsHelperBlock();
150
+ return $this->_reviewsHelperBlock->getSummaryHtml($product, $templateType, $displayIfNoReviews);
151
+ }
152
+
153
+ /**
154
+ * Add/replace reviews summary template by type
155
+ *
156
+ * @param string $type
157
+ * @param string $template
158
+ */
159
+ public function addReviewSummaryTemplate($type, $template)
160
+ {
161
+ $this->_initReviewsHelperBlock();
162
+ $this->_reviewsHelperBlock->addTemplate($type, $template);
163
+ }
164
+
165
+ /**
166
+ * Create reviews summary helper block once
167
+ *
168
+ */
169
+ protected function _initReviewsHelperBlock()
170
+ {
171
+ if (!$this->_reviewsHelperBlock) {
172
+ $this->_reviewsHelperBlock = $this->getLayout()->createBlock('salesperson/review_helper');
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Retrieve currently viewed product object
178
+ *
179
+ * @return Mage_Catalog_Model_Product
180
+ */
181
+ public function getProduct()
182
+ {
183
+ if (!$this->hasData('product')) {
184
+ $this->setData('product', Mage::registry('product'));
185
+ }
186
+ return $this->getData('product');
187
+ }
188
+
189
+ public function getTierPriceTemplate()
190
+ {
191
+ if (!$this->hasData('tier_price_template')) {
192
+ return $this->_tierPriceDefaultTemplate;
193
+ }
194
+
195
+ return $this->getData('tier_price_template');
196
+ }
197
+ /**
198
+ * Returns product tierprice block html
199
+ *
200
+ * @param Mage_Catalog_Model_Product $product
201
+ */
202
+ public function getTierPriceHtml($product = null)
203
+ {
204
+ if (is_null($product)) {
205
+ $product = $this->getProduct();
206
+ }
207
+ return $this->_getPriceBlock($product->getTypeId())
208
+ ->setTemplate($this->getTierPriceTemplate())
209
+ ->setProduct($product)
210
+ ->setInGrouped($this->getProduct()->isGrouped())
211
+ ->toHtml();
212
+ }
213
+
214
+ /**
215
+ * Get tier prices (formatted)
216
+ *
217
+ * @param Mage_Catalog_Model_Product $product
218
+ * @return array
219
+ */
220
+ public function getTierPrices($product = null)
221
+ {
222
+ if (is_null($product)) {
223
+ $product = $this->getProduct();
224
+ }
225
+ $prices = $product->getFormatedTierPrice();
226
+
227
+ $res = array();
228
+ if (is_array($prices)) {
229
+ foreach ($prices as $price) {
230
+ $price['price_qty'] = $price['price_qty']*1;
231
+ if ($product->getPrice() != $product->getFinalPrice()) {
232
+ if ($price['price']<$product->getFinalPrice()) {
233
+ $price['savePercent'] = ceil(100 - (( 100/$product->getFinalPrice() ) * $price['price'] ));
234
+ $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])));
235
+ $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)));
236
+ $res[] = $price;
237
+ }
238
+ }
239
+ else {
240
+ if ($price['price']<$product->getPrice()) {
241
+ $price['savePercent'] = ceil(100 - (( 100/$product->getPrice() ) * $price['price'] ));
242
+ $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'])));
243
+ $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true)));
244
+ $res[] = $price;
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ return $res;
251
+ }
252
+
253
+ /**
254
+ * Add all attributes and apply pricing logic to products collection
255
+ * to get correct values in different products lists.
256
+ * E.g. crosssells, upsells, new products, recently viewed
257
+ *
258
+ * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
259
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
260
+ */
261
+ protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection)
262
+ {
263
+ return $collection
264
+ ->addMinimalPrice()
265
+ ->addFinalPrice()
266
+ ->addTaxPercents()
267
+ ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
268
+ }
269
+
270
+ /**
271
+ * Retrieve given media attribute label or product name if no label
272
+ *
273
+ * @param Mage_Catalog_Model_Product $product
274
+ * @param string $mediaAttributeCode
275
+ *
276
+ * @return string
277
+ */
278
+ public function getImageLabel($product=null, $mediaAttributeCode='image')
279
+ {
280
+ if (is_null($product)) {
281
+ $product = $this->getProduct();
282
+ }
283
+
284
+ $label = $product->getData($mediaAttributeCode.'_label');
285
+ if (empty($label)) {
286
+ $label = $product->getName();
287
+ }
288
+
289
+ return $label;
290
+ }
291
+
292
+ public function getMapping($code_field = ""){
293
+ return $this->helper('salesperson/mapping')->getMapping($code_field);
294
+ }
295
+
296
+ /**
297
+ * Retrieve Product URL using UrlDataObject
298
+ *
299
+ * @param Mage_Catalog_Model_Product $product
300
+ * @param array $additional the route params
301
+ * @return string
302
+ */
303
+ public function getProductUrl($product)
304
+ {
305
+ return $product->Field[$this->getMapping('link')];
306
+ }
307
+
308
+ /**
309
+ * Check Product has URL
310
+ *
311
+ * @param Mage_Catalog_Model_Product $product
312
+ * @return bool
313
+ */
314
+ public function hasProductUrl($product)
315
+ {
316
+ if ($product->getVisibleInSiteVisibilities()) {
317
+ return true;
318
+ }
319
+ if ($product->hasUrlDataObject()) {
320
+ if (in_array($product->hasUrlDataObject()->getVisibility(), $product->getVisibleInSiteVisibilities())) {
321
+ return true;
322
+ }
323
+ }
324
+
325
+ return false;
326
+ }
327
+
328
+ /**
329
+ * Retrieve product amount per row
330
+ *
331
+ * @return int
332
+ */
333
+ public function getColumnCount()
334
+ {
335
+ if (!$this->_getData('column_count')) {
336
+ $pageLayout = $this->getPageLayout();
337
+ if ($pageLayout && $this->getColumnCountLayoutDepend($pageLayout)) {
338
+ $this->setData(
339
+ 'column_count',
340
+ $this->getColumnCountLayoutDepend($pageLayout)
341
+ );
342
+ } else {
343
+ $this->setData('column_count', $this->_defaultColumnCount);
344
+ }
345
+ }
346
+
347
+ return (int)$this->_getData('column_count');
348
+ }
349
+
350
+ /**
351
+ * Add row size depends on page layout
352
+ *
353
+ * @param string $pageLayout
354
+ * @param int $rowSize
355
+ * @return Mage_Catalog_Block_Product_List
356
+ */
357
+ public function addColumnCountLayoutDepend($pageLayout, $columnCount)
358
+ {
359
+ $this->_columnCountLayoutDepend[$pageLayout] = $columnCount;
360
+ return $this;
361
+ }
362
+
363
+ /**
364
+ * Remove row size depends on page layout
365
+ *
366
+ * @param string $pageLayout
367
+ * @return Mage_Catalog_Block_Product_List
368
+ */
369
+ public function removeColumnCountLayoutDepend($pageLayout)
370
+ {
371
+ if (isset($this->_columnCountLayoutDepend[$pageLayout])) {
372
+ unset($this->_columnCountLayoutDepend[$pageLayout]);
373
+ }
374
+
375
+ return $this;
376
+ }
377
+
378
+ /**
379
+ * Retrieve row size depends on page layout
380
+ *
381
+ * @param string $pageLayout
382
+ * @return int|boolean
383
+ */
384
+ public function getColumnCountLayoutDepend($pageLayout)
385
+ {
386
+ if (isset($this->_columnCountLayoutDepend[$pageLayout])) {
387
+ return $this->_columnCountLayoutDepend[$pageLayout];
388
+ }
389
+
390
+ return false;
391
+ }
392
+
393
+ /**
394
+ * Retrieve current page layout
395
+ *
396
+ * @return Varien_Object
397
+ */
398
+ public function getPageLayout()
399
+ {
400
+ $pageLayoutHandles = Mage::getSingleton('page/config')->getPageLayoutHandles();
401
+ $pageLayoutHandleskeys = array_keys($pageLayoutHandles);
402
+ // return false;
403
+ switch(Mage::getStoreConfig('salesperson/display_settings/layout')){
404
+ case "salesperson/1column.phtml":
405
+ return $pageLayoutHandleskeys[1];
406
+ break;
407
+ case "salesperson/2columns-left.phtml":
408
+ return $pageLayoutHandleskeys[2];
409
+ break;
410
+ case "salesperson/2columns-right.phtml":
411
+ return $pageLayoutHandleskeys[3];
412
+ break;
413
+ case "salesperson/3columns.phtml":
414
+ return $pageLayoutHandleskeys[4];
415
+ break;
416
+
417
+ }
418
+ //return $this->helper('page/layout')->getCurrentPageLayout();
419
+ }
420
+
421
+ /**
422
+ * If exists price template block, retrieve price blocks from it
423
+ *
424
+ * @return Mage_Catalog_Block_Product_Abstract
425
+ */
426
+ protected function _prepareLayout()
427
+ {
428
+ parent::_prepareLayout();
429
+
430
+ /* @var $block Mage_Catalog_Block_Product_Price_Template */
431
+ $block = $this->getLayout()->getBlock('salesperson_product_price_template');
432
+ if ($block) {
433
+ foreach ($block->getPriceBlockTypes() as $type => $priceBlock) {
434
+ $this->addPriceBlockType($type, $priceBlock['block'], $priceBlock['template']);
435
+ }
436
+ }
437
+
438
+ return $this;
439
+ }
440
+ }
app/code/local/Celebros/Salesperson/Block/Product/List.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Product_List extends Celebros_Salesperson_Block_Product_Abstract
11
+ {
12
+ /**
13
+ * Default toolbar block name
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_defaultToolbarBlock = 'salesperson/product_list_toolbar';
18
+
19
+ /**
20
+ * Product Collection
21
+ *
22
+ * @var Celebros_Salesperson_Model_Api_QwiserProducts->Items
23
+ */
24
+ protected $_productCollection;
25
+
26
+ public function getQwiserSearchResults(){
27
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
28
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
29
+ }
30
+
31
+ public function getStoreId(){
32
+ return Mage::Helper('core')->getStoreId();
33
+ }
34
+
35
+ protected function _getProductCollection()
36
+ {
37
+ if (is_null($this->_productCollection)) {
38
+ $this->_productCollection = $this->getQwiserSearchResults()->Products->Items;
39
+ }
40
+ return $this->_productCollection;
41
+ }
42
+
43
+ /**
44
+ * Retrieve search result count
45
+ *
46
+ * @return string
47
+ */
48
+ public function getResultCount()
49
+ {
50
+ return $this->getQwiserSearchResults()->GetRelevantProductsCount();
51
+ }
52
+
53
+ /**
54
+ * Retrieve loaded category collection
55
+ *
56
+ * @return Celebros_Salesperson_Model_Api_QwiserProducts
57
+ */
58
+ public function getLoadedProductCollection()
59
+ {
60
+ return $this->_getProductCollection();
61
+ }
62
+
63
+ /**
64
+ * Retrieve current view mode
65
+ *
66
+ * @return string
67
+ */
68
+ public function getMode()
69
+ {
70
+ return $this->getChild('toolbar')->getCurrentMode();
71
+ }
72
+
73
+ /**
74
+ * Need use as _prepareLayout - but problem in declaring collection from
75
+ * another block (was problem with search result)
76
+ */
77
+ protected function _beforeToHtml()
78
+ {
79
+ $toolbar = $this->getToolbarBlock();
80
+
81
+ // called prepare sortable parameters
82
+ $collection = $this->_getProductCollection();
83
+
84
+ // use sortable parameters
85
+ if ($orders = $this->getAvailableOrders()) {
86
+ $toolbar->setAvailableOrders($orders);
87
+ }
88
+ if ($sort = $this->getSortBy()) {
89
+ $toolbar->setDefaultOrder($sort);
90
+ }
91
+ if ($modes = $this->getModes()) {
92
+ $toolbar->setModes($modes);
93
+ }
94
+
95
+ // set collection to tollbar and apply sort
96
+ $toolbar->setCollection($collection);
97
+
98
+ $this->setChild('toolbar', $toolbar);
99
+
100
+ return parent::_beforeToHtml();
101
+ }
102
+
103
+ /**
104
+ * Retrieve Toolbar block
105
+ *
106
+ * @return Celebros_Salesperson_Block_Product_List_Toolbar
107
+ */
108
+ public function getToolbarBlock()
109
+ {
110
+ if ($blockName = $this->getToolbarBlockName()) {
111
+ if ($block = $this->getLayout()->getBlock($blockName)) {
112
+ return $block;
113
+ }
114
+ }
115
+ $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
116
+ return $block;
117
+ }
118
+
119
+ /**
120
+ * Retrieve list toolbar HTML
121
+ *
122
+ * @return string
123
+ */
124
+ public function getToolbarHtml()
125
+ {
126
+ return $this->getChildHtml('toolbar');
127
+ }
128
+
129
+
130
+
131
+ public function getPriceBlockTemplate()
132
+ {
133
+ return $this->_getData('price_block_template');
134
+ }
135
+
136
+
137
+ }
app/code/local/Celebros/Salesperson/Block/Product/List/Toolbar.php ADDED
@@ -0,0 +1,909 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Product_List_Toolbar extends Mage_Core_Block_Template
11
+ {
12
+ /**
13
+ * Products collection
14
+ *
15
+ * @var Mage_Core_Model_Mysql4_Collection_Abstract
16
+ */
17
+ protected $_collection = null;
18
+
19
+ /**
20
+ * GET parameter page variable
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_pageVarName = 'p';
25
+
26
+ /**
27
+ * GET parameter order variable
28
+ *
29
+ * @var string
30
+ */
31
+ protected $_orderVarName = 'order';
32
+
33
+ /**
34
+ * GET parameter direction variable
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_directionVarName = 'dir';
39
+
40
+ /**
41
+ * GET parameter mode variable
42
+ *
43
+ * @var string
44
+ */
45
+ protected $_modeVarName = 'mode';
46
+
47
+ /**
48
+ * GET parameter limit variable
49
+ *
50
+ * @var string
51
+ */
52
+ protected $_limitVarName = 'size';
53
+
54
+ /**
55
+ * GET parameter search handle variable
56
+ *
57
+ * @var string
58
+ */
59
+ protected $_searchHandleVarName = 'sh';
60
+
61
+ /**
62
+ * List of available order fields
63
+ *
64
+ * @var array
65
+ */
66
+ protected $_availableOrder = array();
67
+
68
+ /**
69
+ * List of available view types
70
+ *
71
+ * @var string
72
+ */
73
+ protected $_availableMode = array();
74
+
75
+ /**
76
+ * Is enable View switcher
77
+ *
78
+ * @var bool
79
+ */
80
+ protected $_enableViewSwitcher = true;
81
+
82
+ /**
83
+ * Is Expanded
84
+ *
85
+ * @var bool
86
+ */
87
+ protected $_isExpanded = true;
88
+
89
+ /**
90
+ * Default Order field
91
+ *
92
+ * @var string
93
+ */
94
+ protected $_orderField = null;
95
+
96
+ /**
97
+ * Default direction
98
+ *
99
+ * @var string
100
+ */
101
+ protected $_direction = 'asc';
102
+
103
+ /**
104
+ * Default View mode
105
+ *
106
+ * @var string
107
+ */
108
+ protected $_viewMode = null;
109
+
110
+ /**
111
+ * Available page limits for different list modes
112
+ *
113
+ * @var array
114
+ */
115
+ protected $_availableLimit = array();
116
+
117
+ /**
118
+ * Default limits per page
119
+ *
120
+ * @var array
121
+ */
122
+ protected $_defaultAvailableLimit = array(10=>10,20=>20,50=>50);
123
+
124
+ /**
125
+ * @var bool $_paramsMemorizeAllowed
126
+ */
127
+ protected $_paramsMemorizeAllowed = true;
128
+
129
+ /**
130
+ * Retrieve salesperson session
131
+ *
132
+ * @return Mage_Catalog_Model_Session
133
+ */
134
+ protected function _getSession()
135
+ {
136
+ return Mage::getSingleton('salesperson/session');
137
+ }
138
+ /**
139
+ * Retrieve Catalog Config object
140
+ *
141
+ * @return Mage_Catalog_Model_Config
142
+ */
143
+ protected function _getConfig()
144
+ {
145
+ return Mage::getSingleton('catalog/config');
146
+ }
147
+
148
+ /**
149
+ * Init Toolbar
150
+ *
151
+ */
152
+ protected function _construct()
153
+ {
154
+ parent::_construct();
155
+ $this->_orderField = Mage::getStoreConfig(
156
+ Mage_Catalog_Model_Config::XML_PATH_LIST_DEFAULT_SORT_BY
157
+ );
158
+
159
+ $this->_availableOrder = $this->_getConfig()->getAttributeUsedForSortByArray();
160
+
161
+ switch (Mage::getStoreConfig('catalog/frontend/list_mode')) {
162
+ case 'grid':
163
+ $this->_availableMode = array('grid' => $this->__('Grid'));
164
+ break;
165
+
166
+ case 'list':
167
+ $this->_availableMode = array('list' => $this->__('List'));
168
+ break;
169
+
170
+ case 'grid-list':
171
+ $this->_availableMode = array('grid' => $this->__('Grid'), 'list' => $this->__('List'));
172
+ break;
173
+
174
+ case 'list-grid':
175
+ $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'));
176
+ break;
177
+ }
178
+ $this->setTemplate('catalog/product/list/toolbar.phtml');
179
+ }
180
+
181
+ /**
182
+ * Disable list state params memorizing
183
+ */
184
+ public function disableParamsMemorizing()
185
+ {
186
+ $this->_paramsMemorizeAllowed = false;
187
+ return $this;
188
+ }
189
+
190
+ /**
191
+ * Memorize parameter value for session
192
+ *
193
+ * @param string $param parameter name
194
+ * @param mixed $value parameter value
195
+ * @return Mage_Catalog_Block_Product_List_Toolbar
196
+ */
197
+ protected function _memorizeParam($param, $value)
198
+ {
199
+ $session = Mage::getSingleton('salesperson/session');
200
+ if ($this->_paramsMemorizeAllowed && !$session->getParamsMemorizeDisabled()) {
201
+ $session->setData($param, $value);
202
+ }
203
+ return $this;
204
+ }
205
+
206
+ /**
207
+ * Set collection to pager
208
+ *
209
+ * @param Varien_Data_Collection $collection
210
+ * @return Mage_Catalog_Block_Product_List_Toolbar
211
+ */
212
+ public function setCollection($collection)
213
+ {
214
+ // $this->_collection = $collection;
215
+ //
216
+ // $this->_collection->setCurPage($this->getCurrentPage());
217
+ //
218
+ // // we need to set pagination only if passed value integer and more that 0
219
+ // $limit = (int)$this->getLimit();
220
+ // if ($limit) {
221
+ // $this->_collection->setPageSize($limit);
222
+ // }
223
+ // if ($this->getCurrentOrder()) {
224
+ // $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
225
+ // }
226
+ // return $this;
227
+ }
228
+
229
+ /**
230
+ * Return products collection instance
231
+ *
232
+ * @return Mage_Core_Model_Mysql4_Collection_Abstract
233
+ */
234
+ public function getCollection()
235
+ {
236
+ return $this->_collection;
237
+ }
238
+
239
+ protected function getQwiserSearchResults(){
240
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
241
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
242
+ }
243
+
244
+ /**
245
+ * Retrieve search result count
246
+ *
247
+ * @return string
248
+ */
249
+ public function getResultCount()
250
+ {
251
+ return $this->getQwiserSearchResults()->GetRelevantProductsCount();
252
+ }
253
+
254
+ /**
255
+ * Getter for $_pageVarName
256
+ *
257
+ * @return string
258
+ */
259
+ public function getPageVarName()
260
+ {
261
+ return $this->_pageVarName;
262
+ }
263
+
264
+ /**
265
+ * Retrieve order field GET var name
266
+ *
267
+ * @return string
268
+ */
269
+ public function getOrderVarName()
270
+ {
271
+ return $this->_orderVarName;
272
+ }
273
+
274
+ /**
275
+ * Retrieve sort direction GET var name
276
+ *
277
+ * @return string
278
+ */
279
+ public function getDirectionVarName()
280
+ {
281
+ return $this->_directionVarName;
282
+ }
283
+
284
+ /**
285
+ * Retrieve view mode GET var name
286
+ *
287
+ * @return string
288
+ */
289
+ public function getModeVarName()
290
+ {
291
+ return $this->_modeVarName;
292
+ }
293
+
294
+ /**
295
+ * Getter for $_limitVarName
296
+ *
297
+ * @return string
298
+ */
299
+ public function getLimitVarName()
300
+ {
301
+ return $this->_limitVarName;
302
+ }
303
+
304
+ /**
305
+ * Getter for $_searchHandleVarName
306
+ *
307
+ * @return string
308
+ */
309
+ public function getSearchHandleVarName(){
310
+ return $this->_searchHandleVarName;
311
+ }
312
+
313
+ /**
314
+ * Return current page from request
315
+ *
316
+ * @return int
317
+ */
318
+ public function getCurrentPage()
319
+ {
320
+ if ($page = (int) $this->getRequest()->getParam($this->getPageVarName())) {
321
+ return $page;
322
+ }
323
+ return 1;
324
+ }
325
+
326
+ /**
327
+ * Get grit products sort order field
328
+ *
329
+ * @return string
330
+ */
331
+ public function getCurrentOrder()
332
+ {
333
+ $order = $this->_getData('_current_grid_order');
334
+ if ($order) {
335
+ return $order;
336
+ }
337
+
338
+ $orders = $this->getAvailableOrders();
339
+ $defaultOrder = 'relevancy';//$this->_orderField; //Changed by Eli Sagy
340
+
341
+ if (!isset($orders[$defaultOrder])) {
342
+ $keys = array_keys($orders);
343
+ $defaultOrder = $keys[0];
344
+ }
345
+
346
+ $order = $this->getRequest()->getParam($this->getOrderVarName());
347
+ if ($order && isset($orders[$order])) {
348
+ if ($order == $defaultOrder) {
349
+ Mage::getSingleton('salesperson/session')->unsSortOrder();
350
+ } else {
351
+ $this->_memorizeParam('sort_order', $order);
352
+ //Mage::Helper('salesperson')->getQuery()->qsr = Mage::Helper('salesperson/salespersonSearchApi')->SortByField($this->getQwiserSearchResults()->GetSearchHandle(), $order, true, true);
353
+ }
354
+ } else {
355
+ //$order = Mage::getSingleton('salesperson/session')->getSortOrder();// Removed by Eli Sagy
356
+ }
357
+ // validate session value
358
+ if (!$order || !isset($orders[$order])) {
359
+ $order = $defaultOrder;
360
+ }
361
+ $this->setData('_current_grid_order', $order);
362
+ return $order;
363
+ }
364
+
365
+ /**
366
+ * Retrieve current direction
367
+ *
368
+ * @return string
369
+ */
370
+ public function getCurrentDirection()
371
+ {
372
+ $dir = $this->_getData('_current_grid_direction');
373
+ if ($dir) {
374
+ return $dir;
375
+ }
376
+
377
+ $directions = array('asc', 'desc');
378
+ $dir = strtolower($this->getRequest()->getParam($this->getDirectionVarName()));
379
+ if ($dir && in_array($dir, $directions)) {
380
+ if ($dir == $this->_direction) {
381
+ Mage::getSingleton('catalog/session')->unsSortDirection();
382
+ } else {
383
+ $this->_memorizeParam('sort_direction', $dir);
384
+ }
385
+ } else {
386
+ $dir = Mage::getSingleton('catalog/session')->getSortDirection();
387
+ }
388
+ // validate direction
389
+ if (!$dir || !in_array($dir, $directions)) {
390
+ $dir = $this->_direction;
391
+ }
392
+ $this->setData('_current_grid_direction', $dir);
393
+ return $dir;
394
+ }
395
+
396
+ /**
397
+ * Set default Order field
398
+ *
399
+ * @param string $field
400
+ * @return Mage_Catalog_Block_Product_List_Toolbar
401
+ */
402
+ public function setDefaultOrder($field)
403
+ {
404
+ if (isset($this->_availableOrder[$field])) {
405
+ $this->_orderField = $field;
406
+ }
407
+ return $this;
408
+ }
409
+
410
+ /**
411
+ * Set default sort direction
412
+ *
413
+ * @param string $dir
414
+ * @return Mage_Catalog_Block_Product_List_Toolbar
415
+ */
416
+ public function setDefaultDirection($dir)
417
+ {
418
+ if (in_array(strtolower($dir), array('asc', 'desc'))) {
419
+ $this->_direction = strtolower($dir);
420
+ }
421
+ return $this;
422
+ }
423
+
424
+ /**
425
+ * Retrieve available Order fields list
426
+ *
427
+ * @return array
428
+ */
429
+ public function getAvailableOrders()
430
+ {
431
+ if (isset($this->_availableOrder['position'])){
432
+ unset($this->_availableOrder['position']);
433
+ }
434
+ $this->_availableOrder['relevancy'] = "Relevancy";
435
+ return $this->_availableOrder;
436
+ }
437
+
438
+ /**
439
+ * Set Available order fields list
440
+ *
441
+ * @param array $orders
442
+ * @return Mage_Catalog_Block_Product_List_Toolbar
443
+ */
444
+ public function setAvailableOrders($orders)
445
+ {
446
+ $this->_availableOrder = $orders;
447
+ return $this;
448
+ }
449
+
450
+ /**
451
+ * Add order to available orders
452
+ *
453
+ * @param string $order
454
+ * @param string $value
455
+ * @return Mage_Catalog_Block_Product_List_Toolbar
456
+ */
457
+ public function addOrderToAvailableOrders($order, $value)
458
+ {
459
+ $this->_availableOrder[$order] = $value;
460
+ return $this;
461
+ }
462
+ /**
463
+ * Remove order from available orders if exists
464
+ *
465
+ * @param string $order
466
+ * @param Mage_Catalog_Block_Product_List_Toolbar
467
+ */
468
+ public function removeOrderFromAvailableOrders($order)
469
+ {
470
+ if (isset($this->_availableOrder[$order])) {
471
+ unset($this->_availableOrder[$order]);
472
+ }
473
+ return $this;
474
+ }
475
+
476
+ /**
477
+ * Compare defined order field vith current order field
478
+ *
479
+ * @param string $order
480
+ * @return bool
481
+ */
482
+ public function isOrderCurrent($order)
483
+ {
484
+ return $order == $this->getCurrentOrder();
485
+ }
486
+
487
+ /**
488
+ * Retrieve Pager URL
489
+ *
490
+ * @param string $order
491
+ * @param string $direction
492
+ * @return string
493
+ */
494
+ public function getOrderUrl($order, $direction)
495
+ {
496
+ if (is_null($order)) {
497
+ $order = $this->getCurrentOrder() ? $this->getCurrentOrder() : $this->_availableOrder[0];
498
+ }
499
+ $params = array(
500
+ "salespersonaction"=>"sort",
501
+ $this->getOrderVarName()=>$order,
502
+ $this->getDirectionVarName()=>$direction,
503
+ $this->getPageVarName() => null
504
+ );
505
+ return $this->getPagerUrl($params);
506
+ }
507
+
508
+ /**
509
+ * Return current URL with rewrites and additional parameters
510
+ *
511
+ * @param array $params Query parameters
512
+ * @return string
513
+ */
514
+ public function getPagerUrl($params=array())
515
+ {
516
+ $params['searchHandle'] = $this->getQwiserSearchResults()->GetSearchHandle();
517
+ $urlParams = array();
518
+ $urlParams['_current'] = true;
519
+ $urlParams['_escape'] = true;
520
+ $urlParams['_use_rewrite'] = true;
521
+ $urlParams['_query'] = $params;
522
+ return $this->getUrl('*/*/change', $urlParams);
523
+ }
524
+
525
+ /**
526
+ * Retrieve current View mode
527
+ *
528
+ * @return string
529
+ */
530
+ public function getCurrentMode()
531
+ {
532
+ $mode = $this->_getData('_current_grid_mode');
533
+ if ($mode) {
534
+ return $mode;
535
+ }
536
+ $modes = array_keys($this->_availableMode);
537
+ $defaultMode = current($modes);
538
+ $mode = $this->getRequest()->getParam($this->getModeVarName());
539
+ if ($mode) {
540
+ if ($mode == $defaultMode) {
541
+ Mage::getSingleton('catalog/session')->unsDisplayMode();
542
+ } else {
543
+ $this->_memorizeParam('display_mode', $mode);
544
+ }
545
+ } else {
546
+ $mode = Mage::getSingleton('catalog/session')->getDisplayMode();
547
+ }
548
+
549
+ if (!$mode || !isset($this->_availableMode[$mode])) {
550
+ $mode = $defaultMode;
551
+ }
552
+ $this->setData('_current_grid_mode', $mode);
553
+ return $mode;
554
+ }
555
+
556
+ /**
557
+ * Compare defined view mode with current active mode
558
+ *
559
+ * @param string $mode
560
+ * @return bool
561
+ */
562
+ public function isModeActive($mode)
563
+ {
564
+ return $this->getCurrentMode() == $mode;
565
+ }
566
+
567
+ /**
568
+ * Retrieve availables view modes
569
+ *
570
+ * @return array
571
+ */
572
+ public function getModes()
573
+ {
574
+ return $this->_availableMode;
575
+ }
576
+
577
+ /**
578
+ * Set available view modes list
579
+ *
580
+ * @param array $modes
581
+ * @return Mage_Catalog_Block_Product_List_Toolbar
582
+ */
583
+ public function setModes($modes)
584
+ {
585
+ if(!isset($this->_availableMode)){
586
+ $this->_availableMode = $modes;
587
+ }
588
+ return $this;
589
+ }
590
+
591
+ /**
592
+ * Retrive URL for view mode
593
+ *
594
+ * @param string $mode
595
+ * @return string
596
+ */
597
+ public function getModeUrl($mode)
598
+ {
599
+ $urlParams = array();
600
+ $urlParams['_current'] = true;
601
+ $urlParams['_escape'] = true;
602
+ $urlParams['_use_rewrite'] = true;
603
+ $urlParams['_query'] = array($this->getModeVarName()=>$mode, $this->getPageVarName() => null);
604
+ return $this->getUrl('*/*/*', $urlParams);
605
+ }
606
+
607
+ /**
608
+ * Disable view switcher
609
+ *
610
+ * @return Mage_Catalog_Block_Product_List_Toolbar
611
+ */
612
+ public function disableViewSwitcher()
613
+ {
614
+ $this->_enableViewSwitcher = false;
615
+ return $this;
616
+ }
617
+
618
+ /**
619
+ * Enable view switcher
620
+ *
621
+ * @return Mage_Catalog_Block_Product_List_Toolbar
622
+ */
623
+ public function enableViewSwitcher()
624
+ {
625
+ $this->_enableViewSwitcher = true;
626
+ return $this;
627
+ }
628
+
629
+ /**
630
+ * Is a enabled view switcher
631
+ *
632
+ * @return bool
633
+ */
634
+ public function isEnabledViewSwitcher()
635
+ {
636
+ return $this->_enableViewSwitcher;
637
+ }
638
+
639
+ /**
640
+ * Disable Expanded
641
+ *
642
+ * @return Mage_Catalog_Block_Product_List_Toolbar
643
+ */
644
+ public function disableExpanded()
645
+ {
646
+ $this->_isExpanded = false;
647
+ return $this;
648
+ }
649
+
650
+ /**
651
+ * Enable Expanded
652
+ *
653
+ * @return Mage_Catalog_Block_Product_List_Toolbar
654
+ */
655
+ public function enableExpanded()
656
+ {
657
+ $this->_isExpanded = true;
658
+ return $this;
659
+ }
660
+
661
+ /**
662
+ * Check is Expanded
663
+ *
664
+ * @return bool
665
+ */
666
+ public function isExpanded()
667
+ {
668
+ return $this->_isExpanded;
669
+ }
670
+
671
+ /**
672
+ * Retrieve default per page values
673
+ *
674
+ * @return string (comma separated)
675
+ */
676
+ public function getDefaultPerPageValue()
677
+ {
678
+ if ($this->getCurrentMode() == 'list') {
679
+ if ($default = $this->getDefaultListPerPage()) {
680
+ return $default;
681
+ }
682
+ return Mage::getStoreConfig('catalog/frontend/list_per_page');
683
+ }
684
+ elseif ($this->getCurrentMode() == 'grid') {
685
+ if ($default = $this->getDefaultGridPerPage()) {
686
+ return $default;
687
+ }
688
+ return Mage::getStoreConfig('catalog/frontend/grid_per_page');
689
+ }
690
+ return 0;
691
+ }
692
+
693
+ /**
694
+ * Add new limit to pager for mode
695
+ *
696
+ * @param string $mode
697
+ * @param string $value
698
+ * @param string $label
699
+ * @return Mage_Catalog_Block_Product_List_Toolbar
700
+ */
701
+ public function addPagerLimit($mode, $value, $label='')
702
+ {
703
+ if (!isset($this->_availableLimit[$mode])) {
704
+ $this->_availableLimit[$mode] = array();
705
+ }
706
+ $this->_availableLimit[$mode][$value] = empty($label) ? $value : $label;
707
+ return $this;
708
+ }
709
+
710
+ /**
711
+ * Retrieve available limits for current view mode
712
+ *
713
+ * @return array
714
+ */
715
+ public function getAvailableLimit()
716
+ {
717
+ return array(9=>'9',15=>'15',21=>'21');
718
+
719
+ $currentMode = $this->getCurrentMode();
720
+ if (in_array($currentMode, array('list', 'grid'))) {
721
+ return $this->_getAvailableLimit($currentMode);
722
+ } else {
723
+ return $this->_defaultAvailableLimit;
724
+ }
725
+ }
726
+
727
+ /**
728
+ * Retrieve available limits for specified view mode
729
+ *
730
+ * @return array
731
+ */
732
+ protected function _getAvailableLimit($mode)
733
+ {
734
+ if (isset($this->_availableLimit[$mode])) {
735
+ return $this->_availableLimit[$mode];
736
+ }
737
+ $perPageConfigKey = 'catalog/frontend/' . $mode . '_per_page_values';
738
+ $perPageValues = (string)Mage::getStoreConfig($perPageConfigKey);
739
+ $perPageValues = explode(',', $perPageValues);
740
+ $perPageValues = array_combine($perPageValues, $perPageValues);
741
+ if (Mage::getStoreConfigFlag('catalog/frontend/list_allow_all')) {
742
+ return ($perPageValues + array('all'=>$this->__('All')));
743
+ } else {
744
+ return $perPageValues;
745
+ }
746
+ }
747
+
748
+ /**
749
+ * Get specified products limit display per page
750
+ *
751
+ * @return string
752
+ */
753
+ public function getLimit()
754
+ {
755
+ $limit = $this->_getData('_current_limit');
756
+ if ($limit) {
757
+ return $limit;
758
+ }
759
+
760
+ $limits = $this->getAvailableLimit();
761
+ $defaultLimit = $this->getDefaultPerPageValue();
762
+ if (!$defaultLimit || !isset($limits[$defaultLimit])) {
763
+ $keys = array_keys($limits);
764
+ $defaultLimit = $keys[0];
765
+ }
766
+
767
+ $limit = $this->getRequest()->getParam($this->getLimitVarName());
768
+ if ($limit && isset($limits[$limit])) {
769
+ if ($limit == $defaultLimit) {
770
+ Mage::getSingleton('catalog/session')->unsLimitPage();
771
+ } else {
772
+ $this->_memorizeParam('limit_page', $limit);
773
+ }
774
+ } else {
775
+ $limit = Mage::helper('salesperson')->getDefaultPageSize();
776
+ //$limit = Mage::getSingleton('catalog/session')->getLimitPage();
777
+ }
778
+ if (!$limit || !isset($limits[$limit])) {
779
+ $limit = $defaultLimit;
780
+ }
781
+
782
+ $this->setData('_current_limit', $limit);
783
+
784
+ return $limit;
785
+ }
786
+
787
+ /**
788
+ * Retrieve Limit Pager URL
789
+ *
790
+ * @param int $limit
791
+ * @return string
792
+ */
793
+ public function getLimitUrl($limit)
794
+ {
795
+ return $this->getPagerUrl(array(
796
+ "salespersonaction"=>"limit",
797
+ $this->getLimitVarName() => $limit,
798
+ $this->getPageVarName() => null,
799
+ ));
800
+
801
+ return $this->getUrl('*/*/change', $urlParams);
802
+ }
803
+
804
+ public function isLimitCurrent($limit)
805
+ {
806
+ return $limit == $this->getLimit();
807
+ }
808
+
809
+ public function getFirstNum()
810
+ {
811
+ return $this->getQwiserSearchResults()->SearchInformation->PageSize * ($this->getQwiserSearchResults()->SearchInformation->CurrentPage) + 1;
812
+ }
813
+
814
+ public function getLastNum()
815
+ {
816
+ if ($this->getQwiserSearchResults()->SearchInformation->CurrentPage != 0) {
817
+ $lastNum = $this->getQwiserSearchResults()->SearchInformation->PageSize * ($this->getQwiserSearchResults()->SearchInformation->CurrentPage) + $this->getQwiserSearchResults()->SearchInformation->PageSize;
818
+ }
819
+ else {
820
+ $lastNum = $this->getQwiserSearchResults()->SearchInformation->PageSize * ($this->getQwiserSearchResults()->SearchInformation->CurrentPage) + $this->getQwiserSearchResults()->SearchInformation->PageSize;
821
+ }
822
+ if ($lastNum < $this->getTotalNum()){
823
+ return $lastNum;
824
+ }
825
+ else{
826
+ return $this->getTotalNum();
827
+ }
828
+ }
829
+
830
+ public function getTotalNum()
831
+ {
832
+ return (int)$this->getResultCount();
833
+ }
834
+
835
+ public function isFirstPage()
836
+ {
837
+ return $this->getQwiserSearchResults()->SearchInformation->CurrentPage == 0;
838
+ }
839
+
840
+ public function getLastPageNum()
841
+ {
842
+ if (0 === $this->getResultCount()) {
843
+ return 1;
844
+ }
845
+ elseif($this->getQwiserSearchResults()->SearchInformation->PageSize) {
846
+ return ceil($this->getResultCount()/$this->getQwiserSearchResults()->SearchInformation->PageSize);
847
+ }
848
+ else{
849
+ return 1;
850
+ }
851
+ }
852
+
853
+ /**
854
+ * Render pagination HTML
855
+ *
856
+ * @return string
857
+ */
858
+ public function getPagerHtml()
859
+ {
860
+ $pagerBlock = new Celebros_Salesperson_Block_Product_List_Toolbar_Pager;//$this->getChild('product_list_toolbar_pager');
861
+
862
+ if ($pagerBlock instanceof Varien_Object) {
863
+
864
+ /* @var $pagerBlock Mage_Page_Block_Html_Pager */
865
+ $pagerBlock->setAvailableLimit($this->getAvailableLimit());
866
+
867
+ $pagerBlock->setUseContainer(false)
868
+ ->setShowPerPage(false)
869
+ ->setShowAmounts(false)
870
+ ->setLimitVarName($this->getLimitVarName())
871
+ ->setPageVarName($this->getPageVarName())
872
+ ->setLimit($this->getLimit())
873
+ ->setFrameLength(Mage::getStoreConfig('design/pagination/pagination_frame'))
874
+ ->setJump(Mage::getStoreConfig('design/pagination/pagination_frame_skip'));
875
+ // ->setCollection($this->getCollection());
876
+
877
+ return $pagerBlock->toHtml();
878
+ }
879
+
880
+ return '';
881
+ }
882
+
883
+ public function getPageSizeSelectorType() {
884
+ return Mage::getStoreConfig('salesperson/display_settings/page_size_selector');
885
+ }
886
+
887
+ public function getSortingSelectorType() {
888
+ return Mage::getStoreConfig('salesperson/display_settings/sorting_selector');
889
+ }
890
+ public function getPageNavType() {
891
+ return Mage::getStoreConfig('salesperson/display_settings/page_nav_type');
892
+ }
893
+
894
+ public function getPageUrl($page)
895
+ {
896
+ return $this->getPagerUrl(array("salespersonaction"=>"page",$this->getPageVarName()=>$page));
897
+ }
898
+
899
+ public function getNextPageUrl()
900
+ {
901
+ return $this->getPageUrl($this->getCurrentPage() + 1);
902
+ }
903
+
904
+ public function getPreviousPageUrl()
905
+ {
906
+ return $this->getPageUrl($this->getCurrentPage() - 1);
907
+ }
908
+
909
+ }
app/code/local/Celebros/Salesperson/Block/Product/List/Toolbar/Pager.php ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Product_List_Toolbar_Pager extends Mage_Core_Block_Template
11
+ {
12
+ protected $_pageVarName = 'p';
13
+ protected $_limitVarName = 'size';
14
+ protected $_availableLimit = array(10=>10,20=>20,50=>50);
15
+ protected $_dispersion = 3;
16
+ protected $_displayPages = 5;
17
+ protected $_showPerPage = true;
18
+ protected $_limit = null;
19
+ protected $_outputRequired = true;
20
+ /**
21
+ * Pages quantity per frame
22
+ * @var int
23
+ */
24
+ protected $_frameLength = 5;
25
+
26
+ /**
27
+ * Next/previous page position relatively to the current frame
28
+ * @var int
29
+ */
30
+ protected $_jump = 5;
31
+
32
+ /**
33
+ * Frame initialization flag
34
+ * @var bool
35
+ */
36
+ protected $_frameInitialized = false;
37
+
38
+ /**
39
+ * Start page position in frame
40
+ * @var int
41
+ */
42
+ protected $_frameStart;
43
+
44
+ /**
45
+ * Finish page position in frame
46
+ * @var int
47
+ */
48
+ protected $_frameEnd;
49
+
50
+ /**
51
+ * Retrieve salesperson session
52
+ *
53
+ * @return Mage_Catalog_Model_Session
54
+ */
55
+ protected function _getSession()
56
+ {
57
+ return Mage::getSingleton('salesperson/session');
58
+ }
59
+
60
+ protected function _construct()
61
+ {
62
+ parent::_construct();
63
+ $this->setData('show_amounts', true);
64
+ $this->setData('use_container', true);
65
+ $this->setTemplate('salesperson/product/list/toolbar/pager.phtml');
66
+ }
67
+
68
+ public function getCurrentPage()
69
+ {
70
+ if ($page = (int) $this->getRequest()->getParam($this->getPageVarName())) {
71
+ return $page;
72
+ }
73
+ return 1;
74
+ }
75
+
76
+ public function getQwiserSearchResults(){
77
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
78
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
79
+ }
80
+
81
+ /**
82
+ * Return pager limitation from request or as assigned value
83
+ *
84
+ * @return int
85
+ */
86
+ public function getLimit()
87
+ {
88
+ if ($this->_limit !== null) {
89
+ return $this->_limit;
90
+ }
91
+ return parent::getLimit();
92
+ }
93
+
94
+ /**
95
+ * Setter for $_limit
96
+ *
97
+ * @param int $limit
98
+ * @return Mage_Catalog_Block_Product_List_Toolbar_Pager
99
+ */
100
+ public function setLimit($limit)
101
+ {
102
+ $this->_limit = abs(intval($limit));
103
+ return $this;
104
+ }
105
+
106
+ public function getPageVarName()
107
+ {
108
+ return $this->_pageVarName;
109
+ }
110
+
111
+ public function setPageVarName($varName)
112
+ {
113
+ $this->_pageVarName = $varName;
114
+ return $this;
115
+ }
116
+
117
+ public function getShowPerPage()
118
+ {
119
+ if(sizeof($this->getAvailableLimit())<=1) {
120
+ return false;
121
+ }
122
+ return $this->_showPerPage;
123
+ }
124
+
125
+ public function setShowPerPage($varName)
126
+ {
127
+ $this->_showPerPage=$varName;
128
+ return $this;
129
+ }
130
+
131
+ public function setLimitVarName($varName)
132
+ {
133
+ $this->_limitVarName = $varName;
134
+ return $this;
135
+ }
136
+
137
+ public function getLimitVarName()
138
+ {
139
+ return $this->_limitVarName;
140
+ }
141
+
142
+ public function setAvailableLimit(array $limits)
143
+ {
144
+ $this->_availableLimit = $limits;
145
+ }
146
+
147
+ public function getAvailableLimit()
148
+ {
149
+ return $this->_availableLimit;
150
+ }
151
+
152
+ public function getTotalNum()
153
+ {
154
+ return $this->getQwiserSearchResults()->GetRelevantProductsCount();
155
+ }
156
+
157
+ /**
158
+ * Retrieve search result count
159
+ *
160
+ * @return string
161
+ */
162
+ public function getResultCount()
163
+ {
164
+ return $this->getQwiserSearchResults()->GetRelevantProductsCount();
165
+ }
166
+
167
+ /**
168
+ * Getter for $_frameStart
169
+ *
170
+ * @return int
171
+ */
172
+ public function getFrameStart()
173
+ {
174
+ $this->_initFrame();
175
+ return $this->_frameStart;
176
+ }
177
+
178
+ /**
179
+ * Getter for $_frameEnd
180
+ *
181
+ * @return int
182
+ */
183
+ public function getFrameEnd()
184
+ {
185
+ $this->_initFrame();
186
+ return $this->_frameEnd;
187
+ }
188
+
189
+ /**
190
+ * Return array of pages in frame
191
+ *
192
+ * @return array
193
+ */
194
+ public function getFramePages()
195
+ {
196
+ $start = $this->getFrameStart();
197
+ $end = $this->getFrameEnd();
198
+ return range($start, $end);
199
+ }
200
+
201
+ /**
202
+ * Return page number of Previous jump
203
+ *
204
+ * @return int
205
+ */
206
+ public function getPreviousJumpPage()
207
+ {
208
+ if (!$this->getJump()) {
209
+ return null;
210
+ }
211
+ $frameStart = $this->getFrameStart();
212
+ if ($frameStart - 1 > 1) {
213
+ return max(2, $frameStart - $this->getJump());
214
+ }
215
+
216
+ return null;
217
+ }
218
+
219
+ /**
220
+ * Prepare URL for Previous Jump
221
+ *
222
+ * @return string
223
+ */
224
+ public function getPreviousJumpUrl()
225
+ {
226
+ return $this->getPageUrl($this->getPreviousJumpPage());
227
+ }
228
+
229
+ public function getPageUrl($page)
230
+ {
231
+ return $this->getPagerUrl(array("salespersonaction"=>"page",$this->getPageVarName()=>$page));
232
+ }
233
+
234
+ public function isFirstPage()
235
+ {
236
+ return $this->getCurrentPage() == 1;
237
+ }
238
+
239
+ public function getLastPageNum()
240
+ {
241
+ return $this->getQwiserSearchResults()->SearchInformation->NumberOfPages;
242
+ }
243
+
244
+ public function isLastPage()
245
+ {
246
+ return $this->getCurrentPage() >= $this->getLastPageNum();
247
+ }
248
+
249
+ public function isLimitCurrent($limit)
250
+ {
251
+ return $limit == $this->getLimit();
252
+ }
253
+
254
+ public function isPageCurrent($page)
255
+ {
256
+ return $page == $this->getCurrentPage();
257
+ }
258
+
259
+ public function getPages()
260
+ {
261
+ $pages = array();
262
+ if ($this->getLastPageNum() <= $this->_displayPages) {
263
+ $pages = range(1, $this->getLastPageNum());
264
+ }
265
+ else {
266
+ $half = ceil($this->_displayPages / 2);
267
+ if ($this->getCurrentPage() >= $half && $this->getCurrentPage() <= $this->getLastPageNum() - $half) {
268
+ $start = ($this->getCurrentPage() - $half) + 1;
269
+ $finish = ($start + $this->_displayPages) - 1;
270
+ }
271
+ elseif ($this->getCurerentPage() < $half) {
272
+ $start = 1;
273
+ $finish = $this->_displayPages;
274
+ }
275
+ elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) {
276
+ $finish = $this->getLastPageNum();
277
+ $start = $finish - $this->_displayPages + 1;
278
+ }
279
+
280
+ $pages = range($start, $finish);
281
+ }
282
+ return $pages;
283
+ }
284
+
285
+ public function getFirstPageUrl()
286
+ {
287
+ return $this->getPageUrl(1);
288
+ }
289
+
290
+ public function getPreviousPageUrl()
291
+ {
292
+ return $this->getPageUrl($this->getCurrentPage() - 1);
293
+ }
294
+
295
+ public function getNextPageUrl()
296
+ {
297
+ return $this->getPageUrl($this->getCurrentPage() + 1);
298
+ }
299
+
300
+ public function getLastPageUrl()
301
+ {
302
+ return $this->getPageUrl($this->getLastPageNum());
303
+ }
304
+
305
+ public function getLimitUrl($limit)
306
+ {
307
+ return $this->getPagerUrl(array("salespersonaction"=>"limit",$this->getLimitVarName()=>$limit));
308
+ }
309
+
310
+ public function getPagerUrl($params=array())
311
+ {
312
+ $params['searchHandle'] = $this->getQwiserSearchResults()->GetSearchHandle();
313
+ $urlParams = array();
314
+ $urlParams['_current'] = true;
315
+ $urlParams['_escape'] = true;
316
+ $urlParams['_use_rewrite'] = true;
317
+ $urlParams['_query'] = $params;
318
+ return $this->getUrl('*/*/change', $urlParams);
319
+ }
320
+
321
+
322
+ /**
323
+ * Return page number of Next jump
324
+ *
325
+ * @return int
326
+ */
327
+ public function getNextJumpPage()
328
+ {
329
+ if (!$this->getJump()) {
330
+ return null;
331
+ }
332
+ $frameEnd = $this->getFrameEnd();
333
+ if ($this->getLastPageNum() - $frameEnd > 1) {
334
+ return min($this->getLastPageNum() - 1, $frameEnd + $this->getJump());
335
+ }
336
+
337
+ return null;
338
+ }
339
+
340
+ /**
341
+ * Prepare URL for Next Jump
342
+ *
343
+ * @return string
344
+ */
345
+ public function getNextJumpUrl()
346
+ {
347
+ return $this->getPageUrl($this->getNextJumpPage());
348
+ }
349
+
350
+ /**
351
+ * Getter for $_frameLength
352
+ *
353
+ * @return int
354
+ */
355
+ public function getFrameLength()
356
+ {
357
+ return $this->_frameLength;
358
+ }
359
+
360
+ /**
361
+ * Getter for $_jump
362
+ *
363
+ * @return int
364
+ */
365
+ public function getJump()
366
+ {
367
+ return $this->_jump;
368
+ }
369
+
370
+ /**
371
+ * Setter for $_frameLength
372
+ *
373
+ * @param int $frame
374
+ * @return Mage_Page_Block_Html_Pager
375
+ */
376
+ public function setFrameLength($frame)
377
+ {
378
+ $frame = abs(intval($frame));
379
+ if ($frame == 0) {
380
+ $frame = $this->_frameLength;
381
+ }
382
+ if ($this->getFrameLength() != $frame) {
383
+ $this->_setFrameInitialized(false);
384
+ $this->_frameLength = $frame;
385
+ }
386
+
387
+ return $this;
388
+ }
389
+
390
+ /**
391
+ * Setter for $_jump
392
+ *
393
+ * @param int $jump
394
+ * @return Mage_Page_Block_Html_Pager
395
+ */
396
+ public function setJump($jump)
397
+ {
398
+ $jump = abs(intval($jump));
399
+ if ($this->getJump() != $jump) {
400
+ $this->_setFrameInitialized(false);
401
+ $this->_jump = $jump;
402
+ }
403
+
404
+ return $this;
405
+ }
406
+
407
+ /**
408
+ * Whether to show first page in pagination or not
409
+ *
410
+ * @return bool
411
+ */
412
+ public function canShowFirst()
413
+ {
414
+ return $this->getJump() > 1 && $this->getFrameStart() > 1;
415
+ }
416
+
417
+ /**
418
+ * Whether to show last page in pagination or not
419
+ *
420
+ * @return bool
421
+ */
422
+ public function canShowLast()
423
+ {
424
+ return $this->getJump() > 1 && $this->getFrameEnd() < $this->getLastPageNum();
425
+ }
426
+
427
+ /**
428
+ * Whether to show link to Previous Jump
429
+ *
430
+ * @return bool
431
+ */
432
+ public function canShowPreviousJump()
433
+ {
434
+ return $this->getPreviousJumpPage() !== null;
435
+ }
436
+
437
+ /**
438
+ * Whether to show link to Next Jump
439
+ *
440
+ * @return bool
441
+ */
442
+ public function canShowNextJump()
443
+ {
444
+ return $this->getNextJumpPage() !== null;
445
+ }
446
+
447
+ /**
448
+ * Initialize frame data, such as frame start, frame start etc.
449
+ *
450
+ * @return Mage_Page_Block_Html_Pager
451
+ */
452
+ protected function _initFrame()
453
+ {
454
+ if (!$this->isFrameInitialized()) {
455
+ $start = 0;
456
+ $end = 0;
457
+
458
+ if ($this->getLastPageNum() <= $this->getFrameLength()) {
459
+ $start = 1;
460
+ $end = $this->getLastPageNum();
461
+ }
462
+ else {
463
+ $half = ceil($this->getFrameLength() / 2);
464
+ if ($this->getCurrentPage() >= $half && $this->getCurrentPage() <= $this->getLastPageNum() - $half) {
465
+ $start = ($this->getCurrentPage() - $half) + 1;
466
+ $end = ($start + $this->getFrameLength()) - 1;
467
+ }
468
+ elseif ($this->getCurPage() < $half) {
469
+ $start = 1;
470
+ $end = $this->getFrameLength();
471
+ }
472
+ elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) {
473
+ $end = $this->getLastPageNum();
474
+ $start = $end - $this->getFrameLength() + 1;
475
+ }
476
+ }
477
+ $this->_frameStart = $start;
478
+ $this->_frameEnd = $end;
479
+
480
+ $this->_setFrameInitialized(true);
481
+ }
482
+
483
+ return $this;
484
+ }
485
+
486
+ /**
487
+ * Setter for flag _frameInitialized
488
+ *
489
+ * @param bool $flag
490
+ * @return Mage_Page_Block_Html_Pager
491
+ */
492
+ protected function _setFrameInitialized($flag)
493
+ {
494
+ $this->_frameInitialized = (bool)$flag;
495
+ return $this;
496
+ }
497
+
498
+ /**
499
+ * Check if frame data was initialized
500
+ *
501
+ * @return Mage_Page_Block_Html_Pager
502
+ */
503
+ public function isFrameInitialized()
504
+ {
505
+ return $this->_frameInitialized;
506
+ }
507
+
508
+ /**
509
+ * Getter for alternative text for Previous link in pagination frame
510
+ *
511
+ * @return string
512
+ */
513
+ public function getAnchorTextForPrevious()
514
+ {
515
+ return Mage::getStoreConfig('design/pagination/anchor_text_for_previous');
516
+ }
517
+
518
+ /**
519
+ * Getter for alternative text for Next link in pagination frame
520
+ *
521
+ * @return string
522
+ */
523
+ public function getAnchorTextForNext()
524
+ {
525
+ return Mage::getStoreConfig('design/pagination/anchor_text_for_next');
526
+ }
527
+
528
+ /**
529
+ * Set whether output of the pager is mandatory
530
+ *
531
+ * @param bool $isRequired
532
+ * @return Mage_Page_Block_Html_Pager
533
+ */
534
+ public function setIsOutputRequired($isRequired)
535
+ {
536
+ $this->_outputRequired = (bool)$isRequired;
537
+ return $this;
538
+ }
539
+
540
+ /**
541
+ * Render block HTML
542
+ *
543
+ * @return string
544
+ */
545
+ protected function _toHtml()
546
+ {
547
+ if ($this->getQwiserSearchResults()->SearchInformation->NumberOfPages > 1) {
548
+ if ($this->_outputRequired || $this->getTotalNum() > $this->getLimit()) {
549
+ return Mage_Core_Block_Template::_toHtml();
550
+ }
551
+ } else {
552
+ return '';
553
+ }
554
+ }
555
+
556
+ public function getPageNavType() {
557
+ return Mage::getStoreConfig('salesperson/display_settings/page_nav_type');
558
+ }
559
+ }
app/code/local/Celebros/Salesperson/Block/Result.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Result extends Mage_Core_Block_Template
11
+ {
12
+ /**
13
+ * Catalog Product collection
14
+ *
15
+ * @var Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection
16
+ */
17
+ protected $_productCollection;
18
+
19
+ /**
20
+ * Retrieve salesperson session
21
+ *
22
+ * @return Mage_Catalog_Model_Session
23
+ */
24
+
25
+ var $helper;
26
+
27
+ protected function _getSession()
28
+ {
29
+ return Mage::getSingleton('salesperson/session');
30
+ }
31
+
32
+ /**
33
+ * Retrieve QwiserSearchApi model object
34
+ *
35
+ * @return Mage_CatalogSearch_Model_Query
36
+ */
37
+ protected function _getSalespersonApi()
38
+ {
39
+ if(!$this->helper)
40
+ $this->helper = $this->helper('salesperson');
41
+
42
+ return $this->helper->getSalespersonApi();
43
+ }
44
+
45
+ protected function _getSalespersonAnlxApi()
46
+ {
47
+ if(!$this->helper)
48
+ $this->helper = $this->helper('salesperson');
49
+
50
+ return $this->helper->getSalespersonAnlxApi();
51
+ }
52
+
53
+ /**
54
+ * Prepare layout
55
+ *
56
+ * @return Mage_CatalogSearch_Block_Result
57
+ */
58
+ protected function _prepareLayout()
59
+ {
60
+ // add Home breadcrumb
61
+ $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
62
+ if ($breadcrumbs) {
63
+ $title = $this->__("Search results for: '%s'", $this->helper('salesperson')->getQueryText());
64
+
65
+ $breadcrumbs->addCrumb('home', array(
66
+ 'label' => $this->__('Home'),
67
+ 'title' => $this->__('Go to Home Page'),
68
+ 'link' => Mage::getBaseUrl()
69
+ ));
70
+ if(Mage::getStoreConfigFlag('salesperson/display_settings/breadcrumbs') && count($this->_getSalespersonApi()->results->SearchPath->Items) > 0){
71
+ $breadcrumbs->addCrumb('search', array(
72
+ 'label' => $title,
73
+ 'title' => $title,
74
+ 'link' => Mage::Helper('salesperson')->getResultUrl($this->helper('salesperson')->getQueryText())
75
+ ));
76
+ $searchPathEntry = 0;
77
+ $paths = array();
78
+ $totalEntries = $this->_getSalespersonApi()->results->SearchPath->Count;
79
+ $searchPaths = $this->_getSalespersonApi()->results->SearchPath->Items;
80
+ for($i = 0; $i < $totalEntries; $i++){
81
+ $paths[] = $searchPaths[($totalEntries - 1) - $i]->Answers->Items[0]->Id;
82
+ }
83
+ array_pop($paths);
84
+ foreach($searchPaths as $key => $searchPath){
85
+ $crumb = array(
86
+ 'label' => $searchPath->Answers->Items[0]->Text,
87
+ 'title' => $searchPath->Answers->Items[0]->Text,
88
+ );
89
+ $searchPathEntry++;
90
+ if($searchPathEntry < $totalEntries){
91
+ $crumb['link'] = Mage::getBlockSingleton('salesperson/layer_state')->getRemoveAnswersFromBredcrumbsUrl($paths);
92
+ array_pop($paths);
93
+ }
94
+ $breadcrumbs->addCrumb($searchPath->Answers->Items[0]->Id, $crumb);
95
+ }
96
+ }
97
+ else {
98
+ $breadcrumbs->addCrumb('search', array(
99
+ 'label' => $title,
100
+ 'title' => $title,
101
+ ));
102
+ }
103
+ }
104
+
105
+ // modify page title
106
+ $title = $this->__("Search results for: '%s'", $this->helper('salesperson')->getEscapedQueryText());
107
+ $this->getLayout()->getBlock('head')->setTitle($title);
108
+ Mage::Helper('salesperson')->setRelatedSearches($this->hasRelatedSearches());
109
+
110
+ return parent::_prepareLayout();
111
+ }
112
+
113
+ /**
114
+ * Retrieve search list toolbar block
115
+ *
116
+ * @return Mage_Catalog_Block_Product_List
117
+ */
118
+ public function getListBlock()
119
+ {
120
+ return $this->getChild('search_result_list');
121
+ }
122
+
123
+ /**
124
+ * Set search available list orders
125
+ *
126
+ * @return Mage_CatalogSearch_Block_Result
127
+ */
128
+ public function setListOrders() {
129
+ $category = Mage::getSingleton('salesperson/layer')
130
+ ->getCurrentCategory();
131
+ /* @var $category Mage_Catalog_Model_Category */
132
+ $availableOrders = $category->getAvailableSortByOptions();
133
+ unset($availableOrders['position']);
134
+ $availableOrders = array_merge(array(
135
+ 'relevance' => $this->__('Relevance')
136
+ ), $availableOrders);
137
+
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * Set available view mode
143
+ *
144
+ * @return Mage_CatalogSearch_Block_Result
145
+ */
146
+ public function setListModes() {
147
+ $this->getListBlock()
148
+ ->setModes(array(
149
+ 'grid' => $this->__('Grid'),
150
+ 'list' => $this->__('List'))
151
+ );
152
+ return $this;
153
+ }
154
+
155
+ /**
156
+ * Set Search Result collection
157
+ *
158
+ * @return Mage_CatalogSearch_Block_Result
159
+ */
160
+ public function setListCollection() {
161
+ // $this->getListBlock()
162
+ // ->setCollection($this->_getProductCollection());
163
+ // return $this;
164
+ }
165
+
166
+ /**
167
+ * Retrieve Search result list HTML output
168
+ *
169
+ * @return string
170
+ */
171
+ public function getProductListHtml()
172
+ {
173
+
174
+ return $this->getChildHtml('search_result_list');
175
+ }
176
+
177
+ /**
178
+ * Retrieve loaded category collection
179
+ *
180
+ * @return Celebros_Helper_QwiserApi_QwiserProduct
181
+ */
182
+ protected function getProductCollection()
183
+ {
184
+ if (is_null($this->_productCollection)) {
185
+ $query = $this->_getSalespersonApi();
186
+ if(count($query->qsr->Products)>0){
187
+ $this->_productCollection = $query->qsr->Products->Items;
188
+ }
189
+ }
190
+
191
+ return $this->_productCollection;
192
+ }
193
+
194
+ /**
195
+ * Retrieve search result count
196
+ *
197
+ * @return string
198
+ */
199
+ public function getResultCount()
200
+ {
201
+ if($this->_getSalespersonApi()->results){
202
+ return $this->_getSalespersonApi()->results->GetRelevantProductsCount();
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Retrieve no Minimum query length Text
208
+ *
209
+ * @return string
210
+ */
211
+ public function getNoMinQueryLengthText()
212
+ {
213
+ if (Mage::helper('salesperson')->isMinQueryLength()) {
214
+ return Mage::helper('salesperson')->__('Minimum Search query length is %s', $this->_getSalespersonApi()->getMinQueryLength());
215
+ }
216
+ return $this->_getData('no_result_text');
217
+ }
218
+
219
+
220
+ public function hasRelatedSearches(){
221
+ if(!empty($this->_getSalespersonApi()->results->RelatedSearches)){
222
+ $relatedSearches = $this->_getSalespersonApi()->results->RelatedSearches;
223
+ $out = array();
224
+ foreach ($relatedSearches as $key => $relatedSearch){
225
+ $urlParams = array();
226
+ $urlParams['_current'] = false;
227
+ $urlParams['_escape'] = true;
228
+ $urlParams['_use_rewrite'] = true;
229
+ $urlParams['_query'] = array(
230
+ 'q' => $relatedSearch,
231
+ );
232
+ $out[$relatedSearch] = Mage::getUrl('*/*/index', $urlParams);
233
+ }
234
+ return $out;
235
+ }
236
+ return false;
237
+ }
238
+
239
+ public function getBannerImage(){
240
+ return $this->bannerImage != '' ? $this->bannerImage : false;
241
+ }
242
+
243
+ public function getCustomMessage(){
244
+ return $this->customMessage != '' ? $this->customMessage : false;
245
+ }
246
+
247
+
248
+ /**
249
+ * get's the Celebros_Analytics_SearchResults function from the API
250
+ * and return the image
251
+ */
252
+ /*public function getAnlxSerachResultFunction(){
253
+ return Mage::getModel('salesperson/api_anlx_analyticsFunctions')
254
+ ->Celebros_Analytics_SearchResults(
255
+ Mage::Helper('salesperson')->getSalespersonApi()->results->GetSearchHandle(),//sSearchHandle
256
+ Mage::Helper('salesperson')->getSalespersonApi()->results->GetLogHandle(),//sLogHandle
257
+ Mage::getStoreConfig('salesperson/general_settings/sitekey'),//sUserID
258
+ '1',//sGroupID
259
+ $this->_getSession()->getId(),//sWebSessionID
260
+ $_SERVER['PHP_SELF'],//sPreviousPageURL
261
+ true,//bIsSSL
262
+ true//bFromQwiser
263
+ );
264
+ }*/
265
+ }
app/code/local/Celebros/Salesperson/Block/Review/Helper.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Block_Review_Helper extends Mage_Review_Block_Helper
11
+ {
12
+ protected $_availableTemplates = array(
13
+ 'default' => 'review/helper/summary.phtml',
14
+ 'short' => 'review/helper/summary_short.phtml'
15
+ );
16
+
17
+ public function getSummaryHtml($product, $templateType, $displayIfNoReviews)
18
+ {
19
+ // pick template among available
20
+ if (empty($this->_availableTemplates[$templateType])) {
21
+ $templateType = 'default';
22
+ }
23
+ $this->setTemplate($this->_availableTemplates[$templateType]);
24
+
25
+ $this->setDisplayIfEmpty($displayIfNoReviews);
26
+
27
+ $this->setProduct($product);
28
+
29
+ return $this->toHtml();
30
+ }
31
+
32
+ public function getRatingSummary()
33
+ {
34
+ return $this->getProduct()->Field[$this->helper('salesperson/mapping')->getMapping('rating')];
35
+ }
36
+
37
+ public function getReviewsCount()
38
+ {
39
+ return key_exists(
40
+ $this->helper('salesperson/mapping')->getMapping('rating')
41
+ ,$this->getProduct()->Field
42
+ )
43
+ && (int)$this->getProduct()->Field[$this->helper('salesperson/mapping')->getMapping('rating')] > 0;
44
+ }
45
+
46
+ public function getReviewsUrl()
47
+ {
48
+ return Mage::getUrl('review/product/list', array(
49
+ 'id' => $this->getProduct()->Field[$this->helper('salesperson/mapping')->getMapping('id')],
50
+ ));
51
+ }
52
+ }
app/code/local/Celebros/Salesperson/Block/System/Convert/Profile/Edit/Tab/Run.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+
27
+ /**
28
+ * Convert profile edit tab
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Adminhtml
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Celebros_Salesperson_Block_System_Convert_Profile_Edit_Tab_Run extends Mage_Adminhtml_Block_System_Convert_Profile_Edit_Tab_Run
35
+ {
36
+ public function getRunButtonHtml()
37
+ {
38
+ $profile_name=Mage::registry('current_convert_profile')->getName();
39
+ $html = '';
40
+ if ($profile_name == "Salesperson Exporter")
41
+ {
42
+ $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setType('button')
43
+ ->setLabel($this->__('Celebros Export Products'))
44
+ ->setOnClick('window.open(\''.Mage::getBaseUrl().'salesperson/export/export_celebros\')')
45
+ ->toHtml();
46
+ }
47
+ else
48
+ {
49
+ /* old button*/
50
+ $html.=$this->getLayout()->createBlock('adminhtml/widget_button')->setType('button')
51
+ ->setClass('save')->setLabel($this->__('Run Profile in Popup'))
52
+ ->setOnClick('runProfile(true)')
53
+ ->toHtml();
54
+ /*end old button*/
55
+ }
56
+ return $html;
57
+
58
+ }
59
+ }
app/code/local/Celebros/Salesperson/Helper/Checkout/Cart.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Helper_Checkout_Cart extends Mage_Core_Helper_Url
11
+ {
12
+ /**
13
+ * Retrieve url for add product to cart
14
+ *
15
+ * @param Mage_Catalog_Model_Product $product
16
+ * @return string
17
+ */
18
+ public function getAddUrl($product, $additional = array())
19
+ {
20
+ $continueUrl = Mage::helper('core')->urlEncode($this->getCurrentUrl());
21
+ $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
22
+
23
+ if(key_exists(Mage::Helper('salesperson/mapping')->getMapping('id'), $product->Field)){
24
+ $routeParams = array(
25
+ $urlParamName => $continueUrl,
26
+ 'product' => $product->Field[Mage::Helper('salesperson/mapping')->getMapping('id')]
27
+ );
28
+ }
29
+
30
+ if (!empty($additional)) {
31
+ $routeParams = array_merge($routeParams, $additional);
32
+ }
33
+
34
+ // if ($product->hasUrlDataObject()) {
35
+ // $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
36
+ // $routeParams['_store_to_url'] = true;
37
+ // }
38
+
39
+ if ($this->_getRequest()->getRouteName() == 'checkout'
40
+ && $this->_getRequest()->getControllerName() == 'cart') {
41
+ $routeParams['in_cart'] = 1;
42
+ }
43
+
44
+ return $this->_getUrl('checkout/cart/add', $routeParams);
45
+ }
46
+ }
app/code/local/Celebros/Salesperson/Helper/Data.php ADDED
@@ -0,0 +1,380 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Helper_Data extends Mage_CatalogSearch_Helper_Data
11
+ {
12
+ const QUERY_VAR_NAME = 'q';
13
+ const MAX_QUERY_LEN = 200;
14
+ const ICONV_CHARSET = 'UTF-8';
15
+
16
+ /**
17
+ * Query object
18
+ *
19
+ * @var Mage_CatalogSearch_Model_Query
20
+ */
21
+ protected $_query;
22
+
23
+ /**
24
+ * QwiserSearchApi object
25
+ *
26
+ * @var Mage_CatalogSearch_Model_Query
27
+ */
28
+ protected $_api;
29
+
30
+ /**
31
+ * Query string
32
+ *
33
+ * @var string
34
+ */
35
+ protected $_queryText;
36
+
37
+ /**
38
+ * Note messages
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_messages = array();
43
+
44
+ /**
45
+ * Is a maximum length cut
46
+ *
47
+ * @var bool
48
+ */
49
+ protected $_isMaxLength = false;
50
+
51
+ protected $_gmessages;
52
+
53
+ protected $_bannerImage;
54
+ protected $_customMessage;
55
+ protected $_relatedSearches;
56
+
57
+ /**
58
+ * Retrieve salesperson session
59
+ *
60
+ * @return Mage_Catalog_Model_Session
61
+ */
62
+ protected function _getSession()
63
+ {
64
+ return Mage::getSingleton('salesperson/session');
65
+ }
66
+
67
+ /**
68
+ * Retrieve search query parameter name
69
+ *
70
+ * @return string
71
+ */
72
+ public function getQueryParamName()
73
+ {
74
+ return self::QUERY_VAR_NAME;
75
+ }
76
+
77
+ public function getSalespersonApi()
78
+ {
79
+ if (!$this->_api) {
80
+ $this->_api = Mage::getModel('salesperson/salespersonSearchApi');
81
+ }
82
+ return $this->_api;
83
+ }
84
+
85
+ public function getSalespersonAnlxApi()
86
+ {
87
+ return Mage::getModel('salesperson/salespersonAnalyticsApi');
88
+ }
89
+
90
+ /**
91
+ *
92
+ * Clean non UTF-8 characters
93
+ *
94
+ * @param string $string
95
+ * @return string
96
+ * @author Sveta Oksen copied from Magento v1.5
97
+ * @since 31/03/2011
98
+ */
99
+ public function cleanString($string)
100
+ {
101
+ return '"libiconv"' == ICONV_IMPL ? iconv(self::ICONV_CHARSET, self::ICONV_CHARSET . '//IGNORE', $string) : $string;
102
+ }
103
+
104
+ public function getQueryText()
105
+ {
106
+ if (is_null($this->_queryText)) {
107
+ $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
108
+ if ($this->_queryText === null) {
109
+ $this->_queryText = '';
110
+ } else {
111
+ if (is_array($this->_queryText)) {
112
+ $this->_queryText = null;
113
+ }
114
+ $this->_queryText = trim($this->_queryText);
115
+ $this->_queryText = $this->cleanString($this->_queryText);
116
+
117
+ if (Mage::helper('core/string')->strlen($this->_queryText) > $this->getMaxQueryLength()) {
118
+ $this->_queryText = Mage::helper('core/string')->substr(
119
+ $this->_queryText,
120
+ 0,
121
+ $this->getMaxQueryLength()
122
+ );
123
+ $this->_isMaxLength = true;
124
+ }
125
+ }
126
+ }
127
+ return $this->_queryText;
128
+ }
129
+
130
+ /**
131
+ * Retrieve HTML escaped search query
132
+ *
133
+ * @return string
134
+ */
135
+ public function getEscapedQueryText()
136
+ {
137
+ return $this->htmlEscape($this->getQueryText());
138
+ }
139
+
140
+ public function getDefaultPageSize(){
141
+ if (substr(Mage::getStoreConfig('catalog/frontend/list_mode'),0,4) == 'grid'){
142
+ return Mage::getStoreConfig('catalog/frontend/grid_per_page');
143
+ }
144
+ else {
145
+ return Mage::getStoreConfig('catalog/frontend/list_per_page');
146
+ }
147
+ }
148
+
149
+ public function getDefaultSortByField(){
150
+ return Mage::getStoreConfig('catalog/frontend/default_sort_by');
151
+ }
152
+
153
+ public function getStoreSearchProfile(){
154
+ return Mage::getStoreConfig('salesperson/display_settings/search_profile');
155
+ }
156
+
157
+ /**
158
+ * Is a minimum query length
159
+ *
160
+ * @return bool
161
+ */
162
+ public function isMinQueryLength()
163
+ {
164
+ if (Mage::helper('core/string')->strlen($this->getQueryText()) < $this->getMinQueryLength()) {
165
+ return true;
166
+ }
167
+ return false;
168
+ }
169
+
170
+ /**
171
+ * Retrieve minimum query length
172
+ *
173
+ * @param mixed $store
174
+ * @return int
175
+ */
176
+ public function getMinQueryLength($store = null)
177
+ {
178
+ return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MIN_QUERY_LENGTH, $store);
179
+ }
180
+
181
+ /**
182
+ * Retrieve result page url and set "secure" param to avoid confirm
183
+ * message when we submit form from secure page to unsecure
184
+ *
185
+ * @param string $query
186
+ * @return string
187
+ */
188
+ public function getResultUrl($query = null)
189
+ {
190
+ return $this->_getUrl('salesperson/result', array(
191
+ '_query' => array(self::QUERY_VAR_NAME => $query),
192
+ '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()
193
+ ));
194
+ }
195
+
196
+ /**
197
+ * Prepare save query for result
198
+ *
199
+ * @return Mage_CatalogSearch_Model_Query
200
+ */
201
+ public function prepare(Mage_CatalogSearch_Model_Query $query, $num_result)
202
+ {
203
+ if (!$query->getId()) {
204
+ $query->setIsActive(0);
205
+ $query->setIsProcessed(0);
206
+ $query->setNumResults($num_result);
207
+ $query->save();
208
+ $query->setIsActive(1);
209
+ }
210
+
211
+ return $this;
212
+ }
213
+
214
+ /**
215
+ * Retrieve suggest url
216
+ *
217
+ * @return string
218
+ */
219
+ public function getSuggestUrl()
220
+ {
221
+ return $this->_getUrl('catalogsearch/ajax/suggest');
222
+ }
223
+
224
+ /**
225
+ * Retrieve search term url
226
+ *
227
+ * @return string
228
+ */
229
+ public function getSearchTermUrl()
230
+ {
231
+ return $this->_getUrl('catalogsearch/term/popular');
232
+ }
233
+
234
+ /**
235
+ * Retrieve advanced search URL
236
+ *
237
+ * @return string
238
+ */
239
+ public function getAdvancedSearchUrl()
240
+ {
241
+ return $this->_getUrl('catalogsearch/advanced');
242
+ }
243
+
244
+ /**
245
+ * Retrieve maximum query words count for like search
246
+ *
247
+ * @param mixed $store
248
+ * @return int
249
+ */
250
+ public function getMaxQueryWords($store = null)
251
+ {
252
+ return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_WORDS, $store);
253
+ }
254
+
255
+ /**
256
+ * Retrieve maximum query length
257
+ *
258
+ * @param mixed $store
259
+ * @return int
260
+ */
261
+ public function getMaxQueryLength($store = null)
262
+ {
263
+ return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_LENGTH, $store);
264
+ }
265
+
266
+ /**
267
+ * Add Note message
268
+ *
269
+ * @param string $message
270
+ * @return Mage_CatalogSearch_Helper_Data
271
+ */
272
+ public function addNoteMessage($message)
273
+ {
274
+ $this->_messages[] = $message;
275
+ return $this;
276
+ }
277
+
278
+ /**
279
+ * Set Note messages
280
+ *
281
+ * @param array $messages
282
+ * @return Mage_CatalogSearch_Helper_Data
283
+ */
284
+ public function setNoteMessages(array $messages)
285
+ {
286
+ $this->_messages = $messages;
287
+ return $this;
288
+ }
289
+
290
+ /**
291
+ * Get the recommended attribute from salesperson API and add it to NoteMessages
292
+ *
293
+ */
294
+ public function getRecommendedMessages(){
295
+ if($this->getSalespersonApi()->results->GetRecommendedMessage() != ''){
296
+ $message = preg_replace('/#%/', '', $this->getSalespersonApi()->results->GetRecommendedMessage());
297
+ $message = preg_replace('/%#/', '', $message);
298
+ $this->addNoteMessage($this->__($message));
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Retrieve Current Note messages
304
+ *
305
+ * @return array
306
+ */
307
+ public function getNoteMessages()
308
+ {
309
+ return $this->_messages;
310
+ }
311
+
312
+ /**
313
+ * Check query of a warnings
314
+ *
315
+ * @param mixed $store
316
+ * @return Celebros_Salesperson_Helper_Data
317
+ */
318
+ public function checkNotes($store = null)
319
+ {
320
+ if ($this->_isMaxLength) {
321
+ $this->addNoteMessage($this->__('Maximum Search query length is %s. Your query was cut.', $this->getMaxQueryLength()));
322
+ }
323
+
324
+ $stringHelper = Mage::helper('core/string');
325
+ /* @var $stringHelper Mage_Core_Helper_String */
326
+
327
+ }
328
+
329
+
330
+ public function getNonLeadQuestionsPosition(){
331
+ if (Mage::getStoreConfig('salesperson/display_settings/display_non_lead_top'))
332
+ return 'top';
333
+ elseif (Mage::getStoreConfig('salesperson/display_settings/display_non_lead_left'))
334
+ return 'left';
335
+ elseif (Mage::getStoreConfig('salesperson/display_settings/display_non_lead_right'))
336
+ return 'right';
337
+ }
338
+ public function goToProductOnOneResult(){
339
+ return Mage::getStoreConfigFlag('salesperson/display_settings/go_to_product_on_one_result');
340
+ }
341
+
342
+ public function getResultCount()
343
+ {
344
+ if($this->getSalespersonApi()->results){
345
+ return $this->getSalespersonApi()->results->GetRelevantProductsCount();
346
+ }
347
+ }
348
+
349
+ public function getNoteHelperMessages() {
350
+ return $this->_gmessages;
351
+ }
352
+
353
+ public function setNoteHelperMessages($messages) {
354
+ $this->_gmessages = $messages;
355
+ }
356
+
357
+ public function setRelatedSearches($relatedSearches){
358
+ return $this->_relatedSearches = $relatedSearches;
359
+ }
360
+
361
+ public function setBannerImage($img){
362
+ $this->_bannerImage = $img;
363
+ }
364
+
365
+ public function setCustomMessage($msg){
366
+ $this->_customMessage = $msg;
367
+ }
368
+
369
+ public function getBannerImage(){
370
+ return $this->_bannerImage != '' ? $this->_bannerImage : false;
371
+ }
372
+
373
+ public function getCustomMessage(){
374
+ return $this->_customMessage != '' ? $this->_customMessage : false;
375
+ }
376
+
377
+ public function getRelatedSearches(){
378
+ return $this->_relatedSearches;
379
+ }
380
+ }
app/code/local/Celebros/Salesperson/Helper/Mapping.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Celebros_Salesperson_Helper_Mapping extends Mage_CatalogSearch_Helper_Data
4
+ {
5
+
6
+ /**
7
+ * Retrieve Mapping array
8
+ *
9
+ * @return array
10
+ */
11
+
12
+ public function getMappingFieldsArray(){
13
+ return Mage::getSingleton("salesperson/mapping")->getFieldsArray();
14
+ }
15
+
16
+ /**
17
+ * Retrieve a mapping for a field
18
+ *
19
+ * @return string
20
+ *
21
+ */
22
+ public function getMapping($code_field = ""){
23
+ $mappingArray = $this->getMappingFieldsArray();
24
+ if(!key_exists($code_field, $mappingArray)){
25
+ return $code_field;
26
+ }
27
+ return strtolower($mappingArray[$code_field]);
28
+ }
29
+ }
app/code/local/Celebros/Salesperson/Helper/Product/Compare.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Helper_Product_Compare extends Mage_Core_Helper_Url
11
+ {
12
+ /**
13
+ * Get parameters used for build add product to compare list urls
14
+ *
15
+ * @param Mage_Catalog_Model_Product $product
16
+ * @return array
17
+ */
18
+ protected function _getUrlParams($product)
19
+ {
20
+ if(key_exists(Mage::Helper('salesperson/mapping')->getMapping('id'),$product->Field)){
21
+ $productId = $product->Field[Mage::Helper('salesperson/mapping')->getMapping('id')];
22
+ }
23
+ return array(
24
+ 'product' => $productId,
25
+ Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
26
+ );
27
+
28
+ }
29
+
30
+ /**
31
+ * Retrieve url for adding product to conpare list
32
+ *
33
+ * @param Mage_Catalog_Model_Product $product
34
+ * @return string
35
+ */
36
+ public function getAddUrl($product)
37
+ {
38
+ return $this->_getUrl('catalog/product_compare/add', $this->_getUrlParams($product));
39
+ }
40
+ }
app/code/local/Celebros/Salesperson/Helper/Wishlist/Data.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Helper_Wishlist_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Retrieve Item Store for URL
14
+ *
15
+ * @param Celebros_Salesperson_Model_Api_QwiserProduct|Mage_Wishlist_Model_Item $item
16
+ * @return Mage_Core_Model_Store
17
+ */
18
+ protected function _getUrlStore($item)
19
+ {
20
+ Mage::log("wishlist");
21
+ $storeId = null;
22
+ if ($item instanceof Celebros_Salesperson_Model_Api_QwiserProduct) {
23
+ if(key_exists(Mage::Helper('salesperson/mapping')->getMapping('visible'),$item->Field) && key_exists(Mage::Helper('salesperson/mapping')->getMapping('store_id'),$item->Field)){
24
+ if ($item->Field[Mage::Helper('salesperson/mapping')->getMapping('visible')] == '1' ) {
25
+ $storeId = $item->Field[Mage::Helper('salesperson/mapping')->getMapping('store_id')];
26
+ }
27
+ }
28
+ }
29
+ return Mage::app()->getStore($storeId);
30
+ }
31
+
32
+ /**
33
+ * Retrieve url for adding product to wishlist with params
34
+ *
35
+ * @param Celebros_Salesperson_Model_Api_QwiserProduct|Mage_Wishlist_Model_Item $product
36
+ * @param array $param
37
+ * @return string|boolean
38
+ */
39
+ public function getAddUrlWithParams($item, array $params = array())
40
+ {Mage::log("wishlist");
41
+ $productId = null;
42
+ if ($item instanceof Celebros_Salesperson_Model_Api_QwiserProduct) {
43
+ if(key_exists(Mage::Helper('salesperson/mapping')->getMapping('id'),$item->Field)){
44
+ $productId = $item->Field[Mage::Helper('salesperson/mapping')->getMapping('id')];
45
+ }
46
+ }
47
+ if ($item instanceof Mage_Wishlist_Model_Item) {
48
+ $productId = $item->getProductId();
49
+ }
50
+
51
+ if ($productId) {
52
+ $params['product'] = $productId;
53
+ return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
54
+ }
55
+
56
+ return false;
57
+ }
58
+ }
app/code/local/Celebros/Salesperson/Model/Api/Anlx/AnalyticsFunctions.php ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ include("LogRequest.php");
3
+
4
+ //define("G_DATA_COLLECTOR_ADDRESS","");
5
+ //define("G_CUSTOMER_ID","");
6
+ //define("G_CUSTOMER_NAME","");
7
+ //define("G_PUBLIC_KEY","");
8
+
9
+ class Celebros_Salesperson_Model_Api_Anlx_AnalyticsFunctions
10
+ {
11
+ var $DATA_COLLECTOR_ADDRESS;
12
+ var $CUSTOMER_ID;
13
+ var $CUSTOMER_NAME;
14
+ var $PUBLIC_KEY;
15
+
16
+ // validate result
17
+ var $ValidateResult;
18
+
19
+ // Anlx object
20
+ var $AnlxApi;
21
+
22
+ function Celebros_Salesperson_Model_Api_Anlx_AnalyticsFunctions($arguments)
23
+ {
24
+ $this->DATA_COLLECTOR_ADDRESS=$arguments["G_DATA_COLLECTOR_ADDRESS"];
25
+ $this->CUSTOMER_ID=$arguments["G_CUSTOMER_ID"];
26
+ $this->CUSTOMER_NAME=$arguments["G_CUSTOMER_NAME"];
27
+ $this->PUBLIC_KEY=$arguments["G_PUBLIC_KEY"];
28
+
29
+ //$this->AnlxApi = $this->GetAnlxObject($bIsSSL);
30
+ }
31
+
32
+ function GetAnlxObject( $IsSSL )
33
+ {
34
+ $AnlxApi = new LogRequest();
35
+
36
+ if ($IsSSL)
37
+ $AnlxApi->Mode="secured";
38
+ else
39
+ $AnlxApi->Mode="plainData";
40
+
41
+ $this->ValidateResult = new sValidateResult();
42
+
43
+ $AnlxApi->DataCollectorIP=$this->DATA_COLLECTOR_ADDRESS;
44
+ $AnlxApi->CustomerID=$this->CUSTOMER_ID;
45
+ $AnlxApi->CustomerName=$this->CUSTOMER_NAME;
46
+ $AnlxApi->PublicKeyToken=$this->PUBLIC_KEY;
47
+
48
+ return $AnlxApi;
49
+ }
50
+
51
+ /**
52
+ * Call this function from any page on the site to have Qwiser Analytics log information about visits to this page.
53
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
54
+ * @param sGroupID The ID of the testing group to which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
55
+ * @param sWebSessionID The ID of the current web server's session ID.
56
+ * @param sReferrer The URL of the page which led the user to this page (the referrer). The URL should not contain any parameters.
57
+ * @param bIsSSL Set to true if the calling page is on a Secure Socket Layer (SSL)
58
+ **/
59
+
60
+ function Celebros_Analytics_Visit($sUserID,$sGroupID,$sWebSessionID,$sReferrer,$bIsSSL)
61
+ {
62
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
63
+
64
+ if ($sGroupID==null || trim($sGroupID)=="")
65
+ $sGroupID = "1";
66
+
67
+ $AnlxApi->sGroupID=$sGroupID;
68
+ $AnlxApi->sUserID=$sUserID;
69
+ $AnlxApi->sWebSessionID=$sWebSessionID;
70
+
71
+ // visit info
72
+ $AnlxApi->sPreviousPageURL=$sReferrer;
73
+
74
+ $sLogRequest = $AnlxApi->GetLogRequest("LogVisitInfo");
75
+ $this->ValidateResult = $AnlxApi->GetValidateResult();
76
+
77
+ return $sLogRequest;
78
+ }
79
+
80
+ /**
81
+ * Call this function from a Qwiser search results page to have Qwiser Analytics collect user search behavior information.
82
+ * <b>This function is not intended for use with a search results page that does not use Qwiser.</b>
83
+ * @param sSearchHandle The SearchHandle String of the current search state.
84
+ * @param sLogHandle The Qwiser LogHandle String (additional information for Qwiser Analytics) generated by Qwiser for the current state of the search results.
85
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
86
+ * @param sGroupID The ID of the testing group which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
87
+ * @param sWebSessionID The ID of the current web server's session ID.
88
+ * @param sReferrer The URL of the page from which the user got to this page (the referrer). The URL should not contain any parameters.
89
+ * @param bIsSSL Set to true if the calling page is on a Secure Socket Layer (SSL)
90
+ * @param bFromQwiser Set to true if Qwiser Search is used
91
+ * **/
92
+
93
+ function Celebros_Analytics_SearchResults($sSearchSession,$sLogHandle,$sUserID,$sGroupID,$sWebSessionID,$sReferrer, $bIsSSL, $bFromQwiser)
94
+ {
95
+ /*echo "<br>P:<br>";
96
+ var_dump($sSearchSession);
97
+ echo "<br>P:<br>";
98
+ var_dump($sLogHandle);
99
+ echo "<br>P:<br>";
100
+ var_dump($sUserID);
101
+ echo "<br>P:<br>";
102
+ var_dump($sGroupID);
103
+ echo "<br>P:<br>";
104
+ var_dump($sWebSessionID);
105
+ echo "<br>P:<br>";
106
+ var_dump($sReferrer);
107
+ echo "<br>P:<br>";
108
+ var_dump($bIsSSL);
109
+ echo "<br>P:<br>";
110
+ var_dump($bFromQwiser);
111
+ exit();*/
112
+
113
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
114
+
115
+ $AnlxApi->SID=$sSearchSession;
116
+ $AnlxApi->LH=$sLogHandle;
117
+ $AnlxApi->FromQwiser=$bFromQwiser;
118
+
119
+
120
+ if ($sGroupID==null || trim($sGroupID)=="")
121
+ $sGroupID = "1";
122
+
123
+ $AnlxApi->sGroupID=$sGroupID;
124
+ $AnlxApi->sUserID=$sUserID;
125
+ $AnlxApi->sWebSessionID=$sWebSessionID;
126
+ $AnlxApi->sPreviousPageURL=$sReferrer;
127
+
128
+ $sLogRequest = $AnlxApi->GetLogRequest("LogSearchResult");
129
+ $this->ValidateResult = $AnlxApi->ValidateResult;
130
+
131
+ return $sLogRequest;
132
+ }
133
+
134
+ /**
135
+ * Call this function from any search results page to have Qwiser Analytics collect user search behavior information.
136
+ * <b>This function intend for use with a search results page that does not use Qwiser.</b>
137
+ * @param sSessionID A unique string to identify the current search state.
138
+ * @param sQuery The query string that the user used for his search.
139
+ * @param bFromBrowse Is the search is coming from a browser or not.
140
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
141
+ * @param sGroupID The ID of the testing group which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
142
+ * @param sWebSessionID The ID of the current web server's session ID.
143
+ * @param sReferrer The URL of the page from which the user got to this page (the referrer). The URL should not contain any parameters.
144
+ * @param bIsSSL Set to true if the calling page is on a Secure Socket Layer (SSL)
145
+ * **/
146
+
147
+ function Celebros_Analytics_GenericSearchResults($sSessionID,$sQuery,$bFromBrowse,$sUserID,$sGroupID,$sWebSessionID,$sReferrer, $bIsSSL)
148
+ {
149
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
150
+
151
+ $this->AnlxApi->strSearchSessionID = $sSessionID;
152
+ $this->AnlxApi->strQuery = $sQuery;
153
+ $this->AnlxApi->bFromBrowse = $bFromBrowse;
154
+
155
+ if ($sGroupID==null || trim($sGroupID)=="")
156
+ $sGroupID = "1";
157
+
158
+ $this->AnlxApi->sGroupID=$sGroupID;
159
+ $this->AnlxApi->sUserID=$sUserID;
160
+ $this->AnlxApi->sWebSessionID=$sWebSessionID;
161
+ $this->AnlxApi->sPreviousPageURL=$sReferrer;
162
+
163
+ $sLogRequest = $this->AnlxApi->GetLogRequest("LogGenericSearchResult");
164
+ $this->ValidateResult = $this->AnlxApi->ValidateResult;
165
+
166
+ return $sLogRequest;
167
+
168
+ }
169
+
170
+
171
+ /**
172
+ * Call this function from a product details page to have Qwiser Analytics collect information about traffic in the product details page.
173
+ * @param sSKU The SKU or product code of the current product being displayed.
174
+ * @param sVariant Any String definition that would distinguish this product from other products in a certain product group. e.g. "Blue" or "GS23" (a child SKU). The combination of the sSKU parameter and this one should be unique for every product variant. If this information is not available or not applicable, you may pass an empty ("") String.
175
+ * @param sName The name or title of the product being displayed.
176
+ * @param fPrice The price of the product being displayed.
177
+ * @param sCategory The category to which this product belongs, if available. If not, you may pass an empty ("") String.
178
+ * @param sSearchSession The SearchHandle String of the current search state, if available. If not, you may pass an empty ("") String.
179
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
180
+ * @param sGroupID The ID of the testing group to which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
181
+ * @param sWebSessionID The ID of the current web server's session ID.
182
+ * @param sReferrer The URL of the page which led the user to this page (the referrer). The URL should not contain any parameters.
183
+ * @param iSourceType The type of location that linked to this page:<ul><li><b>Value -> </b><b>Description</b></li><li>0 -> Qwiser Search</li><li>1 -> Banner&#47;Ad on web page</li><li>2 -> Browse (the shopper did not use the search)</li><li>3 -> E-Mail promotion</li><li>4 -> Direct Mailing (Hard copy catalog, etc.)</li><li>5 -> Print (Newspapers, periodicals, in-flight magazines, etc.)</li><li>6 -> Television</li><li>100 -> Other sources</li></ul>
184
+ * @param sSourceName If the source type is "Other", provide a name for this source to distinguish between custom sources. Otherwise, you may pass an empty ("") String.
185
+ * @param bIsSSL Set to true if the calling page is on a Secure Socket Layer (SSL)
186
+ * **/
187
+
188
+ function Celebros_Analytics_ProductDetails($sSKU,$sVariant,$sName,$fPrice,$sCategory,$sSearchSession,$sUserID,$sGroupID,$sWebSessionID,$sReferrer,$iSourceType,$sSourceTypeName, $bIsSSL)
189
+ {
190
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
191
+
192
+ if ($sGroupID==null || trim($sGroupID)=="")
193
+ $sGroupID = "1";
194
+
195
+ $AnlxApi->sGroupID=$sGroupID;
196
+ $AnlxApi->sUserID=$sUserID;
197
+ $AnlxApi->sWebSessionID=$sWebSessionID;
198
+
199
+ if($iSourceType==0)
200
+ $AnlxApi->bUsingQwiserSearch=true;
201
+ else
202
+ $AnlxApi->bUsingQwiserSearch=false;
203
+
204
+ $AnlxApi->SID=$sSearchSession;
205
+
206
+ // visit info
207
+ $AnlxApi->sPreviousPageURL=$sReferrer;
208
+ $AnlxApi->iSourceType=$iSourceType;
209
+ $AnlxApi->sSourceTypeName=$sSourceTypeName;
210
+
211
+ //product info
212
+ $AnlxApi->sProductSKU=$sSKU;
213
+ $AnlxApi->sProductVariant=$sVariant;
214
+ $AnlxApi->sProductName=$sName;
215
+ $AnlxApi->fProductPrice=$fPrice;
216
+ $AnlxApi->sProductCategory=$sCategory;
217
+
218
+ $sLogRequest = $AnlxApi->GetLogRequest("LogProductDetails");
219
+ $this->ValidateResult = $AnlxApi->ValidateResult;
220
+
221
+ return $sLogRequest;
222
+ }
223
+ /**
224
+ * Call this function from the Add-To-Cart page to have Qwiser Analytics collect information about user activity with their shopping cart.
225
+ * This function is not intended for use when editing items in the cart or removing items from the cart.
226
+ * When the user purchases the items in the cart, those cart changes will be picked up.
227
+ * @param sSKU The SKU or product code of the current product being added.
228
+ * @param sVariant Any String definition that would distinguish this product from other products in a certain product group. e.g. "Blue" or "GS23" (a child SKU). The combination of the sSKU parameter and this one should be unique for every product variant. If this information is not available or not applicable, you may pass an empty ("") String.
229
+ * @param sName The name or title of the product being added.
230
+ * @param iQuantity The number of individual units of this specific product that are added to the cart.
231
+ * @param fPrice The price of the product being displayed.
232
+ * @param sCategory The category to which this product belongs, if available. If not, you may pass an empty ("") String.
233
+ * @param sCartID The ID of the user's cart, as defined in your cart management system, or another ID that can uniquely identify the specific cart.
234
+ * @param iCartProductCount The number of products in the cart after the new addition.
235
+ * @param fCartSubTotal The Subtotal price of all the items in the cart after the new addition.
236
+ * @param sCartCoupon A String representing a coupon used in this cart (which applies to the entire cart), if any. If no coupon was used, you may pass an empty ("") String.
237
+ * @param fCartDiscount The discount factor for this cart. e.g. If the entire cart is discounted by 25%, use 0.25. If there is no discount, use 0.
238
+ * @param sSearchSession The SearchHandle String of the current search state.
239
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
240
+ * @param sGroupID The ID of the testing group to which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
241
+ * @param sWebSessionID The ID of the current web server's session ID.
242
+ * @param sReferrer The URL of the page which led the user to this page (the referrer). The URL should not contain any parameters.
243
+ * @param bIsSSL Set to true if your Add-To-Cart page is on a Secure Socket Layer (SSL).
244
+ **/
245
+
246
+ function Celebros_Analytics_AddToCart($sSKU,$sVariant,$sName,$iQuantity,$fPrice,$sCategory,$sCartID,$iCartProductCount,$fCartSubTotal, $sCartCoupon,$fCartDiscount,$sSearchSession,$sUserID,$sGroupID,$sWebSessionID,$sReferrer,$bIsSSL)
247
+ {
248
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
249
+
250
+ if ($sGroupID==null || trim($sGroupID)=="")
251
+ $sGroupID = "1";
252
+
253
+ $AnlxApi->sGroupID=$sGroupID;
254
+ $AnlxApi->sUserID=$sUserID;
255
+ $AnlxApi->sWebSessionID=$sWebSessionID;
256
+
257
+ //search handle
258
+ if(!($sSearchSession=="" || $sSearchSession==null))
259
+ {
260
+ $AnlxApi->SID=$sSearchSession;
261
+ $AnlxApi->bUsingQwiserSearch=true;
262
+ }
263
+ else
264
+ {
265
+ $AnlxApi->bUsingQwiserSearch=false;
266
+ $AnlxApi->SID=$sWebSessionID;
267
+ }
268
+
269
+ // visit info
270
+ $AnlxApi->sPreviousPageURL=$sReferrer;
271
+
272
+ //'cart info
273
+ $AnlxApi->sCartID=$sCartID;
274
+ $AnlxApi->sCartCoupon=$sCartCoupon;
275
+ $AnlxApi->fCartDiscount=$fCartDiscount;
276
+ $AnlxApi->iCartProductCount=$iCartProductCount;
277
+ $AnlxApi->fCartSubTotal=$fCartSubTotal;
278
+
279
+ //product info
280
+ $AnlxApi->sProductSKU=$sSKU;
281
+ $AnlxApi->sProductVariant=$sVariant;
282
+ $AnlxApi->sProductName=$sName;
283
+ $AnlxApi->fProductPrice=$fPrice;
284
+ $AnlxApi->sProductCategory=$sCategory;
285
+ $AnlxApi->iProductQuantity=$iQuantity;
286
+
287
+ $sLogRequest = $AnlxApi->GetLogRequest("LogAddToCart");
288
+ $this->ValidateResult = $AnlxApi->ValidateResult;
289
+
290
+ return $sLogRequest;
291
+ }
292
+
293
+ /**
294
+ * Call this function from the Checkout page to have Qwiser Analytics collect purchase activity information.
295
+ * @param ProductsArray A 2-dimensional array containing information about all products being purchased. Each element in the first dimension represents a product. Elements in the second dimension contain product information as follows:<br><br><table border=1><tr><td><b>Index</b></td><td><b>Description</b></td></tr><tr><td>0</td><td>sSKU: The SKU or product code of the current product being purchased.</td></tr><tr><td>1</td><td>sVariant: Any string definition that would distinguish this product from other products in a certain products group. e.g. "Blue" or "GS23" (a child SKU). The combination of the sSKU parameter and this one should be unique for every product variant. If this information is not available or not applicable, you may pass an empty ("") string.</td></tr><tr><td>2</td><td>fPrice: The price of the product being purchased.</td></tr><tr><td>3</td><td>iQuantity: The number of units of this specific product being purchased.</td></tr><tr><td>4</td><td>fProductDiscount: The discount factor applied to this specific product ot the entire cart), e.g. If there is a 25% discount on this product, use 0.25. If there is no discount, use 0.</td></tr><tr><td>5</td><td>sProductCoupon: A String representing a coupon used to purchase this product (i.e. A coupon that applies to this specific product, as opposed to one applied to the entire cart), if any. (optional)</td></tr></table><hr>
296
+ * @param sCartID The ID of the user's cart, as defined in your cart management system, or another ID that can uniquely identify the specific cart.
297
+ * @param iCartProductCount The number of products in the cart.
298
+ * @param fCartTotal The total price of all items in the cart being purchased.
299
+ * @param sCartCoupon A String representing a coupon used in this cart (which applies to the entire cart), if any. If no coupon was used, you may pass an empty ("") String.
300
+ * @param fCartDiscount The discount factor for this cart. e.g. If the entire cart is discounted by 25%, use 0.25. If there is no discount, use 0.
301
+ * @param sUserID A unique ID for the user. It could be any type of ID such as the Web Server ID, session ID, etc.
302
+ * @param sGroupID The ID of the testing group to which this user belongs to, as defined in the Qwiser Analytics system. If you do not know what to pass here, you may pass an empty ("") String.
303
+ * @param sWebSessionID The ID of the current web server's session ID.
304
+ * @param sReferrer The URL of the page which led the user to this page (the referrer). The URL should not contain any parameters.
305
+ * @param bIsSSL Set to true if the calling page is on a Secure Socket Layer (SSL) .
306
+ **/
307
+
308
+ function Celebros_Analytics_CheckOut($sOrderID, $ProductsArray,$sCartID,$iCartProductCount,$fCartTotal,$sCartCoupon,$fCartDiscount,$sUserID,$sGroupID,$sWebSessionID,$sReferrer,$bIsSSL)
309
+ {
310
+ $AnlxApi = $this->GetAnlxObject($bIsSSL);
311
+ if ($sGroupID==null || trim($sGroupID)=="")
312
+ $sGroupID = "1";
313
+
314
+ $AnlxApi->sGroupID=$sGroupID;
315
+ $AnlxApi->sUserID=$sUserID;
316
+ $AnlxApi->sWebSessionID=$sWebSessionID;
317
+ $AnlxApi->sPreviousPageURL =$sReferrer;
318
+
319
+ //products
320
+ $AnlxApi->ProductsArray=$ProductsArray;
321
+ //'cart info
322
+ $AnlxApi->sCartID=$sCartID;
323
+ $AnlxApi->sCartCoupon=$sCartCoupon;
324
+ $AnlxApi->fCartDiscount=$fCartDiscount;
325
+ $AnlxApi->iCartProductCount=$iCartProductCount;
326
+ $AnlxApi->fCartSubTotal=$fCartTotal;
327
+
328
+ // order info
329
+ $AnlxApi->sOrderID=$sOrderID;
330
+
331
+ $sLogRequest = $AnlxApi->GetLogRequest("LogCheckOut");
332
+ $this->ValidateResult = $AnlxApi->ValidateResult;
333
+
334
+ return $sLogRequest;
335
+ }
336
+
337
+ /*function AddCustomProperty($Name, $Value)
338
+ {
339
+ $this->AnlxApi = $this->GetAnlxObject($bIsSSL);
340
+ $this->AnlxApi->AddCustomProperty($Name, $Value);
341
+ }*/
342
+
343
+ function GetLastErrorMessage()
344
+ {
345
+ return $this->ValidateResult->strMessage;
346
+ }
347
+
348
+ function GetLastErrorSeverity()
349
+ {
350
+ return $this->ValidateResult->iSeverity;
351
+ }
352
+ }
353
+
354
+ ?>
355
+
app/code/local/Celebros/Salesperson/Model/Api/Anlx/DataStructure.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ /*function GetValidateMessageID($messageID)
3
+ {
4
+ switch ($messageID)
5
+ {
6
+ CASE "NoError":
7
+ return "0";
8
+ CASE "evrErrSearchHandleIsMissing":
9
+ return "1";
10
+ CASE "evrErrSearchSessionIDIsMissing":
11
+ return "2";
12
+ CASE "evrErrSearchSessionIsMissing":
13
+ return "3";
14
+ CASE "evrErrSKUIsMissing":
15
+ return "4";
16
+ CASE "evrErrCartIDIsMissing":
17
+ return "5";
18
+ CASE "evrErrServerNameIsMissing":
19
+ return "6";
20
+ CASE "evrErrCustomerIDIsMissing":
21
+ return "7";
22
+ CASE "evrWrnCustomerNameISMissing":
23
+ return "8";
24
+ CASE "evrWrnConflictInDCParam":
25
+ return "9";
26
+ CASE "evrErrOrderIDIsMissing":
27
+ return "10";
28
+ CASE "evrErrLogHandleIsMissing":
29
+ return "11";
30
+
31
+ default:
32
+ return "0";
33
+ }
34
+
35
+ }*/
36
+
37
+ /*function GetSeverity($Severity)
38
+ {
39
+ switch ($Severity)
40
+ {
41
+ case "RequestOK":
42
+ return "0";
43
+ case "Warning":
44
+ return "1";
45
+ case "Error":
46
+ return "2";
47
+
48
+ }
49
+ }*/
50
+
51
+ class sValidateResult
52
+ {
53
+ var $iSeverity;
54
+ var $strMessage;
55
+ }
56
+
57
+
58
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/DynamicProperty.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+
3
+ define('DEFAULT_DELIMITER',"&");
4
+
5
+ class DynamicProperty
6
+ {
7
+
8
+ var $m_properties;
9
+ //private Hashtable m_properties = new Hashtable();
10
+
11
+ // constructors
12
+ function DynamicProperty()
13
+ {
14
+ $m_properties = array();
15
+ }
16
+
17
+
18
+ function SetDPWithProp($strProp)//:this(strProp,DEFAULT_DELIMITER)
19
+ {
20
+ $this->SetDPWIthDelimiter($strProp, DEFAULT_DELIMITER);
21
+ }
22
+
23
+
24
+ function SetDPWIthDelimiter($strProp,$strDelimit)
25
+ {
26
+ $Prop = $strProp;
27
+ //m_properties.Clear();
28
+ $m_properties = array();
29
+
30
+ //if (Prop.StartsWith(strDelimit))
31
+ if (strchr($Prop, $strDelimit) == 0 )
32
+ {
33
+ $start = strlen($strDelimit);
34
+ $end = strlen($Prop);
35
+ $Prop = substr($Prop, $start, $end-$start);
36
+ }
37
+
38
+ $parts[] = split($strDelimit, $Prop);
39
+
40
+ foreach ($parts as $pairs)
41
+ {
42
+ $pair[] = split("=", $pairs, 2);
43
+ if ( count($pair) == 2 )
44
+ {
45
+ $this->m_properties[$pair[0]] = $pair[1];
46
+ }
47
+ }
48
+ }
49
+
50
+ /*function SetDynamicProperty(DynamicProperty dynamicProp)
51
+ {
52
+ Hashtable properties = dynamicProp.GetAllProperties();
53
+
54
+ m_properties.Clear();
55
+ // Enumerate properties and create report server specific string.
56
+ IDictionaryEnumerator customPropEnumerator = properties.GetEnumerator();
57
+ while ( customPropEnumerator.MoveNext() )
58
+ {
59
+ m_properties.Add(customPropEnumerator.Key,customPropEnumerator.Value);
60
+ }
61
+ }*/
62
+
63
+
64
+
65
+ /// <summary>
66
+ /// create string that hold all parameters delimit by delimit parameter
67
+ /// </summary>
68
+ /// <param name="strDelimit">string seperator between pairs.</param>
69
+ /// <returns>string with all parameters.</returns>
70
+ function BuildStringWithDel($strDelimit)
71
+ {
72
+ $strParameters = $this->EmumProperties($this->m_properties,$strDelimit);
73
+ return $strParameters;
74
+ }
75
+
76
+ #endregion
77
+
78
+ #region Methods
79
+
80
+ /// <summary>
81
+ /// Enumerate Hashtable and create report server access specific string.
82
+ /// </summary>
83
+ /// <param name="properties">hash table of all properties</param>
84
+ /// <param name="strDelimiter">string use to delimiter between pairs. (empty string will become ampersand)</param>
85
+ /// <returns></returns>
86
+ //function EmumProperties(Hashtable properties,$strDelimiter)
87
+ function EmumProperties($properties,$strDelimiter)
88
+ {
89
+ $paramsString = "";
90
+ if ($strDelimiter == "")
91
+ $strDelimiter = DEFAULT_DELIMITER;
92
+
93
+ // Enumerate properties and create report server specific string.
94
+ //IDictionaryEnumerator customPropEnumerator = properties.GetEnumerator();
95
+ //$customPropEnumerator = $properties.GetEnumerator();
96
+
97
+ /*while (list($key,$value) = each($goodfoodArray)) {
98
+ echo "$key : $value<br>";*/
99
+
100
+ if ($properties != null)
101
+ {
102
+ $key = array_keys($properties);
103
+ foreach ($key as $value)
104
+ {
105
+ $paramsString .= $strDelimiter
106
+ . $value . "=" . $properties[$value];
107
+ }
108
+ }
109
+ return $paramsString;
110
+ }
111
+
112
+ /// <summary>
113
+ /// get all the parameters
114
+ /// </summary>
115
+ /// <returns>Hashtable that hold all the parameters in the DP object</returns>
116
+ /*public Hashtable GetAllProperties()
117
+ {
118
+ return m_properties;
119
+ }*/
120
+
121
+ /// <summary>
122
+ /// Add or remove url access string properties.
123
+ /// </summary>
124
+ /// <param name="name"></param>
125
+ /// <param name="value"></param>
126
+ function SetProperty($name, $value)
127
+ {
128
+ //try
129
+ //{
130
+ // Remove if value is null or empty. Value is null of the property grid value
131
+ // is null or empty. Empty or null removes the property from the Hashtable.
132
+ if($value == null || $value == "" )
133
+ {
134
+ if ($name != null && $name != "")
135
+ {
136
+ $bFound = false;
137
+ in_array($name, $bFound);
138
+ if ($bFound)
139
+ $this->m_properties.Remove($name);
140
+ }
141
+ }
142
+ else
143
+ {
144
+ if ($this->m_properties != null)
145
+ {
146
+ if( array_key_exists($name, $this->m_properties) )
147
+ {
148
+ // Change if key exists
149
+ $this->m_properties[$name] = $value;
150
+ }
151
+ else
152
+ {
153
+ // Add if key does not exist
154
+ $this->m_properties[$name] = $value;
155
+ }
156
+ }
157
+ }
158
+ // Build a new string with all the parameters as pairs.
159
+ $this->BuildString();
160
+ /*
161
+ }
162
+ catch(Exception ex)
163
+ {
164
+ // throws the exception to the client
165
+ throw ex;
166
+ }*/
167
+ }
168
+
169
+ // create string that hold all parameters delimit by ampersand
170
+ function BuildString()
171
+ {
172
+ $strParameters = $this->EmumProperties($this->m_properties,"");
173
+ return $strParameters;
174
+ }
175
+
176
+ }
177
+
178
+ ?>
179
+
app/code/local/Celebros/Salesperson/Model/Api/Anlx/Holders.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ class ReferrerInfoHolder
3
+ {
4
+ var $ReferrerUrl;
5
+ var $CampaignName;
6
+ var $CampaignType;
7
+
8
+ function ToString()
9
+ {
10
+ $strStream = "";
11
+ $sc;
12
+
13
+ if( trim($this->CampaignType=="") || $this->CampaignType==null)
14
+ $this->CampaignType=0;
15
+
16
+ $sc[]=$this->ReferrerUrl;
17
+ $sc[]=$this->CampaignName;
18
+ $sc[]=$this->CampaignType;
19
+ $sc[]=$this->SearchPhrase;
20
+
21
+ $strStream = GetStream($sc);
22
+ $strStream = UUEncode($strStream);
23
+ return $strStream;
24
+ }
25
+ }
26
+
27
+ class GenericSRHolder
28
+ {
29
+ var $SearchSession;
30
+ var $Query;
31
+ var $FromBrowse;
32
+
33
+ function ToString()
34
+ {
35
+ $strStream = "";
36
+ $sc;
37
+
38
+ $sc[]=$this->SearchSession;
39
+ $sc[]=$this->Query;
40
+ $sc[]=$this->FromBrowse;
41
+
42
+ $strStream = GetStream($sc);
43
+ $strStream = UUEncode($strStream);
44
+ return $strStream;
45
+ }
46
+ }
47
+
48
+ class SRAdditionalHolder
49
+ {
50
+ var $SpellingCorrectionDriven;
51
+ var $CorrectedFrom;
52
+ var $FromBrowse;
53
+
54
+
55
+ function ToString()
56
+ {
57
+ $strStream = "";
58
+ $sc;
59
+
60
+ $sc[]=$this->SpellingCorrectionDriven;
61
+ $sc[]=$this->CorrectedFrom;
62
+ $sc[]=$this->FromBrowse;
63
+
64
+ $strStream = GetStream($sc);
65
+ $strStream = UUEncode($strStream);
66
+ return $strStream;
67
+ }
68
+ }
69
+
70
+ class CartInfoHolder
71
+ {
72
+ var $CartID;
73
+ var $Coupon;
74
+ var $Discount;
75
+ var $ProductCount;
76
+ var $SubTotal;
77
+
78
+ function ToString()
79
+ {
80
+ $strStream = "";
81
+ $sc=array();
82
+
83
+ if($this->ProductCount==null || trim($this->ProductCount)=="")
84
+ $this->ProductCount=0;
85
+ if($this->Discount==null || trim($this->ProductCount==""))
86
+ $this->Discount=0;
87
+ if($this->SubTotal==null || trim($this->SubTotal==""))
88
+ $this->SubTotal=0;
89
+
90
+ $sc[]=$this->CartID;
91
+ $sc[]=$this->ProductCount;
92
+ $sc[]=$this->Coupon;
93
+ $sc[]=$this->Discount;
94
+ $sc[]=$this->SubTotal;
95
+
96
+ $strStream = GetStream($sc);
97
+ $strStream = UUEncode($strStream);
98
+ return $strStream;
99
+ }
100
+ }
101
+
102
+ class ProductDetailsHolder
103
+ {
104
+ var $ProductList;
105
+
106
+ function ToString()
107
+ {
108
+ $strStream = "";
109
+ $sc=array();
110
+
111
+ // add the number of products in array.
112
+ $sc[]=count($this->ProductList);
113
+
114
+ // add products
115
+ foreach ($this->ProductList as $p)
116
+ {
117
+ if($p["Price"]==null || trim($p["Price"])=="")
118
+ $p["Price"]=0;
119
+ if($p["Quantity"]==null || trim($p["Quantity"])=="")
120
+ $p["Quantity"]=0;
121
+
122
+ $scProduct[]=$p["SKU"];
123
+ $scProduct[]=$p["Variant"];
124
+ $scProduct[]=$p["Price"];
125
+ $scProduct[]=$p["Quantity"];
126
+ $scProduct[]=$p["Category"];
127
+ $scProduct[]=$p["Name"];
128
+
129
+ $sc[]=GetStream($scProduct);
130
+ }
131
+
132
+ $strStream = GetStream($sc);
133
+ $strStream = UUEncode($strStream);
134
+ //$strStream = UUEncode($sc);
135
+ return $strStream;
136
+ }
137
+ }
138
+
139
+ class ProductCOHolder
140
+ {
141
+ var $ProductList;
142
+
143
+ function ToString()
144
+ {
145
+ $strStream = "";
146
+ $sc=array();
147
+
148
+ // add the number of products in array.
149
+ $sc[]=count($this->ProductList);
150
+ if (count($this->ProductList)>0)
151
+ {
152
+ // add products
153
+ foreach ($this->ProductList as $p)
154
+ {
155
+ if($p["Price"]==null || trim($p["Price"])=="")
156
+ $p["Price"]=0;
157
+ if($p["Quantity"]==null || trim($p["Quantity"])=="")
158
+ $p["Quantity"]=0;
159
+ if($p["Discount"]==null || trim($p["Discount"])=="")
160
+ $p["Discount"]=0;
161
+
162
+ $scProduct[]=$p["SKU"];
163
+ $scProduct[]=$p["Variant"];
164
+ $scProduct[]=$p["Price"];
165
+ $scProduct[]=$p["Quantity"];
166
+ $scProduct[]=$p["Coupon"];
167
+ $scProduct[]=$p["Discount"];
168
+
169
+ $sc[]=GetStream($scProduct);
170
+ //echo "FROM HOLDERS _____ ".var_dump($sc) . "<br>";
171
+ $scProduct=array();
172
+ }
173
+ }
174
+ $strStream = GetStream($sc);
175
+ $strStream = UUEncode($strStream);
176
+ return $strStream;
177
+ }
178
+ }
179
+
180
+ class PageInfoHolder
181
+ {
182
+ var $Name;
183
+ var $Url;
184
+ var $Category;
185
+
186
+ function ToString()
187
+ {
188
+ $sc[]=$this->Name;
189
+ $sc[]=$this->Url;
190
+ $sc[]=$this->Category;
191
+ $str=GetStream($sc);
192
+ return UUEncode($str);
193
+ }
194
+ }
195
+
196
+
197
+ function GetStream($arr)
198
+ {
199
+ $sb = "";
200
+ for($i=0;$i<count($arr);$i++)
201
+ {
202
+ $strStream = $arr[$i];
203
+ $strStream = MakeStreamItem($strStream);
204
+ $sb.=$strStream;
205
+ }
206
+ $res = MakeStreamItem($sb);
207
+ return $res;
208
+ }
209
+
210
+ function MakeStreamItem($strItem)
211
+ {
212
+ $res = "";
213
+
214
+ $strLength = strlen($strItem);
215
+ for($i=strlen($strLength);$i<4;$i++)
216
+ $res.="0";
217
+ $res.=$strLength;
218
+ $res.=$strItem;
219
+
220
+ return $res;
221
+ }
222
+
223
+
224
+
225
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/LogRequest.php ADDED
@@ -0,0 +1,637 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ include_once("packetizer.php");
3
+ include_once("StringEncoder.php");
4
+ include_once("Holders.php");
5
+ include_once("DataStructure.php");
6
+ include_once("ValidateResult.php");
7
+ include_once("DynamicProperty.php");
8
+
9
+ define("MAX_PACKET_SIZE",800);
10
+ define("UNSECURED_PORT",80);
11
+ define("SECURED_PORT" ,443);
12
+
13
+
14
+
15
+ class LogRequest
16
+ {
17
+ var $DataCollectorIP;
18
+ var $dpCustomProperties;
19
+ var $PublicKeyToken;
20
+ var $Referrer;
21
+
22
+ var $RequestID;
23
+ var $CustomerID;
24
+ var $CustomerName;
25
+
26
+ // Product members
27
+
28
+ var $bUsingQwiserSearch;
29
+ var $sProductName;
30
+ var $sProductSKU;
31
+ var $sProductVariant;
32
+ var $fProductPrice;
33
+ var $sProductCategory;
34
+ var $iProductQuantity;
35
+
36
+ //General memebers
37
+
38
+ var $sUserID;
39
+ var $sGroupID;
40
+ var $sWebSessionID;
41
+ var $Mode;
42
+ var $SID;
43
+ var $LH;
44
+ var $sCurrentPageURL;
45
+ var $sPreviousPageURL;
46
+ var $iSourceType;
47
+ var $sSourceTypeName;
48
+ var $SearchPhrase;
49
+
50
+ // QWACart memebers
51
+
52
+ var $sCartID;
53
+ var $sCartCoupon;
54
+ var $fCartDiscount;
55
+ var $iCartProductCount;
56
+ var $fCartSubTotal;
57
+
58
+ // checkout members
59
+ var $sOrderID;
60
+
61
+ // Product array
62
+ var $ProductsArray;
63
+
64
+ // Search result memebers
65
+ var $SpellingCorrectionDriven = false;
66
+ var $CorrectedFrom;
67
+
68
+ // Generic search members
69
+ var $strQuery;
70
+ var $strSearchSessionID;
71
+ var $bFromBrowse = false;
72
+ var $bFromQwiser = true;
73
+
74
+ // QWAValidateResult memebers
75
+ var $ValidateResult;
76
+
77
+ // custom property
78
+ var $m_customProperty;
79
+
80
+
81
+ function GetLogRequest($LogRequestName)
82
+ {
83
+ $strHttp = "";
84
+ $iCurrentPort= 0;
85
+ $strLogReq = ""; // return string with img tags.
86
+ $strRqtID =uniqid(rand(), true); //????? id of the log Request.
87
+ $RequestData = $this->GetData($LogRequestName); // actual data.
88
+ $DataLength = strlen($RequestData); // total length of the data.
89
+ $dTimeStamp = gmdate("U") - 946684800; // mktime()-946677600; //946684800 <- time from 01/01/1970 till 01/01/2000; 946080000;946634400
90
+ $strAsmVer = "3.0";
91
+
92
+ if ( $this->ValidateLogRequest($LogRequestName) == "Error")
93
+ {
94
+ return "";
95
+ }
96
+
97
+ switch ($this->Mode)
98
+ {
99
+ case "plainData":
100
+ $strHttp = "http";
101
+ $iCurrentPort = UNSECURED_PORT;
102
+ break;
103
+ case "encrypted":
104
+ break;
105
+ case "secured":
106
+ $strHttp = "https";
107
+ $iCurrentPort = SECURED_PORT;
108
+ break;
109
+ default:
110
+ $strHttp = "http";
111
+ $iCurrentPort = UNSECURED_PORT;
112
+ break;
113
+ }
114
+
115
+ // packetizer
116
+ $p = new Packetizer("bySize",MAX_PACKET_SIZE);
117
+ $splitData = $p->Split($RequestData);
118
+
119
+ $nSplitIdx = 0;
120
+
121
+ foreach ($splitData as $packet) // the split method.
122
+ {
123
+ $strLogReq .= "<IMG BORDER='0' NAME='QWISERIMG' WIDTH='1' HEIGHT='1' SRC='" . $strHttp . "://" . $this->DataCollectorIP . ":" . $iCurrentPort . "/QwiserDataCollector/EventListener.aspx";
124
+
125
+ // concatenate additional attributes:
126
+ // source identifier
127
+
128
+ $strLogReq .= "?";
129
+
130
+ $strLogReq .= "rqt_t=" . $dTimeStamp //Time when the event was fire
131
+ . "&amp;sys_sm=" . $p->GetSplitMethod() //$p->SplitMethod //split method - byPair | bySize
132
+ . "&amp;sys_sid=" . $p->SplitID //split guid
133
+ . "&amp;sys_sx=" . $nSplitIdx //Split indeX - index number of the packet
134
+ . "&amp;sys_stp=" . $p->TotalPackets; //split total - total number of packets in this split
135
+
136
+ $strLogReq .= "&amp;sys_dz=" . $DataLength; //request size (data only.)
137
+
138
+ $strLogReq .= "&amp;ctm_id=" . urlencode($this->CustomerID) //celebros customer ID
139
+ . "&amp;ctm_n=" . urlencode($this->CustomerName) // name of the customer
140
+ . "&amp;ctm_pkt=" . $this->PublicKeyToken //Public Key Token for encryption
141
+ . "&amp;rqt_id=" . $this->GetLogRequestID($LogRequestName) //the id of the request predefine / custom //TODO: add GetId mechanizm
142
+ . "&amp;rqt_g=" . $this->sGroupID //Group ID
143
+ . "&amp;rqt_s=" . $this->sWebSessionID //Web Session ID
144
+ . "&amp;rqt_n=" . $this->RqtNmae($LogRequestName) //Name of the request. significant only in customProperty
145
+ . "&amp;rqt_u=" . urlencode($this->sUserID) //User ID
146
+ . "&amp;rqt_v=" . $strAsmVer
147
+ . "&amp;rqt_m=" . $this->iMode($this->Mode) ; //Mode of the request compressed | unprocessed | enctypted
148
+
149
+ //check sum number
150
+
151
+ // data section
152
+ // d_dat will hold only split encoded data
153
+ $strLogReq .= "&amp;d_dat=" . $packet; // actual data of the request
154
+
155
+ // close tag
156
+ $strLogReq .= "'>";
157
+
158
+ $strLogReq = str_replace("?&","?",$strLogReq);
159
+
160
+ $nSplitIdx++;
161
+ }
162
+ return $strLogReq;
163
+ }
164
+
165
+ function GetData($LogRequestName)
166
+ {
167
+ switch ($LogRequestName)
168
+ {
169
+ case "LogSearchResult":
170
+ return $this->GetLogSearchResult();
171
+ break;
172
+ case "LogProductDetails":
173
+ return $this->GetLogProductDetails();
174
+ break;
175
+ case "LogAddToCart":
176
+ return $this->GetLogAddToCart();
177
+ break;
178
+ case "LogCheckOut":
179
+ return $this->GetLogCheckOut();
180
+ break;
181
+ case "LogVisitInfo":
182
+ return $this->GetLogVisitInfo();
183
+ break;
184
+ case "LogGenericSearchResult":
185
+ return $this->GetLogGenericSearch();
186
+ break;
187
+ default:
188
+ return $this->GetLogVisitInfo();
189
+ }
190
+ }
191
+
192
+ //TODO: add implementation in the dbase to hold all extra properties.
193
+ /// <summary>
194
+ /// Add Custom Properties to the log.
195
+ /// </summary>
196
+ /// <param name="strName">name of the new parameter</param>
197
+ /// <param name="strValue">value of the new parameter</param>
198
+ function AddCustomProperty($strName, $strValue)
199
+ {
200
+ if ($this->m_customProperty == null )
201
+ $this->m_customProperty = new DynamicProperty();
202
+
203
+ $name = "cd_" . $strName;
204
+ $this->m_customProperty->SetProperty($name, $strValue);
205
+ }
206
+
207
+ function GetCustomData()
208
+ {
209
+ // data in override implementation should be serialized with the string encoder to
210
+ // prevent char problems and security issues.
211
+ //... for additional data don't forget the & delimiter between pairs.
212
+
213
+ if ($this->m_customProperty == null )
214
+ return "";
215
+
216
+ $strProperties = $this->m_customProperty->BuildString();
217
+ return UUEncode($strProperties);
218
+ }
219
+
220
+
221
+ function GetLogProductDetails()
222
+ {
223
+ $strCustomData = $this->GetCustomData();
224
+ $strData = "";
225
+ $strProductDetails ="";
226
+ $strReferrerData = $this->GetReferrerData();
227
+
228
+ //sProduct p = new sProduct();
229
+ $Prod = new ProductDetailsHolder();
230
+
231
+ //$value = trim($value);
232
+ if($this->iProductQuantity==null || $this->iProductQuantity=="" || (trim($this->iProductQuantity))=="")
233
+ $this->iProductQuantity=1;
234
+ if( $this->fProductPrice==null || $this->fProductPrice=="" || (trim($this->fProductPrice))=="")
235
+ $this->fProductPrice=0;
236
+
237
+ $Prod->ProductList[0]["SKU"] = $this->sProductSKU;
238
+ $Prod->ProductList[0]["Variant"] = $this->sProductVariant;
239
+ $Prod->ProductList[0]["Name"] = $this->sProductName;
240
+ $Prod->ProductList[0]["Price"] = $this->fProductPrice;
241
+ $Prod->ProductList[0]["Category"] = $this->sProductCategory;
242
+ $Prod->ProductList[0]["Quantity"] = $this->iProductQuantity;
243
+
244
+
245
+ $strProductDetails =$Prod->ToString();
246
+ if (!($strProductDetails=="") || (trim($this->fProductPrice))=="")
247
+ $strData .= "0d_pd=" . $strProductDetails;
248
+
249
+ if ( $this->bUsingQwiserSearch == true )
250
+ {
251
+ if (!($this->SID == null || $this->SID=="" || (trim($this->SID)) == "" ))
252
+ $strData .= "0d_sid=" . UUEncode($this->SID);
253
+ }
254
+ else
255
+ {
256
+ $strData .= "0d_sid=" . UUEncode($this->sWebSessionID);
257
+ }
258
+
259
+ if (!($strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData)) == "" ))
260
+ $strData .= "0d_ref=" . $strReferrerData;
261
+
262
+ if (!( $strCustomData == "" || (trim($strCustomData)) == "" ))
263
+ $strData .= "0d_cd=" . $strCustomData;
264
+
265
+ return $strData;
266
+ }
267
+
268
+ function GetLogSearchResult()
269
+ {
270
+ $strCustomData = $this->GetCustomData();
271
+ $strData = "";
272
+ $strReferrerData = $this->GetReferrerData();
273
+
274
+ if (!($strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData))==""))
275
+ $strData .= "0d_ref=" . $strReferrerData;
276
+
277
+ if (!($this->SID == null || $this->SID == "" || (trim($this->SID)) == "" ))
278
+ $strData .= "0d_ssid=" . UUencode($this->SID);
279
+
280
+ if (!($this->LH == null || $this->LH == "" || (trim($this->LH)) == "" ))
281
+ $strData .= "0d_lh=" . $this->LH;
282
+
283
+ $strData .= "0d_fq=" . $this->BoolToString($this->bFromQwiser);
284
+
285
+
286
+ $ADSearchHolder = new SRAdditionalHolder();
287
+ $ADSearchHolder->SpellingCorrectionDriven = $this->BoolToString($this->SpellingCorrectionDriven);
288
+ $ADSearchHolder->CorrectedFrom = $this->CorrectedFrom;
289
+ $ADSearchHolder->FromBrowse = $this->BoolToString($this->bFromBrowse);
290
+
291
+ $strADSearchInfo = $ADSearchHolder->ToString();
292
+ if (!($strADSearchInfo=="" || (trim($strADSearchInfo)) == "" ))
293
+ $strData .= "0d_sr=" . $strADSearchInfo;
294
+
295
+ // SRAdditionalHolder SRHolder = new SRAdditionalHolder();
296
+ // SRHolder.SpellingCorrectionDriven = m_bSpellingCorrectionDriven;
297
+ // SRHolder.CorrectedFrom = m_strCorrectedFrom;
298
+ // SRHolder.FromBrowse = m_bFromBrowse;
299
+ // string strSRAdditional = SRHolder.ToString();
300
+ //
301
+ // if (!String.Empty.Equals(strSRAdditional))
302
+ // strData += "0d_sr=" + strSRAdditional;
303
+ //
304
+ if (!($strCustomData == "" || (trim($strCustomData)) == "" ))
305
+ $strData .= "0d_cd=" . $strCustomData;
306
+
307
+ return $strData;
308
+ }
309
+
310
+ function GetLogGenericSearch()
311
+ {
312
+ $strCustomData = $this->GetCustomData();
313
+ $strData = "";
314
+ $strGenericInfo = "";
315
+ $strReferrerData = $this->GetReferrerData();
316
+
317
+ if (!($strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData)) == "" ))
318
+ $strData .= "0d_ref=" . $strReferrerData;
319
+
320
+ $GenericHolder = new GenericSRHolder();
321
+ $GenericHolder->SearchSession = $this->strSearchSessionID;
322
+ $GenericHolder->Query = $this->strQuery;
323
+ $GenericHolder->FromBrowse = $this->BoolToString($this->bFromBrowse);
324
+
325
+ $strGenericInfo = $GenericHolder->ToString();
326
+ if (!($strGenericInfo=="" || (trim($strGenericInfo)) == "" ))
327
+ $strData .= "0d_gsr=" . $strGenericInfo;
328
+
329
+ if (!($strCustomData == "" || (trim($strCustomData)) == "" ))
330
+ $strData .= "0d_cd=" . $strCustomData;
331
+
332
+ return $strData;
333
+ }
334
+
335
+
336
+ function GetLogAddToCart()
337
+ {
338
+ $strCustomData = $this->GetCustomData();
339
+ $strData = "";
340
+ $strCartInfo = "";
341
+ $strProductDetails = "";
342
+ $strReferrerData = $this->GetReferrerData();
343
+
344
+ $Prod = new ProductDetailsHolder();
345
+
346
+ if($this->iProductQuantity==null || $this->iProductQuantity=="" || (trim($this->iProductQuantity)) == "" )
347
+ $this->iProductQuantity=1;
348
+
349
+ $Prod->ProductList[0]["SKU"] = $this->sProductSKU;
350
+ $Prod->ProductList[0]["Variant"] = $this->sProductVariant;
351
+ $Prod->ProductList[0]["Name"] = $this->sProductName;
352
+ $Prod->ProductList[0]["Price"] = $this->fProductPrice;
353
+ $Prod->ProductList[0]["Category"] = $this->sProductCategory;
354
+ $Prod->ProductList[0]["Quantity"] = $this->iProductQuantity;
355
+
356
+ $strProductDetails = $Prod->ToString();
357
+ if (!($strProductDetails=="" || (trim($strProductDetails)) == "" ))
358
+ $strData .= "0d_pd=" . $strProductDetails;
359
+
360
+ $cartHolder = new CartInfoHolder();
361
+ $cartHolder->CartID = $this->sCartID;
362
+ $cartHolder->Coupon = $this->sCartCoupon;
363
+ $cartHolder->Discount = $this->fCartDiscount;
364
+ $cartHolder->ProductCount = $this->iCartProductCount;
365
+ $cartHolder->SubTotal = $this->fCartSubTotal;
366
+
367
+ $strCartInfo = $cartHolder->ToString();
368
+ if (!($strCartInfo=="" || (trim($strCartInfo)) == ""))
369
+ $strData .= "0d_ci=" . $strCartInfo;
370
+
371
+ if ( $this->bUsingQwiserSearch == true )
372
+ {
373
+ if (!( $this->SID == null || $this->SID=="" || (trim($this->SID)) == "" ))
374
+ $strData .= "0d_sid=" . UUEncode($this->SID);
375
+ }
376
+ else
377
+ {
378
+ $strData .= "0d_sid=" . UUEncode($this->sWebSessionID);
379
+ }
380
+ //new code: Ignoring the bUsingQwiserSearch parameter
381
+ /*
382
+ if (!( $this->SID == null || $this->SID=="" || (trim($this->SID)) == "" ))
383
+ $strData .= "0d_sid=" . UUEncode($this->SID);
384
+ else
385
+ $strData .= "0d_sid=" . UUEncode($this->sWebSessionID);
386
+ */
387
+
388
+ if (!($strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData)) == "" ))
389
+ $strData .= "0d_ref=" . $strReferrerData;
390
+
391
+ if (!($strCustomData == "" || (trim($strCustomData)) == "" ))
392
+ $strData .= "0d_cd=" . $strCustomData;
393
+
394
+ return $strData;
395
+ }
396
+
397
+
398
+ function GetLogCheckOut()
399
+ {
400
+ $strCustomData = $this->GetCustomData();
401
+ $strData = "";
402
+ $strReferrerData = $this->GetReferrerData();
403
+
404
+ // fill all products
405
+ $Prod = new ProductCOHolder();
406
+ if(count($this->ProductsArray)>0)
407
+ {
408
+ for($i=0;$i<count($this->ProductsArray);$i++)
409
+ {
410
+ $Prod->ProductList[$i]["SKU"] = $this->ProductsArray[$i]["SKU"];
411
+ $Prod->ProductList[$i]["Variant"] = $this->ProductsArray[$i]["Variant"];
412
+ $Prod->ProductList[$i]["Discount"] = $this->ProductsArray[$i]["Discount"];
413
+ $Prod->ProductList[$i]["Price"] = $this->ProductsArray[$i]["Price"];
414
+ $Prod->ProductList[$i]["Quantity"] = $this->ProductsArray[$i]["Quantity"];
415
+ $Prod->ProductList[$i]["Coupon"] = $this->ProductsArray[$i]["Coupon"];
416
+ }
417
+ }
418
+ $strProductDetails = $Prod->ToString();
419
+
420
+ if (!($strProductDetails=="" || (trim($strProductDetails)) == ""))
421
+ $strData .= "0d_pdco=" . $strProductDetails;
422
+
423
+ // fill cart info
424
+ $cartHolder = new CartInfoHolder();
425
+ $cartHolder->CartID = $this->sCartID;
426
+ $cartHolder->Coupon = $this->sCartCoupon;
427
+ $cartHolder->Discount = $this->fCartDiscount;
428
+ $cartHolder->ProductCount = $this->iCartProductCount;
429
+ $cartHolder->SubTotal = $this->fCartSubTotal;
430
+
431
+ $strCartInfo = $cartHolder->ToString();
432
+
433
+ if (!($strCartInfo=="" || (trim($strCartInfo)) == ""))
434
+ $strData .= "0d_ci=" . $strCartInfo;
435
+
436
+ if (!($this->sOrderID=="" || (trim($this->sOrderID)) == "" ))
437
+ $strData .= "0d_oid=" . UUEncode($this->sOrderID);
438
+
439
+
440
+ if (!( $strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData)) == "" ))
441
+ $strData .= "0d_ref=" . $strReferrerData;
442
+
443
+ if (!($strCustomData == "" || (trim($strCustomData)) == ""))
444
+ $strData .= "0d_cd=" . $strCustomData;
445
+
446
+ return $strData;
447
+ }
448
+
449
+
450
+ function GetLogVisitInfo()
451
+ {
452
+ $strCustomData = $this->GetCustomData();
453
+ $strData = "";
454
+ $strReferrerData = $this->GetReferrerData();
455
+ $PageInfo = new PageInfoHolder();
456
+
457
+ if (!($strReferrerData == null || $strReferrerData=="" || (trim($strReferrerData)) == "" ))
458
+ $strData .= "0d_ref=" . $strReferrerData;
459
+
460
+ $PageInfo->Name = $this->Name;
461
+ $PageInfo->Url = $this->sCurrentPageURL;
462
+ $PageInfo->Category = $this->Category;
463
+
464
+ $strPage = $PageInfo->ToString();
465
+
466
+ if (!($strPage == null || $strPage=="" || (trim($strPage)) == "" ))
467
+ $strData .= "0d_page=" . $strPage;
468
+
469
+ //... for additional data don't forget the & between pairs.*/
470
+
471
+ if (!($strCustomData == "" || (trim($strCustomData)) == "" ))
472
+ $strData .= "0d_cd=" . $strCustomData;
473
+
474
+ return $strData;
475
+ }
476
+
477
+ function ValidateLogRequest($LogRequestName)
478
+ {
479
+ $Message = "";
480
+
481
+ $this->ValidateResult = new sValidateResult();
482
+
483
+ // error message
484
+ $iSeverity = "Error";
485
+
486
+ // customer error
487
+ if ( $this->CustomerID == null || $this->CustomerID == "" || (trim($this->CustomerID)) == "" )
488
+ {
489
+ $Message = "evrErrCustomerIDIsMissing";
490
+ }
491
+
492
+ // data collector errors
493
+ elseif ( $this->DataCollectorIP == null || $this->DataCollectorIP == "" || (trim($this->DataCollectorIP)) == "")
494
+ {
495
+ $Message = "evrErrServerNameIsMissing";
496
+ }
497
+
498
+ if ( $Message == "" )
499
+ {
500
+
501
+ switch ($LogRequestName)
502
+ {
503
+ case "LogSearchResult":
504
+ $Message = GetSRValidateResult($this->SID, $this->LH);
505
+ break;
506
+ case "LogGenericSearchResult":
507
+ $Message = GetGRValidateResult($this->strSearchSessionID);
508
+ break;
509
+ case "LogProductDetails":
510
+ $Message = GetPDValidateResult($this->SID, $this->sProductSKU);
511
+ break;
512
+ case "LogAddToCart":
513
+ $Message = GetATCValidateResult($this->SID, $this->sProductSKU, $this->sCartID);
514
+ break;
515
+ case "LogCheckOut":
516
+ $Message = GetCOValidateResult($this->sCartID, $this->sOrderID);
517
+ break;
518
+ default:
519
+ $Message = "";
520
+ }
521
+ }
522
+
523
+ if ($Message == "")
524
+ {
525
+
526
+ $iSeverity = "Warning";
527
+
528
+ /*if ( (DataCollector.Port == UNSECURED_PORT) && (m_Mode == enumRequestMode.secured) )
529
+ {
530
+ sCurrValidateRes.MessageID = enumValidateResult.evrWrnConflictInDCParam;
531
+ return sCurrValidateRes;
532
+ }*/
533
+ if ( $this->CustomerName == null || $this->CustomerName = "" || (trim($this->CustomerName)) == "")
534
+ {
535
+ $Message = "evrWrnCustomerNameISMissing";
536
+
537
+ }
538
+ }
539
+
540
+ if ($Message == "" )
541
+ {
542
+ $iSeverity = "RequestOK";
543
+ }
544
+
545
+ $this->ValidateResult->iSeverity = $iSeverity;
546
+ $this->ValidateResult->strMessage = $Message;
547
+
548
+ return $iSeverity;
549
+
550
+ }
551
+
552
+ function iMode($Mode)
553
+ {
554
+ switch ($Mode)
555
+ {
556
+ case "plainData":
557
+ return 0;
558
+ case "encrypted":
559
+ return 1;
560
+ case "secured":
561
+ return 2;
562
+ default:
563
+ return -1;
564
+ }
565
+ }
566
+
567
+ function RqtNmae($LogRequestName)
568
+ {
569
+ switch ($LogRequestName)
570
+ {
571
+ CASE "LogSearchResult":
572
+ return "sr";
573
+ CASE "LogProductDetails":
574
+ return "PD";
575
+ CASE "LogAddToCart":
576
+ return "ToCRT";
577
+ CASE "LogCheckOut":
578
+ return "CkOut";
579
+ CASE "LogVisitInfo":
580
+ return "VisitInfo";
581
+ case "LogGenericSearchResult":
582
+ return "GSR";
583
+ default:
584
+ return -1;//TODO
585
+ }
586
+ }
587
+
588
+ function GetLogRequestID($LogRequestName)
589
+ {
590
+ switch ($LogRequestName)
591
+ {
592
+ CASE "LogSearchResult":
593
+ return "1";
594
+ CASE "LogProductDetails":
595
+ return "2";
596
+ CASE "LogAddToCart":
597
+ return "3";
598
+ CASE "LogCheckOut":
599
+ return "4";
600
+ CASE "LogVisitInfo":
601
+ return "5";
602
+ CASE "LogGenericSearchResult":
603
+ return "6";
604
+ default:
605
+ return -1;//TODO
606
+ }
607
+ }
608
+
609
+
610
+ function GetReferrerData()
611
+ {
612
+ $RefInfo = new ReferrerInfoHolder();
613
+
614
+ $RefInfo->ReferrerUrl = $this->sPreviousPageURL;
615
+ $RefInfo->CampaignName = $this->sSourceTypeName;
616
+ $RefInfo->SearchPhrase = $this->SearchPhrase;
617
+ $RefInfo->CampaignType = $this->iSourceType;
618
+
619
+ return $RefInfo->ToString();
620
+ }
621
+
622
+ function GetValidateResult()
623
+ {
624
+ return $this->ValidateResult;
625
+ }
626
+
627
+ function BoolToString($bool)
628
+ {
629
+ if ($bool == 1 )
630
+ return "True";
631
+ else
632
+ return "False";
633
+ }
634
+ }
635
+
636
+
637
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/RunLogReq.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ include_once("AnalyticsFunctions.php");
3
+
4
+ //$sr =new AnalyticsFunctions();
5
+ //$sr->Celebros_Analytics_Visit("","","","","");
6
+
7
+
8
+
9
+ $gr =new LogRequest();
10
+ $gr->CustomerID = "yfat";
11
+ $gr->CustomerName = "yfat";
12
+ $gr->SH = "aaa";
13
+ $gr->DataCollectorIP = "1";
14
+
15
+ $gr->AddCustomProperty("yfat","test");
16
+ $gr->bFromBrowse="true";
17
+ $gr->CorrectedFrom = "yfat";
18
+ $gr->SpellingCorrectionDriven = "true";
19
+ $a = $gr->GetLogRequest("LogSearchResult");
20
+
21
+ $b = $a;
22
+
23
+ //$gr->Celebros_Analytics_GenericSearchResults("1","red","true","23","","","","");
24
+ /*$gr->AddCustomProperty("a","b");
25
+ $message = $gr->GetLastErrorMessage();
26
+ $message1 = $gr->GetLastErrorSeverity();
27
+ */
28
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/StringEncoder.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ function UUEncode($strString)
3
+ {
4
+ $sbCodedString="";
5
+
6
+ $strString = utf8_encode($strString); //encode the string to UTF8
7
+ for ($i=0;$i<strlen($strString);$i++)
8
+ {
9
+ $c = $strString[$i];
10
+ $intHigh = (128 + 64 + 32 + 16) & ord($c);
11
+ $intLow = (8 + 4 + 2 + 1) & ord($c);
12
+ $sbCodedString.=chr(($intHigh/16)+65);
13
+ $sbCodedString.=chr($intLow+65);
14
+ }
15
+ return "ZZ" . $sbCodedString;
16
+ }
17
+
18
+ /*
19
+ /// <summary> FROM .NET
20
+ /// UUEncode - encode a given string
21
+ /// </summary>
22
+ /// <param name="strString"></param>
23
+ /// <returns></returns>
24
+ public static string UUEncode(string strString)
25
+ {
26
+ StringBuilder sbCodedString = new StringBuilder(strString.Length*2);
27
+ byte[] byteArr = System.Text.Encoding.UTF8.GetBytes(strString);//Get UTF8Encoding to byte array from string
28
+ byte b;
29
+ int i,intHigh,intLow;
30
+
31
+ for (i=0;i<byteArr.Length;i++)
32
+ {
33
+ b = byteArr[i];
34
+ intHigh = (128 + 64 + 32 + 16) & b;
35
+ intLow = (8 + 4 + 2 + 1) & b;
36
+ sbCodedString.Append((char)((intHigh/16)+65));
37
+ sbCodedString.Append((char)(intLow+65));
38
+ }
39
+ return "ZZ"+sbCodedString.ToString();
40
+ }
41
+ */
42
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/ValidateResult.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ function GetSRValidateResult($searchHandle, $logHandle)
3
+ {
4
+ if ($searchHandle == "" || $searchHandle == null)
5
+ {
6
+ return "evrErrSearchSessionIDIsMissing";
7
+ }
8
+ elseif ($logHandle == "" || $logHandle == null)
9
+ {
10
+ return "evrErrLogHandleIsMissing";
11
+ }
12
+
13
+ return "";
14
+ }
15
+
16
+ function GetGRValidateResult($sessionID)
17
+ {
18
+ if ($sessionID == "" || $sessionID == null)
19
+ {
20
+ return "evrErrSearchSessionIDIsMissing";
21
+ }
22
+ return "";
23
+ }
24
+
25
+ function GetPDValidateResult($sessionID,$sku)
26
+ {
27
+ if ($sessionID == null || $sessionID = "")
28
+ {
29
+ return "evrErrSearchSessionIDIsMissing";
30
+ }
31
+ elseif ($sku == null || $sku == "")
32
+ {
33
+ return "evrErrSKUIsMissing";
34
+ }
35
+ return "";
36
+ }
37
+
38
+ function GetATCValidateResult($sessionID, $sku, $cartID)
39
+ {
40
+ if ($sessionID == null || $sessionID = "")
41
+ {
42
+ return "evrErrSearchSessionIDIsMissing";
43
+ }
44
+ elseif ($sku == null || $sku == "")
45
+ {
46
+ return "evrErrSKUIsMissing";
47
+ }
48
+ elseif ($cartID == null || $cartID = "")
49
+ {
50
+ return "evrErrCartIDIsMissing";
51
+ }
52
+ return "";
53
+
54
+ }
55
+
56
+ function GetCOValidateResult($cartID, $orderID)
57
+ {
58
+ if ($cartID == null || $cartID = "")
59
+ {
60
+ return "evrErrCartIDIsMissing";
61
+ }
62
+ elseif ($orderID == null || $orderID == "")
63
+ {
64
+ return "evrErrOrderIDIsMissing";
65
+ }
66
+ return "";
67
+ }
68
+
69
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/Anlx/packetizer.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <? //@-; This file was released in build:QANLX V1.6.0049 Date: 9/20/2006 6:32:27 PM @@@
2
+ class packetizer
3
+ {
4
+ var $SplitMethod;
5
+ var $PacketSize;
6
+ var $SplitID;
7
+ var $TotalPackets;
8
+
9
+ function packetizer($SplitMethod,$PacketSize)
10
+ {
11
+ $this->SplitMethod=$SplitMethod;
12
+ $this->PacketSize=$PacketSize;
13
+ $this->SplitID=uniqid(rand(), true);
14
+ }
15
+
16
+ function Split($Data)
17
+ {
18
+ if($this->PacketSize<strlen($Data))
19
+ {
20
+ $len=strlen($Data)/$this->PacketSize;
21
+ $len=ceil($len);
22
+ $this->TotalPackets=$len;
23
+ for($i=0;$i<$len;$i++)
24
+ {
25
+ $splitArray[$i]=substr($Data,$i*$this->PacketSize,$this->PacketSize);
26
+ }
27
+
28
+ }
29
+ else
30
+ {
31
+ $splitArray[0]=$Data;
32
+ $this->TotalPackets=1;
33
+ }
34
+
35
+ return $splitArray;
36
+
37
+ }
38
+
39
+ function GetSplitMethod()
40
+ {
41
+ switch ($this->SplitMethod)
42
+ {
43
+ CASE "bySize":
44
+ return "2";
45
+ default:
46
+ return "-1";//TODO
47
+ }
48
+
49
+
50
+ }
51
+
52
+ }
53
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserAnswer.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ Class Celebros_Salesperson_Model_Api_QwiserAnswer
3
+ {
4
+ var $Id;
5
+ var $ImageHeight;
6
+ var $ImageSku;
7
+ var $ImageUrl;
8
+ var $ImageWidth;
9
+ var $ProductCount;
10
+ var $Text;
11
+ var $Type;
12
+ var $DynamicProperties;
13
+
14
+ Function Celebros_Salesperson_Model_Api_QwiserAnswer($AnswerNode)
15
+ {
16
+ if(is_object($AnswerNode))
17
+ {
18
+ $this->Id = $AnswerNode->get_attribute("Id");
19
+ $this->ImageHeight = $AnswerNode->get_attribute("ImageHeight");
20
+ $this->ImageSku = $AnswerNode->get_attribute("ImageSku");
21
+ $this->ImageUrl = $AnswerNode->get_attribute("ImageUrl");
22
+ $this->ImageWidth = $AnswerNode->get_attribute("ImageWidth");
23
+ $this->ProductCount = $AnswerNode->get_attribute("ProductCount");
24
+ $this->Text = $AnswerNode->get_attribute("Text");
25
+ $this->Type = $AnswerNode->get_attribute("Type");
26
+ $this->DynamicProperties = GetQwiserSimpleStringDictionary(current($AnswerNode->get_elements_by_tagname("DynamicProperties")));
27
+ }
28
+ }
29
+ }
30
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserAnswers.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ Class Celebros_Salesperson_Model_Api_QwiserAnswers
3
+ {
4
+ var $Count = 0; //the number of products
5
+ var $Items; //indexer .
6
+
7
+ Function Celebros_Salesperson_Model_Api_QwiserAnswers($xml_Answers)
8
+ {
9
+ //if we got an array of QwiserAnswer
10
+ if(is_array($xml_Answers))
11
+ {
12
+ $this->Items = $xml_Answers;
13
+ $this->Count = count($xml_Answers);
14
+ }
15
+ //if we got a node of QwiserAnswers
16
+ else
17
+ {
18
+ if(is_object($xml_Answers))
19
+ {
20
+ $xml_AnswersNodes = $xml_Answers->child_nodes();
21
+ $xml_AnswersNodes = getDomElements($xml_AnswersNodes);
22
+ $this->Count = count($xml_AnswersNodes);
23
+
24
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
25
+ {
26
+ $AnswerNode = $xml_AnswersNodes[$i];
27
+ $this->Items[$i] = new Celebros_Salesperson_Model_Api_QwiserAnswer($AnswerNode);
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ //Return Answer By Id.
34
+ Function GetAnswerById($ID)
35
+ {
36
+ foreach ($this->Items as $Ans)
37
+ {
38
+ if($Ans->Id=$ID)
39
+ {
40
+ return $ans;
41
+ }
42
+ }
43
+ }
44
+
45
+ //Gets a QwiserAnswers object of all answers in this collection that have the specified text
46
+ Function GetAnswersByText($Text)
47
+ {
48
+ $ansArray = array();
49
+ foreach ($this->Items as $Ans)
50
+ {
51
+ if($Ans->Text = $Text)
52
+ {
53
+ $ansArray[] = $Ans;
54
+ }
55
+ }
56
+ return new Celebros_Salesperson_Model_Api_QwiserAnswers($ansArray);
57
+ }
58
+
59
+ //Gets a QwiserAnswers object of all answers in this collection that are of the specified type
60
+ Function GetAnswersByType($Type)
61
+ {
62
+ $ansArray = array();
63
+ foreach ($this->Items as $Ans)
64
+ {
65
+ if($Ans->Type = $Type)
66
+ {
67
+ $ansArray[] = $Ans;
68
+ }
69
+ }
70
+ return new QwiserAnswers($ansArray);
71
+ }
72
+
73
+ //Sorts This QwiserAnswers collection with CompareTo method.
74
+ Function SortByAnswerText()
75
+ {
76
+ usort($this->Items,array("QwiserAnswers","CompareTo"));
77
+ }
78
+
79
+ Function CompareTo($a,$b)
80
+ {
81
+ $al = strtolower($a->Text);
82
+ $bl = strtolower($b->Text);
83
+ if ($al == $bl) {
84
+ return 0;
85
+ }
86
+ return ($al > $bl) ? +1 : -1;
87
+ //return strcmp($a1,$b1);
88
+ }
89
+
90
+
91
+ }
92
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserConcept.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserConcept
3
+ {
4
+ var $Id; //the concept id.
5
+ var $Name; //the concept name.
6
+ var $Rank; //the concept rank.
7
+ var $Type; //the concept type(attribute,commodity,temathic).
8
+ var $DynamicProperties; //the concept dynamic properties.
9
+
10
+ function Celebros_Salesperson_Model_Api_QwiserConcept($ConceptNode)
11
+ {
12
+ if(is_object($ConceptNode))
13
+ {
14
+ $this->Id = $ConceptNode->get_attribute("Id");
15
+ $this->Name = $ConceptNode->get_attribute("Name");
16
+ $this->Rank = $ConceptNode->get_attribute("Rank");
17
+ $this->Type = $ConceptNode->get_attribute("Type");
18
+ $this->DynamicProperties = GetQwiserSimpleStringDictionary(current($ConceptNode->get_elements_by_tagname("DynamicProperties")));
19
+ }
20
+ }
21
+ }
22
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserConcepts.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserConcepts
3
+ {
4
+ var $Count = 0; //number of concepts.
5
+ var $Items; //QwiserConcept array
6
+
7
+ function Celebros_Salesperson_Model_Api_QwiserConcepts($xml_Concepts)
8
+ {
9
+ if(is_object($xml_Concepts))
10
+ {
11
+ $xml_ConceptsNodes = $xml_Concepts->child_nodes();
12
+ $xml_ConceptsNodes = getDomElements($xml_ConceptsNodes);
13
+ $this->Count = count($xml_ConceptsNodes);
14
+
15
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
16
+ {
17
+ $ConceptNode = $xml_ConceptsNodes[$i];
18
+ $this->Items[$i] = new Celebros_Salesperson_Model_Api_QwiserConcept($ConceptNode);
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProduct.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProduct
3
+ {
4
+ var $Field;
5
+ var $FoundInAnswerId;
6
+ var $FoundInAnswerPath;
7
+ var $IsBestSeller;
8
+ var $MatchClassFound;
9
+ var $Price;
10
+ var $Sku;
11
+
12
+ function Celebros_Salesperson_Model_Api_QwiserProduct($ProdNode)
13
+ {
14
+ if(is_object($ProdNode))
15
+ {
16
+ $this->Field = $this->GetProductCommonInformation($ProdNode);
17
+ $this->FoundInAnswerId = $ProdNode->get_attribute("FoundInAnswerId");
18
+ $this->FoundInAnswerPath = $ProdNode->get_attribute("FoundInAnswerPath");
19
+ $this->IsBestSeller = $ProdNode->get_attribute("IsBestSeller");
20
+ $this->MatchClassFound = $ProdNode->get_attribute("MatchClassFound");
21
+ $this->Price = $ProdNode->get_attribute("Price");
22
+ $this->Sku = $ProdNode->get_attribute("Sku");
23
+ }
24
+ }
25
+
26
+ function GetProductCommonInformation($ProdNode)
27
+ {
28
+ $ProductFields=current(getDomElements($ProdNode->child_nodes()));
29
+ $ProductFieldsArray=getDomElements($ProductFields->child_nodes());
30
+ foreach ($ProductFieldsArray as $Pfield)
31
+ {
32
+
33
+ /**
34
+ * Make Fields keys lowercase
35
+ *
36
+ * @modifyed by Sveta Oksen - sveta.oksen@gmail.com
37
+ * @since 28/03/2011
38
+ */
39
+ $ProdField[strtolower($Pfield->get_attribute("name"))] = $Pfield->get_attribute("value");
40
+ }
41
+ return $ProdField;
42
+ }
43
+ }
44
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProductAnswer.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProductAnswer
3
+ {
4
+ var $Id;
5
+ var $Name;
6
+ var $QuestionId;
7
+ var $Sku;
8
+
9
+ Function Celebros_Salesperson_Model_Api_QwiserProductAnswer($ProductAnswerNode)
10
+ {
11
+ if(is_object($ProductAnswerNode))
12
+ {
13
+ $this->Id = $ProductAnswerNode->get_attribute("Id");
14
+ $this->Name = $ProductAnswerNode->get_attribute("Name");
15
+ $this->QuestionId = $ProductAnswerNode->get_attribute("QuestionId");
16
+ $this->Sku = $ProductAnswerNode->get_attribute("Sku");
17
+ }
18
+ }
19
+ }
20
+
21
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProductAnswers.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProductAnswers
3
+ {
4
+ var $Count;
5
+ var $Items;
6
+ Function Celebros_Salesperson_Model_Api_QwiserProductAnswers($xml_ProductAnswers)
7
+ {
8
+ if(is_object($xml_ProductAnswers))
9
+ {
10
+ $xml_ProductAnswersNodes = $xml_ProductAnswers->child_nodes();
11
+ $xml_ProductAnswersNodes = getDomElements($xml_ProductAnswersNodes);
12
+ $this->Count = count($xml_ProductAnswersNodes);
13
+
14
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
15
+ {
16
+ $ProductAnswerNode = $xml_ProductAnswersNodes[$i];
17
+ $this->Items[$i] = new Celebros_Salesperson_Model_Api_QwiserProductAnswer($ProductAnswerNode);
18
+ }
19
+ }
20
+ }
21
+ }
22
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProductField.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProductField
3
+ {
4
+ var $FieldType;
5
+ var $Name;
6
+
7
+
8
+ Function Celebros_Salesperson_Model_Api_QwiserProductField($ProductFieldNode)
9
+ {
10
+ if(is_object($ProductFieldNode))
11
+ {
12
+ $this->FieldType = $ProductFieldNode->get_attribute("FieldType");
13
+ $this->Name = $ProductFieldNode->get_attribute("Name");
14
+ }
15
+ }
16
+ }
17
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProductFields.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProductFields
3
+ {
4
+ var $Count;
5
+ var $Items;
6
+
7
+ Function Celebros_Salesperson_Model_Api_QwiserProductFields($xml_ProductFields)
8
+ {
9
+ if(is_object($xml_ProductFields))
10
+ {
11
+ $xml_ProductFieldsNodes = $xml_ProductFields->child_nodes();
12
+ $xml_ProductFieldsNodes = getDomElements($xml_ProductFieldsNodes);
13
+ $this->Count = count($xml_ProductFieldsNodes);
14
+
15
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
16
+ {
17
+ $ProductFieldNode = $xml_ProductFieldsNodes[$i];
18
+ $this->Items[$i] = new QwiserProductField($ProductFieldNode);
19
+ }
20
+ }
21
+ }
22
+ }
23
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserProducts.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserProducts
3
+ {
4
+ var $Count = 0; //the number of products.
5
+ var $Items; //indexer .
6
+
7
+ Function Celebros_Salesperson_Model_Api_QwiserProducts($xml_Products)
8
+ {
9
+ if(is_object($xml_Products))
10
+ {
11
+ $xml_productsNodes = $xml_Products->child_nodes();
12
+ $xml_productsNodes = getDomElements($xml_productsNodes);
13
+ $this->Count = count($xml_productsNodes);
14
+
15
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
16
+ {
17
+ $ProdNode = $xml_productsNodes[$i];
18
+
19
+ $this->Items[$i] = new Celebros_Salesperson_Model_Product($ProdNode);
20
+
21
+ }
22
+ }
23
+ }
24
+
25
+
26
+ }
27
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserQuestion.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserQuestion
3
+ {
4
+ var $Id;
5
+ var $Rank;
6
+ var $SideText;
7
+ var $Text;
8
+ var $Type;
9
+ var $HasMoreAnswers;
10
+ var $ExtraAnswers;
11
+ var $DynamicProperties;
12
+ var $Answers;
13
+
14
+ Function Celebros_Salesperson_Model_Api_QwiserQuestion($QuestionNode)
15
+ {
16
+ if(is_object($QuestionNode))
17
+ {
18
+ $this->Id = $QuestionNode->get_attribute("Id");
19
+ $this->Rank = $QuestionNode->get_attribute("Rank");
20
+ $this->SideText = $QuestionNode->get_attribute("SideText");
21
+ $this->Text = $QuestionNode->get_attribute("Text");
22
+ $this->Type = $QuestionNode->get_attribute("Type");
23
+ $this->Answers = new Celebros_Salesperson_Model_Api_QwiserAnswers(current($QuestionNode->get_elements_by_tagname("Answers")));
24
+ $this->ExtraAnswers = new Celebros_Salesperson_Model_Api_QwiserAnswers(current($QuestionNode->get_elements_by_tagname("ExtraAnswers")));
25
+ $this->HasMoreAnswers = ($this->ExtraAnswers->Count > 0) ? true : false;
26
+ $this->DynamicProperties = GetQwiserSimpleStringDictionary(current($QuestionNode->get_elements_by_tagname("DynamicProperties")));
27
+ }
28
+ }
29
+ }
30
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserQuestions.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserQuestions
3
+ {
4
+ var $Count; //the number of questions.
5
+ var $Items; //indexer .
6
+
7
+ Function Celebros_Salesperson_Model_Api_QwiserQuestions($xml_Questions)
8
+ {
9
+ if(is_array($xml_Questions))
10
+ {
11
+ $this->Items = $xml_Questions;
12
+ $this->Count = count($xml_Questions);
13
+ }
14
+ else
15
+ {
16
+ if(is_object($xml_Questions))
17
+ {
18
+ $xml_questionsNodes = $xml_Questions->child_nodes();
19
+ $xml_questionsNodes = getDomElements($xml_questionsNodes);
20
+ $this->Count = count($xml_questionsNodes);
21
+
22
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
23
+ {
24
+ $QuestionNode = $xml_questionsNodes[$i];
25
+ $this->Items[$i] = new Celebros_Salesperson_Model_Api_QwiserQuestion($QuestionNode);
26
+ }
27
+ }
28
+ }
29
+
30
+ }
31
+
32
+ Function GetAllQuestions(){
33
+ return $this->Items;
34
+ }
35
+
36
+ //get a question by its id .
37
+ Function GetQuestionById($ID)
38
+ {
39
+ foreach ($this->Items as $q)
40
+ {
41
+ if($q->Id=$ID)
42
+ {
43
+ return $q;
44
+ }
45
+ }
46
+ }
47
+
48
+ //get all questions with the given side text
49
+ Function GetQuestionsBySideText($SideText)
50
+ {
51
+ $qArray = array();
52
+ foreach ($this->Items as $q)
53
+ {
54
+ if($q->SideText=$SideText)
55
+ {
56
+ $qArray[] = $q;
57
+ }
58
+ }
59
+ return $qArray;
60
+ }
61
+
62
+ //get all question with the given text .
63
+ Function GetQuestionsByText($QuestionText)
64
+ {
65
+ $qArray = array();
66
+ foreach ($this->Items as $q)
67
+ {
68
+ if($q->Text=$QuestionText)
69
+ {
70
+ $qArray[] = $q;
71
+ }
72
+ }
73
+ return $qArray;
74
+ }
75
+
76
+ //get all question with the given type .
77
+ Function GetQuestionsByType($Type)
78
+ {
79
+ $qArray = array();
80
+ foreach ($this->Items as $q)
81
+ {
82
+ if($q->Type=$Type)
83
+ {
84
+ $qArray[] = $q;
85
+ }
86
+ }
87
+ return $qArray;
88
+
89
+ }
90
+ }
91
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchPath.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserSearchPath
3
+ {
4
+ var $Count = 0;
5
+ var $Items;
6
+
7
+ Function Celebros_Salesperson_Model_Api_QwiserSearchPath($xml_SearchPath)
8
+ {
9
+ if(is_object($xml_SearchPath))
10
+ {
11
+ $xml_SearchPathNodes = $xml_SearchPath->child_nodes();
12
+ $xml_SearchPathNodes = getDomElements($xml_SearchPathNodes);
13
+ $this->Count = count($xml_SearchPathNodes);
14
+
15
+ for ($i = 0 ; $i <= $this->Count - 1;$i++)
16
+ {
17
+ $SearchPathNode = $xml_SearchPathNodes[$i];
18
+ $this->Items[$i] = new Celebros_Salesperson_Model_Api_QwiserSearchPathEntry($SearchPathNode);
19
+ }
20
+ }
21
+ }
22
+ }
23
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchPathEntry.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserSearchPathEntry
3
+ {
4
+ var $AnswerIndex;
5
+ var $Answers;
6
+ var $QuestionId;
7
+
8
+ Function Celebros_Salesperson_Model_Api_QwiserSearchPathEntry($EntryNode)
9
+ {
10
+ if(is_object($EntryNode))
11
+ {
12
+ $this->AnswerIndex = $EntryNode->get_attribute("AnswerIndex");
13
+ $this->QuestionId = $EntryNode->get_attribute("QuestionID");
14
+ $this->Answers = new Celebros_Salesperson_Model_Api_QwiserAnswers(current(getDomElements($EntryNode->child_nodes())));
15
+ }
16
+ }
17
+ }
18
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserSearchResults.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserSearchResults
3
+ {
4
+ var $xml_root;
5
+ var $QwiserSearchResults;
6
+ var $QwiserErrorOccurred;
7
+ var $QwiserErrorMessage;
8
+ var $SearchInformation;
9
+ var $Questions;
10
+ var $SearchPath;
11
+ var $Products;
12
+ var $QueryConcepts;
13
+ var $SpellerInformation ;
14
+ var $RelatedSearches;
15
+ var $SpecialCasesDetectedInThisSearch;
16
+
17
+ Function Celebros_Salesperson_Model_Api_QwiserSearchResults($root)
18
+ {
19
+ $this->xml_root = $root;
20
+ $this->QwiserSearchResults = current($this->xml_root->get_elements_by_tagname("QwiserSearchResults"));
21
+ $this->QwiserErrorOccurred = (bool)$this->xml_root->get_attribute("ErrorOccurred");
22
+ $this->QwiserErrorMessage = current($this->xml_root->get_elements_by_tagname("QwiserError"));
23
+ $this->SearchInformation = NEW Celebros_Salesperson_Model_Api_SearchInformation(current($this->xml_root->get_elements_by_tagname("SearchInformation")));
24
+ $this->Questions = NEW Celebros_Salesperson_Model_Api_QwiserQuestions(current($this->xml_root->get_elements_by_tagname("Questions")));
25
+ $this->SearchPath = NEW Celebros_Salesperson_Model_Api_QwiserSearchPath(current($this->xml_root->get_elements_by_tagname("SearchPath")));
26
+ $this->Products = NEW Celebros_Salesperson_Model_Api_QwiserProducts(current($this->xml_root->get_elements_by_tagname("Products")));
27
+ $this->QueryConcepts = NEW Celebros_Salesperson_Model_Api_QwiserConcepts(current($this->xml_root->get_elements_by_tagname("QueryConcepts")));
28
+ $this->SpellerInformation = NEW Celebros_Salesperson_Model_Api_QwiserSpellerInformation(current($this->xml_root->get_elements_by_tagname("SpellerInformation")));
29
+ $this->RelatedSearches = GetQwiserSimpleStringCollection(current($this->xml_root->get_elements_by_tagname("RelatedSearches")));
30
+ $this->SpecialCasesDetectedInThisSearch = current($this->xml_root->get_elements_by_tagname("SpecialCasesDetectedInThisSearch"));
31
+ }
32
+
33
+ Function GetErrorOccurred(){
34
+ return $this->QwiserErrorOccurred;
35
+ }
36
+
37
+ Function GetErrorMessage(){
38
+ if ($this->GetErrorOccurred()){
39
+ return $this->QwiserErrorMessage->get_attribute("ErrorMessage");
40
+ }
41
+ }
42
+
43
+ Function GetExactMatchFound()
44
+ {
45
+ return $this->QwiserSearchResults->get_attribute("ExactMatchFound");
46
+ }
47
+
48
+ Function GetLogHandle()
49
+ {
50
+ return $this->QwiserSearchResults->get_attribute("LogHandle");
51
+ }
52
+
53
+ Function GetSearchHandle()
54
+ {
55
+ return $this->QwiserSearchResults->get_attribute("SearchHandle");
56
+ }
57
+
58
+ Function GetMaxMatchClassFound()
59
+ {
60
+ return $this->QwiserSearchResults->get_attribute("MaxMatchClassFound");
61
+ }
62
+
63
+ Function GetMinMatchClassFound()
64
+ {
65
+ return $this->QwiserSearchResults->get_attribute("MinMatchClassFound");
66
+ }
67
+
68
+ Function GetRecommendedMessage()
69
+ {
70
+ return $this->QwiserSearchResults->get_attribute("RecommendedMessage");
71
+ }
72
+
73
+ Function GetRedirectionUrl()
74
+ {
75
+ return $this->QwiserSearchResults->get_attribute("RedirectionUrl");
76
+ }
77
+
78
+ Function GetRelevantProductsCount()
79
+ {
80
+ return $this->QwiserSearchResults->get_attribute("RelevantProductsCount");
81
+ }
82
+
83
+ Function GetSearchDataVersion()
84
+ {
85
+ return $this->QwiserSearchResults->get_attribute("SearchDataVersion");
86
+ }
87
+
88
+ Function GetSearchEngineTimeDuration()
89
+ {
90
+ return $this->QwiserSearchResults->get_attribute("SearchEngineTimeDuration");
91
+ }
92
+
93
+ Function GetSearchTimeDuration()
94
+ {
95
+ return $this->QwiserSearchResults->get_attribute("SearchTimeDuration");
96
+ }
97
+
98
+ Function GetSearchStatus()
99
+ {
100
+ return $this->QwiserSearchResults->get_attribute("SearchStatus");
101
+ }
102
+
103
+ /*Function GetLogHandle()
104
+ {
105
+ return $this->QwiserSearchResults->get_attribute("LogHandle");
106
+ }*/
107
+
108
+ }
109
+
110
+
111
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/QwiserSpellerInformation.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_QwiserSpellerInformation
3
+ {
4
+ var $AdditionalSuggestions;
5
+ var $SpellerAutoCorrection;
6
+ var $SpellingErrorDetected = "false";
7
+
8
+ function Celebros_Salesperson_Model_Api_QwiserSpellerInformation($xml_SpellerInformation)
9
+ {
10
+ if(is_object($xml_SpellerInformation))
11
+ {
12
+ $this->SpellingErrorDetected = $xml_SpellerInformation->get_attribute("SpellingErrorDetected");
13
+ $this->SpellerAutoCorrection = $xml_SpellerInformation->get_attribute("SpellerAutoCorrection");
14
+ $this->AdditionalSuggestions = GetQwiserSimpleStringCollection(current(getDomElements($xml_SpellerInformation->child_nodes())));
15
+ }
16
+ }
17
+ }
18
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/SearchInformation.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_SearchInformation
3
+ {
4
+ var $Query;
5
+ var $OriginalQuery;
6
+ var $SearchProfileName;
7
+ var $PriceFieldName;
8
+ var $NumberOfPages;
9
+ var $CurrentPage;
10
+ var $PageSize;
11
+ var $IsDefaultPageSize;
12
+ var $IsDefaultSearchProfileName;
13
+ var $SkuSearchOccured;
14
+ var $DeadEndOccurred;
15
+ var $FirstQuestionId;
16
+ var $SessionId;
17
+ var $Stage;
18
+ var $SortingOptions;
19
+
20
+
21
+ Function Celebros_Salesperson_Model_Api_SearchInformation($xml_SearchInformation)
22
+ {
23
+ if(is_object($xml_SearchInformation))
24
+ {
25
+ $this->Query = $xml_SearchInformation->get_attribute("Query");
26
+ $this->OriginalQuery = $xml_SearchInformation->get_attribute("OriginalQuery");
27
+ $this->SearchProfileName = $xml_SearchInformation->get_attribute("SearchProfileName");
28
+ $this->PriceFieldName = $xml_SearchInformation->get_attribute("PriceFieldName");
29
+ $this->NumberOfPages = $xml_SearchInformation->get_attribute("NumberOfPages");
30
+ $this->CurrentPage = $xml_SearchInformation->get_attribute("CurrentPage");
31
+ $this->PageSize = $xml_SearchInformation->get_attribute("PageSize");
32
+ $this->IsDefaultPageSize = $xml_SearchInformation->get_attribute("IsDefaultPageSize");
33
+ $this->SkuSearchOccured = $xml_SearchInformation->get_attribute("SkuSearchOccured");
34
+ $this->DeadEndOccurred = $xml_SearchInformation->get_attribute("DeadEndOccurred");
35
+ $this->FirstQuestionId = $xml_SearchInformation->get_attribute("FirstQuestionId");
36
+ $this->SessionId = $xml_SearchInformation->get_attribute("SessionId");
37
+ $this->Stage = $xml_SearchInformation->get_attribute("Stage");
38
+
39
+ $this->SortingOptions = new Celebros_Salesperson_Model_Api_SortingOptions(current($xml_SearchInformation->get_elements_by_tagname("SortingOptions")));
40
+ }
41
+ }
42
+ }
43
+
44
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/SortingOptions.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ class Celebros_Salesperson_Model_Api_SortingOptions
3
+ {
4
+ var $Ascending;
5
+ var $FieldName;
6
+ var $NumericSort;
7
+ var $Method;
8
+
9
+ Function Celebros_Salesperson_Model_Api_SortingOptions($xml_SortingOptions)
10
+ {
11
+ if(is_object($xml_SortingOptions))
12
+ {
13
+ $this->Ascending = $xml_SortingOptions->get_attribute("Ascending");
14
+ $this->FieldName = $xml_SortingOptions->get_attribute("FieldName");
15
+ $this->NumericSort = $xml_SortingOptions->get_attribute("NumericSort");
16
+ $this->Method = $xml_SortingOptions->get_attribute("Method");
17
+ }
18
+ }
19
+ }
20
+ ?>
app/code/local/Celebros/Salesperson/Model/Api/domxml-php4-to-php5.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Requires PHP5, uses built-in DOM extension.
4
+ To be used in PHP4 scripts using DOMXML extension.
5
+ Allows PHP4/DOMXML scripts to run on PHP5/DOM.
6
+ (Requires PHP5/XSL extension for domxml_xslt functions)
7
+
8
+ Typical use:
9
+ {
10
+ if (version_compare(PHP_VERSION,'5','>='))
11
+ require_once('domxml-php4-to-php5.php');
12
+ }
13
+ */
14
+
15
+ function domxml_new_doc($version) {return new php4DOMDocument('');}
16
+ function domxml_open_file($filename) {return new php4DOMDocument($filename);}
17
+ function domxml_open_mem($str)
18
+ {
19
+ $dom=new php4DOMDocument('');
20
+ $dom->myDOMNode->loadXML($str);
21
+ return $dom;
22
+ }
23
+ function html_doc($html_doc,$from_file=false)
24
+ {
25
+ $dom=new php4DOMDocument('');
26
+ if ($from_file) $dom->myDOMNode->loadHTMLFile($html_doc);
27
+ else $dom->myDOMNode->loadHTML($html_doc);
28
+ return $dom;
29
+ }
30
+ function html_doc_file($filename) {return html_doc($filename,true);}
31
+ function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->xpath_eval($eval_str,$contextnode);}
32
+ function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);}
33
+ function xpath_register_ns($xpath_context,$prefix,$namespaceURI) {return $xpath_context->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
34
+
35
+ class php4DOMAttr extends php4DOMNode
36
+ {
37
+ function php4DOMAttr($aDOMAttr) {$this->myDOMNode=$aDOMAttr;}
38
+ function name() {return $this->myDOMNode->name;}
39
+ function set_value($content) {return $this->myDOMNode->value=$content;}
40
+ function specified() {return $this->myDOMNode->specified;}
41
+ function value() {return $this->myDOMNode->value;}
42
+ }
43
+
44
+ class php4DOMDocument extends php4DOMNode
45
+ {
46
+ function php4DOMDocument($filename='')
47
+ {
48
+ $this->myDOMNode=new DOMDocument();
49
+ $this->myOwnerDocument=$this;
50
+ if ($filename!='') $this->myDOMNode->load($filename);
51
+ }
52
+ function add_root($name)
53
+ {
54
+ if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
55
+ return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument);
56
+ }
57
+ function create_attribute($name,$value)
58
+ {
59
+ $myAttr=$this->myDOMNode->createAttribute($name);
60
+ $myAttr->value=$value;
61
+ return new php4DOMAttr($myAttr,$this);
62
+ }
63
+ function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);}
64
+ function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);}
65
+ function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);}
66
+ function create_text_node($content) {return new php4DOMText($this->myDOMNode->createTextNode($content),$this);}
67
+ function document_element() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);}
68
+ function dump_file($filename,$compressionmode=false,$format=false)
69
+ {
70
+ $format0=$this->myDOMNode->formatOutput;
71
+ $this->myDOMNode->formatOutput=$format;
72
+ $res=$this->myDOMNode->save($filename);
73
+ $this->myDOMNode->formatOutput=$format0;
74
+ return $res;
75
+ }
76
+ function dump_mem($format=false,$encoding=false)
77
+ {
78
+ $format0=$this->myDOMNode->formatOutput;
79
+ $this->myDOMNode->formatOutput=$format;
80
+ $encoding0=$this->myDOMNode->encoding;
81
+ if ($encoding) $this->myDOMNode->encoding=$encoding;
82
+ $dump=$this->myDOMNode->saveXML();
83
+ $this->myDOMNode->formatOutput=$format0;
84
+ if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0; //UTF-8 is XML default encoding
85
+ return $dump;
86
+ }
87
+ // function dump_node($node) {return $this->myDOMNode->saveXML($node->myDOMNode);}
88
+ function free()
89
+ {
90
+ if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
91
+ $this->myDOMNode=null;
92
+ $this->myOwnerDocument=null;
93
+ }
94
+ function get_element_by_id($id) {return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);}
95
+ function get_elements_by_tagname($name)
96
+ {
97
+ $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
98
+ $nodeSet=array();
99
+ $i=0;
100
+ if (isset($myDOMNodeList))
101
+ while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this);
102
+ return $nodeSet;
103
+ }
104
+ function html_dump_mem() {return $this->myDOMNode->saveHTML();}
105
+ function root() {return parent::_newDOMElement($this->myDOMNode->documentElement,$this);}
106
+ function xpath_new_context() {return new php4DOMXPath($this);}
107
+ }
108
+
109
+ class php4DOMElement extends php4DOMNode
110
+ {
111
+ function get_attribute($name) {return $this->myDOMNode->getAttribute($name);}
112
+ function get_elements_by_tagname($name)
113
+ {
114
+ $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
115
+ $nodeSet=array();
116
+ $i=0;
117
+ if (isset($myDOMNodeList))
118
+ while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
119
+ return $nodeSet;
120
+ }
121
+ function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);}
122
+ function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);}
123
+ function set_attribute($name,$value) {return $this->myDOMNode->setAttribute($name,$value);}
124
+ function set_name($name)
125
+ {
126
+ if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name);
127
+ else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name);
128
+ $myDOMNodeList=$this->myDOMNode->attributes;
129
+ $i=0;
130
+ if (isset($myDOMNodeList))
131
+ while ($node=$myDOMNodeList->item($i++))
132
+ if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value);
133
+ else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value);
134
+ $myDOMNodeList=$this->myDOMNode->childNodes;
135
+ if (isset($myDOMNodeList))
136
+ while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node);
137
+ $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode);
138
+ $this->myDOMNode=$newNode;
139
+ return true;
140
+ }
141
+ function tagname() {return $this->myDOMNode->tagName;}
142
+ }
143
+
144
+ class php4DOMNode
145
+ {
146
+ var $myDOMNode;
147
+ var $myOwnerDocument;
148
+ function php4DOMNode($aDomNode,$aOwnerDocument)
149
+ {
150
+ $this->myDOMNode=$aDomNode;
151
+ $this->myOwnerDocument=$aOwnerDocument;
152
+ }
153
+ function __get($name)
154
+ {
155
+ switch ($name)
156
+ {
157
+ case 'type': return $this->myDOMNode->nodeType;
158
+ case 'tagname': return $this->myDOMNode->tagName;
159
+ case 'content': return $this->myDOMNode->textContent;
160
+ case 'name': return $this->myDOMNode->name;
161
+ case 'value': return $this->myDOMNode->value;
162
+ default:
163
+ $myErrors=debug_backtrace();
164
+ trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
165
+ return false;
166
+ }
167
+ }
168
+ function append_child($newnode) {return self::_newDOMElement($this->myDOMNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);}
169
+ function append_sibling($newnode) {return self::_newDOMElement($this->myDOMNode->parentNode->appendChild($this->_importNode($newnode)),$this->myOwnerDocument);}
170
+ function attributes()
171
+ {
172
+ $myDOMNodeList=$this->myDOMNode->attributes;
173
+ $nodeSet=array();
174
+ $i=0;
175
+ if (isset($myDOMNodeList))
176
+ while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument);
177
+ return $nodeSet;
178
+ }
179
+ function child_nodes()
180
+ {
181
+ $myDOMNodeList=$this->myDOMNode->childNodes;
182
+ $nodeSet=array();
183
+ $i=0;
184
+ if (isset($myDOMNodeList))
185
+ while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=self::_newDOMElement($node,$this->myOwnerDocument);
186
+ return $nodeSet;
187
+ }
188
+ function children() {return $this->child_nodes();}
189
+ function clone_node($deep=false) {return self::_newDOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);}
190
+ function dump_node() {return $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode);}
191
+ function first_child() {return self::_newDOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);}
192
+ function get_content() {return $this->myDOMNode->textContent;}
193
+ function has_attributes() {return $this->myDOMNode->hasAttributes();}
194
+ function has_child_nodes() {return $this->myDOMNode->hasChildNodes();}
195
+ function insert_before($newnode,$refnode) {return self::_newDOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);}
196
+ function is_blank_node() {return ($this->myDOMNode->nodeType==XML_TEXT_NODE)&&preg_match('%^\s*$%',$this->myDOMNode->nodeValue);}
197
+ function last_child() {return self::_newDOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);}
198
+ function new_child($name,$content)
199
+ {
200
+ $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
201
+ $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(html_entity_decode($content,ENT_QUOTES)));
202
+ $this->myDOMNode->appendChild($mySubNode);
203
+ return new php4DOMElement($mySubNode,$this->myOwnerDocument);
204
+ }
205
+ function next_sibling() {return self::_newDOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);}
206
+ function node_name() {return ($this->myDOMNode->nodeType==XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;} //avoid namespace prefix for DOMElement
207
+ function node_type() {return $this->myDOMNode->nodeType;}
208
+ function node_value() {return $this->myDOMNode->nodeValue;}
209
+ function owner_document() {return $this->myOwnerDocument;}
210
+ function parent_node() {return self::_newDOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);}
211
+ function prefix() {return $this->myDOMNode->prefix;}
212
+ function previous_sibling() {return self::_newDOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);}
213
+ function remove_child($oldchild) {return self::_newDOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);}
214
+ function replace_child($oldnode,$newnode) {return self::_newDOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$this->_importNode($newnode)),$this->myOwnerDocument);}
215
+ function set_content($text) {return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text));}
216
+ //function set_name($name) {return $this->myOwnerDocument->renameNode($this->myDOMNode,$this->myDOMNode->namespaceURI,$name);}
217
+ protected function _importNode($newnode) {return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,true);} //to import DOMNode from another DOMDocument
218
+ static function _newDOMElement($aDOMNode,$aOwnerDocument)
219
+ {//to check the PHP5 DOMNode before creating a new associated PHP4 DOMNode wrapper
220
+ if ($aDOMNode==null) return null;
221
+ switch ($aDOMNode->nodeType)
222
+ {
223
+ case XML_ELEMENT_NODE: return new php4DOMElement($aDOMNode,$aOwnerDocument);
224
+ case XML_TEXT_NODE: return new php4DOMText($aDOMNode,$aOwnerDocument);
225
+ case XML_ATTRIBUTE_NODE: return new php4DOMAttr($aDOMNode,$aOwnerDocument);
226
+ default: return new php4DOMNode($aDOMNode,$aOwnerDocument);
227
+ }
228
+ }
229
+ }
230
+
231
+ class php4DOMText extends php4DOMNode
232
+ {
233
+ function __get($name)
234
+ {
235
+ if ($name=='tagname') return '#text';
236
+ else return parent::__get($name);
237
+ }
238
+ function tagname() {return '#text';}
239
+ }
240
+
241
+ if (!defined('XPATH_NODESET'))
242
+ {
243
+ define('XPATH_UNDEFINED',0);
244
+ define('XPATH_NODESET',1);
245
+ /*define('XPATH_BOOLEAN',2);
246
+ define('XPATH_NUMBER',3);
247
+ define('XPATH_STRING',4);
248
+ define('XPATH_POINT',5);
249
+ define('XPATH_RANGE',6);
250
+ define('XPATH_LOCATIONSET',7);
251
+ define('XPATH_USERS',8);
252
+ define('XPATH_XSLT_TREE',9);*/
253
+ }
254
+
255
+ class php4DOMNodelist
256
+ {//TODO: To be updated for PHP/5.1 to allow XPath boolean expressions etc. DOMXPath->evaluate()
257
+ var $myDOMNodelist;
258
+ var $nodeset;
259
+ var $type;
260
+ function php4DOMNodelist($aDOMNodelist,$aOwnerDocument)
261
+ {
262
+ $this->myDOMNodelist=$aDOMNodelist;
263
+ $this->nodeset=array();
264
+ $i=0;
265
+ if (isset($this->myDOMNodelist))
266
+ {
267
+ $this->type=XPATH_NODESET;
268
+ while ($node=$this->myDOMNodelist->item($i++)) $this->nodeset[]=php4DOMNode::_newDOMElement($node,$aOwnerDocument);
269
+ }
270
+ else $this->type=XPATH_UNDEFINED;
271
+ }
272
+ }
273
+
274
+ class php4DOMXPath
275
+ {
276
+ var $myDOMXPath;
277
+ var $myOwnerDocument;
278
+ function php4DOMXPath($dom_document)
279
+ {
280
+ $this->myOwnerDocument=$dom_document;
281
+ $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode);
282
+ }
283
+ function xpath_eval($eval_str,$contextnode=null) {return isset($contextnode) ? new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument) : new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument);}
284
+ function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
285
+ }
286
+
287
+ if (extension_loaded('xsl'))
288
+ {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
289
+ function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));}
290
+ function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);}
291
+ function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));}
292
+ class php4DomXsltStylesheet
293
+ {
294
+ var $myxsltProcessor;
295
+ function php4DomXsltStylesheet($dom_document)
296
+ {
297
+ $this->myxsltProcessor=new xsltProcessor();
298
+ $this->myxsltProcessor->importStyleSheet($dom_document);
299
+ }
300
+ function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
301
+ {
302
+ foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value);
303
+ $myphp4DOMDocument=new php4DOMDocument();
304
+ $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
305
+ return $myphp4DOMDocument;
306
+ }
307
+ function result_dump_file($dom_document,$filename)
308
+ {
309
+ $html=$dom_document->myDOMNode->saveHTML();
310
+ file_put_contents($filename,$html);
311
+ return $html;
312
+ }
313
+ function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();}
314
+ }
315
+ }
316
+ ?>
app/code/local/Celebros/Salesperson/Model/Convert/Adapter/Io.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Convert_Adapter_Io extends Mage_Dataflow_Model_Convert_Adapter_Abstract
11
+ {
12
+ /**
13
+ * @return Varien_Io_Abstract
14
+ */
15
+ public function getResource($forWrite = false)
16
+ {
17
+ if (!$this->_resource) {
18
+ $type = Mage::getStoreConfig('salesperson/export_settings/type');
19
+ if ($type == ''){
20
+ $type = $this->getVar('type', 'file');
21
+ }
22
+ $className = 'Varien_Io_'.ucwords($type);
23
+ $this->_resource = new $className();
24
+
25
+ $isError = false;
26
+
27
+ $ioConfig = $this->getVars();
28
+ if (Mage::getStoreConfig('salesperson/export_settings/type')!= ''){
29
+ $ioConfig['type'] = Mage::getStoreConfig('salesperson/export_settings/type');
30
+ }
31
+ if (Mage::getStoreConfig('salesperson/export_settings/ftp_host')!= ''){
32
+ $ioConfig['host'] = Mage::getStoreConfig('salesperson/export_settings/ftp_host');
33
+ }
34
+ if (Mage::getStoreConfig('salesperson/export_settings/ftp_port')!= ''){
35
+ $ioConfig['port'] = Mage::getStoreConfig('salesperson/export_settings/ftp_port');
36
+ }
37
+ if (Mage::getStoreConfig('salesperson/export_settings/ftp_user')!= ''){
38
+ $ioConfig['user'] = Mage::getStoreConfig('salesperson/export_settings/ftp_user');
39
+ }
40
+ if (Mage::getStoreConfig('salesperson/export_settings/ftp_password')!= ''){
41
+ $ioConfig['password'] = Mage::getStoreConfig('salesperson/export_settings/ftp_password');
42
+ }
43
+ if (Mage::getStoreConfig('salesperson/export_settings/passive')!= ''){
44
+ $ioConfig['passive'] = Mage::getStoreConfig('salesperson/export_settings/passive');
45
+ }
46
+ switch ($type) {
47
+ case 'file':
48
+ $t_path = Mage::getStoreConfig('salesperson/export_settings/path');
49
+ if (preg_match('#^'.preg_quote(DS, '#').'#', $t_path) ||
50
+ preg_match('#^[a-z]:'.preg_quote(DS, '#') .'#i', $t_path)) {
51
+
52
+ $path = $this->_resource->getCleanPath($t_path);
53
+ }
54
+ else {
55
+ $baseDir = Mage::getBaseDir();
56
+ $path = $this->_resource->getCleanPath($baseDir . DS . trim($t_path, DS));
57
+ }
58
+ $this->_resource->checkAndCreateFolder($path);
59
+
60
+ $realPath = realpath($path);
61
+
62
+ if (!$isError && $realPath === false) {
63
+ $message = Mage::helper('dataflow')->__('Destination folder "%s" does not exist or not access to create', Mage::getStoreConfig('salesperson/export_settings/path'));
64
+ Mage::throwException($message);
65
+ }
66
+ elseif (!$isError && !is_dir($realPath)) {
67
+ $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a directory', $realPath);
68
+ Mage::throwException($message);
69
+ }
70
+ elseif (!$isError) {
71
+ if ($forWrite && !is_writeable($realPath)) {
72
+ $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a writeable', $realPath);
73
+ Mage::throwException($message);
74
+ }
75
+ else {
76
+ $ioConfig['path'] = rtrim($realPath, DS);
77
+ }
78
+ }
79
+ break;
80
+ default:
81
+ $ioConfig['path'] = rtrim(Mage::getStoreConfig('salesperson/export_settings/path'), '/');
82
+ break;
83
+ }
84
+
85
+ if ($isError) {
86
+ return false;
87
+ }
88
+ try {
89
+ $this->_resource->open($ioConfig);
90
+ } catch (Exception $e) {
91
+ $message = Mage::helper('dataflow')->__('Error occured during file opening: "%s"', $e->getMessage());
92
+ Mage::throwException($message);
93
+ }
94
+ }
95
+ return $this->_resource;
96
+ }
97
+
98
+ /**
99
+ * Load data
100
+ *
101
+ * @return Mage_Dataflow_Model_Convert_Adapter_Io
102
+ */
103
+ public function load()
104
+ {
105
+ if (!$this->getResource()) {
106
+ return $this;
107
+ }
108
+
109
+ $batchModel = Mage::getSingleton('dataflow/batch');
110
+ $destFile = $batchModel->getIoAdapter()->getFile(true);
111
+
112
+ $result = $this->getResource()->read($this->getVar('filename'), $destFile);
113
+ $filename = $this->getResource()->pwd() . '/' . $this->getVar('filename');
114
+ if (false === $result) {
115
+ $message = Mage::helper('dataflow')->__('Could not load file: "%s"', $filename);
116
+ Mage::throwException($message);
117
+ } else {
118
+ $message = Mage::helper('dataflow')->__('Loaded successfully: "%s"', $filename);
119
+ $this->addException($message);
120
+ }
121
+
122
+ $this->setData($result);
123
+ return $this;
124
+ }
125
+
126
+ /**
127
+ * Save result to destionation file from temporary
128
+ *
129
+ * @return Mage_Dataflow_Model_Convert_Adapter_Io
130
+ */
131
+ public function save()
132
+ {
133
+ if (!$this->getResource(true)) {
134
+ return $this;
135
+ }
136
+
137
+ $batchModel = Mage::getSingleton('dataflow/batch');
138
+
139
+ $dataFile = $batchModel->getIoAdapter()->getFile(true);
140
+
141
+ $filename = $this->getVar('filename', 'products.txt');
142
+
143
+ $result = $this->getResource()->write($filename, $dataFile, 0777);
144
+
145
+ if (false === $result) {
146
+ $message = Mage::helper('dataflow')->__('Could not save file: %s', $filename);
147
+ Mage::throwException($message);
148
+ } else {
149
+ $message = Mage::helper('dataflow')->__('Saved successfully: "%s" [%d byte(s)]', $filename, $batchModel->getIoAdapter()->getFileSize());
150
+ if ($this->getVar('link')) {
151
+ $message .= Mage::helper('dataflow')->__('<a href="%s" target="_blank">Link</a>', $this->getVar('link'));
152
+ }
153
+ $this->addException($message);
154
+ }
155
+ return $this;
156
+ }
157
+ }
app/code/local/Celebros/Salesperson/Model/Convert/Mapper/Column.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Convert_Mapper_Column extends Mage_Dataflow_Model_Convert_Mapper_Abstract
11
+ {
12
+ /**
13
+ * Dataflow batch model
14
+ *
15
+ * @var Mage_Dataflow_Model_Batch
16
+ */
17
+ protected $_batch;
18
+
19
+ /**
20
+ * Dataflow batch export model
21
+ *
22
+ * @var Mage_Dataflow_Model_Batch_Export
23
+ */
24
+ protected $_batchExport;
25
+
26
+ /**
27
+ * Dataflow batch import model
28
+ *
29
+ * @var Mage_Dataflow_Model_Batch_Import
30
+ */
31
+ protected $_batchImport;
32
+
33
+ /**
34
+ * Retrieve Batch model singleton
35
+ *
36
+ * @return Mage_Dataflow_Model_Batch
37
+ */
38
+ public function getBatchModel()
39
+ {
40
+ if (is_null($this->_batch)) {
41
+ $this->_batch = Mage::getSingleton('dataflow/batch');
42
+ }
43
+ return $this->_batch;
44
+ }
45
+
46
+ /**
47
+ * Retrieve Batch export model
48
+ *
49
+ * @return Mage_Dataflow_Model_Batch_Export
50
+ */
51
+ public function getBatchExportModel()
52
+ {
53
+ if (is_null($this->_batchExport)) {
54
+ $object = Mage::getModel('dataflow/batch_export');
55
+ $this->_batchExport = Varien_Object_Cache::singleton()->save($object);
56
+ }
57
+ return Varien_Object_Cache::singleton()->load($this->_batchExport);
58
+ }
59
+
60
+ /**
61
+ * Retrieve Batch import model
62
+ *
63
+ * @return Mage_Dataflow_Model_Import_Export
64
+ */
65
+ public function getBatchImportModel()
66
+ {
67
+ if (is_null($this->_batchImport)) {
68
+ $object = Mage::getModel('dataflow/batch_import');
69
+ $this->_batchImport = Varien_Object_Cache::singleton()->save($object);
70
+ }
71
+ return Varien_Object_Cache::singleton()->load($this->_batchImport);
72
+ }
73
+
74
+ public function map()
75
+ {
76
+ $batchModel = $this->getBatchModel();
77
+ $batchExport = $this->getBatchExportModel();
78
+
79
+ $batchExportIds = $batchExport
80
+ ->setBatchId($this->getBatchModel()->getId())
81
+ ->getIdCollection();
82
+
83
+ $onlySpecified = (bool)$this->getVar('_only_specified') === true;
84
+
85
+ if (!$onlySpecified) {
86
+ foreach ($batchExportIds as $batchExportId) {
87
+ $batchExport->load($batchExportId);
88
+ $batchModel->parseFieldList($batchExport->getBatchData());
89
+ }
90
+
91
+ return $this;
92
+ }
93
+
94
+ if ($this->getVar('map') && is_array($this->getVar('map'))) {
95
+ $attributesToSelect = $this->getVar('map');
96
+ }
97
+ else {
98
+ $attributesToSelect = array();
99
+ }
100
+
101
+ if (!$attributesToSelect) {
102
+ $this->getBatchExportModel()
103
+ ->setBatchId($this->getBatchModel()->getId())
104
+ ->deleteCollection();
105
+
106
+ Mage::throwException(Mage::helper('dataflow')->__('Error field mapping! Fields list for mapping is not defined'));
107
+ }
108
+
109
+ foreach ($batchExportIds as $batchExportId) {
110
+ $batchExport = $this->getBatchExportModel()->load($batchExportId);
111
+ $row = $batchExport->getBatchData();
112
+
113
+ $newRow = array();
114
+ foreach ($attributesToSelect as $field => $mapField) {
115
+ if (isset($row[$field])){
116
+ if (preg_match('/{{is_filterable}}{{is_searchable}}/', $row[$field])){
117
+ $row[$field] = preg_replace('/{{is_filterable}}{{is_searchable}}/', '', $row[$field], 1);
118
+ }
119
+ elseif (preg_match('/{{is_filterable}}/', $row[$field])){
120
+ $row[$field] = preg_replace('/{{is_filterable}}/', '', $row[$field], 1);
121
+ }
122
+ elseif (preg_match('/{{is_searchable}}/', $row[$field])){
123
+ $row[$field] = preg_replace('/{{is_searchable}}/', '', $row[$field], 1);
124
+ }
125
+ $newRow[$mapField] = $row[$field];
126
+ }
127
+ else {
128
+ $newRow[$mapField] = null;
129
+ }
130
+ }
131
+
132
+ /* Add any filterable / searchable attribute to the map */
133
+ foreach($row as $field => $val){
134
+ $attr = array();
135
+ if (preg_match('/{{is_filterable}}{{is_searchable}}/', $val)){
136
+ $val = preg_replace('/{{is_filterable}}{{is_searchable}}/', '', $val, 1);
137
+ $attr['field'] = $field;
138
+ $attr['val'] = $val;
139
+ // print ($field ." => ". $val)."<br/>";
140
+ }
141
+ elseif (preg_match('/{{is_filterable}}/', $val)){
142
+ $val = preg_replace('/{{is_filterable}}/', '', $val, 1);
143
+ $attr['field'] = $field;
144
+ $attr['val'] = $val;
145
+ // print ($field ." => ". $val)."<br/>";
146
+ }
147
+ elseif (preg_match('/{{is_searchable}}/', $val)){
148
+ $val = preg_replace('/{{is_searchable}}/', '', $val, 1);
149
+ $attr['field'] = $field;
150
+ $attr['val'] = $val;
151
+ // print ($field ." => ". $val)."<br/>";
152
+ }
153
+ if (!empty($attr)){
154
+ // Set the new field with the c:<field>:<<type>> structure
155
+ // if (!key_exists('c:'.$attr['field'].':string', $newRow) && !key_exists($attr['field'], $newRow)) {
156
+ // $newRow['c:'.$attr['field'].':string'] = $attr['val'];
157
+ // }
158
+ // Set Clean fields names structure
159
+ if (!key_exists($attr['field'], $newRow)){
160
+ $newRow[$attr['field']] = $attr['val'];
161
+ }
162
+ }
163
+ }
164
+
165
+
166
+
167
+ $batchExport->setBatchData($newRow)
168
+ ->setStatus(1)
169
+ ->save();
170
+ $this->getBatchModel()->parseFieldList($batchExport->getBatchData());
171
+ }
172
+
173
+ return $this;
174
+ }
175
+ }
app/code/local/Celebros/Salesperson/Model/Convert/Parser/Csv.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Convert_Parser_Csv extends Mage_Dataflow_Model_Convert_Parser_Abstract
11
+ {
12
+ protected $_fields;
13
+
14
+ protected $_mapfields = array();
15
+
16
+ public function parse()
17
+ {
18
+ // fixed for multibyte characters
19
+ setlocale(LC_ALL, Mage::app()->getLocale()->getLocaleCode().'.UTF-8');
20
+
21
+ $fDel = Mage::getStoreConfig('salesperson/export_settings/delimiter');
22
+ if ($fDel == ''){
23
+ $fDel = $this->getVar('delimiter', '\t');
24
+ }
25
+ $fEnc = Mage::getStoreConfig('salesperson/export_settings/enclosed_values');
26
+ // if ($fEnc == ''){
27
+ // $fEnc = $this->getVar('enclose', '');
28
+ // }
29
+ if ($fDel == '\t') {
30
+ $fDel = "\t";
31
+ }
32
+
33
+ $adapterName = $this->getVar('adapter', null);
34
+ $adapterMethod = $this->getVar('method', 'saveRow');
35
+
36
+ if (!$adapterName || !$adapterMethod) {
37
+ $message = Mage::helper('dataflow')->__('Please declare "adapter" and "method" node first');
38
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
39
+ return $this;
40
+ }
41
+
42
+ try {
43
+ $adapter = Mage::getModel($adapterName);
44
+ }
45
+ catch (Exception $e) {
46
+ $message = Mage::helper('dataflow')->__('Declared adapter %s not found', $adapterName);
47
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
48
+ return $this;
49
+ }
50
+
51
+ if (!is_callable(array($adapter, $adapterMethod))) {
52
+ $message = Mage::helper('dataflow')->__('Method "%s" not defined in adapter %s', $adapterMethod, $adapterName);
53
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::FATAL);
54
+ return $this;
55
+ }
56
+
57
+ $batchModel = $this->getBatchModel();
58
+ $batchIoAdapter = $this->getBatchModel()->getIoAdapter();
59
+
60
+ if (Mage::app()->getRequest()->getParam('files')) {
61
+ $file = Mage::app()->getConfig()->getTempVarDir().'/import/'
62
+ . urldecode(Mage::app()->getRequest()->getParam('files'));
63
+ $this->_copy($file);
64
+ }
65
+
66
+ $batchIoAdapter->open(false);
67
+
68
+ $isFieldNames = $this->getVar('fieldnames', '') == 'true' ? true : false;
69
+ if (!$isFieldNames && is_array($this->getVar('map'))) {
70
+ $fieldNames = $this->getVar('map');
71
+ }
72
+ else {
73
+ $fieldNames = array();
74
+ foreach ($batchIoAdapter->read(true, $fDel, $fEnc) as $v) {
75
+ $fieldNames[$v] = $v;
76
+ }
77
+ }
78
+
79
+ $countRows = 0;
80
+ while (($csvData = $batchIoAdapter->read(true, $fDel, $fEnc)) !== false) {
81
+ if (count($csvData) == 1 && $csvData[0] === null) {
82
+ continue;
83
+ }
84
+
85
+ $itemData = array();
86
+ $countRows ++; $i = 0;
87
+ foreach ($fieldNames as $field) {
88
+ $itemData[$field] = isset($csvData[$i]) ? $csvData[$i] : null;
89
+ $i ++;
90
+ }
91
+
92
+ $batchImportModel = $this->getBatchImportModel()
93
+ ->setId(null)
94
+ ->setBatchId($this->getBatchModel()->getId())
95
+ ->setBatchData($itemData)
96
+ ->setStatus(1)
97
+ ->save();
98
+ }
99
+
100
+ $this->addException(Mage::helper('dataflow')->__('Found %d rows', $countRows));
101
+ $this->addException(Mage::helper('dataflow')->__('Starting %s :: %s', $adapterName, $adapterMethod));
102
+
103
+ $batchModel->setParams($this->getVars())
104
+ ->setAdapter($adapterName)
105
+ ->save();
106
+
107
+ //$adapter->$adapterMethod();
108
+
109
+ return $this;
110
+
111
+ // // fix for field mapping
112
+ // if ($mapfields = $this->getProfile()->getDataflowProfile()) {
113
+ // $this->_mapfields = array_values($mapfields['gui_data']['map'][$mapfields['entity_type']]['db']);
114
+ // } // end
115
+ //
116
+ // if (!$this->getVar('fieldnames') && !$this->_mapfields) {
117
+ // $this->addException('Please define field mapping', Mage_Dataflow_Model_Convert_Exception::FATAL);
118
+ // return;
119
+ // }
120
+ //
121
+ // if ($this->getVar('adapter') && $this->getVar('method')) {
122
+ // $adapter = Mage::getModel($this->getVar('adapter'));
123
+ // }
124
+ //
125
+ // $i = 0;
126
+ // while (($line = fgetcsv($fh, null, $fDel, $fEnc)) !== FALSE) {
127
+ // $row = $this->parseRow($i, $line);
128
+ //
129
+ // if (!$this->getVar('fieldnames') && $i == 0 && $row) {
130
+ // $i = 1;
131
+ // }
132
+ //
133
+ // if ($row) {
134
+ // $loadMethod = $this->getVar('method');
135
+ // $adapter->$loadMethod(compact('i', 'row'));
136
+ // }
137
+ // $i++;
138
+ // }
139
+ //
140
+ // return $this;
141
+ }
142
+
143
+ public function parseRow($i, $line)
144
+ {
145
+ if (sizeof($line) == 1) return false;
146
+
147
+ if (0==$i) {
148
+ if ($this->getVar('fieldnames')) {
149
+ $this->_fields = $line;
150
+ return;
151
+ } else {
152
+ foreach ($line as $j=>$f) {
153
+ // $this->_fields[$j] = 'column'.($j+1);
154
+ $this->_fields[$j] = $this->_mapfields[$j];
155
+ }
156
+ }
157
+ }
158
+
159
+ $resultRow = array();
160
+
161
+ foreach ($this->_fields as $j=>$f) {
162
+ $resultRow[$f] = isset($line[$j]) ? $line[$j] : '';
163
+ }
164
+ return $resultRow;
165
+ }
166
+
167
+ /**
168
+ * Read data collection and write to temporary file
169
+ *
170
+ * @return Mage_Dataflow_Model_Convert_Parser_Csv
171
+ */
172
+ public function unparse()
173
+ {
174
+ $batchExport = $this->getBatchExportModel()
175
+ ->setBatchId($this->getBatchModel()->getId());
176
+ $fieldList = $this->getBatchModel()->getFieldList();
177
+ $batchExportIds = $batchExport->getIdCollection();
178
+
179
+ if (!$batchExportIds) {
180
+ return $this;
181
+ }
182
+
183
+ $io = $this->getBatchModel()->getIoAdapter();
184
+ $io->open();
185
+
186
+ if ($this->getVar('fieldnames')) {
187
+ $csvData = $this->getCsvString($fieldList);
188
+ $io->write($csvData);
189
+ }
190
+
191
+ foreach ($batchExportIds as $batchExportId) {
192
+ $csvData = array();
193
+ $batchExport->load($batchExportId);
194
+ $row = $batchExport->getBatchData();
195
+
196
+ foreach ($fieldList as $field) {
197
+ $csvData[] = isset($row[$field]) ? $row[$field] : '';
198
+ }
199
+ $csvData = $this->getCsvString($csvData);
200
+ $io->write($csvData);
201
+ }
202
+
203
+ $io->close();
204
+
205
+ return $this;
206
+ }
207
+
208
+ public function unparseRow($args)
209
+ {
210
+ $i = $args['i'];
211
+ $row = $args['row'];
212
+
213
+
214
+ $fDel = Mage::getStoreConfig('salesperson/export_settings/delimiter');
215
+ if ($fDel == ''){
216
+ $fDel = $this->getVar('delimiter', '\t');
217
+ }
218
+ $fEnc = Mage::getStoreConfig('salesperson/export_settings/enclosed_values');
219
+ // if ($fEnc == ''){
220
+ //$fEnc = $this->getVar('enclose', '');
221
+ // }
222
+ $fEsc = $this->getVar('escape', '\\');
223
+ $lDel = "\r\n";
224
+
225
+ if ($fDel == '\t') {
226
+ $fDel = "\t";
227
+ }
228
+
229
+ $line = array();
230
+ foreach ($this->_fields as $f) {
231
+ $v = isset($row[$f]) ? str_replace(array('"', '\\'), array($fEnc.'"', $fEsc.'\\'), $row[$f]) : '';
232
+ $line[] = $fEnc.$v.$fEnc;
233
+ }
234
+
235
+ return join($fDel, $line);
236
+ }
237
+
238
+ /**
239
+ * Retrieve csv string from array
240
+ *
241
+ * @param array $fields
242
+ * @return sting
243
+ */
244
+ public function getCsvString($fields = array()) {
245
+ $delimiter = Mage::getStoreConfig('salesperson/export_settings/delimiter');
246
+ if ($delimiter == ''){
247
+ $delimiter = $this->getVar('delimiter', '\t');
248
+ }
249
+ $enclosure = Mage::getStoreConfig('salesperson/export_settings/enclosed_values');//$this->getVar('enclose', '');
250
+ $escapeChar = $this->getVar('escape', '\\');
251
+
252
+ if ($delimiter == '\t') {
253
+ $delimiter = "\t";
254
+ }
255
+
256
+ $str = '';
257
+
258
+ foreach ($fields as $value) {
259
+ if (strpos($value, $delimiter) !== false ||
260
+ empty($enclosure) ||
261
+ strpos($value, $enclosure) !== false ||
262
+ strpos($value, "\n") !== false ||
263
+ strpos($value, "\r") !== false ||
264
+ strpos($value, "\t") !== false ||
265
+ strpos($value, ' ') !== false) {
266
+ $str2 = $enclosure;
267
+ $escaped = 0;
268
+ $len = strlen($value);
269
+ for ($i=0;$i<$len;$i++) {
270
+ if ($value[$i] == $escapeChar) {
271
+ $escaped = 1;
272
+ } else if (!$escaped && $value[$i] == $enclosure) {
273
+ $str2 .= $enclosure;
274
+ } else {
275
+ $escaped = 0;
276
+ }
277
+ $str2 .= $value[$i];
278
+ }
279
+ $str2 .= $enclosure;
280
+ $str .= $str2.$delimiter;
281
+ } else {
282
+ $str .= $enclosure.$value.$enclosure.$delimiter;
283
+ }
284
+ }
285
+ return substr($str, 0, -1) . "\n";
286
+ }
287
+ }
app/code/local/Celebros/Salesperson/Model/Convert/Parser/Product.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Convert_Parser_Product
11
+ extends Mage_Catalog_Model_Convert_Parser_Product
12
+ {
13
+ protected $_store;
14
+ protected $_storeId;
15
+
16
+ public function getStore()
17
+ {
18
+ if (is_null($this->_store)) {
19
+ try {
20
+ $store = Mage::app()->getStore(Mage::getStoreConfig('salesperson/export_settings/store_id'));
21
+ }
22
+ catch (Exception $e) {
23
+ $this->addException(Mage::helper('catalog')->__('Invalid store specified please check the configuration'), Varien_Convert_Exception::FATAL);
24
+ throw $e;
25
+ }
26
+ $this->_store = $store;
27
+ }
28
+ return $this->_store;
29
+ }
30
+
31
+ public function getStoreId()
32
+ {
33
+ if (is_null($this->_storeId)) {
34
+ $this->_storeId = $this->getStore()->getId();
35
+ }
36
+ return $this->_storeId;
37
+ }
38
+ /**
39
+ * Unparse (prepare data) loaded products
40
+ *
41
+ * @return Mage_Catalog_Model_Convert_Parser_Product
42
+ */
43
+ public function unparse()
44
+ {
45
+ $entityIds = $this->getData();
46
+
47
+ foreach ($entityIds as $i => $entityId) {
48
+
49
+ $allproduct = $this->getProductModel()
50
+ ->setData(array())
51
+ ->load($entityId);
52
+
53
+ $product = $this->getProductModel()
54
+ ->reset()
55
+ ->setStoreId($this->getStoreId())
56
+ ->load($entityId);
57
+ $this->setProductTypeInstance($product);
58
+
59
+ /* Get Product Rating and Calculate Avrage */
60
+
61
+ $ratingResourceModel = new Celebros_Salesperson_Model_Mysql4_Qwiser();
62
+ $ratingPercents = $ratingResourceModel->getRateingByEntityId($product->getEntityId());
63
+
64
+ $productRating = 0;
65
+ foreach ($ratingPercents as $rating){
66
+ $productRating += (int)$rating['percent'];
67
+ }
68
+ if ($productRating != 0){
69
+ $productRating /= count($ratingPercents);
70
+ }
71
+
72
+ if (preg_match("/Search/",$product->getAttributeText('visibility'))) {
73
+ $this->setProductTypeInstance($product);
74
+ /* @var $product Mage_Catalog_Model_Product */
75
+
76
+ $position = Mage::helper('catalog')->__('Line %d, SKU: %s', ($i+1), $product->getSku());
77
+ $this->setPosition($position);
78
+
79
+ $row = array(
80
+ 'store' => $this->getStore()->getCode(),
81
+ 'websites' => '',
82
+ 'attribute_set' => $this->getAttributeSetName($product->getEntityTypeId(), $product->getAttributeSetId()),
83
+ 'type' => $product->getTypeId(),
84
+ 'category' => '',
85
+ 'status' => '',
86
+ 'rating' => $productRating,
87
+ 'id' => $product->getId(),
88
+ 'price' => ''
89
+ );
90
+
91
+ /*product status*/
92
+ $productStatus = $product->getData('status');
93
+
94
+ /*categories names */
95
+
96
+ $categoryNames = array();
97
+ foreach ($product->getCategoryIds() as $categoryId){
98
+ $categoryName = Mage::getModel('catalog/category')->load($categoryId)->getName();
99
+ $categoryNames[$categoryName] = $categoryName;
100
+ }
101
+ $row['category'] = join(',', $categoryNames);
102
+
103
+ /*websites codes*/
104
+ if ($this->getStore()->getCode() == Mage_Core_Model_Store::ADMIN_CODE) {
105
+ $websiteCodes = array();
106
+ foreach ($product->getWebsiteIds() as $websiteId) {
107
+ $websiteCode = Mage::app()->getWebsite($websiteId)->getCode();
108
+ $websiteCodes[$websiteCode] = $websiteCode;
109
+ }
110
+ $row['websites'] = join(',', $websiteCodes);
111
+ }
112
+ else {
113
+ $row['websites'] = $this->getStore()->getWebsite()->getCode();
114
+ if ($this->getVar('url_field')) {
115
+ $row['url'] = $product->getProductUrl(false);
116
+ }
117
+ }
118
+
119
+ if($product->getData('type_id') == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE){
120
+ $resource = Mage::getSingleton('core/resource');
121
+ $DB = $resource->getConnection('catalog_read');
122
+ $prefix = Mage::getConfig()->getNode('global/resources/db/table_prefix');
123
+ $sql = "SELECT * FROM ".$prefix."catalog_product_index_price WHERE `entity_id` ='".$product->getId()."' GROUP BY `entity_id`";
124
+ $result = $DB->fetchAll($sql);
125
+ $row['price'] = $result[0]['min_price'];
126
+ }else{
127
+ $row['price'] = $product->getFinalPrice();
128
+ }
129
+
130
+ foreach ($product->getData() as $field => $value) {
131
+ if (in_array($field, $this->_systemFields) || is_object($value)) {
132
+ continue;
133
+ }
134
+ $attribute = $this->getAttribute($field);
135
+ if (!$attribute) {
136
+ continue;
137
+ }
138
+
139
+ if ($attribute->usesSource()) {
140
+ $option = $attribute->getSource()->getOptionText($value);
141
+ if ($value && empty($option)) {
142
+ $message = Mage::helper('catalog')->__("Invalid option id specified for %s (%s), skipping the record", $field, $value);
143
+ $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);
144
+ continue;
145
+ }
146
+ if (is_array($option)) {
147
+ $value = join(self::MULTI_DELIMITER, $option);
148
+ } else {
149
+ $value = $option;
150
+ }
151
+ unset($option);
152
+ }
153
+ elseif (is_array($value)) {
154
+ continue;
155
+ }
156
+
157
+ $row[$field] = $value;
158
+ }
159
+
160
+ /* Check if there is an Indexable Attribute that is not selected and add it to the array*/
161
+
162
+ $attributes = $product->getAttributes();
163
+ foreach ($attributes as $attribute){
164
+ if($attribute->getIsFilterable()){
165
+ if (key_exists($attribute->getData('attribute_code'), $row)){
166
+ $row[$attribute->getData('attribute_code')] = $row[$attribute->getData('attribute_code')].'{{is_filterable}}';
167
+ }
168
+ }
169
+ if($attribute->getIsSearchable()){
170
+ if (key_exists($attribute->getData('attribute_code'), $row)){
171
+ $row[$attribute->getData('attribute_code')] = $row[$attribute->getData('attribute_code')].'{{is_searchable}}';
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+
178
+ if ($stockItem = $product->getStockItem()) {
179
+ foreach ($stockItem->getData() as $field => $value) {
180
+ if (in_array($field, $this->_systemFields) || is_object($value)) {
181
+ continue;
182
+ }
183
+ $row[$field] = $value;
184
+ }
185
+ }
186
+
187
+ foreach ($this->_imageFields as $field) {
188
+ if (isset($row[$field]) && $row[$field] == 'no_selection') {
189
+ $row[$field] = null;
190
+ }
191
+ }
192
+
193
+ /* EXPORTS TIER PRICING */
194
+ #$_tierPrices = Mage::getModel('bundle/product_price')->getTierPrice("",$product);
195
+ #print_r($product->getTierPrice());
196
+ $row['tier_prices'] = "";
197
+ #$incoming_tierps = $product->getTierPrice();
198
+ $incoming_tierps = $product->getData('tier_price');
199
+ #print_r($incoming_tierps);
200
+ if(is_array($incoming_tierps)) {
201
+ foreach($incoming_tierps as $tier_str){
202
+ #print_r($tier_str);
203
+ $row['tier_prices'] .= $tier_str['cust_group'] . "=" . round($tier_str['price_qty']) . "=" . $tier_str['price'] . "|";
204
+ }
205
+ }
206
+
207
+ $batchExport = $this->getBatchExportModel()
208
+ ->setId(null)
209
+ ->setBatchId($this->getBatchModel()->getId())
210
+ ->setBatchData($row)
211
+ ->setStatus(1)
212
+ ->save();
213
+ }
214
+ }
215
+
216
+ return $this;
217
+ }
218
+ }
app/code/local/Celebros/Salesperson/Model/Layer.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Layer extends Mage_Catalog_Model_Layer
11
+ {
12
+ /**
13
+ * Get layer state key
14
+ *
15
+ * @return string
16
+ */
17
+ public function getStateKey()
18
+ {
19
+ if ($this->_stateKey === null) {
20
+ $this->_stateKey = 'STORE_'.Mage::app()->getStore()->getId()
21
+ . '_CUSTGROUP_' . Mage::getSingleton('customer/session')->getCustomerGroupId();
22
+ }
23
+
24
+ return $this->_stateKey;
25
+ }
26
+
27
+ /**
28
+ * Apply layer
29
+ * Method is colling after apply all filters, can be used
30
+ * for prepare some index data before getting information
31
+ * about existing intexes
32
+ *
33
+ * @return Mage_Catalog_Model_Layer
34
+ */
35
+ public function apply()
36
+ {
37
+ $stateSuffix = '';
38
+ foreach ($this->getState()->getFilters() as $filterItem) {
39
+ $stateSuffix.= '_'.$filterItem['questionId']
40
+ . '=' . $filterItem['answers']->Items[0]->Id;
41
+ }
42
+ if (!empty($stateSuffix)) {
43
+ $this->_stateKey = $this->getStateKey().$stateSuffix;
44
+ }
45
+ return $this;
46
+ }
47
+
48
+ /**
49
+ * Retrieve layer state object
50
+ *
51
+ * @return Mage_Catalog_Model_Layer_State
52
+ */
53
+ public function getState()
54
+ {
55
+ $state = $this->getData('state');
56
+ if (is_null($state)) {
57
+ Varien_Profiler::start(__METHOD__);
58
+ $state = Mage::getModel('salesperson/layer_state');
59
+ $this->setData('state', $state);
60
+ Varien_Profiler::stop(__METHOD__);
61
+ }
62
+ return $state;
63
+ }
64
+
65
+ }
app/code/local/Celebros/Salesperson/Model/Layer/State.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Layer_State extends Varien_Object
11
+ {
12
+ /**
13
+ * Add filter item to layer state
14
+ *
15
+ * @param Mage_Catalog_Model_Layer_Filter_Item $filter
16
+ * @return Mage_Catalog_Model_Layer_State
17
+ */
18
+ public function addFilter($filter)
19
+ {
20
+ $filters = $this->getFilters();
21
+ $filters[] = $filter;
22
+ $this->setFilters($filters);
23
+ return $this;
24
+ }
25
+
26
+ public function removeFilter($answerId){
27
+ $filters = array();
28
+ foreach($this->getFilters() as $filter){
29
+ if($filter['answers']->Items[0]->Id == $answerId){
30
+ continue;
31
+ }
32
+ $filters[] = $filter;
33
+ }
34
+ $this->setFilters($filters);
35
+ }
36
+
37
+ /**
38
+ * Set layer state filter items
39
+ *
40
+ * @param array $filters
41
+ * @return Mage_Catalog_Model_Layer_State
42
+ */
43
+ public function setFilters($filters)
44
+ {
45
+ if (!is_array($filters)) {
46
+ Mage::throwException(Mage::helper('salesperson')->__('Filters must be as array'));
47
+ }
48
+ $this->setData('filters', $filters);
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ * Get applied to layer filter items
54
+ *
55
+ * @return array
56
+ */
57
+ public function getFilters()
58
+ {
59
+ $filters = $this->getData('filters');
60
+ if (is_null($filters)) {
61
+ $filters = array();
62
+ $this->setData('filters', $filters);
63
+ }
64
+ return $filters;
65
+ }
66
+ }
app/code/local/Celebros/Salesperson/Model/Layout.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Core
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Layout model
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Core
33
+ */
34
+ class Celebros_Salesperson_Model_Layout extends Mage_Core_Model_Layout
35
+ {
36
+
37
+ /**
38
+ * Enter description here...
39
+ *
40
+ * @param Varien_Simplexml_Element $node
41
+ * @param Varien_Simplexml_Element $parent
42
+ * @return Mage_Core_Model_Layout
43
+ */
44
+ protected function _generateAction($node, $parent)
45
+ {
46
+ if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
47
+ if (!Mage::getStoreConfigFlag($configPath)) {
48
+ return $this;
49
+ }
50
+ }
51
+
52
+ //
53
+
54
+ if (isset($node['ifright']) && ($configPath = (string)$node['ifright'])) {
55
+ if (Mage::getStoreConfig($configPath) != 'right') {
56
+ return $this;
57
+ }
58
+ }
59
+ if (isset($node['ifleft']) && ($configPath = (string)$node['ifleft'])) {
60
+ if (Mage::getStoreConfig($configPath) != 'left') {
61
+ return $this;
62
+ }
63
+ }
64
+ if (isset($node['iftop']) && ($configPath = (string)$node['iftop'])) {
65
+ if (Mage::getStoreConfig($configPath) != 'top') {
66
+ return $this;
67
+ }
68
+ }
69
+
70
+ //
71
+
72
+ $method = (string)$node['method'];
73
+ if (!empty($node['block'])) {
74
+ $parentName = (string)$node['block'];
75
+ } else {
76
+ $parentName = $parent->getBlockName();
77
+ }
78
+
79
+ $_profilerKey = 'BLOCK ACTION: '.$parentName.' -> '.$method;
80
+ Varien_Profiler::start($_profilerKey);
81
+
82
+ if (!empty($parentName)) {
83
+ $block = $this->getBlock($parentName);
84
+ }
85
+ if (!empty($block)) {
86
+
87
+ $args = (array)$node->children();
88
+ unset($args['@attributes']);
89
+
90
+ foreach ($args as $key => $arg) {
91
+ if (($arg instanceof Mage_Core_Model_Layout_Element)) {
92
+ if (isset($arg['helper'])) {
93
+ $helperName = explode('/', (string)$arg['helper']);
94
+ $helperMethod = array_pop($helperName);
95
+ $helperName = implode('/', $helperName);
96
+ $arg = $arg->asArray();
97
+ unset($arg['@']);
98
+ $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg);
99
+ } else {
100
+ /**
101
+ * if there is no helper we hope that this is assoc array
102
+ */
103
+ $arr = array();
104
+ foreach($arg as $subkey => $value) {
105
+ $arr[(string)$subkey] = $value->asArray();
106
+ }
107
+ if (!empty($arr)) {
108
+ $args[$key] = $arr;
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ if (isset($node['json'])) {
115
+ $json = explode(' ', (string)$node['json']);
116
+ foreach ($json as $arg) {
117
+ $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]);
118
+ }
119
+ }
120
+
121
+ $this->_translateLayoutNode($node, $args);
122
+ call_user_func_array(array($block, $method), $args);
123
+ }
124
+
125
+ Varien_Profiler::stop($_profilerKey);
126
+
127
+ return $this;
128
+ }
129
+ }
app/code/local/Celebros/Salesperson/Model/Mapping.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Celebros_Salesperson_Model_Mapping extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_fieldsArray;
6
+
7
+ protected function _construct()
8
+ {
9
+ $this->_init('salesperson/mapping');
10
+ }
11
+
12
+ protected function _loadFieldsArray(){
13
+ $fieldsCollection = Mage::getSingleton("salesperson/mapping")->getCollection();
14
+ $this->_fieldsArray = array();
15
+ foreach($fieldsCollection as $field){
16
+ $this->_fieldsArray[$field->getCodeField()] = $field->getXmlField();
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Get Fields Array
22
+ *
23
+ * @return array
24
+ */
25
+ public function getFieldsArray(){
26
+ if(!$this->_fieldsArray){
27
+ $this->_loadFieldsArray();
28
+ }
29
+ return $this->_fieldsArray;
30
+ }
31
+
32
+ }
app/code/local/Celebros/Salesperson/Model/Mysql4/Mapping.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ class Celebros_Salesperson_Model_Mysql4_Mapping extends Mage_Core_Model_Mysql4_Abstract{
3
+ protected function _construct()
4
+ {
5
+ $this->_init('salesperson/mapping', 'id');
6
+ }
7
+ }
app/code/local/Celebros/Salesperson/Model/Mysql4/Mapping/Collection.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Celebros_Salesperson_Model_Mysql4_Mapping_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
3
+ protected function _construct()
4
+ {
5
+ $this->_init('salesperson/mapping');
6
+ $this->setOrder('xml_field', Varien_Data_Collection::SORT_ORDER_ASC);
7
+ }
8
+ }
app/code/local/Celebros/Salesperson/Model/Mysql4/Qwiser.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Mysql4_Qwiser extends Mage_Core_Model_Mysql4_Abstract
11
+ {
12
+
13
+ public function _construct()
14
+ {
15
+ $this->_init('rating/rating', 'rating_id');
16
+ }
17
+
18
+ /**
19
+ * Get rating entity type id by code
20
+ *
21
+ * @param string $entityCode
22
+ * @return int
23
+ */
24
+ public function getRateingByEntityId($entityId)
25
+ {
26
+ $select = $this->_getReadAdapter()->select()
27
+ ->from( $this->getTable('rating_vote'), array('percent'))
28
+ ->where('entity_pk_value = ?', $entityId);
29
+ return $this->_getReadAdapter()->fetchAll($select);
30
+ }
31
+ }
app/code/local/Celebros/Salesperson/Model/Observer.php ADDED
@@ -0,0 +1,1065 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ //include_once("createZip.php");
11
+ class Celebros_Salesperson_Model_Observer
12
+ {
13
+ protected $_errors = array();
14
+ protected $_config;
15
+ protected $_conn;
16
+ protected $_read;
17
+ protected $_fDel;
18
+ protected $_fEnclose;
19
+ protected $_fPath;
20
+ protected $_fType;
21
+ protected $_fStore_id;
22
+ protected $_fStore_module_enabled;
23
+ protected $_fProducts_Collection;
24
+ protected $_fProduct_Category_Matrix;
25
+ protected $_fSize;
26
+ protected $_updateStock;
27
+ protected $_flushRecordsCount = 500;
28
+ protected $_fileNameTxt = "products.txt";
29
+ protected $_fileNameZip = "products.zip";
30
+ protected $_getChildrenOfGroupProducts = true;
31
+
32
+
33
+ public function __construct(){
34
+ }
35
+
36
+ /**
37
+ * Retrieve salesperson session
38
+ *
39
+ * @return Mage_Catalog_Model_Session
40
+ */
41
+ protected function _getSession()
42
+ {
43
+ return Mage::getSingleton('salesperson/session');
44
+ }
45
+
46
+ protected function _getAnlxConfig($path){
47
+ return Mage::getStoreConfig('salesperson/anlx_settings/'.$path);
48
+ }
49
+ /**
50
+ * Daily update catalog to salesperson server by cron
51
+ * This method is called from cron process, cron is workink in UTC time and
52
+ *
53
+ * @param Varien_Event_Observer $observer
54
+ * @return Celebros_Salesperson_Model_Observer
55
+ */
56
+ public function catalogUpdate($observer)
57
+ {
58
+ $enabled = Mage::getStoreConfigFlag('salesperson/export_settings/cron_enabled');
59
+ /*$profileId = Mage::getStoreConfig('salesperson/export_settings/profile_id');*/
60
+ if($enabled){
61
+ /*if($profileId == ''){
62
+ Mage::throwException('No profile id specified');
63
+ }
64
+ try {
65
+ $profile = Mage::getModel('dataflow/profile');
66
+ $userModel = Mage::getModel('admin/user');
67
+ $userModel->setUserId(0); // or whatever else
68
+ Mage::getSingleton('admin/session')->setUser($userModel);
69
+
70
+ $profile->load($profileId);
71
+ if (!$profile->getId()) {
72
+ Mage::getSingleton('adminhtml/session')->addError('ERROR: Incorrect profile id');
73
+ }
74
+
75
+ Mage::unregister('current_convert_profile');
76
+ Mage::register('current_convert_profile', $profile);
77
+ $profile->run();
78
+
79
+ $batchModel = Mage::getSingleton('dataflow/batch');
80
+ if ($batchModel->getId()) {
81
+ if ($batchModel->getAdapter()) {
82
+ $batchId = $batchModel->getId();
83
+ $batchExportModel = $batchModel->getBatchExportModel();
84
+ $exportIds = $batchExportModel->getIdCollection();
85
+
86
+ }
87
+ else {
88
+ $batchModel->delete();
89
+ }
90
+ }
91
+ }
92
+ catch (Exception $e) {
93
+ return var_dump($e);
94
+ }*/
95
+ //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl().'../salesperson/export/export_celebros');
96
+ $this->export_celebros();
97
+
98
+
99
+ }
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * Update stock after product update in the backend
105
+ *
106
+ * @param Varien_Event_Observer $observer
107
+ */
108
+ public function updateStockConfig($observer){
109
+ if($this->_updateStock==1)
110
+ {
111
+ $event = $observer->getEvent();
112
+ $product = $event->getProduct();
113
+ $Stock =$product->getData('stock_data');
114
+ if(isset($Stock['is_in_stock']))
115
+ $isInStock=$Stock['is_in_stock'];
116
+ else
117
+ $isInStock=0;
118
+ $sku = $product->getSku();
119
+ if ((int)$isInStock == 0){
120
+ Mage::helper('salesperson')->getSalespersonApi()->RemoveProductFromStock($sku);
121
+ }
122
+ else {
123
+ Mage::helper('salesperson')->getSalespersonApi()->RestoreProductToStock($sku);
124
+ }
125
+ }
126
+ }
127
+
128
+
129
+ /**
130
+ * Update stock after order checkout process in the front-end
131
+ *
132
+ * @param Varien_Event_Observer $observer $observer
133
+ */
134
+ public function updateStockOrder($observer){
135
+ if($this->_updateStock==1)
136
+ {
137
+ $event = $observer->getEvent();
138
+ $order = $event->getOrder();
139
+ $productModel = Mage::getSingleton('catalog/product');
140
+ $itemModel = Mage::getSingleton('cataloginventory/stock_item');
141
+ foreach ($order->getAllItems() as $item){
142
+ $product_info = $item->getProductOptions();
143
+ $product_id = $product_info['info_buyRequest']['product'];
144
+ $product = $productModel->load($product_id);
145
+ $inventoery = $itemModel->loadByProduct($product);
146
+ $isInStock = $inventoery->getData('is_in_stock');
147
+ $sku = $product->getSku();
148
+ if ((int)$isInStock == 0){
149
+ Mage::helper('salesperson')->getSalespersonApi()->RemoveProductFromStock($sku);
150
+ }
151
+ else {
152
+ Mage::helper('salesperson')->getSalespersonApi()->RestoreProductToStock($sku);
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Product page Anlx function
160
+ *
161
+ * @param array $observer
162
+ */
163
+ public function sendProductAnlxInfo($product/*$observer*/){
164
+ //$product = $observer->getEvent()->getProduct();
165
+ $protocol = Mage::getStoreConfigFlag('salesperson/anlx_settings/protocol_connection') ? 'https://': 'http://';
166
+ $uri = $protocol . $this->_getAnlxConfig('ai_writer_address') . '/AIWriter/WriteLog.ashx';
167
+ if (!isset($_SESSION['core']['last_url']) && !key_exists('HTTP_REFERER',$_SERVER)){
168
+ return;
169
+ }
170
+ /**
171
+ * blank config treat
172
+ *
173
+ * @author Sveta Oksen
174
+ * @since 31/03/2011
175
+ */
176
+ if($this->_getAnlxConfig('ai_writer_address') == ""){
177
+ return;
178
+ }
179
+ $ssid = $this->_getSession()->getSearchSessionId();
180
+ $params = array(
181
+ 'type' => 'PD',
182
+ 'cid' => $this->_getAnlxConfig('cid'),
183
+ 'src' => isset($_SESSION['core']['last_url']) ? $_SESSION['core']['last_url'] : $_SERVER['HTTP_REFERER'],
184
+ 'ref' => Mage::getModel('core/url')->getBaseUrl() . $_SERVER['PHP_SELF'],
185
+ 'ssid' => $ssid ? $ssid : 'none',
186
+ 'wsid' => isset($_SESSION['core']['visitor_data']['session_id']) ? $_SESSION['core']['visitor_data']['session_id'] : session_id(),
187
+ 'sku' => $product->getSku(),
188
+ 'name' => $product->getName(),
189
+ 'price' => $product->getFinalPrice()
190
+ );
191
+ if ($product->getCategory() != null){
192
+ $params['category'] = $product->getCategory()->getName();
193
+ }
194
+ if ($this->_getAnlxConfig('dc') != ''){
195
+ $params['dc'] = $this->_getAnlxConfig('dc');
196
+ }
197
+ foreach ($params as $key=>$value){
198
+ $requestData[] = strtolower($key) . '=' . urlencode($value);
199
+ }
200
+ $requestData = implode('&', $requestData);
201
+ $uri = $uri. '?' . $requestData;
202
+ try {
203
+ if( function_exists( "curl_init" )) {
204
+ $curl = curl_init();
205
+ curl_setopt($curl, CURLOPT_URL, $uri);
206
+ curl_setopt($curl, CURLOPT_FAILONERROR, true);
207
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
208
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
209
+ curl_setopt($curl, CURLOPT_TIMEOUT,1);
210
+ $curlResult = curl_exec($curl);
211
+ $curlError = curl_error($curl);
212
+ $curlInfo = curl_getinfo($curl);
213
+ curl_close($curl);
214
+ if(!empty($curlError)) {
215
+ Mage::throwException('Celebros Analytics: ' . $curlError .' Request Url: ' . $uri);
216
+ }
217
+ }
218
+ }
219
+ catch (Exception $e) {
220
+ Mage::logException($e);
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Result page Anlx function
226
+ *
227
+ * @param array $observer
228
+ */
229
+ public function sendResultAnlxInfo($observer){
230
+ $protocol = Mage::getStoreConfigFlag('salesperson/anlx_settings/protocol_connection') ? 'https://': 'http://';
231
+ $uri = $protocol . $this->_getAnlxConfig('ai_writer_address') . '/AIWriter/WriteLog.ashx';
232
+ if (!isset($_SESSION['core']['last_url']) && !key_exists('HTTP_REFERER',$_SERVER)){
233
+ return;
234
+ }
235
+ $ssid = $observer['ssid'];
236
+ $logHandle = $observer['logHandle'];
237
+ $params = array(
238
+ 'type' => 'SR',
239
+ 'cid' => $this->_getAnlxConfig('cid'),
240
+ 'src' => isset($_SESSION['core']['last_url']) ? $_SESSION['core']['last_url'] : $_SERVER['HTTP_REFERER'],
241
+ 'ref' => Mage::getModel('core/url')->getBaseUrl() . $_SERVER['PHP_SELF'],
242
+ 'ssid' => $ssid ? $ssid : 'none',
243
+ 'wsid' => isset($_SESSION['core']['visitor_data']['session_id']) ? $_SESSION['core']['visitor_data']['session_id'] : session_id(),
244
+ 'lh' => $logHandle
245
+ );
246
+ if ($this->_getAnlxConfig('dc') != ''){
247
+ $params['dc'] = $this->_getAnlxConfig('dc');
248
+ }
249
+ foreach ($params as $key=>$value){
250
+ $requestData[] = strtolower($key) . '=' . urlencode($value);
251
+ }
252
+ $requestData = implode('&', $requestData);
253
+ $uri = $uri. '?' . $requestData;
254
+
255
+ try {
256
+ if( function_exists( "curl_init" )) {
257
+ $curl = curl_init();
258
+ curl_setopt($curl, CURLOPT_URL, $uri);
259
+ curl_setopt($curl, CURLOPT_FAILONERROR, true);
260
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
261
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
262
+ $curlResult = curl_exec($curl);
263
+ $curlError = curl_error($curl);
264
+ $curlInfo = curl_getinfo($curl);
265
+ curl_close($curl);
266
+ if(!empty($curlError)) {
267
+ Mage::throwException('Celebros Analytics: ' . $curlError .' Request Url: ' . $uri);
268
+ }
269
+ }
270
+ }
271
+ catch (Exception $e) {
272
+ Mage::logException($e);
273
+ }
274
+ }
275
+
276
+ public function export_celebros()
277
+ {
278
+ $export_start = (float) array_sum(explode(' ',microtime()));
279
+ $this->comments_style('header',0,0);
280
+ $this->comments_style('icon','Starting profile execution, please wait...','start');
281
+ $this->comments_style('warning','Warning: Please don\'t close window during importing/exporting data','warning');
282
+ flush();
283
+
284
+ //-------------------
285
+ //get the configuration
286
+
287
+ //---------------------
288
+ //Connect to the database
289
+ $this->_read=Mage::getSingleton('core/resource')->getConnection('core_read');
290
+
291
+ //-----------------------------------------------------
292
+ //select the name of the categories
293
+
294
+ $this->_fProduct_Category_Matrix = array();
295
+ $product_category_ids = $this->_read->fetchAll('SELECT product_id, category_id FROM '.$this->getTableName("catalog_category_product")); //Added for multi store view purposes by Eli Sagy
296
+ foreach($product_category_ids as $product_category_id)
297
+ {
298
+ if (!isset($this->_fProduct_Category_Matrix[$product_category_id['product_id']])) $this->_fProduct_Category_Matrix[$product_category_id['product_id']] = array();
299
+
300
+ array_push($this->_fProduct_Category_Matrix[$product_category_id['product_id']], $product_category_id['category_id']);
301
+ }
302
+
303
+ unset($product_category_ids);
304
+
305
+ $store_view_ids = $this->_read->fetchAll('SELECT store_id FROM '.$this->getTableName("core_store") . ' WHERE store_id <> 0'); //Added for multi store view purposes by Eli Sagy
306
+
307
+ foreach($store_view_ids as $store_view_id)
308
+ {
309
+ $export_store_start = (float) array_sum(explode(' ',microtime()));
310
+ $this->export_config($store_view_id['store_id']);
311
+
312
+ $dir = true;
313
+
314
+ if($this->_fPath!='')
315
+ {
316
+ if (!is_dir($this->_fPath)) $dir=@mkdir($this->_fPath,0777,true);
317
+ if (file_exists($this->_fPath. "/" . $this->_fileNameTxt)) unlink($this->_fPath . "/" . $this->_fileNameTxt);
318
+ $fh = fopen($this->_fPath . "/" . $this->_fileNameTxt, 'a');
319
+ }
320
+
321
+ if(!$dir) {
322
+ $this->comments_style('error','Could not create the directory in that path','problemwith dir');
323
+ return;
324
+ }
325
+
326
+
327
+ if($this->_fStore_module_disabled) continue;
328
+
329
+ $nameCategory=array();
330
+ $result = $this->getCategoryCollection($store_view_id['store_id']);
331
+
332
+ foreach($result as $res)
333
+ {
334
+ $nameCategory[$res->getId()] = str_replace(",", "&", $res->getName());
335
+ /*$parentIds = $res->getParentIds();
336
+ for ($i = 1; $i < count($parentIds); $i++)
337
+ {
338
+ $parent = $result->getItemById($parentIds[$i]);
339
+ $nameCategory[$res->getId()] = $parent->getName().">".$nameCategory[$res->getId()];
340
+ }*/
341
+ $parentId = $res->getParentId();
342
+ while ($parentId)
343
+ {
344
+ $parent = $result->getItemById($parentId);
345
+ if ($parent != null && $parent->getName() != null) $nameCategory[$res->getId()] = $parent->getName().">".$nameCategory[$res->getId()];
346
+ else break;
347
+ $parentId = $parent->getParentId();
348
+ }
349
+ }
350
+
351
+ unset($result);
352
+
353
+ //------------------------------------------
354
+ $configurProdAttVal=array();
355
+ $sql='SELECT distinct cpsa.product_id, ea.attribute_code, eaov.value
356
+ FROM '.$this->getTableName("eav_attribute_option_value").' eaov
357
+ INNER JOIN '.$this->getTableName("catalog_product_entity_int").' cpei
358
+ ON eaov.option_id = cpei.value
359
+ INNER JOIN '.$this->getTableName("catalog_product_super_attribute").' cpsa
360
+ ON cpei.attribute_id = cpsa.attribute_id
361
+ INNER JOIN '.$this->getTableName("eav_attribute").' ea
362
+ ON cpsa.attribute_id = ea.attribute_id
363
+ WHERE cpsa.product_id
364
+ IN (
365
+ SELECT parent_id
366
+ FROM '.$this->getTableName("catalog_product_super_link").'
367
+ WHERE product_id = cpei.entity_id
368
+ )
369
+ AND cpsa.attribute_id
370
+ IN (
371
+
372
+ SELECT attribute_id
373
+ FROM '.$this->getTableName("catalog_eav_attribute").'
374
+ WHERE is_searchable =1
375
+ OR is_filterable
376
+ IN ( 1, 2 )
377
+ )';
378
+
379
+ $result=$this->_read->fetchAll($sql);
380
+ foreach($result as $res)
381
+ {
382
+ if(!isset($configurProdAttVal[$res["product_id"]][$res["attribute_code"]]))
383
+ $configurProdAttVal[$res["product_id"]][$res["attribute_code"]]=$res["value"];
384
+ else
385
+ {
386
+ $configurProdAttVal[$res["product_id"]][$res["attribute_code"]].=",".$res["value"];
387
+ }
388
+ }
389
+
390
+ unset($result);
391
+
392
+ //--------------------------------------------------
393
+
394
+ //select the name of the attributes
395
+ $this->select_attributes($attributes);
396
+
397
+ //------------------------------------------------------
398
+ $products_collection=array();
399
+ $removeProducts=array();
400
+ $cate=4;
401
+ $typ=9;
402
+ $chil=10;
403
+ $childrenName="";
404
+ $num=0;
405
+ $s="";
406
+
407
+ //print the header
408
+ $s=$this->header($attributes,$cate,$typ,$chil);
409
+
410
+ //Begin the output
411
+ $sql='select min(cpe.entity_id ) as min, max( cpe.entity_id ) as max
412
+ from '.$this->getTableName("catalog_product_entity").' cpe
413
+ where cpe.type_id = "configurable"';
414
+ $result=$this->_read->fetchAll($sql);
415
+ $min=$result[0]["min"];
416
+ if($min)
417
+ {
418
+ $count=$result[0]["max"]-$min+1;
419
+ $count=$count/$this->_flushRecordsCount;
420
+ if(!is_int($count))
421
+ $count=ceil($count);
422
+
423
+ //select the product with the attributes
424
+ //-----------------------------
425
+ while($count>0)
426
+ {
427
+ $max=$min + $this->_flushRecordsCount -1;
428
+ $select='$products_collection=Mage::getModel("catalog/product")->setStoreId($this->_fStore_id)->getCollection()->addStoreFilter($this->_fStore_id)';
429
+ foreach($attributes as $key=>$value)
430
+ $select.='->addAttributeToSelect("'.$key.'")';
431
+ $select.='->addAttributeToSelect("type_id")
432
+ ->addAttributeToFilter("type_id","configurable")
433
+ ->addAttributeToFilter("visibility",array("neq"=>1))
434
+ ->addAttributeToFilter("status",array("neq"=>2))
435
+ ->addFieldToFilter("entity_id",array("from"=>'.$min.',"to"=>'.$max.'));';
436
+ eval($select);
437
+ $min=$max+1;
438
+ $count--;
439
+ //print the content
440
+ $num+=count($products_collection);
441
+ foreach($products_collection as $product)
442
+ {
443
+ $id=$product->getentity_id();
444
+ $sql='SELECT sku AS id FROM '.$this->getTableName("catalog_product_super_link").' INNER JOIN '.$this->getTableName("catalog_product_entity").' ON product_id = entity_id WHERE parent_id = '.$id;
445
+ $childProducts=$this->_read->fetchAll($sql);
446
+ foreach($childProducts as $child)
447
+ {
448
+ $childrenName.=$child["id"].',';
449
+ if(!in_array($child["id"],$removeProducts))
450
+ $removeProducts[]=$child["id"].',';
451
+ }
452
+ if($childrenName!="")
453
+ $childrenName=substr_replace($childrenName,"",strlen($childrenName)-1);
454
+ if(isset($configurProdAttVal[$id])){
455
+ $s.=str_replace("\r\n", " ", $this->content($product,$attributes,$cate,$typ,$chil,1,$configurProdAttVal[$id],$nameCategory,$childrenName));
456
+ }else{
457
+ $s.=str_replace("\r\n", " ", $this->content($product,$attributes,$cate,$typ,$chil,1,array(),$nameCategory,$childrenName));
458
+ }
459
+ $s.="\r\n";
460
+ $childrenName="";
461
+ }
462
+
463
+ //Flushing and cleaning
464
+ unset($products_collection);
465
+ fwrite($fh, $s);
466
+ unset($s);
467
+ $s = "";
468
+ }
469
+ }
470
+
471
+ //-------------------------------------------------------------------------------------------
472
+ $sql='SELECT min( cpe.entity_id ) AS min, max( cpe.entity_id ) AS max
473
+ FROM '.$this->getTableName("catalog_product_entity").' cpe
474
+ WHERE cpe.type_id <> "configurable"';
475
+ //AND cpev.store_id ='.$this->_fStore_id;/*Added for multi store view purposes by Eli Sagy*/
476
+ $result=$this->_read->fetchAll($sql);
477
+ $min=$result[0]["min"];
478
+ if($min)
479
+ {
480
+ $count=$result[0]["max"]-$min+1;
481
+ $count=$count/$this->_flushRecordsCount;
482
+ if(!is_int($count))
483
+ $count=ceil($count);
484
+ while($count>0)
485
+ {
486
+ $max=$min + $this->_flushRecordsCount - 1;
487
+ $select='$products_collection=Mage::getModel("catalog/product")->setStoreId($this->_fStore_id)->getCollection()->addStoreFilter($this->_fStore_id)';
488
+ foreach($attributes as $key=>$value)
489
+ $select.='->addAttributeToSelect("'.$key.'")';
490
+ $select.='->addAttributeToSelect("type_id")
491
+ ->addAttributeToFilter("type_id",array("neq"=>"configurable"))
492
+ ->addAttributeToFilter("visibility",array("neq"=>1))
493
+ ->addAttributeToFilter("status",array("neq"=>2))
494
+ ->addFieldToFilter("entity_id",array("from"=>'.$min.',"to"=>'.$max.'));';
495
+
496
+ eval($select);
497
+ $min=$max+1;
498
+ $count--;
499
+ //print the content
500
+ $num+=count($products_collection);
501
+
502
+ foreach($products_collection as $product)
503
+ {
504
+ $flg=0;
505
+ if($product->gettype_id()=="simple")
506
+ {
507
+ foreach($removeProducts as $removeProduct)
508
+ {
509
+ if($removeProduct===$product->getentity_id().",")
510
+ {
511
+ $flg=1;
512
+ $num--;
513
+ break;
514
+ }
515
+ }
516
+ }
517
+ if($flg===0)
518
+ {
519
+ $id=$product->getentity_id();
520
+ if($product->gettype_id()=="grouped" && $this->_getChildrenOfGroupProducts)
521
+ {
522
+ $sql='SELECT sku AS id FROM '.$this->getTableName("catalog_product_link").' INNER JOIN '.$this->getTableName("catalog_product_entity").' ON linked_product_id = entity_id WHERE link_type_id = 3 AND product_id = '.$id;
523
+ $childProducts=$this->_read->fetchAll($sql);
524
+ foreach($childProducts as $child)
525
+ {
526
+ $childrenName.=$child["id"].',';
527
+ }
528
+ if($childrenName!="")
529
+ $childrenName=substr_replace($childrenName,"",strlen($childrenName)-1);
530
+ }
531
+ $s.=str_replace("\r\n", " ", $this->content($product,$attributes,$cate,$typ,$chil,0,array(),$nameCategory,$childrenName));
532
+ $s.="\r\n";
533
+ }
534
+ $childrenName="";
535
+ }
536
+
537
+ //Flushing and cleaning
538
+ unset($products_collection);
539
+ fwrite($fh, $s);
540
+ unset($s);
541
+ $s = "";
542
+ }
543
+ }
544
+
545
+ fclose($fh);
546
+ unset($fh);
547
+
548
+ $export_store_end = (float) array_sum(explode(' ',microtime()));
549
+
550
+ $this->comments_style('success','Loaded '.$num.' records within ' . round($export_store_end - $export_store_start, 3) . ' sec','load');
551
+
552
+ $this->comments_style('success','Saved successfully: ' . $this->_fileNameTxt . ' '.$this->_fSize.' byte(s)','save');
553
+
554
+ $this->zipFile();
555
+
556
+ //-------------------------------
557
+ //export
558
+
559
+ if($this->_fType==="ftp")
560
+ {
561
+ $ftpRes = $this->ftpfile();
562
+ if(!$ftpRes) $this->comments_style('error','Could not upload to ftp','Could_not_upload_to_ftp');
563
+ }
564
+
565
+ }
566
+
567
+ $export_end = (float) array_sum(explode(' ',microtime()));
568
+
569
+ $this->comments_style('icon','Finished profile execution within ' . round($export_end - $export_start, 3) . ' sec.','finish');
570
+ $this->comments_style('finish',0,0);
571
+ }
572
+ //*********************************************************************************************************
573
+ //*********************************************************************************************************
574
+ //*********************************************************************************************************
575
+ //*********************************************************************************************************
576
+ //*************************************************function************************************************
577
+ public function select_attributes(&$attributes)
578
+ {
579
+ //select requied attributes
580
+ $attributesreq=array('name'=>array('text',1),'url_key'=>array('text',2),
581
+ 'image'=>array('media_image',3),'description'=>array('textarea',5),'short_description'=>array('textarea',6),'status'=>array('select',7)
582
+ ,'visibility'=>array('select',8));
583
+ $i=count($attributesreq)+4;//entity_id,category_ides,type_id,childrenName
584
+ //select entity_type_code=catalog product
585
+ $sql='select entity_type_id
586
+ from '.$this->getTableName("eav_entity_type").'
587
+ where entity_type_code = "catalog_product"';
588
+
589
+ $result=$this->_read->fetchAll($sql);
590
+ $entity_type_id=$result[0]["entity_type_id"];
591
+ //select attribute with type=price
592
+ $sql='SELECT ea.attribute_id, attribute_code, frontend_input
593
+ FROM '.$this->getTableName("eav_attribute").' ea
594
+ WHERE (
595
+ ea.entity_type_id ='.$entity_type_id.'
596
+ )
597
+ AND ea.frontend_input = "price"';
598
+
599
+ $attributesInfo=$this->_read->fetchAll($sql);
600
+ foreach($attributesInfo as $attribute)
601
+ {
602
+ $attributesreq[$attribute["attribute_code"]]=array("price",$i);
603
+ $i++;
604
+ }
605
+ //select searchable or filterable attribute
606
+ $sql='SELECT ea.attribute_id, attribute_code, frontend_input
607
+ FROM '.$this->getTableName("eav_attribute").' ea
608
+ INNER JOIN '.$this->getTableName("catalog_eav_attribute").' cea
609
+ ON ea.attribute_id = cea.attribute_id
610
+ WHERE (
611
+ ea.entity_type_id ='.$entity_type_id.'
612
+ )
613
+ AND (
614
+ cea.is_searchable =1
615
+ OR cea.is_filterable in(1,2)
616
+ )and ea.frontend_input<>"price"';
617
+ $attributesInfo=$this->_read->fetchAll($sql);
618
+ $attributessf=array();
619
+ foreach($attributesInfo as $attribute)
620
+ {
621
+ $attributessf[$attribute["attribute_code"]]=array($attribute["frontend_input"],$i);
622
+ $i++;
623
+ }
624
+ //Union 2 array
625
+ $attributes=array_merge($attributessf,$attributesreq);
626
+ }
627
+ //-------------------------------------------------------------------
628
+
629
+ public function header($attributes,$cate,$typ,$chil)
630
+ {
631
+ $str="";
632
+ $header=array();
633
+ $name=1;
634
+ $url_key =2;
635
+ $image=3;
636
+ $map = Mage::helper('salesperson/mapping');
637
+
638
+ foreach($attributes as $key=>$value) {
639
+ $key = $map->getMapping($key);
640
+ $header[$value[1]]=$this->_fEnclose.$key.$this->_fEnclose;
641
+ }
642
+ //---------------------------
643
+ $header[$name]=$this->_fEnclose.$map->getMapping('title').$this->_fEnclose;
644
+ $header[$url_key]=$this->_fEnclose.$map->getMapping('link').$this->_fEnclose;
645
+ $header[$image]=$this->_fEnclose.$map->getMapping('image_link').$this->_fEnclose;
646
+ $str.=$this->_fEnclose.$map->getMapping('id').$this->_fEnclose.$this->_fDel;
647
+ $header[$cate]=$this->_fEnclose.$map->getMapping('category').$this->_fEnclose;
648
+ $header[$typ]=$this->_fEnclose.$map->getMapping('type').$this->_fEnclose;
649
+ $header[$chil]=$this->_fEnclose.$map->getMapping('children_skus').$this->_fEnclose;
650
+ ksort($header);
651
+ $att= implode($this->_fDel,$header);
652
+ $str.=$att."\r\n";
653
+ return $str;
654
+ }
655
+ //------------------------------------------------------------------
656
+ public function content($product,$attributes,$cate,$typ,$chil,$config,$children,$nameCategory,$childrenName)
657
+ {
658
+ $sql="";
659
+ $result="";
660
+ $products=array();
661
+ $att="";
662
+ // $getcategoties=array();
663
+ $entity_id=$product->getentity_id();
664
+
665
+ foreach($attributes as $att_code => $header_metadata)
666
+ {
667
+ $att_type = $header_metadata[0];
668
+ $header_index = $header_metadata[1];
669
+
670
+ if($config == 1 && array_key_exists($att_code,$children))
671
+ {
672
+ $products[$header_index]= $children[$att_code];
673
+ }
674
+ else
675
+ {
676
+ $products[$header_index] = $this->getProductAttributeValue($product, $att_code, $att_type);
677
+ }
678
+
679
+ //Create a copy of the product images in /media/sales_catalog, in order to remove dependency on Magento cache
680
+ $bCreateCopyOfImagesCatalog = true;
681
+ if ($bCreateCopyOfImagesCatalog && $att_code == 'image') $products[$header_index] = $this->_copyImageToSalespersonCatalog($products[$header_index], $entity_id);
682
+
683
+ $products[$header_index]=str_replace('"','""',$products[$header_index]);
684
+ $products[$header_index]=str_replace('\r',' ',$products[$header_index]);
685
+ $products[$header_index]=str_replace('\n',' ',$products[$header_index]);
686
+ $products[$header_index]=$this->_fEnclose.$products[$header_index].$this->_fEnclose;
687
+ }
688
+ //------------------------------
689
+
690
+ $products[0]=$this->_fEnclose.$entity_id.$this->_fEnclose;
691
+ //---------------------------------------------------
692
+ //Create the Query to get the products:getcategoty
693
+ $products[$cate]=$this->_fEnclose;
694
+ if (isset($this->_fProduct_Category_Matrix[$product->getId()]))
695
+ {
696
+ $getcategoties=$this->_fProduct_Category_Matrix[$product->getId()];
697
+ if($getcategoties)
698
+ {
699
+ $has_categories = false;
700
+ foreach($getcategoties as $getcategory)
701
+ {
702
+ if (isset($nameCategory[$getcategory]))
703
+ {
704
+ $products[$cate].=$nameCategory[$getcategory].',';
705
+ $has_categories = true;
706
+ }
707
+ }
708
+ if ($has_categories) $products[$cate]=substr_replace($products[$cate],"",strlen($products[$cate])-1);
709
+ }
710
+ }
711
+
712
+ $products[$cate].=$this->_fEnclose;
713
+ //-----------------------
714
+ $products[$typ]=$this->_fEnclose.$product->gettype_id().$this->_fEnclose;
715
+ //---------------------------
716
+ $products[$chil]=$this->_fEnclose.$childrenName.$this->_fEnclose;
717
+ //----------------------
718
+ ksort($products);
719
+ $att=implode($this->_fDel, $products);
720
+ return $att;
721
+ }
722
+
723
+ protected function getProductAttributeValue($product, $att_code, $att_type)
724
+ {
725
+ $attributeValue = "";
726
+ $func = 'get'.$att_code;
727
+
728
+ if($att_type === "select")
729
+ {
730
+ $boolKeysArr = array("status", "is_in_stock", "visibility");
731
+ if(in_array($att_code, $boolKeysArr)){
732
+ $attributeValue = $product->getAttributeText($att_code);
733
+ }
734
+ else if ((($data = $product->getData($att_code)) != null) && $data != ""){
735
+ $sql = 'SELECT value FROM '.$this->getTableName("eav_attribute_option_value").' WHERE option_id = '.$data.' AND (store_id = '.$this->_fStore_id.' OR store_id = 0) ORDER BY store_id DESC';
736
+ $result = $this->_read->fetchAll($sql);
737
+ if ($result != null) $attributeValue = $result[0]["value"];
738
+ }
739
+ }
740
+ elseif($att_type === "multiselect")
741
+ {
742
+ $attributeValue = trim($product->getResource()->getAttribute($att_code)->getFrontend()->getValue($product), " , ");
743
+ }
744
+ elseif($att_type === "media_image")
745
+ {
746
+ $attributeValue = $product->getImageUrl();
747
+ //$product->getMediaConfig()->getMediaUrl($product->getData($att_code)));
748
+ }
749
+ elseif($att_type === "textarea")
750
+ {
751
+ $attributeValue = $product->{$func}();
752
+ }
753
+ elseif($att_type === "price")
754
+ {
755
+ if($att_code==="price") $attributeValue = $this->getCalculatedPrice($product);
756
+ elseif($att_code==="giftcard_amounts") $attributeValue = $this->getAllGiftcardAmounts($product);
757
+ }
758
+ else
759
+ {
760
+ if($att_code==="url_key") $attributeValue = $product->getProductUrl(false /*$useSid*/);
761
+ else $attributeValue = $product->getData($att_code);
762
+ }
763
+
764
+ return $attributeValue;
765
+ }
766
+
767
+ public function getCalculatedPrice($product)
768
+ {
769
+ if ($product->getData("type_id") == "giftcard")
770
+ {
771
+ $min_amount = PHP_INT_MAX;
772
+ if ($product->getData("open_amount_min") != null && Mage::getModel('catalog/product')->load($product->getId())->getData("allow_open_amount")) $min_amount = $product->getData("open_amount_min");
773
+ foreach($product->getData("giftcard_amounts") as $amount)
774
+ {
775
+ if($min_amount > $amount["value"]) $min_amount = $amount["value"];
776
+ }
777
+ return number_format($min_amount,2,".","");
778
+ }
779
+ return number_format($product->getPrice(),2,".","");
780
+ }
781
+
782
+ public function getAllGiftcardAmounts($product)
783
+ {
784
+ if($product->getData("type_id") == "giftcard")
785
+ {
786
+ $list = "";
787
+ if(Mage::getModel('catalog/product')->load($product->getId())->getData("allow_open_amount")) $list = $product->getData("open_amount_min")."-".$product->getData("open_amount_max");
788
+ foreach($product->getData("giftcard_amounts") as $amount)
789
+ {
790
+ if($list != "") $list .= ", ";
791
+ $list .= $amount["value"];
792
+ }
793
+ return $list;
794
+ }
795
+ return null;
796
+ //die($priceObject[0]["value"]);
797
+ }
798
+
799
+ //--------------------------------
800
+ public function ftpfile()
801
+ {
802
+ if (!file_exists($this->_fPath . "/" . $this->_fileNameZip)) {
803
+ $this->comments_style('error','No ' . $this->_fileNameZip . ' file found','No_zip_file_found');
804
+ return false;
805
+ }
806
+
807
+ $ioConfig=array();
808
+
809
+ if ($this->_fFTPHost != '')
810
+ {
811
+ $ioConfig['host'] = $this->_fFTPHost;
812
+ }
813
+ else
814
+ {
815
+ $this->comments_style('error','Empty host specified','Empty_host');
816
+ return false;
817
+ }
818
+ if ($this->_fFTPPort != '')
819
+ {
820
+ $ioConfig['port'] = $this->_fFTPPort;
821
+ }
822
+
823
+ if ($this->_fFTPUser != '')
824
+ {
825
+ $ioConfig['user'] = $this->_fFTPUser;
826
+ }
827
+ else
828
+ {
829
+ $ioConfig['user']='anonymous';
830
+ $ioConfig['password']='anonymous@noserver.com';
831
+ }
832
+ if ($this->_fFTPPassword != '')
833
+ {
834
+ $ioConfig['password'] = $this->_fFTPPassword;
835
+ }
836
+
837
+ $ioConfig['passive'] = $this->_fFTPPassive;
838
+
839
+ if ($this->_fPath != '')
840
+ {
841
+ $ioConfig['path']= $this->_fPath;
842
+ }
843
+ $this->_config = $ioConfig;
844
+ $this->_conn =@ftp_connect($this->_config['host'], $this->_config['port']);
845
+ if (!$this->_conn)
846
+ {
847
+ $this->comments_style('error','Could not establish FTP connection, invalid host or port','invalid_ftp_host/port');
848
+ return false;
849
+ }
850
+ if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password']))
851
+ {
852
+ $this->close();
853
+ $this->comments_style('error','Could not establish FTP connection, invalid user name or password','Invalid_ftp_user_name_or_password');
854
+ return false;
855
+ }
856
+ /*if ($this->_config['path']!='')
857
+ {
858
+ if (!$this->ftp_is_dir($this->_conn, $this->_config['path']))
859
+ {
860
+ if(!$this->make_directory($this->_conn,$this->_config['path']))
861
+ {
862
+ $this->close();
863
+ $this->comments_style('error','Invalid path(or couldn\'t create the folders because of permissions)','invalid_path');
864
+ return false;
865
+ }
866
+ }
867
+ }*/
868
+
869
+ if (!@ftp_pasv($this->_conn, true)) {
870
+ $this->close();
871
+ $this->comments_style('error','Invalid file transfer mode','Invalid_file_transfer_mode');
872
+ return false;
873
+ }
874
+
875
+ if (!file_exists($this->_fPath . "/" . $this->_fileNameZip)) {
876
+ $this->comments_style('error','No ' . $this->_fileNameZip . ' file found','No_zip_file_found');
877
+ }
878
+
879
+ $upload = @ftp_put($this->_conn, $this->_fileNameZip, $this->_config['path'] . "/" . $this->_fileNameZip, FTP_BINARY);
880
+ if(!$upload){
881
+ $this->comments_style('error','File upload failed','File_upload_failed');
882
+ $upload=false;
883
+ }
884
+
885
+ return $upload;
886
+ }
887
+ //----------------------------------------------------
888
+ public function make_directory($ftp_stream, $dir)
889
+ {
890
+ // if directory already exists or can be immediately created return true
891
+ if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
892
+ // otherwise recursively try to make the directory
893
+ if (!$this->make_directory($ftp_stream, dirname($dir))) return false;
894
+ // final step to create the directory
895
+ return @ftp_mkdir($ftp_stream, $dir);
896
+ }
897
+ //----------------------------------------
898
+ public function ftp_is_dir($ftp_stream, $dir)
899
+ {
900
+ // get current directory
901
+ $original_directory = ftp_pwd($ftp_stream);
902
+ // test if you can change directory to $dir
903
+ // suppress errors in case $dir is not a file or not a directory
904
+ if ( @ftp_chdir( $ftp_stream, $dir ) ) {
905
+ // If it is a directory, then change the directory back to the original directory
906
+ ftp_chdir( $ftp_stream, $original_directory );
907
+ return true;
908
+ } else {
909
+ return false;
910
+ }
911
+ }
912
+ //----------------------------------------------------
913
+ public function close()
914
+ {
915
+ return ftp_close($this->_conn);
916
+ }
917
+ //-----------------------------------------
918
+ public function comments_style($kind,$text,$alt)
919
+ {
920
+ switch($kind)
921
+ {
922
+ case 'header':
923
+ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
924
+ <html><head><style type="text/css">
925
+ ul { list-style-type:none; padding:0; margin:0; }
926
+ li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
927
+ img { margin-right:5px; }
928
+ </style><title>Salesperson Exporter</title></head>
929
+ <body><ul>';
930
+ break;
931
+ case 'icon':
932
+ echo '<li>
933
+ <img style="margin-right: 5px;" src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/note_msg_icon.gif" alt='.$alt.'/>
934
+ '.$text.'
935
+ </li>';
936
+ break;
937
+ case 'warning':
938
+ echo '<li style="background-color: rgb(255, 255, 221);">
939
+ <img style="margin-right: 5px;" src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/fam_bullet_error.gif" alt='.$alt.'/>
940
+ '.$text.'
941
+ </li>';
942
+ break;
943
+ case 'success':
944
+ echo '<li style="background-color: rgb(221, 221, 255);">
945
+ <img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/fam_bullet_success.gif" alt='.$alt.'/>
946
+ '.$text.'
947
+ </li>';
948
+ break;
949
+ case 'error':
950
+ echo '<li style="background-color: rgb(255, 187, 187);">
951
+ <img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif" alt='.$alt.'/>
952
+ '.$text.'
953
+ </li>';
954
+ break;
955
+ default:
956
+ echo '</ul></body></html>';
957
+ }
958
+ }
959
+ //-------------------------------------------------------------------
960
+ public function export_config($store_id)
961
+ {
962
+ $this->_fStore_id = $store_id;
963
+ $this->_fStore_module_disabled = Mage::app()->getStore($store_id)->getConfig('advanced/modules_disable_output/Celebros_Salesperson');;
964
+ $this->_fDel = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/delimiter');
965
+ if($this->_fDel==='\t') $this->_fDel=" ";
966
+ $this->_fEnclose = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/enclosed_values');
967
+ $this->_fType = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/type');
968
+ $this->_fPath = Mage::app()->getStore(0)->getConfig('salesperson/export_settings/path').'/'.Mage::app()->getStore($store_id)->getWebsite()->getCode().'/'.Mage::app()->getStore($store_id)->getCode();
969
+ $this->_fFTPHost = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/ftp_host');
970
+ $this->_fFTPPort = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/ftp_port');
971
+ $this->_fFTPUser = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/ftp_user');
972
+ $this->_fFTPPassword = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/ftp_password');
973
+ $this->_fFTPPassive = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/passive');
974
+ $this->_fEnableCron = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/cron_enabled');
975
+ $this->_fExportProfileId = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/profile_id');
976
+ $this->CronExpression = Mage::app()->getStore($store_id)->getConfig('salesperson/export_settings/cron_expr');
977
+ }
978
+ //---------------------------
979
+ public function getCategoryCollection($storeId)
980
+ {
981
+ $categoriesPool = $collection = Mage::getModel('catalog/category')->getCollection()->addNameToResult()
982
+ ->addAttributeToSelect('is_active')
983
+ ->setProductStoreId($storeId)
984
+ ->setStoreId($storeId);
985
+
986
+ foreach($categoriesPool as $category)
987
+ {
988
+ if (!in_array($storeId, $category->getStoreIds())) $collection->removeItemByKey($category->getId());
989
+ }
990
+
991
+ return $collection;
992
+ }
993
+ //---------------------------
994
+ public function zipFile()
995
+ {
996
+ $out = false;
997
+
998
+ if (!file_exists($this->_fPath . "/" . $this->_fileNameTxt)) {
999
+ $this->comments_style('error','No ' . $this->_fileNameTxt . ' file found','No_txt_file_found');
1000
+ exit();
1001
+ return false;
1002
+ }
1003
+
1004
+ $zip = new ZipArchive();
1005
+ if ($zip->open($this->_fPath . '/' . $this->_fileNameZip, ZipArchive::CREATE) == true) {
1006
+ $out = $zip->addFile($this->_fPath . '/' . $this->_fileNameTxt, $this->_fileNameTxt);
1007
+ if(!$out) $this->comments_style('error','Could not add ' . $this->_fileNameTxt . 'to zip archive','Could_not_add_txt_file_to_zip_file');
1008
+ $zip->close();
1009
+ unlink($this->_fPath . '/' . $this->_fileNameTxt);
1010
+ }
1011
+ else
1012
+ {
1013
+ $this->comments_style('error','Could not create ' . $this->_fileNameZip . ' file','Could_not_create_zip_file');
1014
+ }
1015
+
1016
+ return $out;
1017
+ }
1018
+
1019
+ //-----------------------------------------
1020
+ public function getTableName($tableName)
1021
+ {
1022
+ $newTableName= Mage::getSingleton('core/resource')->getTableName($tableName);
1023
+ return $newTableName;
1024
+ }
1025
+
1026
+ protected function _copyImageToSalespersonCatalog($imageUrl, $productId){
1027
+
1028
+ $resultUrl = "";
1029
+ $mediaDir = Mage::getBaseDir("media");
1030
+ $pos = strpos($imageUrl, "media") + strlen("media");
1031
+ $catalogRelativeImagePath = substr($imageUrl, $pos + 1, strlen($imageUrl) - $pos - 1);
1032
+ $sourceImagePath = $mediaDir . DIRECTORY_SEPARATOR . $catalogRelativeImagePath;
1033
+ if(file_exists($sourceImagePath)){
1034
+ $fileName = basename($sourceImagePath);
1035
+ $destinationFolder = $mediaDir . DIRECTORY_SEPARATOR . "sales_catalog" . DIRECTORY_SEPARATOR . "product" . DIRECTORY_SEPARATOR . $productId;
1036
+ if(!is_dir($destinationFolder)){
1037
+ if(!mkdir($destinationFolder, 0777, true))
1038
+ {
1039
+ echo "failed to create directory $destinationFolder ...\n";
1040
+ exit();
1041
+ }
1042
+ }
1043
+
1044
+ /*$newCatalogRelativePath = str_replace("catalog", "sales_catalog", $catalogRelativePath);
1045
+ $destinationFolder = $mediaDir . DIRECTORY_SEPARATOR . dirname($newCatalogRelativePath) ;
1046
+ if(!is_dir($destinationFolder)){
1047
+ if(!mkdir($destinationFolder, 0777, true))
1048
+ {
1049
+ echo "failed to create directory $destinationFolder ...\n";
1050
+ exit();
1051
+ }
1052
+ }*/
1053
+
1054
+ $destinationImagePath = $destinationFolder . DIRECTORY_SEPARATOR . $fileName;
1055
+ //var_dump($destinationImagePath); exit();
1056
+ if (!copy($sourceImagePath, $destinationImagePath)) {
1057
+ echo "failed to copy $sourceImagePath to $destinationImagePath ...\n";
1058
+ exit();
1059
+ }
1060
+ }
1061
+
1062
+ $resultUrl = substr($imageUrl, 0, $pos) . DIRECTORY_SEPARATOR . "sales_catalog" . DIRECTORY_SEPARATOR . "product" . DIRECTORY_SEPARATOR . $productId . DIRECTORY_SEPARATOR . $fileName;
1063
+ return $resultUrl;
1064
+ }
1065
+ }
app/code/local/Celebros/Salesperson/Model/Product.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Product extends Celebros_Salesperson_Model_Api_QwiserProduct
11
+ {
12
+ /**
13
+ * Initialize resources
14
+ */
15
+ protected function _construct()
16
+ {
17
+ $this->_init('salesperson/product');
18
+ }
19
+
20
+ /**
21
+ * Retrive product by SKU
22
+ *
23
+ * @param string $productSku
24
+ * @return Celebros_Salesperson_Model_Api_QwiserProduct
25
+ */
26
+ public function load($productSku){
27
+ $products = Mage::Helper("salesperson")->getSalespersonApi()->results->Products->Items;
28
+ foreach ($products as $product)
29
+ {
30
+ if($product->Sku = $productSku){
31
+ return $product;
32
+ }
33
+ }
34
+ }
35
+ /**
36
+ * Retrive QwiserSearchResult
37
+ *
38
+ * @return Celebros_Salesperson_Model_Api_QwiserSearchResult
39
+ */
40
+ protected function getQwiserSearchResults(){
41
+ if(Mage::helper('salesperson')->getSalespersonApi()->results)
42
+ return Mage::helper('salesperson')->getSalespersonApi()->results;
43
+ }
44
+
45
+ /**
46
+ * Retrieve Store Id of the product
47
+ *
48
+ * @return int
49
+ */
50
+ public function getStoreId()
51
+ {
52
+ if (key_exists(Mage::Helper('salesperson/mapping')->getMapping('store_id'),$this->Field)) {
53
+ return $this->Field(Mage::Helper('salesperson/mapping')->getMapping('store_id'));
54
+ }
55
+ return Mage::app()->getStore()->getId();
56
+ }
57
+
58
+ /**
59
+ * Get product url model
60
+ *
61
+ * @return Mage_Catalog_Model_Product_Url
62
+ */
63
+ public function getUrlModel()
64
+ {
65
+ if ($this->_urlModel === null) {
66
+ $this->_urlModel = Mage::getSingleton('catalog/product_url');
67
+ }
68
+ return $this->_urlModel;
69
+ }
70
+
71
+
72
+ /**
73
+ * Get product name
74
+ *
75
+ * @return string
76
+ */
77
+ public function getName()
78
+ {
79
+ return $this->Field(Mage::Helper('salesperson/mapping')->getMapping('title'));
80
+ }
81
+
82
+ /**
83
+ * Get product status
84
+ *
85
+ * @return int
86
+ */
87
+ public function getStatus()
88
+ {
89
+ return $this->Field[Mage::Helper('salesperson/mapping')->getMapping('status')] == 'Enabled';
90
+ }
91
+
92
+ public function getInStock() {
93
+
94
+ // $productModel = Mage::getSingleton('catalog/product');
95
+ // $product = $productModel->load($this->getId());
96
+ // $inventoery = Mage::getSingleton('cataloginventory/stock_item')->loadByProduct($product);
97
+ // $isInStock = $inventoery->getData('is_in_stock');
98
+ // if ((int)$isInStock == 0){ return false; }else { return true; }
99
+ return key_exists(Mage::Helper('salesperson/mapping')->getMapping('is_in_stock'), $this->Field) && (int)$this->Field[Mage::Helper('salesperson/mapping')->getMapping('is_in_stock')] == 1 ? true : false;
100
+ }
101
+
102
+
103
+ public function getSku()
104
+ {
105
+ return key_exists(Mage::Helper('salesperson/mapping')->getMapping('sku'),$this->Field) ? $this->Field[Mage::Helper('salesperson/mapping')->getMapping('sku')] : false;
106
+ }
107
+
108
+ /**
109
+ * Retrive Product Id
110
+ * @return string
111
+ */
112
+ public function getId() {
113
+ return $this->Field[Mage::Helper('salesperson/mapping')->getMapping('id')];
114
+ }
115
+
116
+ /**
117
+ * Retrieve assigned category Ids
118
+ *
119
+ * @return array
120
+ */
121
+ public function getCategory()
122
+ {
123
+ return key_exists(Mage::Helper('salesperson/mapping')->getMapping('category'),$this->Field) ? $this->Field[Mage::Helper('salesperson/mapping')->getMapping('category')] : false;
124
+ }
125
+
126
+ /**
127
+ * Retrieve product websites identifiers
128
+ *
129
+ * @return array
130
+ */
131
+ public function getWebsiteIds()
132
+ {
133
+ if (strpos($this->Field[Mage::Helper('salesperson/mapping')->getMapping('websites')],',')){
134
+ $websitesIds = explode($this->Field[Mage::Helper('salesperson/mapping')->getMapping('websites')]);
135
+ return $websitesIds;
136
+ }
137
+ else {
138
+ return array($this->Field[Mage::Helper('salesperson/mapping')->getMapping('websites')]);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Get all sore ids where product is presented
144
+ *
145
+ * @return array
146
+ */
147
+ public function getStoreIds()
148
+ {
149
+ if (strpos($this->Field[Mage::Helper('salesperson/mapping')->getMapping('store_id')],',')){
150
+ $storeIds = explode($this->Field[Mage::Helper('salesperson/mapping')->getMapping('store_id')]);
151
+ return $storeIds;
152
+ }
153
+ else {
154
+ return array($this->Field[Mage::Helper('salesperson/mapping')->getMapping('store_id')]);
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Retrive if product is new
160
+ * @return bool
161
+ */
162
+ public function isNew(){
163
+ $now = time();
164
+ $newsFrom = $newsTo = '';
165
+ if (key_exists(Mage::Helper('salesperson/mapping')->getMapping('news_from_date'), $this->Field)) $newsFrom= strtotime($this->Field[Mage::Helper('salesperson/mapping')->getMapping('news_from_date')]);
166
+ if (key_exists(Mage::Helper('salesperson/mapping')->getMapping('news_to_date'), $this->Field)) $newsTo= strtotime($this->Field[Mage::Helper('salesperson/mapping')->getMapping('news_to_date')]);
167
+ return ($newsFrom != '' && $newsTo != '') ? ($now>=$newsFrom && $now<=$newsTo) : false;
168
+ }
169
+
170
+ /**
171
+ * Retrive the Rating precent
172
+ *
173
+ * @return string
174
+ */
175
+ public function getRatingSummary()
176
+ {
177
+ return $this->Field[$this->Field[Mage::Helper('salesperson/mapping')->getMapping('rating')]]; //_getData('rating_summary');
178
+ }
179
+ /**
180
+ * Retrieve product found in
181
+ *
182
+ * @return category with link
183
+ */
184
+ public function getAvailableInCategories()
185
+ {
186
+ if(key_exists(Mage::Helper('salesperson/mapping')->getMapping('category'), $this->Field) && $this->Field[Mage::Helper('salesperson/mapping')->getMapping('category')] != ''){
187
+ $categories = strpos($this->Field[Mage::Helper('salesperson/mapping')->getMapping('category')],',')
188
+ ? explode(',',$this->Field[Mage::Helper('salesperson/mapping')->getMapping('category')])
189
+ : $this->Field[Mage::Helper('salesperson/mapping')->getMapping('category')];
190
+ if (is_array($categories)){
191
+ $urls = array();
192
+ foreach ($categories as $category){
193
+ $urlParams = array();
194
+ $urlParams['_current'] = false;
195
+ $urlParams['_escape'] = true;
196
+ $urlParams['_use_rewrite'] = true;
197
+ $urlParams['_query'] = array(
198
+ 'q' => $category,
199
+ );
200
+ $urls[$category] = Mage::getUrl('*/*/index', $urlParams);
201
+ }
202
+ return $urls;
203
+ }
204
+ else {
205
+ $urlParams = array();
206
+ $urlParams['_current'] = false;
207
+ $urlParams['_escape'] = true;
208
+ $urlParams['_use_rewrite'] = true;
209
+ $urlParams['_query'] = array(
210
+ 'q' => $categories,
211
+ );
212
+ return array($categories => Mage::getUrl('*/*/index', $urlParams));
213
+ }
214
+ }
215
+ }
216
+ }
app/code/local/Celebros/Salesperson/Model/SalespersonAnalyticsApi.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ *
8
+ */
9
+
10
+ class Celebros_Salesperson_Model_SalespersonAnalyticsApi extends Mage_Core_Model_Abstract
11
+ {
12
+ protected function _construct()
13
+ {
14
+ $this->_init('salesperson/salespersonAnalyticsApi');
15
+ }
16
+
17
+ /**
18
+ * Retrieve salesperson session
19
+ *
20
+ * @return Mage_Catalog_Model_Session
21
+ */
22
+ protected function _getSession()
23
+ {
24
+ return Mage::getSingleton('salesperson/session');
25
+ }
26
+
27
+ public function getAnlxSearchResultFunction(){
28
+
29
+ if (Mage::getStoreConfig('salesperson/anlx_settings/ai_writer_address') == ""||
30
+ Mage::getStoreConfig('salesperson/anlx_settings/cid') == "")
31
+ return "";
32
+
33
+ /*$observer = array('ssid' => Mage::Helper('salesperson')->getSalespersonApi()->results->SearchInformation->SessionId, 'logHandle' => Mage::Helper('salesperson')->getSalespersonApi()->results->GetLogHandle());
34
+ Mage::getModel('salesperson/observer')->sendResultAnlxInfo($observer);*/
35
+
36
+ $dca = Mage::getStoreConfig('salesperson/anlx_settings/ai_writer_address');
37
+ $cid = Mage::getStoreConfig('salesperson/anlx_settings/cid');
38
+ $results = Mage::Helper('salesperson')->getSalespersonApi()->results;
39
+ $sessionId = $this->_getSession()->getSessionId();
40
+
41
+ return Mage::getModel('salesperson/api_anlx_analyticsFunctions', array("G_DATA_COLLECTOR_ADDRESS" => $dca, "G_CUSTOMER_ID" => $cid, "G_CUSTOMER_NAME" => $cid, "G_PUBLIC_KEY" => "" ) )
42
+ ->Celebros_Analytics_SearchResults(
43
+ $results->SearchInformation->SessionId,//sSearchHandle
44
+ $results->GetLogHandle(),//sLogHandle
45
+ $sessionId,//sUserID
46
+ '1',//sGroupID
47
+ $sessionId,//sWebSessionID
48
+ $_SERVER['HTTP_REFERER'],//sReferrer
49
+ (bool)Mage::getStoreConfig('salesperson/anlx_settings/protocol_connection'),//bIsSSL
50
+ true//bFromQwiser
51
+ );
52
+ }
53
+
54
+ public function getAnlxResultProductClickFunction($product_id){
55
+
56
+ $dca = Mage::getStoreConfig('salesperson/anlx_settings/ai_writer_address');
57
+ $cid = Mage::getStoreConfig('salesperson/anlx_settings/cid');
58
+
59
+ if ($dca == ""|| $cid == "") return "";
60
+
61
+ $product = Mage::getSingleton('catalog/product')->load($product_id);
62
+
63
+ $categoryIds = $product->getCategoryIds();
64
+ $categoryName = Mage::getModel('catalog/category')->load($categoryIds[0])->getName();
65
+
66
+ $sessionId = $this->_getSession()->getSessionId();
67
+ $search_session_id = $this->_getSession()->getSearchSessionId();
68
+ $search_session_id = $search_session_id ? $search_session_id : 'none';
69
+
70
+ $pixel = Mage::getModel('salesperson/api_anlx_analyticsFunctions', array("G_DATA_COLLECTOR_ADDRESS" => $dca, "G_CUSTOMER_ID" => $cid, "G_CUSTOMER_NAME" => $cid, "G_PUBLIC_KEY" => "" ) )
71
+ ->Celebros_Analytics_ProductDetails(
72
+ $product->getSku(), //sSKU
73
+ "", //sVariant
74
+ $product->getName(), //sName
75
+ $product->getFinalPrice(), //fPrice
76
+ $categoryName, //sCategory
77
+ $search_session_id ,//sSearchHandle
78
+ $sessionId,//sUserID
79
+ '1',//sGroupID
80
+ $sessionId,//sWebSessionID
81
+ $_SERVER['HTTP_REFERER'],//sReferrer
82
+ "", //iSourceType
83
+ "", //sSourceTypeName
84
+ (bool)Mage::getStoreConfig('salesperson/anlx_settings/protocol_connection')//bIsSSL
85
+ );
86
+ //var_dump($pixel);
87
+
88
+ if($pixel!="") {
89
+ $arr = explode("'>", $pixel);
90
+ for($i = 0; $i < count($arr); $i++) {
91
+ if($arr[$i] == "") continue;
92
+ $start = strrpos($arr[$i], "SRC='");
93
+ $url = substr($arr[$i], $start + 5);
94
+ //var_dump($url); exit();
95
+ $this->makeWebRequest($url);
96
+ }
97
+ }
98
+
99
+ return $pixel;
100
+ }
101
+
102
+ protected function makeWebRequest($url) {
103
+
104
+ $curl = curl_init();
105
+ curl_setopt($curl, CURLOPT_URL, $url);
106
+ curl_setopt($curl, CURLOPT_FAILONERROR, true);
107
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
108
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
109
+ curl_setopt($curl, CURLOPT_TIMEOUT,1);
110
+ $curlResult = curl_exec($curl);
111
+ $curlError = curl_error($curl);
112
+ $curlInfo = curl_getinfo($curl);
113
+ curl_close($curl);
114
+ if(!empty($curlError)) {
115
+ Mage::throwException('Celebros Analytics: ' . $curlError .' Request Url: ' . $uri);
116
+ }
117
+ }
118
+ }
app/code/local/Celebros/Salesperson/Model/SalespersonSearchApi.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ *
8
+ */
9
+
10
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."SearchInformation.php");
11
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserSearchResults.php");
12
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProducts.php");
13
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProduct.php");
14
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."SortingOptions.php");
15
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserQuestions.php");
16
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserQuestion.php");
17
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserAnswers.php");
18
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserAnswer.php");
19
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserSearchPath.php");
20
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserSearchPathEntry.php");
21
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserSpellerInformation.php");
22
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserConcepts.php");
23
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserConcept.php");
24
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProductAnswers.php");
25
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProductAnswer.php");
26
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProductFields.php");
27
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."QwiserProductField.php");
28
+ include(dirname(dirname(__FILE__)).DS."Model".DS."Api".DS."domxml-php4-to-php5.php");
29
+
30
+ class Celebros_Salesperson_Model_SalespersonSearchApi extends Mage_Core_Model_Abstract
31
+ {
32
+
33
+ var $CommunicationPort; //The name of the comm port to use for access to the search server.
34
+ var $HostName; //The name of the search server to connect to.
35
+ var $SiteKey; //the api site key.
36
+ var $LastOperationErrorMessage; //the last operation error message.
37
+ var $LastOperationSucceeded; //return true if the last operation ended successfully.
38
+ var $WebService; //Search WebService full uri.
39
+
40
+ public $results;
41
+
42
+ /**
43
+ * Init resource model
44
+ *
45
+ */
46
+ protected function _construct()
47
+ {
48
+ $this->_init('salesperson/salespersonSearchApi');
49
+ if (Mage::getStoreConfig('salesperson/general_settings/host') != '' && Mage::getStoreConfig('salesperson/general_settings/port') != '' && Mage::getStoreConfig('salesperson/general_settings/sitekey') != ''){
50
+ $this->HostName = Mage::getStoreConfig('salesperson/general_settings/host');
51
+ if (preg_match('/http:\/\//',$this->HostName)){
52
+ $this->HostName = preg_replace('/http::\/\//','', $this->HostName);
53
+ }
54
+ $this->CommunicationPort = Mage::getStoreConfig('salesperson/general_settings/port');
55
+ $this->SiteKey = Mage::getStoreConfig('salesperson/general_settings/sitekey');
56
+ $this->WebService ="http://".$this->HostName.":".$this->CommunicationPort."/";
57
+ $this->LastOperationSucceeded = true;
58
+ }
59
+ }
60
+
61
+ //Activate serach Profile
62
+ Function ActivateProfile($SearchHandle,$SearchProfile)
63
+ {
64
+ $SearchProfile = urlencode($SearchProfile);
65
+ $RequestUrl = "ActivateProfile?SearchHandle=".$SearchHandle."&SearchProfile=".$SearchProfile."&Sitekey=".$this->SiteKey;
66
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
67
+ return $this;
68
+ }
69
+
70
+ //Answer Question
71
+ Function AnswerQuestion($SearchHandle,$AnswerId,$EffectOnSearchPath)
72
+ {
73
+ $RequestUrl = "AnswerQuestion?SearchHandle=".$SearchHandle."&answerId=".$AnswerId."&EffectOnSearchPath=".$EffectOnSearchPath."&Sitekey=".$this->SiteKey;
74
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
75
+ return $this;
76
+ }
77
+
78
+ //Change Number of Products in Page
79
+ Function ChangePageSize($SearchHandle,$PageSize)
80
+ {
81
+ $RequestUrl = "ChangePageSize?SearchHandle=".$SearchHandle."&pageSize=".$PageSize."&Sitekey=".$this->SiteKey;
82
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
83
+ return $this;
84
+ }
85
+
86
+ //Change the search default price
87
+ Function ChangePriceColumn($SearchHandle,$PriceColumn)
88
+ {
89
+ $RequestUrl = "ChangePriceColumn?SearchHandle=".$SearchHandle."&PriceColumn=".$PriceColumn."&Sitekey=".$this->SiteKey;
90
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
91
+ return $this;
92
+ }
93
+
94
+ //Deactivate Search Profile
95
+ Function DeactivateProfile($SearchHandle)
96
+ {
97
+ $RequestUrl = "DeactivateProfile?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
98
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
99
+ return $this;
100
+ }
101
+
102
+ //Moves to the first page of the results
103
+ Function FirstPage($SearchHandle)
104
+ {
105
+ $RequestUrl = "FirstPage?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
106
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
107
+ return $this;
108
+ }
109
+
110
+ //Forces the BQF to allow the specified question to appear first
111
+ Function ForceQuestionAsFirst($SearchHandle,$QuestionId)
112
+ {
113
+ $RequestUrl = "ForceQuestionAsFirst?SearchHandle=".$SearchHandle."&QuestionId=".$QuestionId."&Sitekey=".$this->SiteKey;
114
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
115
+ return $this;
116
+ }
117
+
118
+ //Get alll the product fields
119
+ Function GetAllProductFields()
120
+ {
121
+ $RequestUrl = "GetAllProductFields?Sitekey=".$this->SiteKey;
122
+ $this->results = $this->GetResult($RequestUrl,"QwiserProductFields");
123
+ return $this;
124
+ }
125
+
126
+ //Return all the questions
127
+ Function GetAllQuestions()
128
+ {
129
+ $RequestUrl = "GetAllQuestions?Sitekey=".$this->SiteKey;
130
+ $this->results = $this->GetResult($RequestUrl,"QwiserQuestions");
131
+ return $this;
132
+ }
133
+
134
+ //Return all search profiles
135
+ Function GetAllSearchProfiles()
136
+ {
137
+ $RequestUrl = "GetAllSearchProfiles?Sitekey=".$this->SiteKey;
138
+ $this->results = $this->GetResult($RequestUrl,"QwiserSimpleStringCollection");
139
+ return $this;
140
+ }
141
+
142
+ //Gets the results for the specified search handle
143
+ Function GetCustomResults($SearchHandle,$bNewSearch,$PreviousSearchHandle)
144
+ {
145
+ $RequestUrl = "GetCustomResults?SearchHandle=".$SearchHandle."&NewSearch=".$bNewSearch."&PreviousSearchHandle=".$PreviousSearchHandle."&Sitekey=".$this->SiteKey;
146
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
147
+ return $this;
148
+ }
149
+
150
+ //Gets Engine Status
151
+ Function GetEngineStatus()
152
+ {
153
+ $RequestUrl = "GetEngineStatus?Sitekey=".$this->SiteKey;
154
+ $this->results = $this->GetResult($RequestUrl,"String");
155
+ return $this;
156
+ }
157
+
158
+ //Gets all the answers that a product exists in
159
+ Function GetProductAnswers($Sku)
160
+ {
161
+ $Sku = urlencode($Sku);
162
+ $RequestUrl = "GetProductAnswers?Sku=".$Sku."&Sitekey=".$this->SiteKey;
163
+ $this->results = $this->GetResult($RequestUrl,"QwiserProductAnswers");
164
+ return $this;
165
+ }
166
+
167
+ //Gets the full path to the best answer for this product under the selected question for the �View All� feature (in the SPD).
168
+ Function GetProductSearchPath($Sku)
169
+ {
170
+ $Sku = urlencode($Sku);
171
+ $RequestUrl = "GetProductSearchPath?Sku=".$Sku."&Sitekey=".$this->SiteKey;
172
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchPath");
173
+ return $this;
174
+ }
175
+
176
+ //Returns the answers for a specific question
177
+ Function GetQuestionAnswers($QuestionId)
178
+ {
179
+ $RequestUrl = "GetQuestionAnswers?QuestionId=".$QuestionId."&Sitekey=".$this->SiteKey;
180
+ $this->results = $this->GetResult($RequestUrl,"QwiserAnswers");
181
+ return $this;
182
+ }
183
+
184
+ //return all the question ampped to the given search profile
185
+ Function GetSearchProfileQuestions($SearchProfile)
186
+ {
187
+ $SearchProfile = urlencode($SearchProfile);
188
+ $RequestUrl = "GetSearchProfileQuestions?SearchProfile=".$SearchProfile."&Sitekey=".$this->SiteKey;
189
+ $this->results = $this->GetResult($RequestUrl,"QwiserQuestions");
190
+ return $this;
191
+ }
192
+
193
+ //Gets all the answers a collection of products exist in.
194
+ Function GetSeveralProductsAnswers($Skus)
195
+ {
196
+ $RequestUrl = "GetSeveralProductsAnswers?Skus=".$Skus."&Sitekey=".$this->SiteKey;
197
+ $this->results = $this->GetResult($RequestUrl,"QwiserProductAnswers");
198
+ return $this;
199
+ }
200
+
201
+ //Return the LastPage.
202
+ Function LastPage($SearchHandle)
203
+ {
204
+ $RequestUrl = "LastPage?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
205
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
206
+ return $this;
207
+ }
208
+
209
+ //Moves to the specified page of the results
210
+ Function MoveToPage($SearchHandle,$Page)
211
+ {
212
+ $RequestUrl = "MoveToPage?SearchHandle=".$SearchHandle."&Page=".$Page."&Sitekey=".$this->SiteKey;
213
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
214
+ return $this;
215
+ }
216
+
217
+ //Moves to the previous page of the results
218
+ Function PreviousPage($SearchHandle)
219
+ {
220
+ $RequestUrl = "PreviousPage?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
221
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
222
+ return $this;
223
+ }
224
+
225
+ //Moves to the next page of the results
226
+ Function NextPage($SearchHandle)
227
+ {
228
+ $RequestUrl = "NextPage?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
229
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
230
+ return $this;
231
+ }
232
+
233
+ //Removes the specified answer from the list of answered answers in this session.
234
+ Function RemoveAnswer($SearchHandle,$AnswerId)
235
+ {
236
+ $RequestUrl = "RemoveAnswer?SearchHandle=".$SearchHandle."&AnswerId=".$AnswerId."&Sitekey=".$this->SiteKey;
237
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
238
+ return $this;
239
+ }
240
+
241
+ //Removes the specified answers from the list of answered answers in this session.
242
+ Function RemoveAnswerAt($SearchHandle,$AnswerIndex)
243
+ {
244
+ $RequestUrl = "RemoveAnswerAt?SearchHandle=".$SearchHandle."&AnswerIndex=".$AnswerIndex."&Sitekey=".$this->SiteKey;
245
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
246
+ return $this;
247
+ }
248
+
249
+ //Removes the specified answers from the list of answered answers in this session.
250
+ Function RemoveAnswers($SearchHandle,$AnswerIds)
251
+ {
252
+ $RequestUrl = "RemoveAnswers?SearchHandle=".$SearchHandle."&AnswerIds=".$AnswerIds."&Sitekey=".$this->SiteKey;
253
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
254
+ return $this;
255
+ }
256
+
257
+ //Remove the all the answer from the search information form the given index
258
+ Function RemoveAnswersFrom($SearchHandle,$StartIndex)
259
+ {
260
+ $RequestUrl = "RemoveAnswersFrom?SearchHandle=".$SearchHandle."&StartIndex=".$StartIndex."&Sitekey=".$this->SiteKey;
261
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
262
+
263
+ return $this;
264
+ }
265
+
266
+ //Marks a product as out of stock.
267
+ Function RemoveProductFromStock($Sku)
268
+ {
269
+ $Sku = urlencode($Sku);
270
+ $RequestUrl = "RemoveProductFromStock?Sku=".$Sku."&Sitekey=".$this->SiteKey;
271
+ $this->results = $this->GetResult($RequestUrl,"String");
272
+
273
+ return $this;
274
+ }
275
+
276
+ //Marks a product as in stock.
277
+ Function RestoreProductToStock($Sku)
278
+ {
279
+ $Sku = urlencode($Sku);
280
+ $RequestUrl = "RestoreProductToStock?Sku=".$Sku."&Sitekey=".$this->SiteKey;
281
+ $this->results = $this->GetResult($RequestUrl,"String");
282
+ return $this;
283
+ }
284
+
285
+ //Gets the results for the specified search term.
286
+ Function Search($Query)
287
+ {
288
+ $Query = urlencode($Query);
289
+ $RequestUrl = "search?Query=".$Query."&sitekey=".$this->SiteKey;
290
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
291
+ return $this;
292
+ }
293
+
294
+ //Gets the results for the specified search term under the specified search profile and the answer which Id was specified.
295
+ Function SearchAdvance($Query,$SearchProfile,$AnswerId,$EffectOnSearchPath,$PriceColumn,$PageSize,$Sortingfield,$bNumericsort,$bAscending)
296
+ {
297
+ $Query = urlencode($Query);
298
+ $SearchProfile = urlencode($SearchProfile);
299
+ $Sortingfield = urlencode($Sortingfield);
300
+ $PriceColumn = urlencode($PriceColumn);
301
+ $RequestUrl = "SearchAdvance?Query=".$Query."&SearchProfile=".$SearchProfile."&AnswerId=".$AnswerId."&EffectOnSearchPath=".$EffectOnSearchPath."&PriceColumn=".$PriceColumn."&PageSize=".$PageSize."&Sortingfield=".$Sortingfield."&Numericsort=".$bNumericsort."&Ascending=".$bAscending."&sitekey=".$this->SiteKey;
302
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
303
+ return $this;
304
+ }
305
+
306
+ //set the general params of the api
307
+ Function SetQwiserSearchAPI($siteKey ,$serverName ,$port )
308
+ {
309
+ $this->SiteKey = $siteKey;
310
+ $this->HostName = $serverName;
311
+ $this->CommunicationPort = $port;
312
+ }
313
+
314
+ //Changes the sorting of the results to display products by the value of the specified field, and whether to perform a numeric sort on that field, in the specified sorting direction.
315
+ Function SortByField($SearchHandle,$FieldName,$bNumericSort,$bAscending)
316
+ {
317
+ $FieldName = urlencode($FieldName);
318
+ $RequestUrl = "SortByField?SearchHandle=".$SearchHandle."&FieldName=".$FieldName."&NumericSort=".$bNumericSort."&Ascending=".$bAscending."&sitekey=".$this->SiteKey;
319
+
320
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
321
+ return $this;
322
+ }
323
+
324
+ //Changes the sorting of the results to display products by their price in the specified sorting direction
325
+ Function SortByPrice($SearchHandle,$bAscending)
326
+ {
327
+ $RequestUrl = "SortByPrice?SearchHandle=".$SearchHandle."&Ascending=".$bAscending."&sitekey=".$this->SiteKey;
328
+
329
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
330
+ return $this;
331
+ }
332
+
333
+ //Changes the sorting of the results to display products by relevancy in descending order.
334
+ Function SortByRelevancy($SearchHandle)
335
+ {
336
+ $RequestUrl = "SortByRelevancy?SearchHandle=".$SearchHandle."&Sitekey=".$this->SiteKey;
337
+
338
+ $this->results = $this->GetResult($RequestUrl,"QwiserSearchResults");
339
+ return $this;
340
+ }
341
+
342
+ Function get_data($url)
343
+ {
344
+ $data = null;
345
+ try {
346
+ $ch = curl_init();
347
+ $timeout = 5;
348
+ curl_setopt($ch,CURLOPT_URL,$url);
349
+ curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
350
+ curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
351
+ $data = curl_exec($ch);
352
+ $curlError = curl_error($curl);
353
+ curl_close($ch);
354
+ if(!empty($curlError)) {
355
+ Mage::throwException('get_data: ' . $curlError .' Request Url: ' . $uri);
356
+ }
357
+
358
+ }
359
+ catch (Exception $e) {
360
+ Mage::logException($e);
361
+ }
362
+ return $data;
363
+ }
364
+
365
+ //Gets the xml file, parse it and chack for Errors.
366
+ Function GetResult($RequestUrl,$ReturnValue)
367
+ {
368
+ if(!$this->WebService) {
369
+ Mage::throwException(Mage::helper('salesperson')->__('Salesperson configuration error! Check saleseperson admin host general settings.'));
370
+ }
371
+
372
+ //print $this->WebService.$RequestUrl;
373
+ //get xml file from url.
374
+
375
+ //$xml_file = file_get_contents($this->WebService.$RequestUrl);
376
+ $xml_file = $this->get_data($this->WebService.$RequestUrl);
377
+
378
+ //file_get_contents return value should be true.
379
+ if(!$xml_file)
380
+ {
381
+ $this->LastOperationSucceeded = false;
382
+ $this->LastOperationErrorMessage = "Error : could not GET XML input, there might be a problem with the connection";
383
+ return;
384
+ }
385
+
386
+ //Parse the xml file with php4 Dom parser.
387
+ $xml_doc=domxml_open_mem($xml_file);
388
+
389
+ //domxml_open_mem should Return object.
390
+ if ((!is_object($xml_doc)) && !$xml_doc)
391
+ {
392
+ $this->LastOperationSucceeded = false;
393
+ $this->LastOperationErrorMessage = "Error : could not parse XML input, there might be a problem with the connection";
394
+ return ;
395
+ }
396
+
397
+ //Get the Root Element.
398
+ $xml_root=$xml_doc->document_element();
399
+
400
+ //Check the ErrorOccured node in the xml file
401
+ // if(!$this->CheckForAPIErrors($xml_root))
402
+ // {
403
+ // return ;
404
+ // }
405
+
406
+ return $this->GetReturnValue($xml_root,$ReturnValue);
407
+ }
408
+
409
+ //return value by xml type
410
+ function GetReturnValue($xml_root,$ReturnValue)
411
+ {
412
+ switch ($ReturnValue)
413
+ {
414
+ case "QwiserSearchResults":
415
+ return (new Celebros_Salesperson_Model_Api_QwiserSearchResults($xml_root));
416
+ break;
417
+ case "String":
418
+ return $this->SimpleStringParser($xml_root);
419
+ break;
420
+ case "QwiserQuestions":
421
+ return (new Celebros_Salesperson_Model_Api_QwiserQuestions(current($xml_root->get_elements_by_tagname("Questions"))));
422
+ break;
423
+ case "QwiserProductAnswers":
424
+ return (new Celebros_Salesperson_Model_Api_QwiserProductAnswers(current($xml_root->get_elements_by_tagname("ProductAnswers"))));
425
+ break;
426
+ case "QwiserProductFields":
427
+ return (new Celebros_Salesperson_Model_Api_QwiserProductFields(current($xml_root->get_elements_by_tagname("ProductFields"))));
428
+ break;
429
+ case "QwiserSearchPath":
430
+ return (new Celebros_Salesperson_Model_Api_QwiserSearchPath(current($xml_root->get_elements_by_tagname("SearchPath"))));
431
+ break;
432
+ case "QwiserAnswers":
433
+ return (new Celebros_Salesperson_Model_Api_QwiserAnswers(current($xml_root->get_elements_by_tagname("Answers"))));
434
+ break;
435
+ case "QwiserSimpleStringCollection":
436
+ return GetQwiserSimpleStringCollection(current($xml_root->get_elements_by_tagname("QwiserSimpleStringCollection")));
437
+ break;
438
+ }
439
+ }
440
+
441
+ //Checks the error node
442
+ function CheckForAPIErrors($xml_root)
443
+ {
444
+
445
+ $ErrorNode = current($xml_root->get_elements_by_tagname("LastError"));
446
+ if(is_object($ErrorNode))
447
+ {
448
+ $MethodName = $ErrorNode->get_attribute("MethodName");
449
+ if($MethodName=="")
450
+ return true;
451
+ $ErrorMessage = $ErrorNode->get_attribute("ErrorMessage");
452
+ $this->LastOperationErrorMessage = "Error: MethodName=".$MethodName." ErrorMessage=".$ErrorMessage;
453
+
454
+ $this->LastOperationSucceeded = false;
455
+
456
+ }
457
+ else {
458
+ $this->LastOperationErrorMessage = "Error: ".$xml_root->get_content();
459
+
460
+ }
461
+
462
+ return false;
463
+
464
+ }
465
+
466
+ //returns the "ReturnValue" node as string
467
+ function SimpleStringParser($xml_root)
468
+ {
469
+ $StringValue = current($xml_root->get_elements_by_tagname("ReturnValue"));
470
+ return $StringValue->get_content();
471
+ }
472
+
473
+ ///////////////////////////////////////////////////////////////////////////////
474
+
475
+ /**
476
+ * Retrieve minimum query length
477
+ *
478
+ * @deprecated after 1.3.2.3 use getMinQueryLength() instead
479
+ * @return int
480
+ */
481
+ public function getMinQueryLenght()
482
+ {
483
+ return Mage::getStoreConfig(self::XML_PATH_MIN_QUERY_LENGTH, $this->getStoreId());
484
+ }
485
+
486
+ /**
487
+ * Retrieve minimum query length
488
+ *
489
+ * @return int
490
+ */
491
+ public function getMinQueryLength(){
492
+ return $this->getMinQueryLenght();
493
+ }
494
+
495
+ /**
496
+ * Retrieve maximum query length
497
+ *
498
+ * @deprecated after 1.3.2.3 use getMaxQueryLength() instead
499
+ * @return int
500
+ */
501
+ public function getMaxQueryLenght()
502
+ {
503
+ return Mage::getStoreConfig(self::XML_PATH_MAX_QUERY_LENGTH, $this->getStoreId());
504
+ }
505
+
506
+ /**
507
+ * Retrieve maximum query length
508
+ *
509
+ * @return int
510
+ */
511
+ public function getMaxQueryLength()
512
+ {
513
+ return $this->getMaxQueryLenght();
514
+ }
515
+
516
+ /**
517
+ * Retrieve maximum query words for like search
518
+ *
519
+ * @return int
520
+ */
521
+ public function getMaxQueryWords()
522
+ {
523
+ return Mage::getStoreConfig(self::XML_PATH_MAX_QUERY_WORDS, $this->getStoreId());
524
+ }
525
+ }
526
+
527
+ //Global function: Returns Array of strings from Array of nodes contents.
528
+ function GetQwiserSimpleStringCollection ($xml_node)
529
+ {
530
+ $xml_nodes = $xml_node->child_nodes();
531
+ $xml_nodes = getDomElements($xml_nodes);
532
+ $arr = array();
533
+ foreach($xml_nodes as $node)
534
+ {
535
+ $arr[] = $node->get_content();
536
+ }
537
+ return $arr;
538
+ }
539
+
540
+ //Global function: Returns hash of value .
541
+ function GetQwiserSimpleStringDictionary($xml_node)
542
+ {
543
+ $xml_nodes = $xml_node->child_nodes();
544
+ $xml_nodes = getDomElements($xml_nodes);
545
+ $arr = array();
546
+ foreach($xml_nodes as $node)
547
+ {
548
+ $arr[$node->get_attribute("name")] = $node->get_attribute("value");
549
+ }
550
+ return $arr;
551
+ }
552
+
553
+ //Global function: Returns Array of only DomElments
554
+ function getDomElements($element)
555
+ {
556
+ $p=0;
557
+ $new_element = array();
558
+ foreach ($element as $value)
559
+ {
560
+ if($value->node_type()==1)
561
+ {
562
+ $new_element[$p]=$value;
563
+ $p++;
564
+ }
565
+ }
566
+ return $new_element;
567
+ }
app/code/local/Celebros/Salesperson/Model/Session.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_Session extends Mage_Core_Model_Session_Abstract
11
+ {
12
+ public function __construct()
13
+ {
14
+ $this->init('salesperson');
15
+ }
16
+
17
+ public function getDisplayMode()
18
+ {
19
+ return $this->_getData('display_mode');
20
+ }
21
+
22
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Backend/Export/Cron.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Backend_Export_Cron extends Mage_Core_Model_Config_Data
11
+ {
12
+ const CRON_STRING_PATH = 'crontab/jobs/salesperson_export/schedule/cron_expr';
13
+ const CRON_MODEL_PATH = 'crontab/jobs/salesperson_export/run/model';
14
+
15
+ /**
16
+ * Cron settings after save
17
+ *
18
+ * @return Celebros_Salesperson_Model_System_Config_Backend_Export_Cron
19
+ */
20
+ protected function _afterSave()
21
+ {
22
+ $enabled = $this->getData('groups/export_settings/fields/cron_enabled/value');
23
+ $cron_expr = $this->getData('groups/export_settings/fields/cron_expr/value');
24
+ try {
25
+ Mage::getModel('core/config_data')
26
+ ->load(self::CRON_STRING_PATH, 'path')
27
+ ->setValue($cron_expr)
28
+ ->setPath(self::CRON_STRING_PATH)
29
+ ->save();
30
+
31
+ Mage::getModel('core/config_data')
32
+ ->load(self::CRON_MODEL_PATH, 'path')
33
+ ->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
34
+ ->setPath(self::CRON_MODEL_PATH)
35
+ ->save();
36
+ }
37
+ catch (Exception $e) {
38
+ Mage::throwException(Mage::helper('adminhtml')->__($e.' - Unable to save Cron expression'));
39
+ }
40
+
41
+ }
42
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Fileftp.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Fileftp
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => 'file', 'label'=>Mage::helper('salesperson')->__('File')),
16
+ array('value' => 'ftp', 'label'=>Mage::helper('salesperson')->__('FTP')),
17
+ );
18
+ }
19
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Layouts.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Layouts{
11
+
12
+ protected $_options;
13
+
14
+ public function toOptionArray()
15
+ {
16
+ if (!$this->_options) {
17
+ $this->_options = array(
18
+ array( 'value'=>'salesperson/1column.phtml','label'=>'1 column'),
19
+ array( 'value'=>'salesperson/2columns-left.phtml','label'=>'2 columns with left bar'),
20
+ array( 'value'=>'salesperson/2columns-right.phtml','label'=>'2 columns with right bar'),
21
+ array( 'value'=>'salesperson/3columns.phtml','label'=>'3 columns'),
22
+ );
23
+ }
24
+ return $this->_options;
25
+ }
26
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Lead.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Lead
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => 1, 'label'=>Mage::helper('salesperson')->__('On top')),
16
+ array('value' => 0, 'label'=>Mage::helper('salesperson')->__('None')),
17
+ );
18
+ }
19
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Nonlead.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Nonlead
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => 'top', 'label'=>Mage::helper('salesperson')->__('On top')),
16
+ array('value' => 'left', 'label'=>Mage::helper('salesperson')->__('On left')),
17
+ array('value' => 'right', 'label'=>Mage::helper('salesperson')->__('On right')),
18
+ );
19
+ }
20
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Pagenavtype.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Pagenavtype
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => 'textual', 'label'=>Mage::helper('salesperson')->__('Limited')),
16
+ array('value' => 'multipage', 'label'=>Mage::helper('salesperson')->__('Full')),
17
+ );
18
+ }
19
+ }
app/code/local/Celebros/Salesperson/Model/System/Config/Source/Selectortype.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_Model_System_Config_Source_Selectortype
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => 'links', 'label'=>Mage::helper('salesperson')->__('Links')),
16
+ array('value' => 'dropdown', 'label'=>Mage::helper('salesperson')->__('Dropdown')),
17
+ );
18
+ }
19
+ }
app/code/local/Celebros/Salesperson/Model/createZip.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class createZip {
3
+ public $compressedData = array();
4
+ public $centralDirectory = array(); // central directory
5
+ public $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
6
+ public $oldOffset = 0;
7
+
8
+ public function addDirectory($directoryName) {
9
+ $directoryName = str_replace("\\", "/", $directoryName);
10
+
11
+ $feedArrayRow = "\x50\x4b\x03\x04";
12
+ $feedArrayRow .= "\x0a\x00";
13
+ $feedArrayRow .= "\x00\x00";
14
+ $feedArrayRow .= "\x00\x00";
15
+ $feedArrayRow .= "\x00\x00\x00\x00";
16
+
17
+ $feedArrayRow .= pack("V",0);
18
+ $feedArrayRow .= pack("V",0);
19
+ $feedArrayRow .= pack("V",0);
20
+ $feedArrayRow .= pack("v", strlen($directoryName) );
21
+ $feedArrayRow .= pack("v", 0 );
22
+ $feedArrayRow .= $directoryName;
23
+
24
+ $feedArrayRow .= pack("V",0);
25
+ $feedArrayRow .= pack("V",0);
26
+ $feedArrayRow .= pack("V",0);
27
+
28
+ $this -> compressedData[] = $feedArrayRow;
29
+
30
+ $newOffset = strlen(implode("", $this->compressedData));
31
+
32
+ $addCentralRecord = "\x50\x4b\x01\x02";
33
+ $addCentralRecord .="\x00\x00";
34
+ $addCentralRecord .="\x0a\x00";
35
+ $addCentralRecord .="\x00\x00";
36
+ $addCentralRecord .="\x00\x00";
37
+ $addCentralRecord .="\x00\x00\x00\x00";
38
+ $addCentralRecord .= pack("V",0);
39
+ $addCentralRecord .= pack("V",0);
40
+ $addCentralRecord .= pack("V",0);
41
+ $addCentralRecord .= pack("v", strlen($directoryName) );
42
+ $addCentralRecord .= pack("v", 0 );
43
+ $addCentralRecord .= pack("v", 0 );
44
+ $addCentralRecord .= pack("v", 0 );
45
+ $addCentralRecord .= pack("v", 0 );
46
+ $ext = "\x00\x00\x10\x00";
47
+ $ext = "\xff\xff\xff\xff";
48
+ $addCentralRecord .= pack("V", 16 );
49
+
50
+ $addCentralRecord .= pack("V", $this -> oldOffset );
51
+ $this -> oldOffset = $newOffset;
52
+
53
+ $addCentralRecord .= $directoryName;
54
+
55
+ $this -> centralDirectory[] = $addCentralRecord;
56
+ }
57
+
58
+ /**
59
+ * Function to add file(s) to the specified directory in the archive
60
+ *
61
+ * @param $directoryName string
62
+ *
63
+ */
64
+
65
+ public function addFile($data, $directoryName) {
66
+
67
+ $directoryName = str_replace("\\", "/", $directoryName);
68
+
69
+ $feedArrayRow = "\x50\x4b\x03\x04";
70
+ $feedArrayRow .= "\x14\x00";
71
+ $feedArrayRow .= "\x00\x00";
72
+ $feedArrayRow .= "\x08\x00";
73
+ $feedArrayRow .= "\x00\x00\x00\x00";
74
+
75
+ $uncompressedLength = strlen($data);
76
+ $compression = crc32($data);
77
+ $gzCompressedData = gzcompress($data);
78
+ $gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2);
79
+ $compressedLength = strlen($gzCompressedData);
80
+ $feedArrayRow .= pack("V",$compression);
81
+ $feedArrayRow .= pack("V",$compressedLength);
82
+ $feedArrayRow .= pack("V",$uncompressedLength);
83
+ $feedArrayRow .= pack("v", strlen($directoryName) );
84
+ $feedArrayRow .= pack("v", 0 );
85
+ $feedArrayRow .= $directoryName;
86
+
87
+ $feedArrayRow .= $gzCompressedData;
88
+
89
+ $feedArrayRow .= pack("V",$compression);
90
+ $feedArrayRow .= pack("V",$compressedLength);
91
+ $feedArrayRow .= pack("V",$uncompressedLength);
92
+
93
+ $this -> compressedData[] = $feedArrayRow;
94
+
95
+ $newOffset = strlen(implode("", $this->compressedData));
96
+
97
+ $addCentralRecord = "\x50\x4b\x01\x02";
98
+ $addCentralRecord .="\x00\x00";
99
+ $addCentralRecord .="\x14\x00";
100
+ $addCentralRecord .="\x00\x00";
101
+ $addCentralRecord .="\x08\x00";
102
+ $addCentralRecord .="\x00\x00\x00\x00";
103
+ $addCentralRecord .= pack("V",$compression);
104
+ $addCentralRecord .= pack("V",$compressedLength);
105
+ $addCentralRecord .= pack("V",$uncompressedLength);
106
+ $addCentralRecord .= pack("v", strlen($directoryName) );
107
+ $addCentralRecord .= pack("v", 0 );
108
+ $addCentralRecord .= pack("v", 0 );
109
+ $addCentralRecord .= pack("v", 0 );
110
+ $addCentralRecord .= pack("v", 0 );
111
+ $addCentralRecord .= pack("V", 32 );
112
+
113
+ $addCentralRecord .= pack("V", $this -> oldOffset );
114
+ $this -> oldOffset = $newOffset;
115
+
116
+ $addCentralRecord .= $directoryName;
117
+
118
+ $this -> centralDirectory[] = $addCentralRecord;
119
+ }
120
+
121
+ /**
122
+ * Fucntion to return the zip file
123
+ *
124
+ * @return zipfile (archive)
125
+ */
126
+
127
+ public function getZippedfile() {
128
+
129
+ $data = implode("", $this -> compressedData);
130
+ $controlDirectory = implode("", $this -> centralDirectory);
131
+
132
+ return
133
+ $data.
134
+ $controlDirectory.
135
+ $this -> endOfCentralDirectory.
136
+ pack("v", sizeof($this -> centralDirectory)).
137
+ pack("v", sizeof($this -> centralDirectory)).
138
+ pack("V", strlen($controlDirectory)).
139
+ pack("V", strlen($data)).
140
+ "\x00\x00";
141
+ }
142
+
143
+ /**
144
+ *
145
+ * Function to force the download of the archive as soon as it is created
146
+ *
147
+ * @param archiveName string - name of the created archive file
148
+ */
149
+
150
+ public function forceDownload($archiveName) {
151
+ $headerInfo = '';
152
+
153
+ if(ini_get('zlib.output_compression')) {
154
+ ini_set('zlib.output_compression', 'Off');
155
+ }
156
+
157
+ // Security checks
158
+ if( $archiveName == "" ) {
159
+ echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>";
160
+ exit;
161
+ }
162
+ elseif ( ! file_exists( $archiveName ) ) {
163
+ echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>";
164
+ exit;
165
+ }
166
+
167
+ header("Pragma: public");
168
+ header("Expires: 0");
169
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
170
+ header("Cache-Control: private",false);
171
+ header("Content-Type: application/zip");
172
+ header("Content-Disposition: attachment; filename=".basename($archiveName).";" );
173
+ header("Content-Transfer-Encoding: binary");
174
+ header("Content-Length: ".filesize($archiveName));
175
+ readfile("$archiveName");
176
+
177
+ }
178
+
179
+ }
180
+
181
+ ?>
app/code/local/Celebros/Salesperson/controllers/Adminhtml/MappingController.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Celebros_Salesperson_Adminhtml_MappingController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout()->renderLayout();
8
+ }
9
+
10
+ public function postAction()
11
+ {
12
+ $post = $this->getRequest()->getPost();
13
+
14
+ try {
15
+ if (empty($post)) {
16
+ Mage::throwException($this->__('Invalid form data.'));
17
+ }
18
+
19
+ /* here's your form processing */
20
+
21
+ $mappingModel = Mage::getSingleton("salesperson/mapping");
22
+
23
+ if (!key_exists('mapping',$post)) {
24
+ Mage::throwException($this->__('Invalid form data.'));
25
+ }
26
+
27
+ foreach($post['mapping'] as $key => $value){
28
+ $mappingModel->load($key);
29
+ $mappingModel->setXmlField($value);
30
+ $mappingModel->save();
31
+ }
32
+
33
+ $message = $this->__('The mapping has been saved successfully.');
34
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
35
+ } catch (Exception $e) {
36
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
37
+ }
38
+ $this->_redirect('*/*');
39
+ }
40
+ }
app/code/local/Celebros/Salesperson/controllers/ExportController.php ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author (this controller only) 3BaseGroup Co. - Miri Meltzer & Shulamit Tal (email: mirim@3basegroup.com)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_ExportController extends Mage_Core_Controller_Front_Action
11
+ {
12
+ // protected $_config;
13
+ // protected $_conn;
14
+ public function export_celebrosAction()
15
+ {
16
+ $model=Mage::getModel('salesperson/observer');
17
+ $model->export_celebros();
18
+ // $this->comments_style(1,0);
19
+ // flush();
20
+ // //-------------------
21
+ // //get the configuration
22
+ // $this->export_config($fDel,$fEnclose,$fPath,$fType,$fStore_id);
23
+ // //---------------------
24
+ // //Connect to the database
25
+ // $read = Mage::getSingleton('core/resource')->getConnection('core_read');
26
+ // //------------------------
27
+ //
28
+ // //Create the Query to get the products:getCategory_ids
29
+ // $sql="select DISTINCT entity_id,value
30
+ // from catalog_category_entity_varchar
31
+ // where attribute_id=33";
32
+ // $result=$read->fetchAll($sql);
33
+ // $categories=array();
34
+ // foreach($result as $category)
35
+ // {
36
+ // $categories[$category["entity_id"]]=$category["value"];
37
+ // }
38
+ // //------------------------------
39
+ //
40
+ // //Create the Query to get the products:getrating
41
+ // $sql="select option_id,value
42
+ // from rating_option";
43
+ // $result=$read->fetchAll($sql);
44
+ // $points=array();
45
+ // foreach($result as $option)
46
+ // {
47
+ // $points[$option["option_id"]]=$option["value"];
48
+ // }
49
+ // //select the name of the attributes
50
+ // $this->select_attributes($attributes);
51
+ // //-------------------------------
52
+ // //try
53
+ //
54
+ // $sql="select min(entity_id) as min,max(entity_id) as max
55
+ // from catalog_product_entity";
56
+ // $result=$read->fetchAll($sql);
57
+ // $min=$result[0]["min"];
58
+ // $count=$result[0]["max"]-$min+1;
59
+ // $count=$count/1000;
60
+ // if(!is_int($count))
61
+ // $count=ceil($count);
62
+ // //Begin the output
63
+ // $rat=5;
64
+ // $cate=8;
65
+ // $stock=16;
66
+ // $num=0;
67
+ // $s="";
68
+ // //print the header
69
+ // $s=$this->header($attributes,$rat,$cate,$stock,$fDel,$fEnclose);
70
+ // //select the product with the attributes
71
+ // while($count>0)
72
+ // {
73
+ // $max=$min+999;
74
+ // $select='$products_collection=Mage::getModel("catalog/product")->getCollection()';
75
+ // foreach($attributes as $key=>$value)
76
+ // $select.='->addAttributeToSelect("'.$key.'")';
77
+ // $select.='->addAttributeToSelect("category_ids")
78
+ // ->addFieldToFilter("entity_id",array("from"=>'.$min.',"to"=>'.$max.'));';
79
+ // eval($select);
80
+ // $min=$max+1;
81
+ // $count--;
82
+ // //print the content
83
+ // $num+=count($products_collection);
84
+ // foreach($products_collection as $product)
85
+ // {
86
+ // $s.=$this->content($product,$attributes,$rat,$cate,$stock,$fDel,$fEnclose,$fStore_id,$read);
87
+ // $s.="\r\n";
88
+ // }
89
+ // unset($products_collection);
90
+ // }
91
+ //
92
+ // $this->comments_style(2,$num);
93
+ // //-------------------------------
94
+ // //export
95
+ // $s=substr_replace($s,"",strlen($s)-2);
96
+ // $f=1;
97
+ // if($fType==="ftp")
98
+ // {
99
+ // $f=$this->ftpfile($fPath,$s);
100
+ // }
101
+ // else
102
+ // {
103
+ // $file='';
104
+ // if($fPath!='')
105
+ // {
106
+ // mkdir($fPath);
107
+ // $file = $fPath.'/';
108
+ // }
109
+ // $file.='products.txt';
110
+ // $writer=fopen($file,"w");
111
+ // fwrite($writer,$s);
112
+ // // Finish output
113
+ // fclose($writer);
114
+ // }
115
+ // if($f==1)
116
+ // $this->comments_style(3,0);
117
+ // $this->comments_style(4,0);
118
+ }
119
+ // //-------------------------------------------------------------------
120
+ // public function export_config(&$fDel,&$fEnclose,&$fPath,&$fType,&$fStore_id)
121
+ // {
122
+ // $fDel = Mage::getStoreConfig('salesperson/export_settings/delimiter');
123
+ // $fEnclose=Mage::getStoreConfig('salesperson/export_settings/enclosed_values');
124
+ // $fType=Mage::getStoreConfig('salesperson/export_settings/type');
125
+ // $fPath= Mage::getStoreConfig('salesperson/export_settings/path');
126
+ // $fStore_id=Mage::getStoreConfig('salesperson/export_settings/store_id');
127
+ //
128
+ //
129
+ //
130
+ // }
131
+ // //-------------------------------------------------------------------
132
+ // public function select_attributes(&$attributes)
133
+ // {
134
+ // //select requied attributes
135
+ //
136
+ // $attributesreq=array('name'=>array('text',3),'price'=>array('price',4),'url_path'=>array("",6),
137
+ // 'image'=>array('media_image',7),'type_id'=>array('text',9),'weight'=>array('text',10),
138
+ // 'manufacturer'=>array('select',11),'color'=>array('select',12),'thumbnail'=>array('media_image',13),
139
+ // 'description'=>array('textarea',14),'short_description'=>array('textarea',15),
140
+ // 'news_from_date'=>array('date',17),'news_to_date'=>array('date',18),
141
+ // 'sku'=>array('text',19),'status'=>array('select',20),'tax_class_id'=>array('select',21));
142
+ // $i=count($attributesreq)+6;//store_1d,websites,entity_id,rating,category_ides,is_in_stock
143
+ // //select searchable or filterable attribute
144
+ //
145
+ // $attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
146
+ // ->setEntityTypeFilter(4)
147
+ // ->AddFieldToFilter("is_searchable","1" or "is_filterable",array("in"=>array("1","2")))
148
+ // ->addSetInfo()
149
+ // ->getData();
150
+ // $attributessf=array();
151
+ // foreach($attributesInfo as $attribute)
152
+ // {
153
+ // $attributessf[$attribute["attribute_code"]]=array($attribute["frontend_input"],$i);
154
+ // $i++;
155
+ // }
156
+ // //Union 2 array
157
+ // $attributes=array_merge($attributessf,$attributesreq);
158
+ // }
159
+ // //-------------------------------------------------------------------
160
+ // public function comments_style($flg,$c)
161
+ // {
162
+ // switch($flg)
163
+ // {
164
+ // case 1:
165
+ // echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
166
+ // echo '<html><head><style type="text/css">
167
+ // ul { list-style-type:none; padding:0; margin:0; }
168
+ // li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
169
+ // img { margin-right:5px; }
170
+ // </style><title>Salesperson Exporter</title></head>';
171
+ // echo '<body><ul>';
172
+ // echo '<li>
173
+ // <img style="margin-right: 5px;" src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/note_msg_icon.gif" alt="start"/>
174
+ // Starting profile execution, please wait...
175
+ // </li>';
176
+ // echo '<li style="background-color: rgb(255, 255, 221);">
177
+ // <img style="margin-right: 5px;" src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/fam_bullet_error.gif" alt="warnung"/>
178
+ // Warning: Please don\'t close window during importing/exporting data
179
+ // </li>';
180
+ // break;
181
+ //
182
+ // case 2:
183
+ // echo '<li style="background-color: rgb(221, 221, 255);">
184
+ // <img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/fam_bullet_success.gif" alt="load"/>
185
+ // Loaded '.$c.' records
186
+ // </li>';
187
+ // break;
188
+ // case 3:
189
+ // echo '<li style="background-color: rgb(221, 221, 255);">
190
+ // <img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/fam_bullet_success.gif" alt="save"/>
191
+ // Saved successfully: "products.txt"
192
+ // </li>';
193
+ // break;
194
+ // default:
195
+ // echo '<li>
196
+ // <img style="margin-right: 5px; "src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/note_msg_icon.gif" alt="finished"/>
197
+ // Finished profile execution.
198
+ // </li>
199
+ // </ul>
200
+ // </body>
201
+ // </html>';
202
+ //
203
+ // }
204
+ // }
205
+ // //-------------------------------------------------------------------
206
+ // public function header($attributes,$rat,$cate,$stock,$fDel,$fEnclose)
207
+ // {
208
+ // $str="";
209
+ // $header=array();
210
+ // $name=3;
211
+ // $url_path=6;
212
+ // $image=7;
213
+ // $type_id=9;
214
+ // $manufacturer=11;
215
+ // $thumbnail=13;
216
+ // foreach($attributes as $key=>$value)
217
+ // $header[$value[1]]=$fEnclose.$key.$fEnclose;
218
+ // //---------------------------
219
+ // $header[$name]=$fEnclose.'title'.$fEnclose;
220
+ // $header[$url_path]=$fEnclose.'link'.$fEnclose;
221
+ // $header[$image]=$fEnclose.'image_link'.$fEnclose;
222
+ // $header[$type_id]=$fEnclose.'type'.$fEnclose;
223
+ // $header[$manufacturer]=$fEnclose.'brand'.$fEnclose;
224
+ // $header[$thumbnail]=$fEnclose.'thumbnail_label'.$fEnclose;
225
+ // $str.=$fEnclose.'store_id'.$fEnclose.$fDel.$fEnclose.'websites'.$fEnclose.$fDel.$fEnclose.'id'.$fEnclose.$fDel;
226
+ // $header[$rat]=$fEnclose.'rating'.$fEnclose;
227
+ // $header[$cate]=$fEnclose.'category'.$fEnclose;
228
+ // $header[$stock]=$fEnclose.'is_in_stock'.$fEnclose;
229
+ // ksort($header);
230
+ // $att= implode($fDel,$header);
231
+ // $str.=$att."\r\n";
232
+ // return $str;
233
+ // }
234
+ // //------------------------------------------------------------------
235
+ // public function content($product,$attributes,$rat,$cate,$stock,$fDel,$fEnclose,$fStore_id,$read)
236
+ // {
237
+ // $products=array();
238
+ // foreach($attributes as $key=>$value)
239
+ // {
240
+ // if($value[0]==="select")
241
+ // {
242
+ // $products[$value[1]]=$fEnclose.$product->getAttributeText($key).$fEnclose;
243
+ // }
244
+ // elseif($value[0]==="media_image")
245
+ // {
246
+ // $func='get'.$key;
247
+ // $temp=$product->{$func}();
248
+ // if($temp==='no_selection')
249
+ // $products[$value[1]]=$fEnclose.$fEnclose;
250
+ // else
251
+ // $products[$value[1]]=$fEnclose.$temp.$fEnclose;
252
+ // }
253
+ // else
254
+ // {
255
+ // $func='get'.$key;
256
+ // $products[$value[1]]=$fEnclose.$product->{$func}().$fEnclose;
257
+ // }
258
+ //
259
+ //
260
+ // }
261
+ // //------------------------------
262
+ // $sql="select website_id
263
+ // from core_store
264
+ // where store_id=".$fStore_id;
265
+ // $result=$read->fetchAll($sql);
266
+ // $website_id=$result[0]["website_id"];
267
+ // $entity_id=$product->getentity_id();
268
+ //
269
+ // //Create the Query to get the products:getWebsites
270
+ //
271
+ // $products[1]=$fEnclose;
272
+ // $sql="select web.code
273
+ // from core_website web inner join catalog_product_website product
274
+ // on web.website_id=product.website_id
275
+ // where web.website_id=".$website_id." and product.product_id=".$entity_id;
276
+ // $result=$read->fetchAll($sql);
277
+ // if(!empty($result))
278
+ // {
279
+ // foreach($result as $website)
280
+ // $products[1].=$website["code"].',';
281
+ // $products[1]=substr_replace($products[1],"",strlen($products[1])-1);
282
+ // $products[1].=$fEnclose;
283
+ //
284
+ // //Create the Query to get the products:getstore_ids
285
+ // $products[0]=$fEnclose;
286
+ // $sql="select cs.store_id
287
+ // from core_store cs inner join catalogsearch_fulltext cf
288
+ // on cs.store_id=cf.store_id
289
+ // where cs.website_id=".$website_id." and cf.product_id=".$entity_id;
290
+ // $result=$read->fetchAll($sql);
291
+ // if(!empty($result))
292
+ // {
293
+ // foreach($result as $store)
294
+ // $products[0].=$store["store_id"].',';
295
+ // $products[0]=substr_replace( $products[0],"",strlen( $products[0])-1);
296
+ // }
297
+ // $products[0].=$fEnclose;
298
+ // }
299
+ // else
300
+ // {
301
+ // $products[0]=$fEnclose.$fEnclose;
302
+ // $products[1].=$fEnclose;
303
+ // }
304
+ // $products[2]=$fEnclose.$entity_id.$fEnclose;
305
+ // //Create the Query to get the products:getRating
306
+ // $products[$rat]=$fEnclose;
307
+ // $sum=0;
308
+ // $sql="select option_id
309
+ // from rating_option_vote
310
+ // where entity_pk_value=".$entity_id;
311
+ // $result=$read->fetchAll($sql);
312
+ // if(!empty($result))
313
+ // {
314
+ // foreach($result as $option)
315
+ // $sum=$sum+$points[$option["option_id"]];
316
+ // $products[$rat].=$sum;
317
+ // }
318
+ // $products[$rat].=$fEnclose;
319
+ // //Create the Query to get the products:getcategoty
320
+ // $products[$cate]=$fEnclose;
321
+ // $getcategoties=$product->getCategory_ids();
322
+ // if(!empty($getcategoties))
323
+ // {
324
+ // foreach($getcategoties as $getcategory)
325
+ // $products[$cate].=$categories[$getcategory].',';
326
+ // $products[$cate]=substr_replace($products[$cate],"",strlen($products[$cate])-1);
327
+ // }
328
+ // $products[$cate].=$fEnclose;
329
+ // //Is_in_stock
330
+ // $products[$stock]=$fEnclose.$product->getData('stock_item')->getData('is_in_stock').$fEnclose;
331
+ // //-----------------------
332
+ // ksort($products);
333
+ // $att= implode($fDel, $products);
334
+ // return $att;
335
+ // }
336
+ // //----------------------------------------------------------------
337
+ // public function ftpfile(&$fPath,$s)
338
+ // {
339
+ // $ioConfig=array();
340
+ // $ioConfig['port']='21';
341
+ // $ioConfig['passive']='false';
342
+ // $ioConfig['password']='';
343
+ // //$ioConfig['path']='';
344
+ // if (Mage::getStoreConfig('salesperson/export_settings/ftp_host')!= '')
345
+ // {
346
+ // $ioConfig['host'] =Mage::getStoreConfig('salesperson/export_settings/ftp_host');
347
+ // }
348
+ // else
349
+ // {
350
+ // echo '<li style="background-color: rgb(255, 187, 187);"><img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif"/> Empty host specified</li>';
351
+ // return 0;
352
+ // }
353
+ // if (Mage::getStoreConfig('salesperson/export_settings/ftp_port')!= '')
354
+ // {
355
+ // $ioConfig['port'] = Mage::getStoreConfig('salesperson/export_settings/ftp_port');
356
+ // }
357
+ //
358
+ // if (Mage::getStoreConfig('salesperson/export_settings/ftp_user')!= '')
359
+ // {
360
+ // $ioConfig['user'] = Mage::getStoreConfig('salesperson/export_settings/ftp_user');
361
+ // }
362
+ // else
363
+ // {
364
+ // $ioConfig['user']='anonymous';
365
+ // $ioConfig['password']='anonymous@noserver.com';
366
+ // }
367
+ // if (Mage::getStoreConfig('salesperson/export_settings/ftp_password')!= '')
368
+ // {
369
+ // $ioConfig['password'] = Mage::getStoreConfig('salesperson/export_settings/ftp_password');
370
+ // }
371
+ //
372
+ // $ioConfig['passive'] = Mage::getStoreConfig('salesperson/export_settings/passive');
373
+ //
374
+ // if (Mage::getStoreConfig('salesperson/export_settings/path')!= '')
375
+ // {
376
+ // $ioConfig['path']= Mage::getStoreConfig('salesperson/export_settings/path');
377
+ // }
378
+ // $this->_config = $ioConfig;
379
+ // $this->_conn =ftp_connect($this->_config['host'], $this->_config['port']);
380
+ // if (!$this->_conn){
381
+ // echo '<li style="background-color: rgb(255, 187, 187);"><img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif"/> Could not establish FTP connection, invalid host or port </li>';
382
+ // return 0;
383
+ // }
384
+ // if (!ftp_login($this->_conn, $this->_config['user'], $this->_config['password']))
385
+ // {
386
+ // $this->close();
387
+ // echo '<li style="background-color: rgb(255, 187, 187);"><img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif"/> Invalid user name or password</li>';
388
+ // return 0;
389
+ // }
390
+ // if (!empty($this->_config['path']))
391
+ // {
392
+ // if (!ftp_chdir($this->_conn, $this->_config['path']))
393
+ // {
394
+ // $this->close();
395
+ // echo '<li style="background-color: rgb(255, 187, 187);"><img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif"/>Invalid path</li>';
396
+ // return 0;
397
+ // }
398
+ // }
399
+ //
400
+ // if (!ftp_pasv($this->_conn, true)) {
401
+ // $this->close();
402
+ // echo '<li style="background-color: rgb(255, 187, 187);"><img src="'.Mage::getBaseUrl().'../skin/adminhtml/default/default/images/error_msg_icon.gif"/>Invalid file transfer mode</li>';
403
+ // return 0;
404
+ // }
405
+ // $stream = tmpfile();
406
+ // fputs($stream,$s);
407
+ // fseek($stream, 0);
408
+ // $file = 'products.txt';
409
+ // ftp_fput($this->_conn,$file,$stream,FTP_BINARY);
410
+ // // Finish output
411
+ // fclose($stream);
412
+ // $this->close();
413
+ // return 1;
414
+ // }
415
+ // //----------------------------------------------------
416
+ // public function close()
417
+ // {
418
+ // return ftp_close($this->_conn);
419
+ // }
420
+ }
421
+
422
+
423
+
424
+
425
+
426
+ ?>
app/code/local/Celebros/Salesperson/controllers/IndexController.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Celebros_Salesperson_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function testModelAction() {
5
+ $mappings = Mage::getModel('salesperson/mapping')->getCollection();
6
+ foreach($mappings as $mapping){
7
+ echo '<h3>'.$mapping->getXmlField().'</h3>';
8
+ echo nl2br($mapping->getCodeField());
9
+ }
10
+ }
11
+ }
app/code/local/Celebros/Salesperson/controllers/ResultController.php ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ class Celebros_Salesperson_ResultController extends Mage_Core_Controller_Front_Action
11
+ {
12
+ const CATALOG_CATEGORY_ATTRIBUTE_ENTITY_TYPE = '9';
13
+ const CATALOG_PRODUCT_ATTRIBUTE_ENTITY_TYPE = '10';
14
+
15
+ /**
16
+ * Retrieve salesperson session
17
+ *
18
+ * @return Mage_Catalog_Model_Session
19
+ */
20
+ protected function _getSession()
21
+ {
22
+ return Mage::getSingleton('salesperson/session');
23
+ }
24
+
25
+ public function indexAction()
26
+ {
27
+ $query = Mage::helper('catalogsearch');
28
+ $query = Mage::getModel('catalogsearch/query')
29
+ ->loadByQuery(Mage::helper('salesperson')->getQueryText());
30
+ /* @var $query Mage_CatalogSearch_Model_Query */
31
+ if (!$query->getId()) {
32
+ $query->setQueryText(Mage::helper('salesperson')->getQueryText());
33
+ }
34
+
35
+ $query->setStoreId(Mage::app()->getStore()->getId());
36
+
37
+ $salesperson = Mage::helper('salesperson')->getSalespersonApi();
38
+ /* @var $query Celebros_Salesperson_Model_QwiserSearchApi */
39
+
40
+ $salesperson->setStoreId(Mage::app()->getStore()->getId());
41
+
42
+ $bNumericsort = 1;
43
+ /*
44
+ * if the sort by attribute is not numeric value then change the $bNumericsort to false
45
+ */
46
+ $defaultSortBy = Mage::getStoreConfig('catalog/frontend/default_sort_by');
47
+
48
+ //if ($sortableAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(self::CATALOG_CATEGORY_ATTRIBUTE_ENTITY_TYPE,$defaultSortBy) == null);
49
+ $sortableAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(self::CATALOG_PRODUCT_ATTRIBUTE_ENTITY_TYPE,$defaultSortBy);
50
+
51
+ if ($sortableAttribute->getBackendType() != 'int'){
52
+ $bNumericsort = 0;
53
+ }
54
+
55
+ if ($defaultSortBy == 'position' || $defaultSortBy == 'relevancy'){
56
+ $defaultSortBy = '';
57
+ }
58
+ if ($defaultSortBy == 'name'){
59
+ $defaultSortBy = 'title';
60
+ }
61
+
62
+ if (Mage::helper('salesperson')->getQueryText()) {
63
+
64
+ $salespersonSearch = $salesperson->SearchAdvance(
65
+ Mage::helper('salesperson')->getQueryText(), //Query
66
+ Mage::Helper('salesperson')->getStoreSearchProfile(),//SearchProfile
67
+ '',//AnswerId
68
+ '',//EffectOnSearchPath
69
+ 'price',//PriceColumn
70
+ Mage::Helper('salesperson')->getDefaultPageSize(),//PageSize
71
+ $defaultSortBy,//Sortingfield
72
+ $bNumericsort,
73
+ true
74
+ );
75
+
76
+ //Save the query string to the suggestion database
77
+ if (Mage::helper('salesperson')->isMinQueryLength()) {
78
+ $query->setId(0)
79
+ ->setIsActive(1)
80
+ ->setIsProcessed(1);
81
+ }
82
+ else {
83
+ if ($query->getId()) {
84
+ $query->setPopularity($query->getPopularity()+1);
85
+ }
86
+ else {
87
+ $query->setPopularity(1);
88
+ }
89
+
90
+ if ($query->getRedirect()){
91
+ $query->save();
92
+ $this->getResponse()->setRedirect($query->getRedirect());
93
+ return;
94
+ }
95
+ else {
96
+ if($salespersonSearch->results){
97
+ Mage::helper('salesperson')->prepare($query, $salespersonSearch->results->GetRelevantProductsCount());
98
+ }
99
+ }
100
+ }
101
+
102
+ if (!Mage::helper('salesperson')->isMinQueryLength()) {
103
+ $query->save();
104
+ }
105
+ //End saving query to the suggestion database
106
+
107
+ if($salespersonSearch){
108
+ //Check the results for errors & concepts
109
+ if($salespersonSearch->results->GetErrorOccurred()){
110
+ if ($salespersonSearch->results->GetErrorMessage() != ''){
111
+ $this->_getSession()->addError($this->__($salespersonSearch->results->GetErrorMessage()));
112
+ }
113
+ }
114
+ if($salespersonSearch->results->QueryConcepts->Count > 0){
115
+ foreach ($queryConcepts = $salespersonSearch->results->QueryConcepts->Items as $queryConcept){
116
+ foreach ($queryConcept->DynamicProperties as $name => $value){
117
+ $query_str = Mage::helper('salesperson')->getQueryText();
118
+ switch($name){
119
+ case "alternative products":
120
+ $msg = str_replace('{{query}}', $query_str, Mage::getStoreConfig('salesperson/display_settings/alt_message'));
121
+ $msg = str_replace('{{new_query}}', $value, $msg);
122
+ if($salespersonSearch->results->GetRelevantProductsCount() == 1 && Mage::Helper('salesperson')->goToProductOnOneResult()){
123
+ if(Mage::getStoreConfig('salesperson/display_settings/alt_message') != '') Mage::getSingleton('catalog/session')->addNotice($msg);
124
+ }
125
+ else {
126
+ if(Mage::getStoreConfig('salesperson/display_settings/alt_message') != '') $this->_getSession()->addNotice($msg);
127
+ }
128
+ break;
129
+ case "banner image":
130
+ $bannerImg = $value;
131
+ break;
132
+ case "custom message":
133
+ $customMessage = $value;
134
+ $this->_getSession()->addNotice($value);
135
+ break;
136
+ case "redirection url":
137
+ $this->getResponse()->setRedirect($value);
138
+ break;
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ //Check if there is only one result & if the store config is set to redirect
145
+ if($salespersonSearch->results->GetRelevantProductsCount() == 1){
146
+ if(Mage::Helper('salesperson')->goToProductOnOneResult()){
147
+ $this->getResponse()->setRedirect($salespersonSearch->results->Products->Items[0]->Field[Mage::Helper('salesperson/mapping')->getMapping('link')]);
148
+ }
149
+ }
150
+
151
+ //Retrieve the recommended message from the search results
152
+ Mage::helper('salesperson')->getRecommendedMessages();
153
+
154
+ //Load the results layout
155
+ $this->loadLayout();
156
+
157
+ //If banner image exists for this search add it to the layout
158
+ if (isset($bannerImg)){
159
+ Mage::Helper('salesperson')->setBannerImage($bannerImg);
160
+ }
161
+ //If custom message exists for this search add it to the layout
162
+ /*if (isset($customMessage)){
163
+ Mage::Helper('salesperson')->setCustomMessage($customMessage);
164
+ }*/
165
+ //Set the result layout according to the store config settings
166
+
167
+ $this->_getSession()->setSearchHandle($salespersonSearch->results->GetSearchHandle());
168
+ // Save the ssid in the current session for anlx in the product page
169
+ $this->_getSession()->setSearchSessionId($salespersonSearch->results->SearchInformation->SessionId);
170
+
171
+ $this->getLayout()->getBlock('root')->setTemplate(Mage::getStoreConfig('salesperson/display_settings/layout'));
172
+ if ($defaultSortBy == ''){
173
+ $defaultSortBy = 'relevancy';
174
+ }
175
+ $this->getLayout()->getBlock('product_list_toolbar')->setData('_current_grid_order', $defaultSortBy);
176
+ $this->_initLayoutMessages('salesperson/session');
177
+ $this->_initLayoutMessages('checkout/session');
178
+ $this->renderLayout();
179
+ }
180
+ else {
181
+
182
+ }
183
+ } // if (Mage::helper('salesperson')->getQueryText()) {
184
+ else {
185
+ //Redirect the user to homepage
186
+ $this->_redirectReferer();
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Every change to the results is made by this action
192
+ *
193
+ */
194
+ public function changeAction(){
195
+
196
+ if($this->getRequest()->getParam("salespersonaction") && $this->getRequest()->getParam("searchHandle")||$this->getRequest()->getParam("mode") && $this->getRequest()->getParam("searchHandle")){
197
+ $salesperson = Mage::helper('salesperson')->getSalespersonApi();
198
+ /* @var $query Celebros_Salesperson_Model_QwiserSearchApi */
199
+
200
+ $salesperson->setStoreId(Mage::app()->getStore()->getId());
201
+ //Retrieve the action type & search handle to perform on the search results
202
+ $action = $this->getRequest()->getParam("salespersonaction");
203
+ $mode=$this->getRequest()->getParam("mode");
204
+ $searchHandle = $this->getRequest()->getParam("searchHandle");
205
+ $salespersonSearch = false;
206
+ if($action)
207
+ {
208
+ switch($action)
209
+ {
210
+ case "limit":
211
+ if(!$mode)
212
+ {
213
+ $size = $this->getRequest()->getParam("size");
214
+ $salespersonSearch = $salesperson->ChangePageSize($searchHandle, $size);
215
+ break;
216
+ }
217
+ else
218
+ {
219
+ $perPageConfigKey = 'catalog/frontend/' . $mode . '_per_page_values';
220
+ $perPageValues = (string)Mage::getStoreConfig($perPageConfigKey);
221
+ $perPageValues = explode(',', $perPageValues);
222
+ $perPageValues = array_combine($perPageValues, $perPageValues);
223
+ if (Mage::getStoreConfigFlag('catalog/frontend/list_allow_all')) {
224
+ $perPageValues=$perPageValues + array('all'=>$this->__('All'));
225
+ }
226
+ $size = $this->getRequest()->getParam("size");
227
+ if(!in_array($size,$perPageValues))
228
+ {
229
+ $size=Mage::Helper('salesperson')->getDefaultPageSize();
230
+
231
+ }
232
+ $salespersonSearch = $salesperson->ChangePageSize($searchHandle, $size);
233
+ break;
234
+ }
235
+ case "sort":
236
+ $newOrder = $this->getRequest()->getParam("order");
237
+ $direction = $this->getRequest()->getParam("dir");
238
+ $direction = ($direction == 'asc') ? 1 : 0;
239
+ switch ($newOrder){
240
+ case 'price':
241
+ $salespersonSearch = $salesperson->SortByPrice($searchHandle, $direction);
242
+ break;
243
+ case 'relevancy':
244
+ $salespersonSearch = $salesperson->SortByRelevancy($searchHandle, $direction);
245
+ break;
246
+ case 'name':
247
+ $newOrder = 'title';
248
+ default:
249
+ $bNumericsort = 1;
250
+ /*
251
+ * if the sort by attribute is not numeric value then change the $bNumericsort to false
252
+ */
253
+ if ($sortableAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(self::CATALOG_CATEGORY_ATTRIBUTE_ENTITY_TYPE,$newOrder) == null);
254
+ $sortableAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(self::CATALOG_PRODUCT_ATTRIBUTE_ENTITY_TYPE,$newOrder);
255
+ if ($sortableAttribute->getBackendType() != 'int'){
256
+ $bNumericsort = 0;
257
+ }
258
+ $salespersonSearch = $salesperson->SortByField($searchHandle, $newOrder, $bNumericsort,$direction);
259
+ break;
260
+ }
261
+
262
+ break;
263
+ case "page":
264
+ $page = (int)$this->getRequest()->getParam("p") - 1;
265
+ if ($page < 0) $page = 0;
266
+ $salespersonSearch = $salesperson->MoveToPage($searchHandle, $page);
267
+ break;
268
+ case "answerQuestion":
269
+ $answerId = $this->getRequest()->getParam("answerId");
270
+ $salespersonSearch = $salesperson->AnswerQuestion($searchHandle, $answerId, 1);
271
+ break;
272
+ case "removeAnswer":
273
+ $answerId = $this->getRequest()->getParam("answerId");
274
+ $salespersonSearch = $salesperson->RemoveAnswer($searchHandle, $answerId);
275
+ Mage::getSingleton('salesperson/layer')
276
+ ->getState()->removeFilter($answerId);
277
+ break;
278
+ case "removeAllAnswers":
279
+ $answerIds = $this->getRequest()->getParam("answerIds");
280
+ if(!strpos($answerIds,',')){ //one answer
281
+ $salespersonSearch = $salesperson->RemoveAnswer($searchHandle, $answerIds);
282
+ }
283
+ else {
284
+ $answerIds = explode(',', $answerIds);
285
+ if (is_array($answerIds)){
286
+ foreach ($answerIds as $answerId){
287
+ Mage::getSingleton('salesperson/layer')
288
+ ->getState()->removeFilter($answerId);
289
+ }
290
+ $answerIds = join('%23', $answerIds);
291
+ $salespersonSearch = $salesperson->RemoveAnswers($searchHandle, $answerIds);
292
+ }
293
+ else {
294
+ $salespersonSearch = $salesperson->RemoveAnswer($searchHandle, $answerIds);
295
+ Mage::getSingleton('salesperson/layer')
296
+ ->getState()->removeFilter($answerIds);
297
+ }
298
+ }
299
+ break;
300
+ case "forceQuestion":
301
+ $questionId = $this->getRequest()->getParam('questionId');
302
+ $salespersonSearch = $salesperson->ForceQuestionAsFirst($searchHandle, $questionId);
303
+ break;
304
+
305
+ }
306
+ }
307
+ else
308
+ {
309
+ $pageSize = Mage::Helper('salesperson')->getDefaultPageSize();
310
+ if ($this->getRequest()->getParam("mode") == "list")
311
+ {
312
+ $pageSize = Mage::getStoreConfig('catalog/frontend/list_per_page');
313
+ }
314
+ if ($this->getRequest()->getParam("mode") == "grid")
315
+ {
316
+ $pageSize = Mage::getStoreConfig('catalog/frontend/list_per_page');
317
+ }
318
+ $salespersonSearch = $salesperson->ChangePageSize($searchHandle,$pageSize);
319
+ }
320
+ if($salespersonSearch){
321
+ //Check the results for errors
322
+ if($salespersonSearch->results->GetErrorOccurred()){
323
+ if ($salespersonSearch->results->GetErrorMessage() != ''){
324
+ $this->_getSession()->addError($this->__($salespersonSearch->results->GetErrorMessage()));
325
+ }
326
+ }
327
+ //Check the results for search path and update the layer state
328
+ if(count($salespersonSearch->results->SearchPath->Items) > 0){
329
+ $state = Mage::getSingleton('salesperson/layer')->getState();
330
+ foreach($salespersonSearch->results->SearchPath->Items as $searchPath){
331
+ $state->addFilter(array(
332
+ 'stage'=> $salespersonSearch->results->SearchInformation->Stage,
333
+ 'questionId' => $searchPath->QuestionId,
334
+ 'answers' => $searchPath->Answers)
335
+ );
336
+ }
337
+ }
338
+
339
+ //Check if there is only one result & if the store config is set to redirect
340
+ if($salespersonSearch->results->GetRelevantProductsCount() == 1){
341
+ if(Mage::Helper('salesperson')->goToProductOnOneResult()){
342
+ $this->_redirect($salespersonSearch->results->Products->Items[0]->Field[Mage::Helper('salesperson/mapping')->getMapping('link')]);
343
+ }
344
+ }
345
+
346
+ //Retrieve the recommended message from the search results
347
+ Mage::helper('salesperson')->getRecommendedMessages();
348
+
349
+ //Load the results layout
350
+ $this->loadLayout();
351
+
352
+ //Set the result layout according to the store config settings
353
+
354
+ $this->_getSession()->setSearchHandle($salespersonSearch->results->GetSearchHandle());
355
+ // Save the ssid in the current session for anlx in the product page
356
+ $this->_getSession()->setSearchSessionId($salespersonSearch->results->SearchInformation->SessionId);
357
+
358
+ $this->getLayout()->getBlock('root')->setTemplate(Mage::getStoreConfig('salesperson/display_settings/layout'));
359
+ $this->_initLayoutMessages('salesperson/session');
360
+ $this->_initLayoutMessages('checkout/session');
361
+ $this->renderLayout();
362
+ }
363
+
364
+ } // if($this->getRequest()->getParam("salespersonaction") && $this->getRequest()->getParam("searchHandle")){
365
+ else {
366
+ //Redirect the user to homepage
367
+ $this->_redirectReferer();
368
+ }
369
+ }
370
+
371
+ public function anlxClickAction(){
372
+ $pixel = Mage::helper('salesperson')->getSalespersonAnlxApi()->getAnlxResultProductClickFunction($this->getRequest()->getParam("product_id"));
373
+ $this->getResponse()->setBody($pixel);
374
+ //Mage::getModel('salesperson/observer')->sendProductAnlxInfo($this->getRequest()->getParam("product_id"));
375
+ }
376
+ }
app/code/local/Celebros/Salesperson/etc/config.xml ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Celebros Qwiser - Magento Extension
5
+ *
6
+ * @category Celebros
7
+ * @package Celebros_Qwiser
8
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
9
+ * svn version 318
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Celebros_Salesperson>
15
+ <version>0.1.1</version>
16
+ </Celebros_Salesperson>
17
+ </modules>
18
+ <global>
19
+ <models>
20
+ <salesperson>
21
+ <class>Celebros_Salesperson_Model</class>
22
+ <resourceModel>salesperson_mysql4</resourceModel>
23
+ </salesperson>
24
+ <core>
25
+ <rewrite>
26
+ <layout>Celebros_Salesperson_Model_Layout</layout>
27
+ </rewrite>
28
+ </core>
29
+ <salesperson_mysql4>
30
+ <class>Celebros_Salesperson_Model_Mysql4</class>
31
+ <entities>
32
+ <mapping>
33
+ <table>celebrosfieldsmapping</table>
34
+ </mapping>
35
+ </entities>
36
+ </salesperson_mysql4>
37
+ </models>
38
+ <blocks>
39
+ <salesperson>
40
+ <class>Celebros_Salesperson_Block</class>
41
+ </salesperson>
42
+ <adminhtml>
43
+ <rewrite>
44
+ <system_convert_profile_edit_tab_run>Celebros_Salesperson_Block_System_Convert_Profile_Edit_Tab_Run</system_convert_profile_edit_tab_run>
45
+ </rewrite>
46
+ </adminhtml>
47
+ </blocks>
48
+ <helpers>
49
+ <salesperson>
50
+ <class>Celebros_Salesperson_Helper</class>
51
+ </salesperson>
52
+ </helpers>
53
+ <resources>
54
+ <salesperson_setup>
55
+ <setup>
56
+ <module>Celebros_Salesperson</module>
57
+ </setup>
58
+ <connection>
59
+ <use>core_setup</use>
60
+ </connection>
61
+ </salesperson_setup>
62
+ <salesperson_write>
63
+ <connection>
64
+ <use>core_write</use>
65
+ </connection>
66
+ </salesperson_write>
67
+ <salesperson_read>
68
+ <connection>
69
+ <use>core_read</use>
70
+ </connection>
71
+ </salesperson_read>
72
+ </resources>
73
+ <events>
74
+ <!--<catalog_product_save_after>-->
75
+ <!-- <observers>-->
76
+ <!-- <Celebros_Salesperson_observer>-->
77
+ <!-- <type>singleton</type>-->
78
+ <!-- <class>salesperson/observer</class>-->
79
+ <!-- <method>updateStockConfig</method>-->
80
+ <!-- </Celebros_Salesperson_observer>-->
81
+ <!-- </observers>-->
82
+ <!--</catalog_product_save_after>-->
83
+ <!-- <sales_order_shipment_save_after>-->
84
+ <!-- <observers>-->
85
+ <!-- <Celebros_Salesperson_observer>-->
86
+ <!-- <type>singleton</type>-->
87
+ <!-- <class>salesperson/observer</class>-->
88
+ <!-- <method>updateStockShipment</method>-->
89
+ <!-- </Celebros_Salesperson_observer>-->
90
+ <!-- </observers>-->
91
+ <!-- </sales_order_shipment_save_after>-->
92
+ <!--<checkout_type_onepage_save_order_after>-->
93
+ <!-- <observers>-->
94
+ <!-- <Celebros_Salesperson_observer>-->
95
+ <!-- <type>singleton</type>-->
96
+ <!-- <class>salesperson/observer</class>-->
97
+ <!-- <method>updateStockOrder</method>-->
98
+ <!-- </Celebros_Salesperson_observer>-->
99
+ <!-- </observers>-->
100
+ <!--</checkout_type_onepage_save_order_after>-->
101
+ <catalog_controller_product_view>
102
+ <observers>
103
+ <Celebros_Salesperson_observer>
104
+ <type>singleton</type>
105
+ <class>salesperson/observer</class>
106
+ <method>sendProductAnlxInfo</method>
107
+ </Celebros_Salesperson_observer>
108
+ </observers>
109
+ </catalog_controller_product_view>
110
+ <salesperson_result_event>
111
+ <observers>
112
+ <Celebros_Salesperson_observer>
113
+ <type>singleton</type>
114
+ <class>salesperson/observer</class>
115
+ <method>sendResultAnlxInfo</method>
116
+ </Celebros_Salesperson_observer>
117
+ </observers>
118
+ </salesperson_result_event>
119
+ </events>
120
+ </global>
121
+ <admin>
122
+ <routers>
123
+ <salesperson>
124
+ <use>admin</use>
125
+ <args>
126
+ <module>Celebros_Salesperson</module>
127
+ <frontName>salesperson</frontName>
128
+ </args>
129
+ </salesperson>
130
+ </routers>
131
+ </admin>
132
+ <frontend>
133
+ <routers>
134
+ <salesperson>
135
+ <use>standard</use>
136
+ <args>
137
+ <module>Celebros_Salesperson</module>
138
+ <frontName>salesperson</frontName>
139
+ </args>
140
+ </salesperson>
141
+ </routers>
142
+ <!-- <translate>-->
143
+ <!-- <modules>-->
144
+ <!-- <Celebros_Salesperson>-->
145
+ <!-- <files>-->
146
+ <!-- <default>Celebros_Salesperson.csv</default>-->
147
+ <!-- </files>-->
148
+ <!-- </Celebros_Salesperson>-->
149
+ <!-- </modules>-->
150
+ <!-- </translate>-->
151
+ <layout>
152
+ <updates>
153
+ <salesperson>
154
+ <file>salesperson.xml</file>
155
+ </salesperson>
156
+ </updates>
157
+ </layout>
158
+ </frontend>
159
+ <adminhtml>
160
+ <translate>
161
+ <modules>
162
+ <Celebros_Salesperson>
163
+ <files>
164
+ <default>Celebros_Salesperson.csv</default>
165
+ </files>
166
+ </Celebros_Salesperson>
167
+ </modules>
168
+ </translate>
169
+ <menu>
170
+ <catalog>
171
+ <children>
172
+ <salesperson_mapping translate="title" module="salesperson">
173
+ <title>Salesperson Mapping</title>
174
+ <action>salesperson/adminhtml_mapping</action>
175
+ </salesperson_mapping>
176
+ </children>
177
+ </catalog>
178
+ </menu>
179
+ <acl>
180
+ <resources>
181
+ <all>
182
+ <title>Allow Everything</title>
183
+ </all>
184
+ <admin>
185
+ <children>
186
+ <system>
187
+ <children>
188
+ <config>
189
+ <children>
190
+ <salesperson>
191
+ <title>Celebros Salesperson Section</title>
192
+ </salesperson>
193
+ </children>
194
+ </config>
195
+ </children>
196
+ </system>
197
+ <catalog>
198
+ <children>
199
+ <salesperson_mapping>
200
+ <title>Salesperson Mapping</title>
201
+ </salesperson_mapping>
202
+ </children>
203
+ </catalog>
204
+ </children>
205
+ </admin>
206
+ </resources>
207
+ </acl>
208
+ <layout>
209
+ <updates>
210
+ <salesperson>
211
+ <file>salesperson.xml</file>
212
+ </salesperson>
213
+ </updates>
214
+ </layout>
215
+ </adminhtml>
216
+
217
+ <default>
218
+ <salesperson>
219
+ <general_settings>
220
+ <host></host>
221
+ <port></port>
222
+ <sitekey></sitekey>
223
+ </general_settings>
224
+ <export_settings>
225
+ <delimiter>\t</delimiter>
226
+ <enclosed_values>"</enclosed_values>
227
+ <type>file</type>
228
+ <path></path>
229
+ </export_settings>
230
+ <display_settings>
231
+ <layout>salesperson/3columns.phtml</layout>
232
+ <display_lead_top>On top</display_lead_top>
233
+ <display_non_lead>left</display_non_lead>
234
+ <breadcrumbs>1</breadcrumbs>
235
+ <display_image_lead_question>1</display_image_lead_question>
236
+ <max_lead_answers>4</max_lead_answers>
237
+ <max_non_lead_questions>4</max_non_lead_questions>
238
+ <max_non_lead_answers>4</max_non_lead_answers>
239
+ <max_non_lead_answers_side_nav>10</max_non_lead_answers_side_nav>
240
+ <show_product_count_in_lead_answers>1</show_product_count_in_lead_answers>
241
+ <show_product_count_in_non_lead_answers>1</show_product_count_in_non_lead_answers>
242
+ <alt_message>We do not have {{query}}, maybe you will be interested in {{new_query}}</alt_message>
243
+ <page_size_selector>dropdown</page_size_selector>
244
+ <sorting_selector>dropdown</sorting_selector>
245
+ <page_nav_type>multipage</page_nav_type>
246
+ <go_to_product_on_one_result>1</go_to_product_on_one_result>
247
+ </display_settings>
248
+ </salesperson>
249
+ </default>
250
+ <crontab>
251
+ <jobs>
252
+ <salesperson_export>
253
+ <schedule></schedule>
254
+ <run><model>salesperson/observer::catalogUpdate</model></run>
255
+ </salesperson_export>
256
+ </jobs>
257
+ </crontab>
258
+ </config>
app/code/local/Celebros/Salesperson/etc/system.xml ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Celebros Qwiser - Magento Extension
5
+ *
6
+ * @category Celebros
7
+ * @package Celebros_Qwiser
8
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
9
+ *
10
+ */
11
+ -->
12
+ <config>
13
+ <tabs>
14
+ <celebros translate="label" module="salesperson">
15
+ <label>Celebros Salesperson</label>
16
+ <sort_order>300</sort_order>
17
+ </celebros>
18
+ </tabs>
19
+ <sections>
20
+ <salesperson translate="label" module="salesperson">
21
+ <label>Salesperson Settings</label>
22
+ <tab>celebros</tab>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>0</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>0</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <groups>
29
+ <general_settings translat="label">
30
+ <label>General Settings</label>
31
+ <frontend_type>text</frontend_type>
32
+ <sort_order>0</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>0</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ <fields>
37
+ <host translate="label">
38
+ <label>Host</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>0</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>0</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </host>
45
+ <port translate="label">
46
+ <label>Port</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>10</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>0</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ </port>
53
+ <sitekey translate="label">
54
+ <label>Site Key</label>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>20</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>0</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+ </sitekey>
61
+ </fields>
62
+ </general_settings>
63
+ <export_settings translat="label">
64
+ <label>Export Data Format Settings</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>10</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>0</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ <fields>
71
+ <delimiter translate="label">
72
+ <label>Value Delimtier</label>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>0</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>0</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ <comment>(\t for tab)</comment>
79
+ </delimiter>
80
+ <enclosed_values translate="label">
81
+ <label>Enclosed Value In</label>
82
+ <frontend_type>text</frontend_type>
83
+ <sort_order>10</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>0</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ <comment>Warning! Empty value can cause problems with CSV format.</comment>
88
+ </enclosed_values>
89
+ <type translate="label">
90
+ <label>Type</label>
91
+ <frontend_type>select</frontend_type>
92
+ <source_model>salesperson/system_config_source_fileftp</source_model>
93
+ <sort_order>20</sort_order>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>0</show_in_website>
96
+ <show_in_store>1</show_in_store>
97
+ </type>
98
+ <path translate="label">
99
+ <label>Absolute Path</label>
100
+ <frontend_type>text</frontend_type>
101
+ <comment>E.g. /var/www/vhosts/yourdomain.com/var/export</comment>
102
+ <sort_order>30</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>0</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </path>
107
+ <ftp_host translate="label">
108
+ <label>FTP Host</label>
109
+ <frontend_type>text</frontend_type>
110
+ <sort_order>40</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>0</show_in_website>
113
+ <show_in_store>1</show_in_store>
114
+ <depends><type>ftp</type></depends>
115
+ </ftp_host>
116
+ <ftp_port translate="label">
117
+ <label>FTP Port</label>
118
+ <frontend_type>text</frontend_type>
119
+ <sort_order>50</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>0</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ <depends><type>ftp</type></depends>
124
+ </ftp_port>
125
+ <ftp_user translate="label">
126
+ <label>FTP User</label>
127
+ <frontend_type>text</frontend_type>
128
+ <sort_order>60</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>0</show_in_website>
131
+ <show_in_store>1</show_in_store>
132
+ <depends><type>ftp</type></depends>
133
+ </ftp_user>
134
+ <ftp_password translate="label">
135
+ <label>FTP Password</label>
136
+ <frontend_type>text</frontend_type>
137
+ <sort_order>70</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>0</show_in_website>
140
+ <show_in_store>1</show_in_store>
141
+ <depends><type>ftp</type></depends>
142
+ </ftp_password>
143
+ <passive translate="label">
144
+ <label>Passive</label>
145
+ <frontend_type>select</frontend_type>
146
+ <source_model>adminhtml/system_config_source_yesno</source_model>
147
+ <sort_order>80</sort_order>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>0</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ <depends><type>ftp</type></depends>
152
+ </passive>
153
+ <cron_enabled translate="label">
154
+ <label>Enable Cron Catalog Update</label>
155
+ <frontend_type>select</frontend_type>
156
+ <source_model>adminhtml/system_config_source_yesno</source_model>
157
+ <sort_order>81</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>0</show_in_website>
160
+ <show_in_store>1</show_in_store>
161
+ </cron_enabled>
162
+ <profile_id translate="label">
163
+ <label>Salesperson Export Profile Id</label>
164
+ <frontend_type>text</frontend_type>
165
+ <sort_order>85</sort_order>
166
+ <show_in_default>1</show_in_default>
167
+ <show_in_website>0</show_in_website>
168
+ <show_in_store>1</show_in_store>
169
+ <depends><cron_enabled>1</cron_enabled></depends>
170
+ </profile_id>
171
+ <cron_expr translate="label">
172
+ <label>Cron Expression</label>
173
+ <frontend_type>text</frontend_type>
174
+ <comment>Cron expression syntax</comment>
175
+ <backend_model>salesperson/system_config_backend_export_cron</backend_model>
176
+ <sort_order>90</sort_order>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>0</show_in_website>
179
+ <show_in_store>1</show_in_store>
180
+ <depends><cron_enabled>1</cron_enabled></depends>
181
+ </cron_expr>
182
+ </fields>
183
+ </export_settings>
184
+ <display_settings>
185
+ <label>Result Display Settings</label>
186
+ <frontend_type>text</frontend_type>
187
+ <sort_order>20</sort_order>
188
+ <show_in_default>1</show_in_default>
189
+ <show_in_website>0</show_in_website>
190
+ <show_in_store>1</show_in_store>
191
+ <fields>
192
+ <alt_message translate="label">
193
+ <label>Alternative Products Message</label>
194
+ <frontend_type>text</frontend_type>
195
+ <comment>Use {{query}}, {{new_query}} tags to display the search terms</comment>
196
+ <sort_order>0</sort_order>
197
+ <show_in_default>1</show_in_default>
198
+ <show_in_website>0</show_in_website>
199
+ <show_in_store>1</show_in_store>
200
+ </alt_message>
201
+ <layout translate="label">
202
+ <label>Page Layout</label>
203
+ <frontend_type>select</frontend_type>
204
+ <source_model>salesperson/system_config_source_layouts</source_model>
205
+ <sort_order>10</sort_order>
206
+ <show_in_default>1</show_in_default>
207
+ <show_in_website>0</show_in_website>
208
+ <show_in_store>1</show_in_store>
209
+ </layout>
210
+ <display_non_lead translate="label">
211
+ <label>Show Non Lead Questions</label>
212
+ <frontend_type>select</frontend_type>
213
+ <source_model>salesperson/system_config_source_nonlead</source_model>
214
+ <sort_order>20</sort_order>
215
+ <show_in_default>1</show_in_default>
216
+ <show_in_website>0</show_in_website>
217
+ <show_in_store>1</show_in_store>
218
+ </display_non_lead>
219
+ <display_lead translate="label">
220
+ <label>Show Lead Question</label>
221
+ <frontend_type>select</frontend_type>
222
+ <source_model>salesperson/system_config_source_lead</source_model>
223
+ <sort_order>30</sort_order>
224
+ <show_in_default>1</show_in_default>
225
+ <show_in_website>0</show_in_website>
226
+ <show_in_store>1</show_in_store>
227
+ </display_lead>
228
+ <breadcrumbs translate="label">
229
+ <label>Show Breadcrumbs</label>
230
+ <frontend_type>select</frontend_type>
231
+ <source_model>adminhtml/system_config_source_yesno</source_model>
232
+ <sort_order>80</sort_order>
233
+ <show_in_default>1</show_in_default>
234
+ <show_in_website>0</show_in_website>
235
+ <show_in_store>1</show_in_store>
236
+ </breadcrumbs>
237
+ <display_image_lead_question translate="label">
238
+ <label>Display Images In Lead Question</label>
239
+ <frontend_type>select</frontend_type>
240
+ <source_model>adminhtml/system_config_source_yesno</source_model>
241
+ <sort_order>85</sort_order>
242
+ <show_in_default>1</show_in_default>
243
+ <show_in_website>0</show_in_website>
244
+ <show_in_store>1</show_in_store>
245
+ </display_image_lead_question>
246
+ <max_lead_answers translate="label">
247
+ <label>Maximum Lead Answers</label>
248
+ <frontend_type>text</frontend_type>
249
+ <sort_order>90</sort_order>
250
+ <show_in_default>1</show_in_default>
251
+ <show_in_website>0</show_in_website>
252
+ <show_in_store>1</show_in_store>
253
+ </max_lead_answers>
254
+ <max_non_lead_questions translate="label">
255
+ <label>Maximum Non Lead Questions</label>
256
+ <frontend_type>text</frontend_type>
257
+ <sort_order>110</sort_order>
258
+ <show_in_default>1</show_in_default>
259
+ <show_in_website>0</show_in_website>
260
+ <show_in_store>1</show_in_store>
261
+ </max_non_lead_questions>
262
+ <max_non_lead_answers translate="label">
263
+ <label>Maximum Non Lead Answers</label>
264
+ <frontend_type>text</frontend_type>
265
+ <sort_order>120</sort_order>
266
+ <show_in_default>1</show_in_default>
267
+ <show_in_website>0</show_in_website>
268
+ <show_in_store>1</show_in_store>
269
+ </max_non_lead_answers>
270
+ <max_non_lead_answers_side_nav translate="label">
271
+ <label>Maximum Non Lead Answers In Side Nav</label>
272
+ <frontend_type>text</frontend_type>
273
+ <sort_order>130</sort_order>
274
+ <show_in_default>1</show_in_default>
275
+ <show_in_website>0</show_in_website>
276
+ <show_in_store>1</show_in_store>
277
+ </max_non_lead_answers_side_nav>
278
+ <show_product_count_in_lead_answers translate="label">
279
+ <label>Show Product Count In Lead Answers</label>
280
+ <frontend_type>select</frontend_type>
281
+ <source_model>adminhtml/system_config_source_yesno</source_model>
282
+ <sort_order>140</sort_order>
283
+ <show_in_default>1</show_in_default>
284
+ <show_in_website>0</show_in_website>
285
+ <show_in_store>1</show_in_store>
286
+ </show_product_count_in_lead_answers>
287
+ <show_product_count_in_non_lead_answers translate="label">
288
+ <label>Show Product Count In Non Lead Answers</label>
289
+ <frontend_type>select</frontend_type>
290
+ <source_model>adminhtml/system_config_source_yesno</source_model>
291
+ <sort_order>150</sort_order>
292
+ <show_in_default>1</show_in_default>
293
+ <show_in_website>0</show_in_website>
294
+ <show_in_store>1</show_in_store>
295
+ </show_product_count_in_non_lead_answers>
296
+ <page_size_selector translate="label">
297
+ <label>Page Size Selector Type</label>
298
+ <frontend_type>select</frontend_type>
299
+ <source_model>salesperson/system_config_source_selectortype</source_model>
300
+ <sort_order>170</sort_order>
301
+ <show_in_default>1</show_in_default>
302
+ <show_in_website>0</show_in_website>
303
+ <show_in_store>1</show_in_store>
304
+ </page_size_selector>
305
+ <sorting_selector translate="label">
306
+ <label>Sort Selector Type</label>
307
+ <frontend_type>select</frontend_type>
308
+ <source_model>salesperson/system_config_source_selectortype</source_model>
309
+ <sort_order>180</sort_order>
310
+ <show_in_default>1</show_in_default>
311
+ <show_in_website>0</show_in_website>
312
+ <show_in_store>1</show_in_store>
313
+ </sorting_selector>
314
+ <page_nav_type translate="label">
315
+ <label>Pagination</label>
316
+ <frontend_type>select</frontend_type>
317
+ <source_model>salesperson/system_config_source_pagenavtype</source_model>
318
+ <sort_order>190</sort_order>
319
+ <show_in_default>1</show_in_default>
320
+ <show_in_website>0</show_in_website>
321
+ <show_in_store>1</show_in_store>
322
+ </page_nav_type>
323
+ <go_to_product_on_one_result translate="label">
324
+ <label>Go To Product Page On One Result</label>
325
+ <frontend_type>select</frontend_type>
326
+ <source_model>adminhtml/system_config_source_yesno</source_model>
327
+ <sort_order>200</sort_order>
328
+ <show_in_default>1</show_in_default>
329
+ <show_in_website>0</show_in_website>
330
+ <show_in_store>1</show_in_store>
331
+ </go_to_product_on_one_result>
332
+ <search_profile translate="label">
333
+ <label>Search profile name</label>
334
+ <frontend_type>text</frontend_type>
335
+ <sort_order>210</sort_order>
336
+ <show_in_default>1</show_in_default>
337
+ <show_in_website>0</show_in_website>
338
+ <show_in_store>1</show_in_store>
339
+ </search_profile>
340
+ </fields>
341
+ </display_settings>
342
+ <anlx_settings>
343
+ <label>Analytics Settings</label>
344
+ <frontend_type>text</frontend_type>
345
+ <sort_order>30</sort_order>
346
+ <show_in_default>1</show_in_default>
347
+ <show_in_website>0</show_in_website>
348
+ <show_in_store>1</show_in_store>
349
+ <fields>
350
+ <ai_writer_address translate="label">
351
+ <label>Analytics Interface Server</label>
352
+ <frontend_type>text</frontend_type>
353
+ <comment>The analytics interface server address</comment>
354
+ <sort_order>0</sort_order>
355
+ <show_in_default>1</show_in_default>
356
+ <show_in_website>0</show_in_website>
357
+ <show_in_store>1</show_in_store>
358
+ </ai_writer_address>
359
+ <cid translate="label">
360
+ <label>Customer Id</label>
361
+ <frontend_type>text</frontend_type>
362
+ <sort_order>10</sort_order>
363
+ <show_in_default>1</show_in_default>
364
+ <show_in_website>0</show_in_website>
365
+ <show_in_store>1</show_in_store>
366
+ </cid>
367
+ <protocol_connection translate="label">
368
+ <label>Secure Connection</label>
369
+ <frontend_type>select</frontend_type>
370
+ <source_model>adminhtml/system_config_source_yesno</source_model>
371
+ <sort_order>20</sort_order>
372
+ <show_in_default>1</show_in_default>
373
+ <show_in_website>0</show_in_website>
374
+ <show_in_store>1</show_in_store>
375
+ </protocol_connection>
376
+ <dc translate="label">
377
+ <label>Data Collector DNS</label>
378
+ <frontend_type>text</frontend_type>
379
+ <sort_order>30</sort_order>
380
+ <show_in_default>1</show_in_default>
381
+ <show_in_website>0</show_in_website>
382
+ <show_in_store>1</show_in_store>
383
+ </dc>
384
+ </fields>
385
+ </anlx_settings>
386
+ </groups>
387
+ </salesperson>
388
+ </sections>
389
+ </config>
app/code/local/Celebros/Salesperson/sql/salesperson_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+
11
+ //echo "started"; exit();
12
+
13
+ $installer = $this;
14
+ /* @var $installer Mage_Core_Model_Resource_Setup */
15
+
16
+ $installer->startSetup();
17
+
18
+ $installer->run(
19
+ "INSERT INTO `{$this->getTable('dataflow_profile')}` (`profile_id`, `name`, `created_at`, `updated_at`, `actions_xml`, `gui_data`, `direction`, `entity_type`, `store_id`, `data_transfer`) VALUES"
20
+ ." (null, 'Salesperson Exporter', '2010-03-03 10:49:35', '2010-03-08 17:54:19',
21
+ '<action type=\"catalog/convert_adapter_product\" method=\"load\">
22
+ <var name=\"store\"><![CDATA[0]]></var>
23
+ </action>
24
+
25
+ <action type=\"salesperson/convert_parser_product\" method=\"unparse\">
26
+ <var name=\"store\"><![CDATA[0]]></var>
27
+ <var name=\"url_field\"><![CDATA[0]]></var>
28
+ </action>
29
+
30
+ <action type=\"salesperson/convert_mapper_column\" method=\"map\">
31
+ <var name=\"map\">
32
+ <map name=\"store_id\"><![CDATA[store_id]]></map>
33
+ <map name=\"websites\"><![CDATA[websites]]></map>
34
+ <map name=\"id\"><![CDATA[id]]></map>
35
+ <map name=\"name\"><![CDATA[title]]></map>
36
+ <map name=\"price\"><![CDATA[price]]></map>
37
+ <map name=\"rating\"><![CDATA[rating]]></map>
38
+ <map name=\"url_path\"><![CDATA[link]]></map>
39
+ <map name=\"thumbnail\"><![CDATA[image_link]]></map>
40
+ <map name=\"category\"><![CDATA[category]]></map>
41
+ <map name=\"type\"><![CDATA[type]]></map>
42
+ <map name=\"weight\"><![CDATA[weight]]></map>
43
+ <map name=\"manufacturer\"><![CDATA[brand]]></map>
44
+ <map name=\"color\"><![CDATA[color]]></map>
45
+ <map name=\"thumbnail_label\"><![CDATA[thumbnail_label]]></map>
46
+ <map name=\"description\"><![CDATA[description]]></map>
47
+ <map name=\"short_description\"><![CDATA[short_description]]></map>
48
+ <map name=\"is_in_stock\"><![CDATA[is_in_stock]]></map>
49
+ <map name=\"news_from_date\"><![CDATA[news_from_date]]></map>
50
+ <map name=\"news_to_date\"><![CDATA[news_to_date]]></map>
51
+ <map name=\"sku\"><![CDATA[product_sku]]></map>
52
+ <map name=\"status\"><![CDATA[status]]></map>
53
+ </var>
54
+ <var name=\"_only_specified\">true</var>
55
+ </action>
56
+
57
+ <action type=\"salesperson/convert_parser_csv\" method=\"unparse\">
58
+ <var name=\"delimiter\"><![CDATA[\t]]></var>
59
+ <var name=\"enclose\"><![CDATA[\"]]></var>
60
+ <var name=\"fieldnames\">true</var>
61
+ </action>
62
+
63
+ <action type=\"salesperson/convert_adapter_io\" method=\"save\">
64
+ <var name=\"type\">file</var>
65
+ <var name=\"path\">var/export</var>
66
+ <var name=\"filename\"><![CDATA[products.txt]]></var>
67
+ </action>',
68
+ '', NULL, '', 0, NULL);"
69
+ );
70
+
71
+
72
+
73
+
74
+ $installer->endSetup();
app/code/local/Celebros/Salesperson/sql/salesperson_setup/mysql4-upgrade-0.1.0-0.1.1.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Celebros Qwiser - Magento Extension
4
+ *
5
+ * @category Celebros
6
+ * @package Celebros_Salesperson
7
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
8
+ *
9
+ */
10
+ $installer = $this;
11
+ /* @var $installer Mage_Core_Model_Resource_Setup */
12
+
13
+ $installer->startSetup();
14
+
15
+ $installer->run("
16
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('celebrosfieldsmapping')}` (
17
+ `id` int(11) NOT NULL auto_increment,
18
+ `xml_field` VARCHAR(255) NULL,
19
+ `code_field` text,
20
+ PRIMARY KEY (`id`)
21
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
22
+
23
+ ALTER TABLE `{$this->getTable('celebrosfieldsmapping')}` ADD UNIQUE `XML_FIELD` ( `xml_field` );
24
+
25
+ INSERT INTO `{$this->getTable('celebrosfieldsmapping')}`
26
+ VALUES
27
+ (null,'title','title'),
28
+ (null, 'link', 'link'),
29
+ (null, 'status','status'),
30
+ (null, 'image_link','image_link'),
31
+ (null, 'thumbnail_label','thumbnail_label'),
32
+ (null, 'rating','rating'),
33
+ (null, 'short_description','short_description'),
34
+ (null, 'id', 'id'),
35
+ (null, 'visible', 'visible'),
36
+ (null, 'store_id', 'store_id'),
37
+ (null, 'is_in_stock', 'is_in_stock'),
38
+ (null, 'product_sku', 'sku'),
39
+ (null, 'category', 'category'),
40
+ (null, 'websites', 'websites'),
41
+ (null, 'news_from_date', 'news_from_date'),
42
+ (null, 'news_to_date', 'news_to_date') ON DUPLICATE KEY UPDATE id=id;
43
+ ");
44
+
45
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/salesperson.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <salesperson_adminhtml_mapping_index>
4
+ <update handle="salesperson_mapping_index"/>
5
+ <reference name="content">
6
+ <block type="salesperson/adminhtml_mapping" name="mapping" template="salesperson/mapping.phtml"/>
7
+ </reference>
8
+ </salesperson_adminhtml_mapping_index>
9
+ </layout>
app/design/adminhtml/default/default/template/salesperson/mapping.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?=$this->__('Mapping')?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Save Mapping</span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <form id="edit_form" name="edit_form" method="post" action="<?=$this->getUrl('*/*/post')?>">
13
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
14
+ <fieldset id="my-fieldset">
15
+ <table cellspacing="0" class="form-list">
16
+ <?php
17
+ $fields = $this->getFields();
18
+ foreach($fields as $field):
19
+ ?>
20
+ <tr>
21
+ <td class="label"><?=$this->__($field->getCodeField())?> <span class="required">*</span></td>
22
+ <td class="input-ele"><input class="input-text required-entry" name="mapping[<?php echo $field->getId() ?>]" value="<?php echo $field->getXmlField() ?>" /></td>
23
+ </tr>
24
+ <?php endforeach; ?>
25
+ </table>
26
+ </fieldset>
27
+ </form>
28
+ </div>
29
+ <script type="text/javascript">
30
+ var editForm = new varienForm('edit_form');
31
+ </script>
app/etc/modules/Celebros_Salesperson.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Celebros Qwiser - Magento Extension
5
+ *
6
+ * @category Celebros
7
+ * @package Celebros_Qwiser
8
+ * @author Omniscience Co. - Dan Aharon-Shalom (email: dan@omniscience.co.il)
9
+ *
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Celebros_Salesperson>
15
+ <active>true</active>
16
+ <codePool>local</codePool>
17
+ </Celebros_Salesperson>
18
+ </modules>
19
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Celebros_Salesperson_Site_Search</name>
4
+ <version>2.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Celebros Salesperson Site-Search provides dynamic navigation and merchandising solutions for Magento</summary>
10
+ <description>Celebros customers experience up to 500% increase in search-traffic conversion! With the introduction of this extension, Magento customers can now enjoy the same business benefits. Celebros delivers a powerful search solution, custom-built and optimized to the merchant&#x2019;s unique catalog and business needs. By using Celebros&#x2019; solutions, any e-retailer can provide visitors with the ultimate personalized shopping experience. Your visitors will get the most relevant and accurate search results using their own personal terms, thus streamlining their path to the checkout page. Celebros Salesperson is the only site search engine that can assist your visitors the way a human salesperson would in the physical world. Enhancing Magento&#x2019;s built-in textual site-search, Celebros provides a conceptual /semantic-based search that understands the context and intent of the shopper. Based on previous shoppers' actions and with a full understanding of the retailer&#x2019;s catalog structure, Celebros Salesperson delivers the most relevant and action-driven search results each and every time. Celebros&#x2019; solutions are provided as a hosted service (SaaS) and require a subscription agreement, which can be obtained by contacting Celebros.. Once an agreement is in place, Celebros, or any of its partners, will set the search solution for the merchant, so it can be made available for use by the store. The Celebros extension for Magento has two main components: A downloaded component, which is installed on the Magento server A Celebros back-end server component provided as a Cloud Service. This component processes the search requests, and feeds the intelligent search</description>
11
+ <notes>Operation of this extension requires subscription to Celebros SaS search solution.</notes>
12
+ <authors><author><name>Itai Bass</name><user>auto-converted</user><email>itaib@celebros.com</email></author></authors>
13
+ <date>2011-11-17</date>
14
+ <time>08:46:13</time>
15
+ <contents><target name="magelocal"><dir name="Celebros"><dir name="Salesperson"><dir name="Block"><dir name="Adminhtml"><file name="Mapping.php" hash="6214c4a9fd0df28d28d361b29908f5a5"/></dir><dir name="Layer"><file name="State.php" hash="3ac9652fafa75688284b72ea6309fe6e"/><file name="View.php" hash="27cb30eb1206748e144499e3e0387b1d"/></dir><dir name="Product"><dir name="List"><dir name="Toolbar"><file name="Pager.php" hash="6b843dddc306e97cdd2a0fa718cb32a6"/></dir><file name="Toolbar.php" hash="f657c5162543dc5e1e59441b195b2922"/></dir><file name="Abstract.php" hash="3fedd999fb6391de43e8486eab0f2024"/><file name="List.php" hash="7ed5b8ab44e471cdfa7f713ce4d47154"/></dir><dir name="Review"><file name="Helper.php" hash="83cab069c7e722245ea11fbefedcb8ae"/></dir><dir name="System"><dir name="Convert"><dir name="Profile"><dir name="Edit"><dir name="Tab"><file name="Run.php" hash="7642e797dd77e31ff093ff7fe67a7b2a"/></dir></dir></dir></dir></dir><file name="Layer.php" hash="b59c3419fa62b21567cba8a228bb7599"/><file name="Result.php" hash="b2c16f38cf30d5092f2bfed241c4e14d"/></dir><dir name="Helper"><dir name="Checkout"><file name="Cart.php" hash="165adfc1fc883b978dc66affcf7f74dd"/></dir><dir name="Product"><file name="Compare.php" hash="3652edf5f33a3df6374b55a061ee2331"/></dir><dir name="Wishlist"><file name="Data.php" hash="5bbe54dfc41e8955ec4a55781ce47e91"/></dir><file name="Data.php" hash="e6bbf5b90d88c00e64a3f7c30ecb93ef"/><file name="Mapping.php" hash="df95b936a10b3452249e4d0404c547c8"/></dir><dir name="Model"><dir name="Api"><dir name="Anlx"><file name="AnalyticsFunctions.php" hash="88c4c383bfe38291b2556434e9ec73f1"/><file name="DataStructure.php" hash="ed42cce6dc9c7dd82603f4a735497a5c"/><file name="DynamicProperty.php" hash="2078d662a55d6d5446f2aeb2b4edd336"/><file name="Holders.php" hash="6994a3fd05f6d3e0177515c64ba242f6"/><file name="LogRequest.php" hash="ca0e160c62df3379acde6f994088fe36"/><file name="RunLogReq.php" hash="86885ccaa37cccb2842b92f779fe2008"/><file name="StringEncoder.php" hash="27a7f13c42ea2d46b6129578a4b2848d"/><file name="ValidateResult.php" hash="5e4fde52e88d6bb96161fac8038f4221"/><file name="packetizer.php" hash="22379657a2530815f06801726db991a1"/></dir><file name="QwiserAnswer.php" hash="8aa181a8fff83dfba669469eee7bbecf"/><file name="QwiserAnswers.php" hash="81b38ccf3c3f633eb6e4a1427fd1cf59"/><file name="QwiserConcept.php" hash="78dd7c2f1b1f92c79978e01da1088b41"/><file name="QwiserConcepts.php" hash="5185ac5434bdc13668800699b32e1c49"/><file name="QwiserProduct.php" hash="6880555d64c78443b55dd31aa071080c"/><file name="QwiserProductAnswer.php" hash="3da0afc6672045fc705e62020cb1b127"/><file name="QwiserProductAnswers.php" hash="90cfc9a7f13f6cef8d6f43e4cb37bf59"/><file name="QwiserProductField.php" hash="06e2f7d4f3f91b5fdadf395410969596"/><file name="QwiserProductFields.php" hash="826b89eca6e2473152caf67580eadc76"/><file name="QwiserProducts.php" hash="ef7dcb00dec97f3b3f8481209ba77565"/><file name="QwiserQuestion.php" hash="07cc46b8ddad2ec34df32f870e57e27d"/><file name="QwiserQuestions.php" hash="a8aa109d2bcce5bc53e9e7f59391b410"/><file name="QwiserSearchPath.php" hash="d3d99cb26447eb3a6007722277a19eed"/><file name="QwiserSearchPathEntry.php" hash="6676506701d6b8835278d78c3b5efc42"/><file name="QwiserSearchResults.php" hash="3d6dcd8a5257e13634cbce8899f6a656"/><file name="QwiserSpellerInformation.php" hash="5fbd30c47c21d9e6ff3ef6c5654beb07"/><file name="SearchInformation.php" hash="65f84e813323873c91e94bad8c2168a7"/><file name="SortingOptions.php" hash="d663f08d7424d7c963f0473be3d3d726"/><file name="domxml-php4-to-php5.php" hash="136ee33875cde8b8478f6949a879b00b"/></dir><dir name="Convert"><dir name="Adapter"><file name="Io.php" hash="695f1e501b0d455e2c92efebacf0ab3d"/></dir><dir name="Mapper"><file name="Column.php" hash="1aa1bb82715c324032d5a4337499715f"/></dir><dir name="Parser"><file name="Csv.php" hash="31e6a040e9074959c25d22f82c75d3c0"/><file name="Product.php" hash="54cbec0ff157e2654690eecbaffd00b6"/></dir></dir><dir name="Layer"><file name="State.php" hash="b8827056de7acb4def27a9b78122134e"/></dir><dir name="Mysql4"><dir name="Mapping"><file name="Collection.php" hash="9317b95386aa4f5ce3513c86914f766a"/></dir><file name="Mapping.php" hash="0aa4c4101300f2352a432054c88bcd63"/><file name="Qwiser.php" hash="706d4827ee92020acffe166f34840877"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Export"><file name="Cron.php" hash="9a4def42ab118369131c05d7d51b61c1"/></dir></dir><dir name="Source"><file name="Fileftp.php" hash="1c9e80f1fe0ff1684176aa5f1ea7735e"/><file name="Layouts.php" hash="f7177558c50390ac452b5f53a5d1e7e6"/><file name="Lead.php" hash="0bedaf310dbb3953126560a996fcb6ac"/><file name="Nonlead.php" hash="76616b746e0a74b7f0ee7030d6cc610b"/><file name="Pagenavtype.php" hash="908ae05da82b93a3e5d3275222288915"/><file name="Selectortype.php" hash="202cb9d53eb75174e64b7f1e11aef812"/></dir></dir></dir><file name="Layer.php" hash="948e89cd046812cc1020c979b7ff9d80"/><file name="Layout.php" hash="2a21fb4873b5edf7f244cf7395d3e303"/><file name="Mapping.php" hash="70a94575746ada3f7f2bd603a23db93d"/><file name="Observer.php" hash="a833aef9761a8d4fa9178644687ab808"/><file name="Product.php" hash="3b626fa7735dc2bed37764c91611c103"/><file name="SalespersonAnalyticsApi.php" hash="ed5970952631f979d287050e228da534"/><file name="SalespersonSearchApi.php" hash="969e6af71e442ca5a2b60eba6a183a38"/><file name="Session.php" hash="4e11b072187bcd3d3d1ea2fb89571523"/><file name="createZip.php" hash="79186f09f8b0717728d2c5350cbbae96"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MappingController.php" hash="bd6c647edca2e70845fe0f0141c4bbfd"/></dir><file name="ExportController.php" hash="a303e33d09172b90033dda7e831f592c"/><file name="IndexController.php" hash="851bc5a3da090734ac905545ed2a4db6"/><file name="ResultController.php" hash="9e9fbd322b112d7152a7a3ab1a1812b9"/></dir><dir name="etc"><file name="config.xml" hash="ecbd9503849b4a0b856b9c00dc5cc6ee"/><file name="system.xml" hash="00af42bde903760a2f407cd84a8ce96c"/></dir><dir name="sql"><dir name="salesperson_setup"><file name="mysql4-install-0.1.0.php" hash="d8feee376615a7708a9db0b21078a2c0"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="39af40545593b6ab594fbffe8238edbf"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="salesperson.xml" hash="815dcee059d1f26047988679cb600ab2"/></dir><dir name="template"><dir name="salesperson"><file name="mapping.phtml" hash="6c0eb3afa5ebec9adaa46fa1a8bde389"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Celebros_Salesperson.xml" hash="d8204fc2e10400f85a8c732ad23d12f5"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>