Smartassistant_Integration_Tool - Version 1.0.0

Version Notes

This extension provides integration with SMARTASSISTANT Platform and gives you access to the WYSIWYG SMARTASSISTANT product advisor configurator.
SMARTASSISTANT Platform is a SaaS-solution that facilitates the fast setup and integration of interactive product advisors. The extension improves the customer experience and purchase decision journey on Magento e-commerce sites as it enables merchants to help their customers with the selection of products or services that fits their individual needs best.

The extension is free to download and install.

Download this release

Release Info

Developer SMARTASSISTANT
Extension Smartassistant_Integration_Tool
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (80) hide show
  1. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export.php +18 -0
  2. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit.php +51 -0
  3. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/BaseTab.php +57 -0
  4. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Form.php +18 -0
  5. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Fields.php +22 -0
  6. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/General.php +48 -0
  7. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Info.php +51 -0
  8. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Rules.php +55 -0
  9. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/ScheduledTasks.php +50 -0
  10. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Synchronization.php +76 -0
  11. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tabs.php +54 -0
  12. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Grid.php +89 -0
  13. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Renderer/Fieldsmap.php +26 -0
  14. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Renderer/Widget.php +9 -0
  15. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/TaskStats.php +18 -0
  16. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks.php +12 -0
  17. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks/Grid.php +84 -0
  18. app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks/Preview.php +42 -0
  19. app/code/community/Smartassistant/Smartassistant/Block/Widget.php +62 -0
  20. app/code/community/Smartassistant/Smartassistant/Helper/Attribute.php +333 -0
  21. app/code/community/Smartassistant/Smartassistant/Helper/CliRunner.php +102 -0
  22. app/code/community/Smartassistant/Smartassistant/Helper/Data.php +47 -0
  23. app/code/community/Smartassistant/Smartassistant/Helper/Exception.php +5 -0
  24. app/code/community/Smartassistant/Smartassistant/Helper/Filesystem.php +71 -0
  25. app/code/community/Smartassistant/Smartassistant/Helper/FtpConnector.php +365 -0
  26. app/code/community/Smartassistant/Smartassistant/Model/Core/CollectionIterator.php +167 -0
  27. app/code/community/Smartassistant/Smartassistant/Model/Export.php +397 -0
  28. app/code/community/Smartassistant/Smartassistant/Model/Exportfield.php +41 -0
  29. app/code/community/Smartassistant/Smartassistant/Model/Generator.php +134 -0
  30. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Export.php +9 -0
  31. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Export/Collection.php +10 -0
  32. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Exportfield.php +9 -0
  33. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Exportfield/Collection.php +10 -0
  34. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Rule.php +9 -0
  35. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Rule/Collection.php +10 -0
  36. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task.php +9 -0
  37. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Collection.php +10 -0
  38. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Config.php +9 -0
  39. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Config/Collection.php +10 -0
  40. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Log.php +9 -0
  41. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Log/Collection.php +10 -0
  42. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Status.php +9 -0
  43. app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Status/Collection.php +10 -0
  44. app/code/community/Smartassistant/Smartassistant/Model/Rule.php +101 -0
  45. app/code/community/Smartassistant/Smartassistant/Model/Rule/Condition/Combine.php +34 -0
  46. app/code/community/Smartassistant/Smartassistant/Model/Rule/Condition/Product.php +179 -0
  47. app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Day.php +43 -0
  48. app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Ftpmodes.php +18 -0
  49. app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Time.php +38 -0
  50. app/code/community/Smartassistant/Smartassistant/Model/Task.php +372 -0
  51. app/code/community/Smartassistant/Smartassistant/Model/Task/Config.php +27 -0
  52. app/code/community/Smartassistant/Smartassistant/Model/Task/Log.php +21 -0
  53. app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Config.php +9 -0
  54. app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Config/Collection.php +10 -0
  55. app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Status.php +9 -0
  56. app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Status/Collection.php +10 -0
  57. app/code/community/Smartassistant/Smartassistant/Model/Task/Status.php +45 -0
  58. app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/ExportController.php +374 -0
  59. app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/PanelController.php +67 -0
  60. app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/TasksController.php +46 -0
  61. app/code/community/Smartassistant/Smartassistant/controllers/SmartassistantController.php +15 -0
  62. app/code/community/Smartassistant/Smartassistant/etc/adminhtml.xml +62 -0
  63. app/code/community/Smartassistant/Smartassistant/etc/config.xml +124 -0
  64. app/code/community/Smartassistant/Smartassistant/etc/system.xml +170 -0
  65. app/code/community/Smartassistant/Smartassistant/etc/widget.xml +22 -0
  66. app/code/community/Smartassistant/Smartassistant/secret/oem.public.key +6 -0
  67. app/code/community/Smartassistant/Smartassistant/sql/smartassistant_setup/mysql4-install-1.0.0.php +90 -0
  68. app/design/adminhtml/default/default/layout/smartassistant.xml +15 -0
  69. app/design/adminhtml/default/default/template/smartassistant/export/loader.phtml +22 -0
  70. app/design/adminhtml/default/default/template/smartassistant/export/mapping.phtml +82 -0
  71. app/design/adminhtml/default/default/template/smartassistant/tasks/preview.phtml +91 -0
  72. app/design/adminhtml/default/default/template/smartassistant/tasks/stats.phtml +21 -0
  73. app/design/frontend/base/default/layout/smartassistant.xml +16 -0
  74. app/etc/modules/Smartassistant_Smartassistant.xml +9 -0
  75. app/locale/en_US/Smartassistant_Smartassistant.csv +114 -0
  76. package.xml +24 -0
  77. shell/smartassistant.php +92 -0
  78. skin/adminhtml/default/default/smartassistant/smartassistant.css +49 -0
  79. skin/adminhtml/default/default/smartassistant/smartassistant.js +86 -0
  80. skin/frontend/base/default/images/smartassistant/logo.png +0 -0
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_controller = 'adminhtml_export';
8
+ $this->_blockGroup = 'smartassistant';
9
+ $this->_headerText = Mage::helper('smartassistant')->__('SMARTASSISTANT CSV configurations');
10
+ $this->_addButtonLabel = Mage::helper('smartassistant')->__('Add configuration');
11
+ parent::__construct();
12
+ }
13
+
14
+ public function getCreateUrl()
15
+ {
16
+ return $this->getUrl('*/*/edit');
17
+ }
18
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'smartassistant';
11
+ $this->_controller = 'adminhtml_export';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('smartassistant')->__('Save configuration'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('smartassistant')->__('Delete configuration'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('smartassistant')->__('Save & Continue edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ if (($id=Mage::app()->getRequest()->getParam('id', null)) !== null) {
23
+ $url = $this->getUrl('*/*/generateSend', array('id' => $id));
24
+ $this->_addButton('generateSend', array(
25
+ 'label' => Mage::helper('smartassistant')->__('Generate & Send'),
26
+ 'onclick' => 'document.location=\''.$url.'\'',
27
+ ), -100);
28
+ }
29
+
30
+ $this->_formScripts[] = "function saveAndContinueEdit(url){
31
+ var tab = $$('.tab-item-link.active').first();
32
+ editForm.submit($('edit_form').action+'back/edit/tab/' + tab.name);
33
+ }";
34
+
35
+ $this->_headerText = Mage::helper('smartassistant')->__('Edit export');
36
+ }
37
+
38
+ public function getLoaderHtml()
39
+ {
40
+ $block = $this->getLayout()->createBlock('core/template');
41
+ $block->setTemplate('smartassistant/export/loader.phtml');
42
+ $block->setRunLoader(Mage::app()->getRequest()->getParam('run'));
43
+ $html = $block->toHtml();
44
+ return $html;
45
+ }
46
+
47
+ protected function _toHtml() {
48
+ return $this->getLoaderHtml() . parent::_toHtml();
49
+ }
50
+
51
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/BaseTab.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ extends Mage_Adminhtml_Block_Widget_Form
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ protected static $_export;
8
+
9
+ protected static $_isInitialized;
10
+
11
+ public function __construct() {
12
+ parent::__construct();
13
+ if (! self::$_isInitialized) {
14
+ self::_init();
15
+ }
16
+ }
17
+
18
+ protected static function _init()
19
+ {
20
+ if (($id = Mage::app()->getRequest()->getParam('id', null)) !== null) {
21
+ self::$_export = Mage::getModel('smartassistant/export')->load($id);
22
+ } else {
23
+ self::$_export = Mage::getModel('smartassistant/export');
24
+ }
25
+ self::$_isInitialized = true;
26
+ }
27
+
28
+ public function export()
29
+ {
30
+ return self::$_export;
31
+ }
32
+
33
+ public function isNew()
34
+ {
35
+ return (! $this->export()->isEmpty());
36
+ }
37
+
38
+ public function canShowTab()
39
+ {
40
+ return true;
41
+ }
42
+
43
+ public function getTabLabel()
44
+ {
45
+ return '';
46
+ }
47
+
48
+ public function getTabTitle()
49
+ {
50
+ return '';
51
+ }
52
+
53
+ public function isHidden()
54
+ {
55
+ return false;
56
+ }
57
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Form.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/edit', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ ));
13
+
14
+ $form->setUseContainer(true);
15
+ $this->setForm($form);
16
+ return parent::_prepareForm();
17
+ }
18
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Fields.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_Fields extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+
9
+ $fields = $form->addFieldset('fields', array(
10
+ 'legend' => Mage::helper('smartassistant')->__('Fields configuration'),
11
+ ));
12
+
13
+ $map = $this->export()->getMap();
14
+
15
+ $mapping = new Smartassistant_Smartassistant_Block_Adminhtml_Renderer_Fieldsmap();
16
+ $mapping->setMap($map);
17
+ $fields->setRenderer($mapping);
18
+
19
+ $this->setForm($form);
20
+ return parent::_prepareForm();
21
+ }
22
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/General.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_General extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $fieldset = $form->addFieldset('post_form', array('legend' => Mage::helper('smartassistant')->__('General export information')));
9
+
10
+
11
+ $fieldset->addField('name', 'text', array(
12
+ 'label' => Mage::helper('smartassistant')->__('Name'),
13
+ 'name' => 'name',
14
+ 'value' => $this->export()->getName(),
15
+ 'required' => true,
16
+ 'after_element_html' => '<p class="note"><span>'.Mage::helper('smartassistant')->__('Name allows you to identify the export').'</span></p>',
17
+ ));
18
+
19
+ $fieldset->addField('filename', 'text', array(
20
+ 'label' => Mage::helper('smartassistant')->__('Filename'),
21
+ 'name' => 'filename',
22
+ 'value' => $this->export()->getFilename(),
23
+ 'required' => true,
24
+ 'after_element_html' => '<p class="note"><span>'.Mage::helper('smartassistant')->__('Filename to be sent to FTP. CSV file extension (.csv) will be added.').'</span></p>',
25
+ ));
26
+
27
+ if (! Mage::app()->isSingleStoreMode()) {
28
+ $fieldset->addField('store_id', 'select', array(
29
+ 'name' => 'store_id',
30
+ 'label' => Mage::helper('smartassistant')->__('Store'),
31
+ 'title' => Mage::helper('smartassistant')->__('Store'),
32
+ 'required' => true,
33
+ 'value' => $this->export()->getStoreId(),
34
+ 'values' => Mage::getSingleton('adminhtml/system_store')
35
+ ->getStoreValuesForForm(false, false),
36
+ ));
37
+ } else {
38
+ $fieldset->addField('store_id', 'hidden', array(
39
+ 'name' => 'store_id',
40
+ 'value' => Mage::app()->getStore(true)->getId(),
41
+ 'required' => true,
42
+ ));
43
+ }
44
+
45
+ $this->setForm($form);
46
+ return parent::_prepareForm();
47
+ }
48
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Info.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_Info extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+
9
+ $fieldset = $form->addFieldset('fields', array(
10
+ 'legend' => Mage::helper('smartassistant')->__('Export generation'),
11
+ ));
12
+
13
+ $lastExportTime = $this->export()->lastExportTime();
14
+ $fieldset->addField('time', 'text', array(
15
+ 'label' => Mage::helper('smartassistant')->__('Last generated'),
16
+ 'value' => $lastExportTime ? date('y-m-d H:i:s', $lastExportTime) : Mage::helper('smartassistant')->__('No export'),
17
+ 'required' => false,
18
+ 'readonly' => true,
19
+ ));
20
+
21
+ $url = $this->getUrl('*/*/generate', array('id' => $this->export()->getId()));
22
+ $fieldset->addField('generate', 'button', array(
23
+ 'label' => Mage::helper('smartassistant')->__('Generate'),
24
+ 'value' => 'Generate',
25
+ 'required' => false,
26
+ 'readonly' => true,
27
+ 'onclick' => "document.location='".$url."'",
28
+ ));
29
+
30
+ $url = $this->getUrl('*/*/send', array('id' => $this->export()->getId()));
31
+ $fieldset->addField('send_to_server', 'button', array(
32
+ 'label' => Mage::helper('smartassistant')->__('Send to Server'),
33
+ 'value' => 'Send',
34
+ 'required' => false,
35
+ 'readonly' => true,
36
+ 'onclick' => "document.location='".$url."'",
37
+ ));
38
+
39
+ $url = $this->getUrl('*/*/download', array('id' => $this->export()->getId()));
40
+ $fieldset->addField('download', 'button', array(
41
+ 'label' => Mage::helper('smartassistant')->__('Download file'),
42
+ 'value' => 'Download',
43
+ 'required' => false,
44
+ 'readonly' => true,
45
+ 'onclick' => "document.location='".$url."'",
46
+ ));
47
+
48
+ $this->setForm($form);
49
+ return parent::_prepareForm();
50
+ }
51
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Rules.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_Rules extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ /**
6
+ * Returns status flag about this tab can be showen or not
7
+ *
8
+ * @return true
9
+ */
10
+ public function canShowTab()
11
+ {
12
+ return true;
13
+ }
14
+
15
+ /**
16
+ * Returns status flag about this tab hidden or not
17
+ *
18
+ * @return true
19
+ */
20
+ public function isHidden()
21
+ {
22
+ return false;
23
+ }
24
+
25
+ protected function _prepareForm()
26
+ {
27
+ $rules = $this->export()->getRuleModel();
28
+
29
+ $form = new Varien_Data_Form();
30
+
31
+ $form->setHtmlIdPrefix('rule_');
32
+
33
+ $rules->getConditions()->setJsFormObject('rule_conditions_fieldset');
34
+
35
+ $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
36
+ ->setTemplate('promo/fieldset.phtml')
37
+ ->setNewChildUrl(
38
+ $this->getUrl('*/*/newConditionHtml/form/rule_conditions_fieldset')
39
+ );
40
+
41
+ $fieldset = $form->addFieldset('conditions_fieldset', array(
42
+ 'legend'=>Mage::helper('smartassistant')->__('Conditions (leave blank for all products)'))
43
+ )->setRenderer($renderer);
44
+
45
+ $fieldset->addField('conditions', 'text', array(
46
+ 'name' => 'conditions',
47
+ 'label' => Mage::helper('smartassistant')->__('Conditions'),
48
+ 'title' => Mage::helper('smartassistant')->__('Conditions'),
49
+ 'required' => true,
50
+ ))->setRule($rules)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
51
+
52
+ $this->setForm($form);
53
+ return parent::_prepareForm();
54
+ }
55
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/ScheduledTasks.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_ScheduledTasks extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+
9
+ $scheduledTasks = $form->addFieldset('fields', array(
10
+ 'legend' => Mage::helper('smartassistant')->__('Schedule'),
11
+ ));
12
+
13
+ $scheduledTasks->addField('autogenerate', 'select', array(
14
+ 'name' => 'autogenerate',
15
+ 'label' => Mage::helper('smartassistant')->__('Autogenerate'),
16
+ 'value' => $this->export()->getAutogenerate(),
17
+ 'values' => Mage::getModel('adminhtml/system_config_source_enabledisable')->toOptionArray(),
18
+ ));
19
+
20
+ $scheduledTasks->addField('autosend', 'select', array(
21
+ 'name' => 'autosend',
22
+ 'label' => Mage::helper('smartassistant')->__('Autosend'),
23
+ 'value' => $this->export()->getAutosend(),
24
+ 'values' => Mage::getModel('adminhtml/system_config_source_enabledisable')->toOptionArray(),
25
+ 'disabled' => (! $this->export()->getAutogenerate()),
26
+ ));
27
+
28
+
29
+ $scheduledTasks->addField('days', 'multiselect', array(
30
+ 'label' => Mage::helper('smartassistant')->__('Days'),
31
+ 'required' => false,
32
+ 'name' => 'days',
33
+ 'values' => Mage::getSingleton('smartassistant/system_config_source_day')->toOptionArray(),
34
+ 'value' => $this->export()->getDays(),
35
+ 'disabled' => (! $this->export()->getAutogenerate()),
36
+ ));
37
+
38
+ $scheduledTasks->addField('hours', 'multiselect', array(
39
+ 'label' => Mage::helper('smartassistant')->__('Time'),
40
+ 'required' => false,
41
+ 'name' => 'hours',
42
+ 'values' => Mage::getSingleton('smartassistant/system_config_source_time')->toOptionArray(),
43
+ 'value' => $this->export()->getHours(),
44
+ 'disabled' => (! $this->export()->getAutogenerate()),
45
+ ));
46
+
47
+ $this->setForm($form);
48
+ return parent::_prepareForm();
49
+ }
50
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tab/Synchronization.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tab_Synchronization extends Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_BaseTab
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $fieldset = $form->addFieldset('post_form', array('legend' => Mage::helper('smartassistant')->__('Synchronization')));
9
+
10
+
11
+ $fieldset->addField('name', 'text', array(
12
+ 'label' => Mage::helper('smartassistant')->__('Name'),
13
+ 'name' => 'name',
14
+ 'value' => $this->export()->getName(),
15
+ 'required' => true,
16
+ ));
17
+
18
+ $fieldset->addField('filename', 'text', array(
19
+ 'label' => Mage::helper('smartassistant')->__('Filename'),
20
+ 'name' => 'filename',
21
+ 'value' => $this->export()->getFilename(),
22
+ 'required' => true,
23
+ ));
24
+
25
+ if (! Mage::app()->isSingleStoreMode()) {
26
+ $fieldset->addField('store_id', 'multiselect', array(
27
+ 'name' => 'stores[]',
28
+ 'label' => Mage::helper('smartassistant')->__('Store'),
29
+ 'title' => Mage::helper('smartassistant')->__('Store'),
30
+ 'required' => true,
31
+ 'value' => $this->export()->getStoreIds(),
32
+ 'values' => Mage::getSingleton('adminhtml/system_store')
33
+ ->getStoreValuesForForm(false, true),
34
+ ));
35
+ } else {
36
+ $fieldset->addField('store_id', 'hidden', array(
37
+ 'label' => Mage::helper('smartassistant')->__('Store'),
38
+ 'title' => Mage::helper('smartassistant')->__('Store'),
39
+ 'name' => 'stores[]',
40
+ 'value' => Mage::app()->getStore(true)->getId(),
41
+ 'required' => true,
42
+ ));
43
+ }
44
+
45
+ $fieldset->addField('active', 'select', array(
46
+ 'label' => Mage::helper('smartassistant')->__('Is active'),
47
+ 'name' => 'active',
48
+ 'value' => $this->export()->getIsActive(),
49
+ 'values' => array(
50
+ array(
51
+ 'value' => 1,
52
+ 'label' => Mage::helper('smartassistant')->__('Yes'),
53
+ ), array(
54
+ 'value' => 0,
55
+ 'label' => Mage::helper('smartassistant')->__('No'),
56
+ ),
57
+ ),
58
+ 'required' => true,
59
+ ));
60
+
61
+ $this->setForm($form);
62
+ // $form->setUseContainer(false);
63
+ return parent::_prepareForm();
64
+ }
65
+
66
+ public function getTabLabel()
67
+ {
68
+ return 'asd';
69
+ }
70
+
71
+ public function getTabTitle()
72
+ {
73
+ return 'asd 2';
74
+ }
75
+
76
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Edit/Tabs.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('export_tabs');
9
+ $this->setDestElementId('edit_form');
10
+ $this->setTitle('Export information');
11
+ }
12
+
13
+ protected function _beforeToHtml()
14
+ {
15
+ $activeTab = Mage::app()->getRequest()->getParam('tab', null);
16
+
17
+ $this->addTab('export_general', array(
18
+ 'label' => Mage::helper('smartassistant')->__('General settings'),
19
+ 'title' => Mage::helper('smartassistant')->__('General settings'),
20
+ 'content' => $this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tab_general')->toHtml(),
21
+ 'active' => ($activeTab == 'export_general'),
22
+ ));
23
+
24
+ $this->addTab('rules', array(
25
+ 'label' => Mage::helper('smartassistant')->__('Conditions'),
26
+ 'title' => Mage::helper('smartassistant')->__('Conditions'),
27
+ 'content' => $this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tab_rules')->toHtml(),
28
+ 'active' => ($activeTab == 'rules'),
29
+ ));
30
+
31
+ $this->addTab('export_fields', array(
32
+ 'label' => Mage::helper('smartassistant')->__('Attributes settings'),
33
+ 'title' => Mage::helper('smartassistant')->__('Attributes settings'),
34
+ 'content' => $this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tab_fields')->toHtml(),
35
+ 'active' => ($activeTab == 'export_fields'),
36
+ ));
37
+
38
+ $this->addTab('scheduled_tasks', array(
39
+ 'label' => Mage::helper('smartassistant')->__('Scheduled tasks'),
40
+ 'title' => Mage::helper('smartassistant')->__('Scheduled tasks'),
41
+ 'content' => $this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tab_scheduledTasks')->toHtml(),
42
+ 'active' => ($activeTab == 'scheduled_tasks'),
43
+ ));
44
+
45
+ $this->addTab('informations', array(
46
+ 'label' => Mage::helper('smartassistant')->__('Export generation'),
47
+ 'title' => Mage::helper('smartassistant')->__('Export generation'),
48
+ 'content' => $this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tab_info')->toHtml(),
49
+ 'active' => ($activeTab == 'informations'),
50
+ ));
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Export/Grid.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Export_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('smarassistant_export_grid');
9
+ $this->setDefaultSort('id');
10
+ $this->setDefaultDir('DESC');
11
+ }
12
+
13
+ protected function _prepareCollection()
14
+ {
15
+ $collection = Mage::getModel('smartassistant/export')->getCollection();
16
+ $this->setCollection($collection);
17
+ return parent::_prepareCollection();
18
+ }
19
+
20
+ protected function _prepareColumns()
21
+ {
22
+
23
+ $this->addColumn('id', array(
24
+ 'header' => Mage::helper('smartassistant')->__('ID'),
25
+ 'align' => 'right',
26
+ 'index' => 'id',
27
+ ));
28
+ $this->addColumn('name', array(
29
+ 'header' => Mage::helper('smartassistant')->__('Name'),
30
+ 'align' => 'left',
31
+ 'index' => 'name',
32
+ ));
33
+ $this->addColumn('filename', array(
34
+ 'header' => Mage::helper('smartassistant')->__('Filename'),
35
+ 'align' => 'left',
36
+ 'index' => 'filename',
37
+ ));
38
+
39
+ $this->addColumn('store_id', array(
40
+ 'header' => Mage::helper('smartassistant')->__('Website'),
41
+ 'index' => 'store_id',
42
+ 'type' => 'store',
43
+ 'width' => '100px',
44
+ 'store_view'=> true,
45
+ 'display_deleted' => true,
46
+ ));
47
+
48
+
49
+ $this->addColumn('active', array(
50
+ 'header' => Mage::helper('smartassistant')->__('Is active'),
51
+ 'align' => 'left',
52
+ 'index' => 'active',
53
+ 'type' => 'options',
54
+ 'options' => array(
55
+ '0' => Mage::helper('smartassistant')->__('No'),
56
+ '1' => Mage::helper('smartassistant')->__('Yes'),
57
+ ),
58
+ ));
59
+
60
+
61
+ $this->addColumn('action', array(
62
+ 'header' => Mage::helper('smartassistant')->__('Action'),
63
+ 'align' => 'left',
64
+ 'type' => 'action',
65
+ 'filter' => false,
66
+ 'sortable' => false,
67
+ 'getter' => 'getId',
68
+ 'actions' => array(
69
+ array(
70
+ 'caption' => Mage::helper('smartassistant')->__('Edit'),
71
+ 'url' => array(
72
+ 'base'=>'*/*/edit',
73
+ ),
74
+ 'field' => 'id'
75
+ )
76
+ ),
77
+ 'is_system' => true
78
+ ));
79
+
80
+ return parent::_prepareColumns();
81
+ }
82
+
83
+ public function getRowUrl($row)
84
+ {
85
+ return $this->getUrl('*/*/edit', array(
86
+ 'id' => $row->getId()
87
+ ));
88
+ }
89
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Renderer/Fieldsmap.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Renderer_Fieldsmap
4
+ implements Varien_Data_Form_Element_Renderer_Interface
5
+ {
6
+ private $_map;
7
+
8
+ public function render(\Varien_Data_Form_Element_Abstract $element)
9
+ {
10
+ return Mage::app()->getLayout()
11
+ ->createBlock('adminhtml/template')
12
+ ->setData('map', $this->getMap())
13
+ ->setTemplate('smartassistant/export/mapping.phtml')
14
+ ->toHtml();
15
+ }
16
+
17
+ public function setMap($map)
18
+ {
19
+ $this->_map = $map;
20
+ }
21
+
22
+ public function getMap()
23
+ {
24
+ return $this->_map;
25
+ }
26
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Renderer/Widget.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Renderer_Widget extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
4
+ {
5
+ public function render(\Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ return '<input type="hidden" name="parameters[unique]" value="'.uniqid().'" style="display:none;">';
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/TaskStats.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Smartassistant_Smartassistant_Block_Adminhtml_TaskStats extends Mage_Core_Block_Template
5
+ {
6
+ public function _construct()
7
+ {
8
+ parent::_construct();
9
+ $this->setTemplate('smartassistant/tasks/stats.phtml');
10
+ }
11
+
12
+ protected function _toHtml()
13
+ {
14
+ $task = Mage::getModel('smartassistant/task')->load($this->getTaskId());
15
+ $this->setStats($task->getStats());
16
+ return parent::_toHtml();
17
+ }
18
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Tasks extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_controller = 'adminhtml_tasks';
8
+ $this->_blockGroup = 'smartassistant';
9
+ $this->_headerText = Mage::helper('smartassistant')->__('SMARTASSISTANT tasks');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks/Grid.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Tasks_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('smarassistant_export_grid');
9
+ $this->setDefaultSort('id');
10
+ $this->setDefaultDir('DESC');
11
+ }
12
+
13
+ protected function _prepareCollection()
14
+ {
15
+ $taskConfigTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/task_config');
16
+ $taskStatusTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/task_status');
17
+
18
+ $collection = Mage::getModel('smartassistant/task')->getCollection();
19
+ $select = $collection->getSelect();
20
+ $select->join(array("ts" => $taskStatusTable), "main_table.status_id = ts.id", array('task_status' => 'ts.name'));
21
+ $select->join(array("tc" => $taskConfigTable), "main_table.id = tc.task_id", array('configs_amount' => 'count(tc.id)'));
22
+ $select->group(array(
23
+ 'main_table.id', 'main_table.time', 'ts.name', 'ts.name'
24
+ ));
25
+
26
+ $this->setCollection($collection);
27
+ return parent::_prepareCollection();
28
+ }
29
+
30
+ protected function _prepareColumns()
31
+ {
32
+ $this->addColumn('id', array(
33
+ 'header' => Mage::helper('smartassistant')->__('ID'),
34
+ 'align' => 'right',
35
+ 'index' => 'id',
36
+ ));
37
+
38
+ $this->addColumn('status', array(
39
+ 'header' => Mage::helper('smartassistant')->__('Status'),
40
+ 'align' => 'left',
41
+ 'index' => 'task_status',
42
+ ));
43
+
44
+ $this->addColumn('configs_amount', array(
45
+ 'header' => Mage::helper('smartassistant')->__('Configs amount'),
46
+ 'align' => 'right',
47
+ 'index' => 'configs_amount',
48
+ ));
49
+
50
+ $this->addColumn('time', array(
51
+ 'header' => Mage::helper('smartassistant')->__('Time'),
52
+ 'align' => 'right',
53
+ 'index' => 'time',
54
+ ));
55
+
56
+ $this->addColumn('action', array(
57
+ 'header' => Mage::helper('smartassistant')->__('Action'),
58
+ 'align' => 'left',
59
+ 'type' => 'action',
60
+ 'filter' => false,
61
+ 'sortable' => false,
62
+ 'getter' => 'getId',
63
+ 'actions' => array(
64
+ array(
65
+ 'caption' => Mage::helper('smartassistant')->__('Preview'),
66
+ 'url' => array(
67
+ 'base'=>'*/*/preview',
68
+ ),
69
+ 'field' => 'id'
70
+ )
71
+ ),
72
+ 'is_system' => true
73
+ ));
74
+
75
+ return parent::_prepareColumns();
76
+ }
77
+
78
+ public function getRowUrl($row)
79
+ {
80
+ return $this->getUrl('*/*/edit', array(
81
+ 'id' => $row->getId()
82
+ ));
83
+ }
84
+ }
app/code/community/Smartassistant/Smartassistant/Block/Adminhtml/Tasks/Preview.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Adminhtml_Tasks_Preview extends Mage_Adminhtml_Block_Abstract
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setTemplate('smartassistant/tasks/preview.phtml');
9
+ }
10
+
11
+ public function getBackUrl()
12
+ {
13
+ return Mage::helper('adminhtml')->getUrl('*/*/');
14
+ }
15
+
16
+ public function getStatusUrl()
17
+ {
18
+ return Mage::helper('adminhtml')->getUrl('*/*/stats');
19
+ }
20
+
21
+ public function getTaskId()
22
+ {
23
+ return Mage::app()->getRequest()->getParam('id', null);
24
+ }
25
+
26
+ public function getTaskRefreshInterval()
27
+ {
28
+ return '5000';
29
+ }
30
+
31
+ public function getTask()
32
+ {
33
+ return Mage::getModel('smartassistant/task')->load($this->getTaskId());
34
+ }
35
+
36
+ public function getStatsBlock()
37
+ {
38
+ $block = $this->getLayout()->createBlock('smartassistant/adminhtml_taskStats');
39
+ $block->setTaskId($this->getTaskId());
40
+ return $block;
41
+ }
42
+ }
app/code/community/Smartassistant/Smartassistant/Block/Widget.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Block_Widget extends Mage_Core_Block_Abstract implements Mage_Widget_Block_Interface
4
+ {
5
+ private $_containerId;
6
+
7
+ public function isEnable()
8
+ {
9
+ $enable = Mage::getStoreConfig('smartassistant/advisor/enable');
10
+ $path = $this->getContextPath();
11
+ $code = $this->getCode();
12
+ return ($enable && ! empty($path) && ! empty($code));
13
+ }
14
+
15
+ public function getContextPath()
16
+ {
17
+ return Mage::getStoreConfig('smartassistant/advisor/contextPath');
18
+ }
19
+
20
+ public function getCode()
21
+ {
22
+ return $this->getData('code');
23
+ }
24
+
25
+ public function getContainerId()
26
+ {
27
+ if ($this->_containerId === null) {
28
+ $this->_containerId = 'advisor-container-' . substr($this->getNameInLayout(), strlen('ANONYMUS_') + 1);
29
+ }
30
+
31
+ return $this->_containerId;
32
+ }
33
+
34
+ public function getJs()
35
+ {
36
+ $js = '<script type="text/javascript">
37
+ if(SmartAssistant){
38
+ smrt42_jquery(function() {
39
+ SmartAssistant.integrate({
40
+ "divId" : "'.$this->getContainerId().'",
41
+ "advisorContextPath" : "'.$this->getContextPath().'",
42
+ "advisorCode" : "'.$this->getCode().'",
43
+ "disableTracking" : false
44
+ });
45
+ });
46
+ }
47
+ </script>';
48
+ return $js;
49
+ }
50
+
51
+ protected function _toHtml()
52
+ {
53
+ if (! $this->isEnable()) {
54
+ return '';
55
+ }
56
+
57
+ $layout = $this->getLayout();
58
+ $body = $layout->getBlock('before_body_end');
59
+ $body->append($layout->createBlock('core/text', $this->getContainerId())->setText($this->getJs()));
60
+ return '<div id="' . $this->getContainerId() . '"></div>';
61
+ }
62
+ }
app/code/community/Smartassistant/Smartassistant/Helper/Attribute.php ADDED
@@ -0,0 +1,333 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_Attribute extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * @var array Additional attribute list
7
+ */
8
+ private $_additionalAttributes = array(
9
+ 'entity_id' => 'Product Id',
10
+ 'is_in_stock' => 'Is In Stock',
11
+ 'qty' => 'Qty',
12
+ 'image' => 'Image',
13
+ 'category' => 'Category Name',
14
+ 'category_id' => 'Category Id',
15
+ 'final_price' => 'Final Price',
16
+ 'store_price' => 'Store Price',
17
+ 'url' => 'Product url',
18
+ );
19
+
20
+ /**
21
+ * Retreive available attributes
22
+ *
23
+ * @return array
24
+ */
25
+ public function getAttributes()
26
+ {
27
+ $attributes = $this->getProductAttributes();
28
+ foreach ($this->_additionalAttributes as $code => $label) {
29
+ $attributes[$code] = array(
30
+ 'label' => Mage::helper('smartassistant')->__($label),
31
+ 'value' => $code,
32
+ );
33
+ }
34
+ return $attributes;
35
+ }
36
+
37
+ /**
38
+ * Retreive product attributes list
39
+ *
40
+ * @return array
41
+ */
42
+ public function getProductAttributes()
43
+ {
44
+ $result = array();
45
+
46
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
47
+ ->addFieldToFilter('attribute_code', array('nin' => array('gallery', 'media_gallery')));
48
+
49
+ foreach ($attributes as $attribute) {
50
+ if ($attribute->getFrontendLabel()) {
51
+ $label = $attribute->getFrontendLabel();
52
+ $code = $attribute->getAttributeCode();
53
+ $result[$code] = array(
54
+ 'label' => $label,
55
+ 'value' => $code,
56
+ );
57
+ }
58
+ }
59
+
60
+ return $result;
61
+ }
62
+
63
+ /**
64
+ * Prepare array with grouped attributes
65
+ *
66
+ * @param array $attributes
67
+ * @return array
68
+ */
69
+ public function getGroupedAttributes($attributes)
70
+ {
71
+ $groupedAttributes = array();
72
+
73
+ $group = '';
74
+
75
+ $primary = array(
76
+ 'entity_id',
77
+ 'full_description',
78
+ 'meta_description',
79
+ 'meta_keyword',
80
+ 'meta_title',
81
+ 'name',
82
+ 'short_description',
83
+ 'description',
84
+ 'sku',
85
+ 'status',
86
+ 'visibility',
87
+ );
88
+
89
+ $stock = array(
90
+ 'is_in_stock',
91
+ 'qty'
92
+ );
93
+
94
+ $price = array(
95
+ 'special_from_date',
96
+ 'special_to_date',
97
+ );
98
+
99
+ foreach ($attributes as $attribute) {
100
+
101
+ $attributeCode = $attribute['value'];
102
+ if (substr($attributeCode, 0, strlen('custom:')) == 'custom:') {
103
+ $group = Mage::helper('smartassistant')->__('Custom Attributes');
104
+ $groupKey = '1';
105
+ } elseif (substr($attributeCode, 0, strlen('mapping:')) == 'mapping:') {
106
+ $group = Mage::helper('smartassistant')->__('Mapping');
107
+ $groupKey = '2';
108
+ } elseif (strpos($attributeCode, 'ammeta') !== false ) {
109
+ $group = Mage::helper('smartassistant')->__('Amasty Meta Tags');
110
+ $groupKey = '3';
111
+ } elseif (in_array($attributeCode, $primary)) {
112
+ $group = Mage::helper('smartassistant')->__('Primary Attributes');
113
+ $groupKey = '4';
114
+ } elseif (in_array($attributeCode, $stock)) {
115
+ $group = Mage::helper('smartassistant')->__('Stock Attributes');
116
+ $groupKey = '5';
117
+ } elseif (in_array($attributeCode, $price) || strpos($attributeCode, 'price') !== false) {
118
+ $group = Mage::helper('smartassistant')->__('Prices & Taxes');
119
+ $groupKey = '6';
120
+ } elseif (strpos($attributeCode, 'image') !== false || strpos($attributeCode, 'thumbnail') !== false) {
121
+ $group = Mage::helper('smartassistant')->__('Images');
122
+ $groupKey = '7';
123
+ } elseif (strpos($attributeCode, 'category') !== false ) {
124
+ $group = Mage::helper('smartassistant')->__('Category');
125
+ $groupKey = '8';
126
+ } else {
127
+ $group = Mage::helper('smartassistant')->__('Others Attributes');
128
+ $groupKey = '9';
129
+ }
130
+
131
+ if (! isset($groupedAttributes[$groupKey])) {
132
+ $groupedAttributes[$groupKey] = array(
133
+ 'label' => $group,
134
+ 'items' => array(),
135
+ );
136
+ }
137
+
138
+ $groupedAttributes[$groupKey]['items'][] = $attribute;
139
+ }
140
+
141
+ ksort($groupedAttributes);
142
+
143
+ return $groupedAttributes;
144
+ }
145
+
146
+ /**
147
+ * Return value of attribute for given product
148
+ *
149
+ * @param Mage_Catalog_Model_Product $product
150
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
151
+ * @return mixed
152
+ */
153
+ public function getAttributeValue($product, $field)
154
+ {
155
+ $code = $field->getAttributeCode();
156
+ $getter = 'get' . uc_words($code, '');
157
+
158
+ if (method_exists($this, $getter)) {
159
+ $value = $this->$getter($product, $field);
160
+ $value = empty($value) ? $field->getWhenEmpty() : $value;
161
+ return $value;
162
+ }
163
+
164
+ $getter = 'get' . uc_words($code, '');
165
+ $value = $product->$getter();
166
+ $value = empty($value) ? $field->getWhenEmpty() : $value;
167
+
168
+ return $value;
169
+ }
170
+
171
+ /**
172
+ * Get value of entity_id attribute id for given item
173
+ *
174
+ * @param Mage_Catalog_Model_Product $product
175
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
176
+ * @return mixed
177
+ */
178
+ private function getEntityId($product, $field)
179
+ {
180
+ return $product->getId();
181
+ }
182
+
183
+ /**
184
+ * Get value of is_in_stock attribute id for given item
185
+ *
186
+ * @param Mage_Catalog_Model_Product $product
187
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
188
+ * @return mixed
189
+ */
190
+ private function getIsInStock($product, $field)
191
+ {
192
+ $stockItem = $product->getStockItem();
193
+ $isInStock = $stockItem->getIsInStock();
194
+ return $isInStock;
195
+ }
196
+
197
+ /**
198
+ * Get value of qty attribute id for given item
199
+ *
200
+ * @param Mage_Catalog_Model_Product $product
201
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
202
+ * @return mixed
203
+ */
204
+ private function getQty($product, $field)
205
+ {
206
+ $stockItem = $product->getStockItem();
207
+ $qty = $stockItem->getQty();
208
+ return $qty;
209
+ }
210
+
211
+ /**
212
+ * Get value of image url attribute id for given item
213
+ *
214
+ * @param Mage_Catalog_Model_Product $product
215
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
216
+ * @return string|null
217
+ */
218
+ private function getImage($product, $field)
219
+ {
220
+ $image = $product->getImage();
221
+ if (strtolower($image) != 'no_selection') {
222
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $image;
223
+ return $url;
224
+ }
225
+ return null;
226
+ }
227
+
228
+ /**
229
+ * Get value of small image url attribute id for given item
230
+ *
231
+ * @param Mage_Catalog_Model_Product $product
232
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
233
+ * @return string|null
234
+ */
235
+ private function getSmallImage($product, $field)
236
+ {
237
+ $image = $product->getSmallImage();
238
+ if (strtolower($image) != 'no_selection') {
239
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $image;
240
+ return $url;
241
+ }
242
+ return null;
243
+ }
244
+
245
+ /**
246
+ * Get value of thumbnail url attribute id for given item
247
+ *
248
+ * @param Mage_Catalog_Model_Product $product
249
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
250
+ * @return string|null
251
+ */
252
+ private function getThumbnail($product, $field)
253
+ {
254
+ $image = $product->getThumbnail();
255
+ if (strtolower($image) != 'no_selection') {
256
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $image;
257
+ return $url;
258
+ }
259
+ return null;
260
+ }
261
+
262
+ /**
263
+ * Get value of categories attribute id for given item
264
+ *
265
+ * @param Mage_Catalog_Model_Product $product
266
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
267
+ * @return mixed
268
+ */
269
+ private function getCategory($product, $field)
270
+ {
271
+ $items = array();
272
+ $collection = $product->getCategoryCollection();
273
+ foreach ($collection as &$item) {
274
+ $item = Mage::getModel('catalog/category')->load($item->getId());
275
+ $items[] = $item->getName();
276
+ }
277
+
278
+ $value = implode(', ', $items);
279
+ return $value;
280
+ }
281
+
282
+ /**
283
+ * Get value of category ids attribute id for given item
284
+ *
285
+ * @param Mage_Catalog_Model_Product $product
286
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
287
+ * @return mixed
288
+ */
289
+ private function getCategoryId($product, $field)
290
+ {
291
+ $ids = $product->getCategoryIds();
292
+ $ids = is_array($ids) ? $ids : array();
293
+ return implode(',', $ids);
294
+ }
295
+
296
+ /**
297
+ * Get product site url for given item
298
+ *
299
+ * @param Mage_Catalog_Model_Product $product
300
+ * @param Smartassistant_Smartassistant_Model_Exportfield $field
301
+ * @return mixed
302
+ */
303
+ private function getUrl($product, $field)
304
+ {
305
+ $storeId = $field->getConfig()->getStoreId();
306
+ $visibility = $product->getVisibility();
307
+ $mayBeChild = in_array($product->getTypeId(), array(
308
+ Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
309
+ Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
310
+ ));
311
+
312
+ if ($visibility != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE || ! $mayBeChild) {
313
+ $url = $product->setStoreId($storeId)->getProductUrl();
314
+ return $url;
315
+ }
316
+
317
+ $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
318
+ if (! $parentIds) {
319
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
320
+ }
321
+ if (! $parentIds) {
322
+ $parentIds = Mage::getModel('bundle/product_type')->getParentIdsByChild($product->getId());
323
+ }
324
+
325
+ if($parentIds) {
326
+ $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
327
+ $url = $parent->setStoreId($storeId)->getProductUrl();
328
+ return $url;
329
+ }
330
+
331
+ return null;
332
+ }
333
+ }
app/code/community/Smartassistant/Smartassistant/Helper/CliRunner.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_CliRunner extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * @var string Type: model
7
+ */
8
+ const MODEL = 'model';
9
+
10
+ /**
11
+ * @var string Type: helper
12
+ */
13
+ const HELPER = 'helper';
14
+
15
+ /**
16
+ * @var string Shell script location
17
+ */
18
+ protected $_shellScript;
19
+
20
+ /**
21
+ * @var string PHP Cli command
22
+ */
23
+ protected $_phpCli;
24
+
25
+ /**
26
+ * @var string Stript name
27
+ */
28
+ protected $_scriptFilename = 'smartassistant.php';
29
+
30
+ /**
31
+ * @var string Separator of arrays in commendline
32
+ */
33
+ protected $_argsSeparator = ';';
34
+
35
+ public function __construct()
36
+ {
37
+ $this->_phpCli = $this->getPhpCliCommand();
38
+ $this->_shellScript = Mage::getBaseDir() . DS . 'shell' . DS . $this->_scriptFilename;
39
+ }
40
+
41
+ /**
42
+ * Retrieve php command and check if shell is available
43
+ *
44
+ * @return string
45
+ */
46
+ public function ping()
47
+ {
48
+ $cmd = $this->_phpCli . ' ' . $this->_shellScript . ' --ping';
49
+ $result = array();
50
+ @exec($cmd, $result);
51
+ return (implode(' ', $result) === '1');
52
+ }
53
+
54
+ /**
55
+ * Run CLI command and execute specified model/helper method
56
+ *
57
+ * @return string
58
+ */
59
+ public function run($type, $class, $method, $params)
60
+ {
61
+ $params = $this->prepareParamsString($params);
62
+ $type .= '/' . $class . '/' . $method;
63
+
64
+ $cmd = $this->_phpCli . ' ' . $this->_shellScript . ' --run ' . $type . ' ' . $params;
65
+ $cmd .= ' 1>/dev/null 2>&1 &';
66
+
67
+ return exec($cmd);
68
+ }
69
+
70
+ /**
71
+ * Prepare params string
72
+ *
73
+ * @return string
74
+ */
75
+ private function prepareParamsString($params)
76
+ {
77
+ foreach ($params as $name => &$value) {
78
+ if (is_array($value)) {
79
+ $value = implode($this->_argsSeparator, $value);
80
+ }
81
+ $value = '--' . $name . ' ' . $value;
82
+ }
83
+ $params = implode(' ', $params);
84
+ return $params;
85
+ }
86
+
87
+ /**
88
+ * Retrieve php command
89
+ *
90
+ * @return string
91
+ */
92
+ private function getPhpCliCommand()
93
+ {
94
+ $phpBin = 'php';
95
+
96
+ if (defined('PHP_BINDIR')) {
97
+ $phpBin = PHP_BINDIR . DS . $phpBin;
98
+ }
99
+
100
+ return $phpBin;
101
+ }
102
+ }
app/code/community/Smartassistant/Smartassistant/Helper/Data.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * Retrieve html of attribute select
7
+ *
8
+ * @param string $name
9
+ * @param string $selected
10
+ * @param array $htmlAttributes
11
+ * @return string
12
+ */
13
+ public function getProductAttributesSelectHtml($name, $selected = null, $htmlAttributes = null)
14
+ {
15
+ /**
16
+ * Convert array with html attributes to string
17
+ */
18
+ if ($htmlAttributes !== null) {
19
+ foreach ($htmlAttributes as $attr => &$value) {
20
+ $value = $attr . '="' . $value . '"';
21
+ }
22
+ $htmlAttributes = implode(' ', $htmlAttributes);
23
+ }
24
+
25
+ /**
26
+ * Revceive attributes
27
+ */
28
+ $helper = Mage::helper('smartassistant/attribute');
29
+ $attributes = $helper->getAttributes();
30
+ $groups = $helper->getGroupedAttributes($attributes);
31
+
32
+ /**
33
+ * Create select html
34
+ */
35
+ $html = '<select name="'.((string)$name).'" '.((string)$htmlAttributes).'>';
36
+ foreach ($groups as $group) {
37
+ $html .= '<optgroup label="'.$group['label'].'">';
38
+ foreach ($group['items'] as $attribute) {
39
+ $html .= '<option value="'.$attribute['value'].'" '.($selected !== null && $attribute['value'] == $selected ? 'selected="selected"' : '').'>'.$attribute['label'].'</option>';
40
+ }
41
+ $html .= '</optgroup>';
42
+ }
43
+ $html .= '</select>';
44
+
45
+ return $html;
46
+ }
47
+ }
app/code/community/Smartassistant/Smartassistant/Helper/Exception.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_Exception extends Exception
4
+ {
5
+ }
app/code/community/Smartassistant/Smartassistant/Helper/Filesystem.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_Filesystem extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * Open / create file to write
7
+ *
8
+ * @param string $path Path of file
9
+ * @return handle
10
+ */
11
+ public function openFile($path)
12
+ {
13
+ $handle = fopen($path, 'a');
14
+ return $handle;
15
+ }
16
+
17
+ /**
18
+ * Write csv line with given fields
19
+ *
20
+ * @param handle $handle
21
+ * @param array $fields
22
+ * @param string $delimiter
23
+ * @param string $enclosure
24
+ * @param string $escapeChar
25
+ * @return boolean
26
+ */
27
+ public function putCsvLine($handle, $fields, $delimiter, $enclosure, $escapeChar)
28
+ {
29
+ $success = (fputcsv($handle, $fields, $delimiter, $enclosure) !== false);
30
+ return $success;
31
+ }
32
+
33
+ /**
34
+ *
35
+ * @param handle $handle
36
+ */
37
+ public function closeFile($handle)
38
+ {
39
+ fclose($handle);
40
+ }
41
+
42
+ /**
43
+ * Retreive directory containing export files
44
+ *
45
+ * @return string|boolean
46
+ */
47
+ public function getExportsDir()
48
+ {
49
+ $smarassistantDir = $this->getSmartassistantDir();
50
+ $dir = rtrim($smarassistantDir, DS) . DS . 'exports/';
51
+ if (! is_dir($dir) && ! mkdir($dir)) {
52
+ return false;
53
+ }
54
+ return $dir;
55
+ }
56
+
57
+ /**
58
+ * Retreive media subdirectory for this module
59
+ *
60
+ * @return string|boolean
61
+ */
62
+ public function getSmartassistantDir()
63
+ {
64
+ $media = Mage::getBaseDir('media');
65
+ $dir = rtrim($media, DS) . DS . 'smartassistant/';
66
+ if (! is_dir($dir) && ! mkdir($dir)) {
67
+ return false;
68
+ }
69
+ return $dir;
70
+ }
71
+ }
app/code/community/Smartassistant/Smartassistant/Helper/FtpConnector.php ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Helper_FtpConnector
4
+ {
5
+ const ASCII = FTP_ASCII;
6
+
7
+ const BINARY = FTP_BINARY;
8
+
9
+ private $_host;
10
+ private $_login;
11
+ private $_password;
12
+ private $_port = 21;
13
+ private $_pasive = false;
14
+ private $_mode = '0755';
15
+ private $_defaultTransferMode = self::BINARY;
16
+ private $_timeout = 30;
17
+ private $_verbose = false;
18
+
19
+ private $_connection;
20
+ private $_currentPath;
21
+ private $_ds = '/';
22
+ private $_tmpFilePrefix = 'ftp_connector_';
23
+
24
+ /**
25
+ *
26
+ * @param type $host
27
+ * @param type $login
28
+ * @param type $password
29
+ * @param type $port
30
+ * @param type $pasive
31
+ */
32
+ public function __construct($host, $login, $password, $port = 21, $pasive = false)
33
+ {
34
+ $this->_host = $host;
35
+ $this->_login = $login;
36
+ $this->_password = $password;
37
+ $this->_port = $port;
38
+ $this->_pasive = $pasive;
39
+ $this->setCurrentPath('.');
40
+ }
41
+
42
+ /**
43
+ * Check if FTP server is available with given configuration
44
+ *
45
+ * @return boolean
46
+ */
47
+ public function ping()
48
+ {
49
+ return ($this->connection() !== null);
50
+ }
51
+
52
+ /**
53
+ * List directory
54
+ *
55
+ * @param string $path
56
+ * @return boolean
57
+ */
58
+ public function ls($path = null)
59
+ {
60
+ $path = $path === null ? $this->_currentPath : $path;
61
+ $path = rtrim($path, $this->_ds);
62
+ $this->log('Listing location: ' . $path);
63
+ if (($result=ftp_nlist($this->connection(), $path)) === false) {
64
+ $this->log('Can not list location: ' . $path);
65
+ return false;
66
+ }
67
+
68
+ $this->log('Listed location: ' . $path);
69
+ return $result;
70
+ }
71
+
72
+ /**
73
+ * Delete file from FTP
74
+ *
75
+ * @param string $filename
76
+ * @param string $path
77
+ * @return boolean
78
+ */
79
+ public function rmvFile($filename, $path = null)
80
+ {
81
+ $this->log('Removing file: ' . $filename);
82
+ $path = $this->preparePath($filename, $path);
83
+ $this->log('Real file path is: ' . $path);
84
+ $success = ftp_delete($this->connection(), $path);
85
+
86
+ if ($success) {
87
+ $this->log('Removed file: ' . $path);
88
+ return true;
89
+ } else {
90
+ $this->log('Can not remove file: ' . $path);
91
+ return false;
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Upload string to FTP as file
97
+ *
98
+ * @param string $destinationFileName
99
+ * @param string $content
100
+ * @param string $path
101
+ * @param int $transferMode
102
+ * @return boolean
103
+ */
104
+ public function putFileString($destinationFileName, $content, $path = null, $transferMode = self::BINARY)
105
+ {
106
+ if (($tmpName = tempnam(sys_get_temp_dir(), $this->_tmpFilePrefix)) === false) {
107
+ $this->log('Prepare temporary file in: ' . $tmpName);
108
+ return false;
109
+ }
110
+
111
+ if (! file_put_contents($tmpName, $content)) {
112
+ $this->log('Can not created temporary file: ' . $tmpName);
113
+ return false;
114
+ }
115
+ $this->log('Created temporary file: ' . $tmpName);
116
+
117
+ $success = $this->putFile($destinationFileName, $tmpName, $path, $transferMode);
118
+
119
+ if (@unlink($tmpName)) {
120
+ $this->log('Removed temporary file: ' . $tmpName);
121
+ } else {
122
+ $this->log('Can not remove temporary file: ' . $tmpName);
123
+ }
124
+
125
+ return $success;
126
+ }
127
+
128
+ /**
129
+ * Upload file to FTP
130
+ *
131
+ * @param string $destinationFileName
132
+ * @param string $sourceFilePath
133
+ * @param string $path
134
+ * @param int $transferMode
135
+ * @return boolean
136
+ */
137
+ public function putFile($destinationFileName, $sourceFilePath, $path = null, $transferMode = self::BINARY)
138
+ {
139
+ $this->log('Uploading file to: ' . $destinationFileName);
140
+ $destinationFilePath = $this->preparePath($destinationFileName, $path);
141
+ $this->log('Real file path is: ' . $destinationFilePath);
142
+ if (! file_exists($sourceFilePath)) {
143
+ $this->log('Can not read source file: ' . $sourceFilePath);
144
+ return false;
145
+ }
146
+ $transferMode = $this->transferMode($transferMode);
147
+ $success = ftp_put($this->connection(), $destinationFilePath, $sourceFilePath, $transferMode);
148
+ if ($success) {
149
+ $this->setPermissionsToFile($destinationFilePath);
150
+ $this->log('File uploaded');
151
+ } else {
152
+ $this->log('Can not upload file');
153
+ }
154
+ return $success;
155
+ }
156
+
157
+ /**
158
+ * Change current directory
159
+ *
160
+ * @param string $path
161
+ * @throws Exception
162
+ */
163
+ public function chdir($path)
164
+ {
165
+ if (! ftp_chdir($this->connection(), $path)) {
166
+ $this->log('Can not change directory to: ' . $path);
167
+ return false;
168
+ }
169
+ $this->setCurrentPath(rtrim($path, '/'));
170
+ $this->log('Current directory changet to: ' . $this->_currentPath);
171
+ }
172
+
173
+ /**
174
+ * Set destination file permissions
175
+ *
176
+ * @param string $mode
177
+ * @return boolean
178
+ */
179
+ public function setMode($mode)
180
+ {
181
+ if (strlen($mode) != 4) {
182
+ $this->log('Wrong permissions. Will use default permissions.');
183
+ return false;
184
+ }
185
+ $this->_mode = $mode;
186
+ $this->log('Set permissions to: ' . $this->_mode);
187
+ return true;
188
+ }
189
+
190
+ /**
191
+ * Set transfer mode (ASCII or BINARY)
192
+ *
193
+ * @param int $transferMode
194
+ */
195
+ public function setDefaultTransferMode($transferMode)
196
+ {
197
+ if ($transferMode !== null && in_array($transferMode, array(self::ASCII, self::BINARY))) {
198
+ $this->log('Cen not set default transfer mode to: ' . $transferMode);
199
+ return true;
200
+ }
201
+
202
+ $this->log('Set default transfer mode to: ' . $this->_defaultTransferMode);
203
+ $this->_defaultTransferMode = $transferMode;
204
+ }
205
+
206
+ /**
207
+ * Set connection timelimit
208
+ *
209
+ * @param int $secounds
210
+ */
211
+ public function setTimeout($secounds)
212
+ {
213
+ $this->_timeout = $secounds;
214
+ $this->log('Set timeout to: ' . $this->_timeout);
215
+ }
216
+
217
+ /**
218
+ * Enable/Disable printing errors
219
+ *
220
+ * @param boolean $verbose
221
+ */
222
+ public function setVerbose($verbose)
223
+ {
224
+ $this->_verbose = (boolean) $verbose;
225
+ $this->log('Set verbose to: ' . $this->_verbose);
226
+ }
227
+
228
+ /**
229
+ * Prepare realpath of file
230
+ *
231
+ * @param strong $file
232
+ * @param string $path
233
+ * @return string
234
+ */
235
+ private function preparePath($file, $path = null)
236
+ {
237
+ $path = empty($path) ? $this->_currentPath : $path;
238
+ $path = rtrim($path, $this->_ds) . '/' . $file;
239
+ return $path;
240
+ }
241
+
242
+ /**
243
+ * Set permissions to file on the FTP
244
+ *
245
+ * @param string $path
246
+ * @throws Exception
247
+ */
248
+ private function setPermissionsToFile($path)
249
+ {
250
+ $this->log('Setting file permissions '.$this->_mode.' to ' . $path);
251
+ if ($this->_mode !== null && ftp_chmod($this->connection(), octdec($this->_mode), $path) != true) {
252
+ $this->log('Can not set permissions');
253
+ return false;
254
+ }
255
+ $this->log('Can set successfully');
256
+ }
257
+
258
+ /**
259
+ * Set current path
260
+ *
261
+ * @param string $path
262
+ * @throws Exception
263
+ */
264
+ public function setCurrentPath($path)
265
+ {
266
+ $this->_currentPath = empty($path) ? '.' : $path;
267
+ }
268
+
269
+ /**
270
+ * Receive transfer mode
271
+ *
272
+ * @param int $transferMode
273
+ * @return int
274
+ */
275
+ private function transferMode($transferMode = null)
276
+ {
277
+ if ($transferMode !== null && in_array($transferMode, array(self::ASCII, self::BINARY))) {
278
+ $this->log('Transfer mode: ' . $transferMode);
279
+ return $transferMode;
280
+ }
281
+ $this->log('Transfer mode: ' . $this->_defaultTransferMode);
282
+ return $this->_defaultTransferMode;
283
+ }
284
+
285
+ /**
286
+ * Get FTP connection handler
287
+ *
288
+ * @return handler
289
+ */
290
+ private function connection()
291
+ {
292
+ if ($this->_connection === null) {
293
+ if (! $this->connect() || ! $this->login()) {
294
+ return null;
295
+ }
296
+ }
297
+
298
+ return $this->_connection;
299
+ }
300
+
301
+ /**
302
+ * Disconect with FTP
303
+ *
304
+ * @throws Exception
305
+ */
306
+ public function disconnect()
307
+ {
308
+ $this->log('Disconnecting');
309
+ if (ftp_close($this->connection())) {
310
+ $this->log('Disconnecting failed');
311
+ return false;
312
+ }
313
+ $this->log('Disconnected');
314
+ return true;
315
+ }
316
+
317
+ /**
318
+ *
319
+ * @throws Exception
320
+ */
321
+ public function connect()
322
+ {
323
+ $this->log('Connecting...');
324
+ if (($this->_connection = ftp_connect($this->_host, $this->_port, $this->_timeout)) === false) {
325
+ $this->log('Connecting failed');
326
+ return false;
327
+ }
328
+ $this->log('Connected');
329
+ return true;
330
+ }
331
+
332
+ /**
333
+ * Connect to FTP
334
+ *
335
+ * @throws Excepion
336
+ */
337
+ public function login()
338
+ {
339
+ $this->log('Login to user: ' . $this->_login);
340
+ if (! ftp_login($this->_connection, $this->_login, $this->_password)){
341
+ $this->log('Login failed');
342
+ return false;
343
+ }
344
+ $this->log('Login success');
345
+ if (ftp_pasv($this->_connection, $this->_pasive)) {
346
+ $this->log('Pasiv mode: ' . ($this->_pasive?'enabled':'disabled'));
347
+ } else {
348
+ $this->log('Can not set pasive mode');
349
+ }
350
+
351
+ return true;
352
+ }
353
+
354
+ /**
355
+ * Put log
356
+ *
357
+ * @param string $message
358
+ */
359
+ private function log($message)
360
+ {
361
+ if ($this->_verbose) {
362
+ echo $message . PHP_EOL;
363
+ }
364
+ }
365
+ }
app/code/community/Smartassistant/Smartassistant/Model/Core/CollectionIterator.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Core_CollectionIterator implements Iterator, Countable
4
+ {
5
+ private $_primaryKey;
6
+
7
+ private $_varienDbSelect;
8
+
9
+ private $_splitedSelect;
10
+
11
+ private $_originalCollection;
12
+
13
+ private $_collection;
14
+
15
+ private $_pick = 5000;
16
+
17
+ private $_connection;
18
+
19
+ private $_current;
20
+
21
+ private $_items = array();
22
+
23
+ private $_count;
24
+
25
+ public function __construct($collection, $varienDbSelect = null)
26
+ {
27
+ $this->_varienDbSelect = ($varienDbSelect !== null ? $varienDbSelect : $collection->getSelect());
28
+ $this->_originalCollection = $collection;
29
+ $this->_connection = Mage::getSingleton('core/resource')->getConnection('core_read');
30
+ $this->_splitedSelect = $this->splitSelect($this->_varienDbSelect, '*', $this->_pick);
31
+ }
32
+
33
+ /**
34
+ * Split select query
35
+ *
36
+ * @param Varien_Db_Select $select
37
+ * @param string $entityIdField
38
+ * @param int $step
39
+ * @return array
40
+ */
41
+ private function splitSelect(Varien_Db_Select $select, $entityIdField = '*', $step = 10000)
42
+ {
43
+ $countSelect = clone $select;
44
+
45
+ $countSelect->reset(Zend_Db_Select::COLUMNS);
46
+ $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
47
+ $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
48
+ $countSelect->columns('COUNT(' . $entityIdField . ')');
49
+
50
+ $row = $this->_connection->fetchRow($countSelect);
51
+ $totalRows = array_shift($row);
52
+
53
+ $bunches = array();
54
+ for ($i = 0; $i <= $totalRows; $i += $step) {
55
+ $bunchSelect = clone $select;
56
+ $bunches[] = $bunchSelect->limit($step, $i);
57
+ }
58
+
59
+ return $bunches;
60
+ }
61
+
62
+ public function setPick($pick)
63
+ {
64
+ $this->_pick = $pick;
65
+ }
66
+
67
+ public function getPick()
68
+ {
69
+ return $this->_pick;
70
+ }
71
+
72
+ private function getSize()
73
+ {
74
+ $countSelect = clone $this->_varienDbSelect;
75
+ $countSelect->reset(Zend_Db_Select::COLUMNS);
76
+ $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
77
+ $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
78
+ $countSelect->columns('COUNT(*)');
79
+ $row = $this->_connection->fetchRow($countSelect);
80
+ $totalRows = array_shift($row);
81
+ return $totalRows;
82
+ }
83
+
84
+ public function loadNextPart()
85
+ {
86
+ if (($select = current($this->_splitedSelect)) === false) {
87
+ $this->_current = null;
88
+ return;
89
+ }
90
+
91
+ next($this->_splitedSelect);
92
+
93
+ $collection = clone $this->_originalCollection;
94
+ $ids = $this->_connection->fetchCol($select);
95
+
96
+ $collection->getSelect()->reset(Zend_Db_Select::WHERE);
97
+ $collection->addAttributeToSelect('*');
98
+ $collection->addAttributeToFilter('entity_id', array( 'in' => $ids ));
99
+
100
+ if ($collection->getSize() <= 0) {
101
+ $this->_current = null;
102
+ return;
103
+ }
104
+
105
+ $this->_items = $collection->getItems();
106
+ $this->_current = key($this->_items);
107
+ }
108
+
109
+
110
+ /**
111
+ * FROM Iterator, Countable
112
+ */
113
+
114
+ /**
115
+ * Pobiera ilosc elementow
116
+ */
117
+ public function count($mode = 'COUNT_NORMAL')
118
+ {
119
+ if ($this->_count === null) {
120
+ $this->_count = $this->getSize();
121
+ }
122
+ return $this->_count;
123
+ }
124
+
125
+ /**
126
+ * Pobiera aktualny obiekt
127
+ */
128
+ public function current()
129
+ {
130
+ return $this->_items[$this->_current];
131
+ }
132
+
133
+ /**
134
+ * Pobiera aktualny klucz
135
+ */
136
+ public function key()
137
+ {
138
+ return $this->_current;
139
+ }
140
+
141
+ /**
142
+ * Przewijamy do nastepnego
143
+ */
144
+ public function next()
145
+ {
146
+ if (next($this->_items) === false) {
147
+ $this->loadNextPart();
148
+ } else {
149
+ $this->_current = key($this->_items);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Przewijamy do poczatku
155
+ */
156
+ public function rewind()
157
+ {
158
+ reset($this->_splitedSelect);
159
+ $this->loadNextPart();
160
+ }
161
+
162
+ public function valid()
163
+ {
164
+ return ($this->_current !== null);
165
+ }
166
+
167
+ }
app/code/community/Smartassistant/Smartassistant/Model/Export.php ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Export extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * @var array Cache of product collection
7
+ */
8
+ private static $_productCollectionIteratorCached;
9
+
10
+ /**
11
+ * @var string Export file path - cache
12
+ */
13
+ private $_filePath;
14
+
15
+ protected $_defaultFields;
16
+
17
+ public function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->_init('smartassistant/export');
21
+ $this->_defaultFields = array(
22
+ 'name' => array(
23
+ 'fieldname' => 'name',
24
+ 'attribute_code' => 'name',
25
+ 'enabled' => '1',
26
+ 'when_empty' => '',
27
+ ),
28
+ 'price' => array(
29
+ 'fieldname' => 'price',
30
+ 'attribute_code' => 'price',
31
+ 'enabled' => '1',
32
+ 'when_empty' => '',
33
+ ),
34
+ 'offerurl' => array(
35
+ 'fieldname' => 'offerurl',
36
+ 'attribute_code' => 'url',
37
+ 'enabled' => '1',
38
+ 'when_empty' => Mage::getBaseUrl(),
39
+
40
+ ),
41
+ 'picture' => array(
42
+ 'fieldname' => 'picture',
43
+ 'attribute_code' => 'image',
44
+ 'enabled' => '1',
45
+ 'when_empty' => rtrim(Mage::getBaseUrl('skin'), '/') . '/frontend/base/default/images/smartassistant/logo.png',
46
+ ),
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Receive days as array
52
+ * @return array
53
+ */
54
+ public function getDays()
55
+ {
56
+ return explode(',', $this->getData('days'));
57
+ }
58
+
59
+ /**
60
+ * Receive hours as array
61
+ * @return array
62
+ */
63
+ public function getHours()
64
+ {
65
+ return explode(',', $this->getData('hours'));
66
+ }
67
+
68
+ /**
69
+ * Set days
70
+ * @param array $values
71
+ */
72
+ public function setDays($values)
73
+ {
74
+ $this->setData('days', implode(',', $values));
75
+ }
76
+
77
+ /**
78
+ * Set hours
79
+ * @param array $values
80
+ */
81
+ public function setHours($values)
82
+ {
83
+ $this->setData('hours', implode(',', $values));
84
+ }
85
+
86
+ /**
87
+ * Receive map of product attributes to export
88
+ * @param true $onlyEnabled If true it will return only active fields
89
+ * @return Smartassistant_Smartassistant_Model_Mysql4_Exportfield_Collection
90
+ */
91
+ public function getMap($onlyEnabled = false)
92
+ {
93
+ if ($this->getId()) {
94
+ $collection = Mage::getModel('smartassistant/exportfield')->getCollection()
95
+ ->addFieldToFilter('export_id', $this->getId());
96
+
97
+ if ($onlyEnabled) {
98
+ $collection->addFieldToFilter('enabled', true);
99
+ }
100
+
101
+ $collection->setOrder('position','ASC');
102
+ } else {
103
+ $collection = new Varien_Data_Collection();
104
+ foreach ($this->_defaultFields as $field) {
105
+ $fieldModel = Mage::getModel('smartassistant/exportfield');
106
+ foreach ($field as $key => $value) {
107
+ $setter = 'set' . uc_words($key, '');
108
+ $fieldModel->$setter($value);
109
+ }
110
+ $collection->addItem($fieldModel);
111
+ }
112
+ }
113
+
114
+ return $collection;
115
+ }
116
+
117
+ /**
118
+ * Retrieve ids of fielsd
119
+ *
120
+ * @return array
121
+ */
122
+ public function getMapIds()
123
+ {
124
+ $collection = $this->getMap();
125
+ $ids = array();
126
+ foreach ($collection as $item) {
127
+ $ids[] = $item->getId();
128
+ }
129
+
130
+ return $ids;
131
+ }
132
+
133
+ /**
134
+ * Create field model
135
+ *
136
+ * @return Smartassistant_Smartassistant_Model_Exportfield
137
+ */
138
+ public function getMapModel()
139
+ {
140
+ return Mage::getModel('smartassistant/exportfield');
141
+ }
142
+
143
+ /**
144
+ * Save fields map in database
145
+ *
146
+ * @param array $map
147
+ * @return boolean
148
+ */
149
+ public function assignFieldsMap($map)
150
+ {
151
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
152
+ try {
153
+ $connection->beginTransaction();
154
+
155
+ $position = 1;
156
+ $ids = $this->getMapIds();
157
+ $idsToRemove = array_diff($ids, array_filter($map['id']));
158
+
159
+ if (count($idsToRemove) > 0) {
160
+ $collection = Mage::getModel('smartassistant/exportfield')->getCollection()
161
+ ->addFieldToFilter('id', array('in' => $idsToRemove));
162
+ foreach ($collection as $itemToRemove) {
163
+ $itemToRemove->delete();
164
+ }
165
+ }
166
+
167
+
168
+ foreach ($map['id'] as $key => $value) {
169
+
170
+ /**
171
+ * If item should be removed we do not saving it
172
+ */
173
+ if (in_array($value, $idsToRemove)) {
174
+ continue;
175
+ }
176
+
177
+ $model = Mage::getModel('smartassistant/exportfield');
178
+ $itemData = array(
179
+ 'export_id' => $this->getId(),
180
+ 'fieldname' => $map['fieldname'][$key],
181
+ 'attribute_code' => $map['attribute_code'][$key],
182
+ 'enabled' => (boolean)$map['enabled'][$key],
183
+ 'when_empty' => $map['when_empty'][$key],
184
+ 'position' => $position++,
185
+ );
186
+ if (! empty($value)) {
187
+ $itemData['id'] = $value;
188
+ }
189
+ $model->setData($itemData);
190
+ if ($model->validate($itemData)) {
191
+ $model->save();
192
+ }
193
+ }
194
+
195
+ $connection->commit();
196
+ return true;
197
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
198
+ $connection->rollback();
199
+ return false;
200
+ } catch (Exception $e) {
201
+ $connection->rollback();
202
+ return false;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Save rules
208
+ *
209
+ * @param array $conditions
210
+ */
211
+ public function saveRules($conditions)
212
+ {
213
+ $rule = $this->getRuleModel();
214
+ $rule->loadPost(array(
215
+ 'conditions' => $conditions,
216
+ 'export_id' => $this->getId(),
217
+ ));
218
+ $rule->save();
219
+ }
220
+
221
+ /**
222
+ * Check if export file exists for this configuration
223
+ *
224
+ * @return boolean
225
+ */
226
+ public function exportExists()
227
+ {
228
+ return file_exists($this->getFilePath());
229
+ }
230
+
231
+ /**
232
+ * Retrieve las export time
233
+ * @return type
234
+ */
235
+ public function lastExportTime()
236
+ {
237
+ if (! $this->exportExists()) {
238
+ return null;
239
+ }
240
+
241
+ return filemtime($this->getFilePath());
242
+ }
243
+
244
+ /**
245
+ * Retrieve products collection for this export
246
+ *
247
+ * @return Smartassistant_Smartassistant_Model_Core_CollectionIterator
248
+ */
249
+ public function getProductsCollection()
250
+ {
251
+ if ($this->_productCollectionIteratorCached === null) {
252
+ $rules = $this->getRuleModel();
253
+ $storeViewId = $this->getStoreId();
254
+ $storeId = Mage::app()->getStore($storeViewId)->getGroupId();
255
+ $rules->setCurrentWebsiteId($storeId);
256
+ $ids = $rules->getMatchingProductIds();
257
+
258
+ $collection = Mage::getModel('catalog/product')->getCollection();
259
+ $collection->setStoreId($storeViewId);
260
+ $collection->addFieldToFilter('entity_id', array('in' => $ids));
261
+
262
+ $this->_productCollectionIteratorCached = new Smartassistant_Smartassistant_Model_Core_CollectionIterator($collection, null, $storeViewId);
263
+ }
264
+
265
+ return $this->_productCollectionIteratorCached;
266
+ }
267
+
268
+ /**
269
+ * Get rule model used in this configuration or create new rule model
270
+ * @return Smartassistant_Smartassistant_Model_Rule
271
+ */
272
+ public function getRuleModel()
273
+ {
274
+ if ($this->isEmpty()) {
275
+ return Mage::getModel('smartassistant/rule');
276
+ }
277
+
278
+ $rule = Mage::getModel('smartassistant/rule')->load($this->getId(), 'export_id');
279
+ if ($rule->isEmpty()) {
280
+ return Mage::getModel('smartassistant/rule');
281
+ }
282
+
283
+ return $rule;
284
+ }
285
+
286
+ /**
287
+ * Get export file path associated with tis configuration
288
+ * @return string
289
+ */
290
+ public function getFilePath()
291
+ {
292
+ if ($this->_filePath === null) {
293
+ $exportsDir = Mage::helper('smartassistant/filesystem')->getExportsDir();
294
+
295
+ $filename = 'export-' . $this->getId() . '.csv';
296
+
297
+ $this->_filePath = rtrim($exportsDir, DS) . DS . $filename;
298
+ }
299
+
300
+ return $this->_filePath;
301
+ }
302
+
303
+ /**
304
+ * Cascade remove configuration with all related data
305
+ *
306
+ * @return boolean
307
+ */
308
+ public function cascadeDelete()
309
+ {
310
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
311
+ $fields = $this->getMap();
312
+ $rule = $this->getRuleModel();
313
+
314
+ try {
315
+ $connection->beginTransaction();
316
+
317
+ $rule->delete();
318
+
319
+ foreach ($fields as $field) {
320
+ $field->delete();
321
+ }
322
+
323
+ $this->delete();
324
+
325
+ @unlink($this->getFilePath());
326
+
327
+ $connection->commit();
328
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
329
+ $connection->rollback();
330
+ return false;
331
+ }
332
+
333
+ return true;
334
+ }
335
+
336
+ /**
337
+ * Get CSV delimiter
338
+ *
339
+ * @return string
340
+ */
341
+ public function getDelimiter()
342
+ {
343
+ return ';';
344
+ }
345
+
346
+ /**
347
+ * Get CSV enclosure
348
+ *
349
+ * @return string
350
+ */
351
+ public function getEnclosure()
352
+ {
353
+ return '"';
354
+ }
355
+
356
+ /**
357
+ * Check if ftp server asotiated with this configuration is valid
358
+ *
359
+ * @return boolean
360
+ */
361
+ public function isFtpValid()
362
+ {
363
+ $storeId = $this->getStoreId();
364
+
365
+ $host = Mage::getStoreConfig('smartassistant/ftp/host', $storeId);
366
+ $login = Mage::getStoreConfig('smartassistant/ftp/user', $storeId);
367
+ $password = Mage::getStoreConfig('smartassistant/ftp/password', $storeId);
368
+ $pasive = Mage::getStoreConfig('smartassistant/ftp/pasivemode', $storeId);
369
+ $transferMode = Smartassistant_Smartassistant_Helper_FtpConnector::BINARY;
370
+ $port = Mage::getStoreConfig('smartassistant/ftp/port', $storeId);
371
+ $port = empty($port) ? 21 : $port;
372
+
373
+ if (empty($host) || empty($login) || empty($password) || empty($transferMode) || empty($port)) {
374
+ return false;
375
+ }
376
+
377
+ $ftp = new Smartassistant_Smartassistant_Helper_FtpConnector($host, $login, $password, $port, $pasive);
378
+ $success = $ftp->ping();
379
+
380
+ return $success;
381
+ }
382
+
383
+ public function getLastTaskId()
384
+ {
385
+ $collection = Mage::getModel('smartassistant/task_config')->getCollection();
386
+ $collection->addFieldToFilter('export_id', $this->getId());
387
+ $select = $collection->getSelect();
388
+ $select->order('id DESC');
389
+ $select->limit(1);
390
+ if ($collection->getSize() <= 0) {
391
+ return null;
392
+ }
393
+ $item = $collection->getFirstItem();
394
+ $id = $item->getTaskId();
395
+ return $id;
396
+ }
397
+ }
app/code/community/Smartassistant/Smartassistant/Model/Exportfield.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Exportfield extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/exportfield');
9
+ }
10
+
11
+ /**
12
+ * Config associated with field
13
+ *
14
+ * @return Smartassistant_Smartassistant_Model_Export
15
+ */
16
+ public function getConfig()
17
+ {
18
+ $config = Mage::getModel('smartassistant/export')->load($this->getExportId());
19
+ return $config;
20
+ }
21
+
22
+ /**
23
+ * Check if field data is valid
24
+ *
25
+ * @return boolean
26
+ */
27
+ public function validate()
28
+ {
29
+ $exportId = $this->getExportId();
30
+ $fieldname = $this->getFieldname();
31
+ $attributeCode = $this->getAttributeCode();
32
+ $position = $this->getPosition();
33
+
34
+ return (
35
+ ! empty($exportId)
36
+ && ! empty($fieldname)
37
+ && ! empty($attributeCode)
38
+ && ! empty($position)
39
+ );
40
+ }
41
+ }
app/code/community/Smartassistant/Smartassistant/Model/Generator.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Generator extends Varien_Object
4
+ {
5
+ /**
6
+ * Run task by cron
7
+ *
8
+ * @param boolean $force Ignore config andforce to run task even when cron is disabled in configuration
9
+ * @return mixed
10
+ */
11
+ public function scheduleRun($force = false)
12
+ {
13
+ if (! $force && ! Mage::getStoreConfig('smartassistant/general/cron')) {
14
+ return;
15
+ }
16
+
17
+ $day = Mage::getSingleton('core/date')->date('w');
18
+ $hour = Mage::getSingleton('core/date')->date('G');
19
+ $minutes = floor(Mage::getSingleton('core/date')->date('i') / 30) == 1 ? 30 : 0;
20
+ $time = ($hour * 60) + $minutes;
21
+
22
+ $collection = Mage::getModel('smartassistant/export')->getCollection();
23
+ $configIds = array();
24
+ foreach ($collection as $export) {
25
+ if ($this->shouldRunCron($export, $day, $time)) {
26
+ $configIds[] = $export->getId();
27
+ }
28
+ }
29
+
30
+ if (count($configIds) < 1) {
31
+ return;
32
+ }
33
+
34
+ $task = Mage::getModel('smartassistant/task');
35
+ $task->configure($configIds, null, null, $this->getTimeString($day, $time));
36
+ return $this->run($task->getId());
37
+ }
38
+
39
+ /**
40
+ * Custom run task
41
+ *
42
+ * @param array $configIds Array of config ids
43
+ * @param boolean $generate Should generate file
44
+ * @param boolean $send Should send file to FTP
45
+ * @return mixed
46
+ * @throws Smartassistant_Smartassistant_Helper_Exception
47
+ */
48
+ public function customRun($configIds, $generate, $send)
49
+ {
50
+ $task = Mage::getModel('smartassistant/task');
51
+ $task->configure($configIds, $generate, $send);
52
+ $useShell = Mage::getStoreConfig('smartassistant/general/useShell');
53
+
54
+ if ($useShell) {
55
+ $runner = Mage::helper('smartassistant/cliRunner');
56
+ if (! $runner->ping()) {
57
+ throw new Smartassistant_Smartassistant_Helper_Exception(
58
+ Mage::helper('smartassistant')->__('Unable to run task. Check if exec() function is enabled on your environment')
59
+ );
60
+ }
61
+ $type = Smartassistant_Smartassistant_Helper_CliRunner::MODEL;
62
+ $class = 'smartassistant/generator';
63
+ $method = 'run';
64
+ $params = array(
65
+ 'taskId' => $task->getId(),
66
+ );
67
+ return $runner->run($type, $class, $method, $params);
68
+ } else {
69
+ return $this->run($task->getId());
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Run task execution
75
+ *
76
+ * @param int $taskId Id of task to run
77
+ */
78
+ public function run($taskId)
79
+ {
80
+ $task = Mage::getModel('smartassistant/task')->load($taskId);
81
+ if(! $task->isEmpty()){
82
+ $task->run();
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Create date/time string
88
+ *
89
+ * @param string $day
90
+ * @param string $time
91
+ * @return string Date/time string
92
+ */
93
+ private function getTimeString($day, $time)
94
+ {
95
+ $timeString = Mage::getSingleton('core/date')->date('Ymd').$day.$time;
96
+ return $timeString;
97
+ }
98
+
99
+ /**
100
+ * Check if we need to run cron actions for provided config
101
+ *
102
+ * @param Smartassistant_Smartassistant_Model_Export $config
103
+ * @param string $day
104
+ * @param string $time
105
+ * @return boolean
106
+ */
107
+ private function shouldRunCron($config, $day, $time)
108
+ {
109
+ $configDays = $config->getDays();
110
+ $configHours = $config->getHours();
111
+
112
+ /**
113
+ * Check if date / time is enable in configuration
114
+ */
115
+ if (! in_array($day, $configDays) || !in_array($time, $configHours)) {
116
+ return false;
117
+ }
118
+
119
+ /**
120
+ * Check if we have task for this configuration in this date / time
121
+ */
122
+ $collection = Mage::getModel('smartassistant/task')->getCollection();
123
+ $select = $collection->getSelect();
124
+ $select->join(
125
+ array('tc' => 'smartassistant_task_config'),
126
+ 'main_table.id=tc.task_id',
127
+ array('export_id' => 'tc.export_id')
128
+ );
129
+ $collection->addFieldToFilter('export_id', $config->getId());
130
+ $collection->addFieldToFilter('time', $this->getTimeString($day, $time));
131
+
132
+ return ($collection->getSize() <= 0);
133
+ }
134
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Export.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Export extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/export', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Export/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Export_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/export');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Exportfield.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Exportfield extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/exportfield', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Exportfield/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Exportfield_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/exportfield');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Rule.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Rule extends Mage_Rule_Model_Mysql4_Rule
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('smartassistant/rule', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Rule/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Rule_Collection extends Mage_Rule_Model_Mysql4_Rule_Collection
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/rule');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Config.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Config extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task_config', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Config/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Config_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_config');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Log.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Log extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task_log', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Log/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_log');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Status.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Status extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task_status', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Mysql4/Task/Status/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Mysql4_Task_Status_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_status');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Rule.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Smartassistant_Smartassistant_Model_Rule extends Mage_Rule_Model_Rule
3
+ {
4
+ public $_productIds;
5
+
6
+ protected function _construct()
7
+ {
8
+ parent::_construct();
9
+ $this->_init('smartassistant/rule');
10
+ }
11
+
12
+ /**
13
+ * Getter for rule conditions collection
14
+ *
15
+ * @return Mage_CatalogRule_Model_Rule_Condition_Combine
16
+ */
17
+ public function getConditionsInstance()
18
+ {
19
+ return Mage::getModel('smartassistant/rule_condition_combine');
20
+ }
21
+
22
+ /**
23
+ * Getter for rule actions collection
24
+ *
25
+ * @return Mage_CatalogRule_Model_Rule_Action_Collection
26
+ */
27
+ public function getActionsInstance()
28
+ {
29
+ return Mage::getModel('catalogrule/rule_action_collection');
30
+ }
31
+
32
+ /**
33
+ * Fill rule with data
34
+ *
35
+ * @param array $data
36
+ * @return \Smartassistant_Smartassistant_Model_Rule
37
+ */
38
+ public function loadPost(array $data)
39
+ {
40
+ $arr = $this->_convertFlatToRecursive($data);
41
+ if (isset($arr['conditions'])) {
42
+ $this->getConditions()->setConditions(array())->loadArray($arr['conditions'][1]);
43
+ }
44
+
45
+ $this->setExportId($data['export_id']);
46
+ return $this;
47
+ }
48
+
49
+ public function getWebsiteIds()
50
+ {
51
+ return array($this->getCurrentWebsiteId());
52
+ }
53
+
54
+ public function getMatchingProductIds()
55
+ {
56
+ if (is_null($this->_productIds)) {
57
+ $this->_productIds = array();
58
+ $this->setCollectedAttributes(array());
59
+
60
+ if ($this->getWebsiteIds()) {
61
+ /** @var $productCollection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
62
+ $productCollection = Mage::getResourceModel('catalog/product_collection');
63
+ $productCollection->addWebsiteFilter($this->getWebsiteIds());
64
+ if ($this->_productsFilter) {
65
+ $productCollection->addIdFilter($this->_productsFilter);
66
+ }
67
+ $this->getConditions()->collectValidatedAttributes($productCollection);
68
+
69
+ Mage::getSingleton('core/resource_iterator')->walk(
70
+ $productCollection->getSelect(),
71
+ array(array($this, 'callbackValidateProduct')),
72
+ array(
73
+ 'attributes' => $this->getCollectedAttributes(),
74
+ 'product' => Mage::getModel('catalog/product'),
75
+ )
76
+ );
77
+ }
78
+ }
79
+
80
+ return $this->_productIds;
81
+ }
82
+
83
+ /**
84
+ * Callback function for product matching
85
+ *
86
+ * @param $args
87
+ * @return void
88
+ */
89
+ public function callbackValidateProduct($args)
90
+ {
91
+ $product = clone $args['product'];
92
+ $websiteIds = $this->getWebsiteIds();
93
+
94
+ $product->setData($args['row']);
95
+ $product->setStoreId($storeId);
96
+
97
+ if ($this->getConditions()->validate($product)) {
98
+ $this->_productIds[] = $product->getId();
99
+ }
100
+ }
101
+ }
app/code/community/Smartassistant/Smartassistant/Model/Rule/Condition/Combine.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Rule_Condition_Combine extends Mage_Rule_Model_Condition_Combine
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setType('smartassistant/rule_condition_combine');
9
+ }
10
+
11
+ public function getNewChildSelectOptions()
12
+ {
13
+ $productCondition = Mage::getModel('smartassistant/rule_condition_product');
14
+ $productAttributes = $productCondition->loadAttributeOptions()->getAttributeOption();
15
+ $attributes = array();
16
+ foreach ($productAttributes as $code=>$label) {
17
+ $attributes[] = array('value'=>'smartassistant/rule_condition_product|'.$code, 'label'=>$label);
18
+ }
19
+ $conditions = parent::getNewChildSelectOptions();
20
+ $conditions = array_merge_recursive($conditions, array(
21
+ array('value'=>'smartassistant/rule_condition_combine', 'label'=>Mage::helper('catalogrule')->__('Conditions Combination')),
22
+ array('label'=>Mage::helper('catalogrule')->__('Product Attribute'), 'value'=>$attributes),
23
+ ));
24
+ return $conditions;
25
+ }
26
+
27
+ public function collectValidatedAttributes($productCollection)
28
+ {
29
+ foreach ($this->getConditions() as $condition) {
30
+ $condition->collectValidatedAttributes($productCollection);
31
+ }
32
+ return $this;
33
+ }
34
+ }
app/code/community/Smartassistant/Smartassistant/Model/Rule/Condition/Product.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Rule_Condition_Product extends Mage_Rule_Model_Condition_Product_Abstract
4
+ {
5
+ // public function loadAttributeOptions()
6
+ // {
7
+ // $productAttributes = Mage::getResourceSingleton('catalog/product')
8
+ // ->loadAllAttributes()
9
+ // ->getAttributesByCode();
10
+ //
11
+ // $attributes = array();
12
+ // foreach ($productAttributes as $attribute) {
13
+ // /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
14
+ // if (!$attribute->isAllowedForRuleCondition()
15
+ // || !$attribute->getDataUsingMethod($this->_isUsedForRuleProperty)
16
+ // ) {
17
+ // continue;
18
+ // }
19
+ // $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel();
20
+ // }
21
+ //
22
+ // $this->_addSpecialAttributes($attributes);
23
+ //
24
+ // asort($attributes);
25
+ // $this->setAttributeOption($attributes);
26
+ //
27
+ // return $this;
28
+ //
29
+ //
30
+ //
31
+ // $attributes = array();
32
+ // $this->_addSpecialAttributes($attributes);
33
+ // asort($attributes);
34
+ // $this->setAttributeOption($attributes);
35
+ // return $this;
36
+ // }
37
+
38
+ // public function prepareConditionSql()
39
+ // {
40
+ // $alias = 'cpf';
41
+ // $attribute = $this->getAttribute();
42
+ //
43
+ // $attrModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $attribute);
44
+ //
45
+ // $columnName = null;
46
+ // if (
47
+ // ($attrSourceModel = Mage::getModel($attrModel->getSourceModel()))
48
+ // && ($flatColumns = $attrModel->getSource()->getFlatColums())
49
+ // ) {
50
+ // $keys = array_keys($flatColumns);
51
+ // foreach ($keys as $key) {
52
+ // if (substr($key, '_value') !== false) {
53
+ // $attribute = $key;
54
+ // }
55
+ // }
56
+ // }
57
+ //
58
+ // $value = $this->getValueParsed();
59
+ // $operator = $this->correctOperator($this->getOperator(), $this->getInputType());
60
+ // if ($attribute == 'category_ids') {
61
+ // $alias = 'ccp';
62
+ // $attribute = 'category_id';
63
+ // $value = $this->bindArrayOfIds($value);
64
+ // }
65
+ //
66
+ // /** @var $ruleResource Mage_Rule_Model_Resource_Rule_Condition_SqlBuilder */
67
+ // $ruleResource = $this->getRuleResourceHelper();
68
+ //
69
+ // return $ruleResource->getOperatorCondition($alias . '.' . $attribute, $operator, $value);
70
+ // }
71
+
72
+ /**
73
+ * Validate product attribute value for condition
74
+ *
75
+ * @param Varien_Object $object
76
+ * @return bool
77
+ */
78
+ public function validate(Varien_Object $object)
79
+ {
80
+ $attrCode = $this->getAttribute();
81
+ if ('category_ids' == $attrCode) {
82
+ return $this->validateAttribute($object->getCategoryIds());
83
+ }
84
+ if ('attribute_set_id' == $attrCode) {
85
+ return $this->validateAttribute($object->getData($attrCode));
86
+ }
87
+
88
+ $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
89
+ $object->setData($attrCode, $this->_getAttributeValue($object));
90
+ $result = $this->_validateProduct($object);
91
+ $this->_restoreOldAttrValue($object, $oldAttrValue);
92
+
93
+ return (bool)$result;
94
+ }
95
+
96
+
97
+ /**
98
+ * Validate product
99
+ *
100
+ * @param Varien_Object $object
101
+ * @return bool
102
+ */
103
+ protected function _validateProduct($object)
104
+ {
105
+ return Mage_Rule_Model_Condition_Abstract::validate($object);
106
+ }
107
+
108
+ /**
109
+ * Restore old attribute value
110
+ *
111
+ * @param Varien_Object $object
112
+ * @param mixed $oldAttrValue
113
+ */
114
+ protected function _restoreOldAttrValue($object, $oldAttrValue)
115
+ {
116
+ $attrCode = $this->getAttribute();
117
+ if (is_null($oldAttrValue)) {
118
+ $object->unsetData($attrCode);
119
+ } else {
120
+ $object->setData($attrCode, $oldAttrValue);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Get attribute value
126
+ *
127
+ * @param Varien_Object $object
128
+ * @return mixed
129
+ */
130
+ protected function _getAttributeValue($object)
131
+ {
132
+ $attrCode = $this->getAttribute();
133
+ $storeId = $object->getStoreId();
134
+ $defaultStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
135
+ $productValues = isset($this->_entityAttributeValues[$object->getId()])
136
+ ? $this->_entityAttributeValues[$object->getId()] : array();
137
+ $defaultValue = isset($productValues[$defaultStoreId])
138
+ ? $productValues[$defaultStoreId] : $object->getData($attrCode);
139
+ $value = isset($productValues[$storeId]) ? $productValues[$storeId] : $defaultValue;
140
+
141
+ $value = $this->_prepareDatetimeValue($value, $object);
142
+ $value = $this->_prepareMultiselectValue($value, $object);
143
+
144
+ return $value;
145
+ }
146
+
147
+
148
+ /**
149
+ * Prepare datetime attribute value
150
+ *
151
+ * @param mixed $value
152
+ * @param Varien_Object $object
153
+ * @return mixed
154
+ */
155
+ protected function _prepareDatetimeValue($value, $object)
156
+ {
157
+ $attribute = $object->getResource()->getAttribute($this->getAttribute());
158
+ if ($attribute && $attribute->getBackendType() == 'datetime') {
159
+ $value = strtotime($value);
160
+ }
161
+ return $value;
162
+ }
163
+
164
+ /**
165
+ * Prepare multiselect attribute value
166
+ *
167
+ * @param mixed $value
168
+ * @param Varien_Object $object
169
+ * @return mixed
170
+ */
171
+ protected function _prepareMultiselectValue($value, $object)
172
+ {
173
+ $attribute = $object->getResource()->getAttribute($this->getAttribute());
174
+ if ($attribute && $attribute->getFrontendInput() == 'multiselect') {
175
+ $value = strlen($value) ? explode(',', $value) : array();
176
+ }
177
+ return $value;
178
+ }
179
+ }
app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Day.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_System_Config_Source_Day
4
+ {
5
+ /**
6
+ * Retrieve list of days
7
+ *
8
+ * @return string
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array(
14
+ 'label' => Mage::helper('smartassistant')->__('Sunday'),
15
+ 'value' => '0'
16
+ ),
17
+ array(
18
+ 'label' => Mage::helper('smartassistant')->__('Monday'),
19
+ 'value' => '1'
20
+ ),
21
+ array(
22
+ 'label' => Mage::helper('smartassistant')->__('Tuesday'),
23
+ 'value' => '2'
24
+ ),
25
+ array(
26
+ 'label' => Mage::helper('smartassistant')->__('Wednesday'),
27
+ 'value' => '3'
28
+ ),
29
+ array(
30
+ 'label' => Mage::helper('smartassistant')->__('Thursday'),
31
+ 'value' => '4'
32
+ ),
33
+ array(
34
+ 'label' => Mage::helper('smartassistant')->__('Friday'),
35
+ 'value' => '5'
36
+ ),
37
+ array(
38
+ 'label' => Mage::helper('smartassistant')->__('Saturday'),
39
+ 'value' => '6'
40
+ ),
41
+ );
42
+ }
43
+ }
app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Ftpmodes.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_System_Config_Source_Ftpmodes
4
+ {
5
+ /**
6
+ * Retrieve list of ftp modes
7
+ *
8
+ * @return string
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $modes = array(
13
+ 'ftp' => 'FTP',
14
+ 'ftps' => 'FTPS',
15
+ );
16
+ return $modes;
17
+ }
18
+ }
app/code/community/Smartassistant/Smartassistant/Model/System/Config/Source/Time.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_System_Config_Source_Time
4
+ {
5
+ /**
6
+ * Retrieve list of Times
7
+ *
8
+ * @return string
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $result = array();
13
+
14
+ for ($i = 0; $i < 24; $i++) {
15
+ $hour = $i;
16
+ $suffix = ' AM';
17
+ if ($hour > 12) {
18
+ $hour -= 12;
19
+ $suffix = ' PM';
20
+ }
21
+
22
+ if ($hour < 10) {
23
+ $hour = '0'.$hour;
24
+ }
25
+
26
+ $result[] = array(
27
+ 'label' => $hour.':00'.$suffix,
28
+ 'value' => $i * 60,
29
+ );
30
+ $result[] = array(
31
+ 'label' => $hour.':30'.$suffix,
32
+ 'value' => $i * 60 + 30,
33
+ );
34
+ }
35
+
36
+ return $result;
37
+ }
38
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task.php ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_summaryProgress = 0;
6
+ private $_progresRefreshFrequency = 5;
7
+ private $_taskConfigCached = array();
8
+ private $_taskLog = null;
9
+
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('smartassistant/task');
14
+ }
15
+
16
+ public function configure($configIds, $generate=null, $send=null, $time = null)
17
+ {
18
+ if ($this->isState(array(
19
+ Smartassistant_Smartassistant_Model_Task_Status::PROCESS,
20
+ Smartassistant_Smartassistant_Model_Task_Status::FINISHED,
21
+ ))) {
22
+ return false;
23
+ }
24
+
25
+ $this->setProgress(0);
26
+ $this->setItems(null);
27
+ $this->setTime($time);
28
+ $this->save();
29
+
30
+ $configIds = is_array($configIds) ? $configIds : array($configIds);
31
+
32
+ $configs = Mage::getModel('smartassistant/export')->getCollection()
33
+ ->addFieldToFilter('id', array('in' => $configIds));
34
+
35
+ foreach ($configs as $config) {
36
+ $generate = $generate !== null ? $generate : $config->getAutogenerate();
37
+ $send = $send !== null ? $send : $config->getAutosend();
38
+ $taskConfig = $this->getTaskConfig($config->getId());
39
+ $taskConfig->setGenerate($generate);
40
+ $taskConfig->setSend($send);
41
+ $taskConfig->save();
42
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::WAITING, $taskConfig);
43
+ }
44
+
45
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::WAITING);
46
+
47
+ return true;
48
+ }
49
+
50
+ public function isConfigured()
51
+ {
52
+ return true;
53
+ }
54
+
55
+ public function run()
56
+ {
57
+ if (! $this->isConfigured()) {
58
+ die('asd');
59
+ }
60
+
61
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::INITIALIZE);
62
+
63
+ /**
64
+ * Some initialize operations
65
+ */
66
+
67
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::PROCESS);
68
+ while (($taskConfig = $this->getNextTaskConfig()) !== null) {
69
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::INITIALIZE, $taskConfig);
70
+
71
+ $amount = $taskConfig->getConfig()->getProductsCollection()->count();
72
+ $this->updateProgress(0, $amount, $taskConfig);
73
+
74
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::PROCESS, $taskConfig);
75
+ if ($taskConfig->getGenerate()) {
76
+ $this->generate($taskConfig);
77
+ $this->updateProgress($amount, $amount, $taskConfig);
78
+ }
79
+ if ($taskConfig->getSend()) {
80
+ $this->sendFtp($taskConfig);
81
+ }
82
+
83
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::FINISHED, $taskConfig);
84
+ }
85
+ $this->updateState(Smartassistant_Smartassistant_Model_Task_Status::FINISHED);
86
+ }
87
+
88
+ private function getTaskConfig($configId)
89
+ {
90
+ if (! isset($this->_taskConfigCached[$configId])) {
91
+ $taskConfig = Mage::getModel('smartassistant/task_config')->getCollection()
92
+ ->addFieldToFilter('export_id', $configId)
93
+ ->addFieldToFilter('task_id', $this->getId())
94
+ ->getFirstItem();
95
+ if($taskConfig->isEmpty()) {
96
+ $taskConfig = Mage::getModel('smartassistant/task_config');
97
+ $taskConfig->setExportId($configId);
98
+ $taskConfig->setTaskId($this->getId());
99
+ $taskConfig->save();
100
+ $this->_taskConfigCached[$configId] = $taskConfig;
101
+ }
102
+ }
103
+ return $this->_taskConfigCached[$configId];
104
+ }
105
+
106
+ private function setTaskConfig($taskConfig)
107
+ {
108
+ $taskConfig->save();
109
+ $this->_taskConfigCached[$taskConfig->getExportId()] = $taskConfig;
110
+ }
111
+
112
+ private function getNextTaskConfig()
113
+ {
114
+ $taskConfig = Mage::getModel('smartassistant/task_config')->getCollection()
115
+ ->addFieldToFilter('task_id', $this->getId())
116
+ ->addFieldToFilter('status_id', Smartassistant_Smartassistant_Model_Task_Status::WAITING)
117
+ ->getFirstItem();
118
+ return $taskConfig->isEmpty() ? null : $taskConfig;
119
+ }
120
+
121
+ private function generate($taskConfig)
122
+ {
123
+ $message = Mage::helper('smartassistant')->__('Generation in process...');
124
+ $this->log($message, $taskConfig);
125
+
126
+ /**
127
+ * @var Smartassistant_Smartassistant_Model_Export
128
+ */
129
+ $config = $taskConfig->getConfig();
130
+
131
+ /**
132
+ * @var Smartassistant_Smartassistant_Model_Mysql4_Exportfield_Collection
133
+ */
134
+ $map = $config->getMap(true);
135
+
136
+ /**
137
+ * @var Mage_Catalog_Model_Resource_Product_Collection
138
+ */
139
+ $productsCollection = $config->getProductsCollection();
140
+
141
+ /**
142
+ * @var int Amount of products to Export
143
+ */
144
+ $productsAmount = $productsCollection->count();
145
+
146
+ $message = Mage::helper('smartassistant')->__('%s products were found', $productsAmount);
147
+ $this->log($message, $taskConfig);
148
+
149
+ /**
150
+ * @var Smartassistant_Smartassistant_Helper_Attribute
151
+ */
152
+ $attributeHelper = Mage::helper('smartassistant/attribute');
153
+
154
+ /**
155
+ * @var Smartassistant_Smartassistant_Helper_Filesystem
156
+ */
157
+ $fileHelper = Mage::helper('smartassistant/filesystem');
158
+
159
+ /**
160
+ * csv configuration
161
+ */
162
+ $delimiter = $config->getDelimiter();
163
+ $enclosure = $config->getEnclosure();
164
+
165
+ /**
166
+ * @var File path
167
+ */
168
+ $path = $config->getFilePath();
169
+
170
+ /**
171
+ * We need to remove old file (if exists)
172
+ */
173
+ if (file_exists($path)) {
174
+ $message = Mage::helper('smartassistant')->__('Export file exists. It will be replaced');
175
+ $this->log($message, $taskConfig);
176
+
177
+ if (! unlink($path)) {
178
+ $message = Mage::helper('smartassistant')->__('Can not remove export file. Generation stoped. Check file permissions to: %s', $path);
179
+ $this->log($message, $taskConfig);
180
+ return;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Openning file
186
+ */
187
+ $handler = $fileHelper->openFile($path);
188
+
189
+ /**
190
+ * Write headers to file
191
+ */
192
+ $headers = array();
193
+ foreach ($map as $field) {
194
+ $headers[] = $field->getFieldname();
195
+ }
196
+ $fileHelper->putCsvLine($handler, $headers, $delimiter, $enclosure);
197
+
198
+ /**
199
+ * Write product data
200
+ */
201
+ $counter = 1;
202
+ foreach ($productsCollection as $product) {
203
+ $productFields = array();
204
+ foreach ($map as $field) {
205
+ $value = $attributeHelper->getAttributeValue($product, $field);
206
+ $productFields[] = $value;
207
+ }
208
+ $fileHelper->putCsvLine($handler, $productFields, $delimiter, $enclosure);
209
+ if ($counter % $this->_progresRefreshFrequency == 0) {
210
+ $this->updateProgress($counter, $productsAmount, $taskConfig);
211
+ }
212
+ $counter++;
213
+ }
214
+
215
+ /**
216
+ * Close file
217
+ */
218
+ $fileHelper->closeFile($handler);
219
+ $message = Mage::helper('smartassistant')->__('Generation is finished');
220
+ $this->log($message, $taskConfig);
221
+ }
222
+
223
+ private function sendFtp($taskConfig)
224
+ {
225
+ $message = Mage::helper('smartassistant')->__('Sending file to FTP...');
226
+ $this->log($message, $taskConfig);
227
+ /**
228
+ * @var Smartassistant_Smartassistant_Model_Export
229
+ */
230
+ $config = $taskConfig->getConfig();
231
+ if(! $config->isFtpValid()) {
232
+ $message = Mage::helper('smartassistant')->__('FTP server is unreachable');
233
+ $this->log($message, $taskConfig);
234
+ }
235
+ if (! $config->exportExists()) {
236
+ $message = Mage::helper('smartassistant')->__('Unable to find export for given configuration');
237
+ $this->log($message, $taskConfig);
238
+ return false;
239
+ }
240
+
241
+ /**
242
+ * @var int Store ID
243
+ */
244
+ $storeId = $config->getStoreId();
245
+
246
+ /**
247
+ * Ftp configuration
248
+ */
249
+ $host = Mage::getStoreConfig('smartassistant/ftp/host', $storeId);
250
+ $login = Mage::getStoreConfig('smartassistant/ftp/user', $storeId);
251
+ $password = Mage::getStoreConfig('smartassistant/ftp/password', $storeId);
252
+ $path = Mage::getStoreConfig('smartassistant/ftp/path', $storeId);
253
+ $pasive = Mage::getStoreConfig('smartassistant/ftp/pasivemode', $storeId);
254
+ $transferMode = Smartassistant_Smartassistant_Helper_FtpConnector::BINARY;
255
+ $port = Mage::getStoreConfig('smartassistant/ftp/port', $storeId);
256
+ $port = empty($port) ? 21 : $port;
257
+
258
+ $destinationFileName = $config->getFilename() . '.csv';
259
+ $sourceFilePath = $config->getFilePath();
260
+
261
+ $ftp = new Smartassistant_Smartassistant_Helper_FtpConnector($host, $login, $password, $port, $pasive);
262
+ $success = $ftp->putFile($destinationFileName, $sourceFilePath, $path, $transferMode);
263
+ if (! $success) {
264
+ $message = Mage::helper('smartassistant')->__('Unable to send file to FTP server. Check access permissions on server');
265
+ $this->log($message, $taskConfig);
266
+ } else {
267
+ $message = Mage::helper('smartassistant')->__('File was sent to FTP');
268
+ $this->log($message, $taskConfig);
269
+ }
270
+
271
+ return $success;
272
+ }
273
+
274
+ private function isState($status)
275
+ {
276
+ $status = is_array($status) ? $status : array($status);
277
+ return in_array($this->getStatusId(), $status);
278
+ }
279
+
280
+ private function updateState($status, $taskConfig = null)
281
+ {
282
+ if ($taskConfig === null) {
283
+ $this->setStatusId($status);
284
+ $this->save();
285
+ } else {
286
+ $taskConfig->setStatusId($status);
287
+ $this->setTaskConfig($taskConfig);
288
+ }
289
+ }
290
+
291
+ private function updateProgress($progress, $all, $taskConfig = null)
292
+ {
293
+ $this->_summaryProgress += $progress;
294
+ $this->setProgress($this->_summaryProgress);
295
+ $this->save();
296
+
297
+ if ($taskConfig !== null) {
298
+ $taskConfig->setProgress($progress);
299
+ $taskConfig->setItems($all);
300
+ $this->setTaskConfig($taskConfig);
301
+ }
302
+ }
303
+
304
+ private function log($message, $taskConfig = null)
305
+ {
306
+ if ($this->_taskLog === null) {
307
+ $this->_taskLog = Mage::getModel('smartassistant/task_log');
308
+ }
309
+ $this->_taskLog->put($message, $this, $taskConfig);
310
+ }
311
+
312
+ public function getStats()
313
+ {
314
+ $configTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/export');
315
+ $taskConfigTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/task_config');
316
+ $taskStatusTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/task_status');
317
+ $taskLogTable = Mage::getSingleton('core/resource')->getTableName('smartassistant/task_log');
318
+
319
+ $collection = Mage::getModel('smartassistant/task_log')->getCollection();
320
+
321
+ $select = $collection->getSelect();
322
+ $select->join(array("tc" => $taskConfigTable), "main_table.task_config_id = tc.id", array(
323
+ 'partial_progress' => 'tc.progress',
324
+ 'partial_amount' => 'tc.items',
325
+ ));
326
+ $select->join(array("tcs" => $taskStatusTable), "tc.status_id = tcs.id", array(
327
+ 'partial_status' => 'tcs.name'
328
+ ));
329
+ $select->join(array("ec" => $configTable), "tc.export_id = ec.id", array(
330
+ 'export_name' => 'ec.name'
331
+ ));
332
+ $select->order('main_table.id');
333
+
334
+ $collection->addFieldToFilter('main_table.task_id', $this->getId());
335
+
336
+ $out = array();
337
+ $items = $collection->getItems();
338
+ foreach ($items as $item) {
339
+ if (! isset($out[$item['task_config_id']])) {
340
+ $out[$item['task_config_id']] = array(
341
+ 'log' => array(),
342
+ 'status' => array(),
343
+ );
344
+ }
345
+ $out[$item['task_config_id']]['log'][] = array(
346
+ 'datetime' => $item['datetime'],
347
+ 'message' => $item['message'],
348
+ );
349
+ $out[$item['task_config_id']]['status'] = array(
350
+ 'export_name' => $item['export_name'],
351
+ 'progress' => $item['partial_progress'],
352
+ 'amount' => $item['partial_amount'],
353
+ 'status' => $item['partial_status'],
354
+ );
355
+ }
356
+
357
+ return $out;
358
+ }
359
+
360
+ public function getTaskConfigs()
361
+ {
362
+ $collection = Mage::getModel('smartassistant/task_config')->getCollection();
363
+ $collection->addFieldToFilter('task_id', array('eq' => $this->getId()));
364
+ return $collection;
365
+ }
366
+
367
+ public function getStatus()
368
+ {
369
+ $model = Mage::getModel('smartassistant/task_status')->load($this->getStatusId());
370
+ return $model;
371
+ }
372
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Config.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Config extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_config');
9
+ }
10
+
11
+ /**
12
+ * Config associated with this task
13
+ *
14
+ * @return Smartassistant_Smartassistant_Model_Export
15
+ */
16
+ public function getConfig()
17
+ {
18
+ $config = Mage::getModel('smartassistant/export')->load($this->getExportId());
19
+ return $config;
20
+ }
21
+
22
+ public function getStatus()
23
+ {
24
+ $config = Mage::getModel('smartassistant/task_status')->load($this->getStatusId());
25
+ return $config;
26
+ }
27
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Log.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Log extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_log');
9
+ }
10
+
11
+ public function put($message, $task, $taskConfig)
12
+ {
13
+ $log = Mage::getModel('smartassistant/task_log');
14
+ $log->setMessage($message);
15
+ $log->setTaskId($task->getId());
16
+ if ($taskConfig !== null) {
17
+ $log->setTaskConfigId($taskConfig->getId());
18
+ }
19
+ $log->save();
20
+ }
21
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Config.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task_config', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Config/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Mysql4_Config_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_config');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Status.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Mysql4_Status extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('smartassistant/task_status', 'id');
8
+ }
9
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Mysql4/Status/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Mysql4_Status_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('smartassistant/task_status');
9
+ }
10
+ }
app/code/community/Smartassistant/Smartassistant/Model/Task/Status.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Model_Task_Status extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * @var int Status - waiting
7
+ */
8
+ const WAITING = 1;
9
+
10
+ /**
11
+ * @var int Status - initialize
12
+ */
13
+ const INITIALIZE = 2;
14
+
15
+ /**
16
+ * @var int Status - process
17
+ */
18
+ const PROCESS = 3;
19
+
20
+ /**
21
+ * @var int Status - finished with success
22
+ */
23
+ const FINISHED = 4;
24
+
25
+ /**
26
+ * @var int Status - file generated
27
+ */
28
+ const GENERATED = 5;
29
+
30
+ /**
31
+ * @var int Status - file send
32
+ */
33
+ const SEND = 6;
34
+
35
+ /**
36
+ * @var int Status - failed
37
+ */
38
+ const FAILED = 7;
39
+
40
+ public function _construct()
41
+ {
42
+ parent::_construct();
43
+ $this->_init('smartassistant/task_status');
44
+ }
45
+ }
app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/ExportController.php ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Adminhtml_Smartassistant_ExportController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * Display grid
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->_setActiveMenu('catalog');
12
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
13
+ $this->_addContent($this->getLayout()->createBlock('smartassistant/adminhtml_export'));
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Display task stats
19
+ */
20
+ public function statsAction()
21
+ {
22
+ $id = Mage::app()->getRequest()->getParam('id', null);
23
+ if (
24
+ ($model = $this->loadCurrentModelInstance($id, false)) !== null
25
+ && ($taskId =$model->getLastTaskId())!==null
26
+ ) {
27
+ $this->loadLayout();
28
+ $block = $this->getLayout()->createBlock('smartassistant/adminhtml_taskStats');
29
+ $block->setTaskId($taskId);
30
+ $this->getResponse()->clearHeaders();
31
+
32
+ $task = Mage::getModel('smartassistant/task')->load($taskId);
33
+ $finished = in_array($task->status_id, array(
34
+ Smartassistant_Smartassistant_Model_Task_Status::FINISHED,
35
+ Smartassistant_Smartassistant_Model_Task_Status::FAILED,
36
+ ));
37
+
38
+ $response = array(
39
+ 'finished' => $finished,
40
+ 'html' => $block->toHtml(),
41
+ );
42
+ $this->getResponse()
43
+ ->clearHeaders()
44
+ ->setHeader('Content-Type', 'application/json')
45
+ ->setBody(json_encode($response));
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Display config edit form
51
+ */
52
+ public function editAction()
53
+ {
54
+ if (Mage::app()->getRequest()->isPost()) {
55
+ try {
56
+ $this->processPost();
57
+ return;
58
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
59
+ die($e->getMessage());
60
+ }
61
+ }
62
+
63
+ $this->_title($this->__('smartassistans'))->_title($this->__('Feed configuration'));
64
+
65
+ $this->loadLayout();
66
+
67
+ $head = $this->getLayout()->getBlock('head');
68
+ $head->setCanLoadExtJs(true);
69
+ $head->setCanLoadExtJs(true);
70
+ $head->setCanLoadRulesJs(true);
71
+
72
+ $head->addItem('js', 'mage/adminhtml/rules.js');
73
+ $head->addItem('skin_js', 'smartassistant/smartassistant.js');
74
+ $head->addItem('skin_css', 'smartassistant/smartassistant.css');
75
+
76
+ $this->_setActiveMenu('catalog');
77
+ $this->_addContent($this->getLayout()->createBlock('smartassistant/adminhtml_export_edit'))
78
+ ->_addLeft($this->getLayout()->createBlock('smartassistant/adminhtml_export_edit_tabs'));
79
+ $this->renderLayout();
80
+ }
81
+
82
+ /**
83
+ * Delete configuration
84
+ */
85
+ public function deleteAction()
86
+ {
87
+ $id = Mage::app()->getRequest()->getParam('id', null);
88
+ try {
89
+ if ($id === null) {
90
+ throw new Smartassistant_Smartassistant_Helper_Exception(
91
+ Mage::helper('smartassistant')->__('Id is invalid')
92
+ );
93
+ }
94
+ if (($model = $this->loadCurrentModelInstance($id, false)) === null) {
95
+ throw new Smartassistant_Smartassistant_Helper_Exception(
96
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
97
+ );
98
+ }
99
+ if (! $model->cascadeDelete()) {
100
+ throw new Smartassistant_Smartassistant_Helper_Exception(
101
+ Mage::helper('smartassistant')->__('Unable remove this model')
102
+ );
103
+ }
104
+
105
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('smartassistant')->__('Success'));
106
+ $this->redirect();
107
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
108
+ Mage::getSingleton('core/session')->addError($e->getMessage());
109
+ $this->redirect($id);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Send generated file to ftp
115
+ */
116
+ public function sendAction()
117
+ {
118
+ $id = Mage::app()->getRequest()->getParam('id', null);
119
+ try {
120
+ if ($id === null) {
121
+ throw new Smartassistant_Smartassistant_Helper_Exception(
122
+ Mage::helper('smartassistant')->__('Id is invalid')
123
+ );
124
+ }
125
+ if (($model = $this->loadCurrentModelInstance($id, false)) === null) {
126
+ throw new Smartassistant_Smartassistant_Helper_Exception(
127
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
128
+ );
129
+ }
130
+ if (! $model->exportExists()) {
131
+ throw new Smartassistant_Smartassistant_Helper_Exception(
132
+ Mage::helper('smartassistant')->__('Unable to find export for given configuration')
133
+ );
134
+ }
135
+ if (! $model->isFtpValid()) {
136
+ throw new Smartassistant_Smartassistant_Helper_Exception(
137
+ Mage::helper('smartassistant')->__('Unable to connect with FTP server. Check access FTP configuration')
138
+ );
139
+ }
140
+
141
+ $generator = Mage::getModel('smartassistant/generator');
142
+ $generator->customRun($model->getId(), false, true);
143
+
144
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('smartassistant')->__('Success'));
145
+ $this->redirect($id, true);
146
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
147
+ Mage::getSingleton('core/session')->addError($e->getMessage());
148
+ $this->redirect($id, true);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Generate file
154
+ */
155
+ public function generateAction()
156
+ {
157
+ $id = Mage::app()->getRequest()->getParam('id', null);
158
+ try {
159
+ if ($id === null) {
160
+ throw new Smartassistant_Smartassistant_Helper_Exception(
161
+ Mage::helper('smartassistant')->__('Id is invalid')
162
+ );
163
+ }
164
+ if (($model = $this->loadCurrentModelInstance($id, false)) === null) {
165
+ throw new Smartassistant_Smartassistant_Helper_Exception(
166
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
167
+ );
168
+ }
169
+
170
+ $generator = Mage::getModel('smartassistant/generator');
171
+ $generator->customRun($model->getId(), true, false);
172
+
173
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('smartassistant')->__('Success'));
174
+ $this->redirect($id, true, true);
175
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
176
+ Mage::getSingleton('core/session')->addError($e->getMessage());
177
+ $this->redirect($id, true);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Download generated file
183
+ */
184
+ public function downloadAction()
185
+ {
186
+ $id = Mage::app()->getRequest()->getParam('id', null);
187
+ try {
188
+ if ($id === null) {
189
+ throw new Smartassistant_Smartassistant_Helper_Exception(
190
+ Mage::helper('smartassistant')->__('Id is invalid')
191
+ );
192
+ }
193
+ if (($model = $this->loadCurrentModelInstance($id, false)) === null) {
194
+ throw new Smartassistant_Smartassistant_Helper_Exception(
195
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
196
+ );
197
+ }
198
+ if (! $model->exportExists()) {
199
+ throw new Smartassistant_Smartassistant_Helper_Exception(
200
+ Mage::helper('smartassistant')->__('Unable to find export for given configuration')
201
+ );
202
+ }
203
+
204
+ $path = $model->getFilePath();
205
+
206
+ header('Content-Type: application/octet-stream');
207
+ header("Content-Transfer-Encoding: Binary");
208
+ header("Content-disposition: attachment; filename=\"" . $model->getFilename() . ".csv\"");
209
+ readfile($path);
210
+ exit;
211
+
212
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
213
+ Mage::getSingleton('core/session')->addError($e->getMessage());
214
+ $this->redirect($id, true);
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Generate file and send it to ftp server
220
+ */
221
+ public function generateSendAction()
222
+ {
223
+ $id = Mage::app()->getRequest()->getParam('id', null);
224
+ try {
225
+ if ($id === null) {
226
+ throw new Smartassistant_Smartassistant_Helper_Exception(
227
+ Mage::helper('smartassistant')->__('Id is invalid')
228
+ );
229
+ }
230
+ if (($model = $this->loadCurrentModelInstance($id, false)) === null) {
231
+ throw new Smartassistant_Smartassistant_Helper_Exception(
232
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
233
+ );
234
+ }
235
+ if (! $model->isFtpValid()) {
236
+ throw new Smartassistant_Smartassistant_Helper_Exception(
237
+ Mage::helper('smartassistant')->__('Unable to connect with FTP server. Check access FTP configuration')
238
+ );
239
+ }
240
+
241
+ $generator = Mage::getModel('smartassistant/generator');
242
+ $generator->customRun($model->getId(), true, true);
243
+
244
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('smartassistant')->__('Success'));
245
+ $this->redirect($id, true, true);
246
+ } catch (Smartassistant_Smartassistant_Helper_Exception $e) {
247
+ Mage::getSingleton('core/session')->addError($e->getMessage());
248
+ $this->redirect($id, true);
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Display new condition html
254
+ */
255
+ public function newConditionHtmlAction()
256
+ {
257
+ $id = $this->getRequest()->getParam('id');
258
+ $typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
259
+ $type = $typeArr[0];
260
+
261
+ $model = Mage::getModel($type)
262
+ ->setId($id)
263
+ ->setType($type)
264
+ ->setRule(Mage::getModel('catalogrule/rule'))
265
+ ->setPrefix('conditions');
266
+ if (!empty($typeArr[1])) {
267
+ $model->setAttribute($typeArr[1]);
268
+ }
269
+
270
+ if ($model instanceof Mage_Rule_Model_Condition_Abstract) {
271
+ $model->setJsFormObject($this->getRequest()->getParam('form'));
272
+ $html = $model->asHtmlRecursive();
273
+ } else {
274
+ $html = '';
275
+ }
276
+ $this->getResponse()->setBody($html);
277
+ }
278
+
279
+ /**
280
+ * Process POST request qith config data and save it in database
281
+ */
282
+ private function processPost()
283
+ {
284
+ if (($configId = Mage::app()->getRequest()->getParam('id', null))!==null) {
285
+ $model = Mage::getModel('smartassistant/export')->load($configId);
286
+ if ($model->isEmpty()) {
287
+ throw new Smartassistant_Smartassistant_Helper_Exception(
288
+ Mage::helper('smartassistant')->__('Unable to find model for given id')
289
+ );
290
+ }
291
+ } else {
292
+ /**
293
+ * If there is no $configId provided we will create new config
294
+ */
295
+ $model = Mage::getModel('smartassistant/export');
296
+ }
297
+
298
+ $data = Mage::app()->getRequest()->getPost();
299
+
300
+ /**
301
+ * We need to assign boolean options directly to provide properly action
302
+ */
303
+ $data['autogenerate'] = (boolean) Mage::app()->getRequest()->getPost('autogenerate', false);
304
+ $data['autosend'] = (boolean) Mage::app()->getRequest()->getPost('autosend', false);
305
+
306
+ $generalData = array_intersect_key($data, array_fill_keys(array(
307
+ 'store_id', 'active', 'name', 'filename', 'autogenerate', 'autosend',
308
+ ), null));
309
+ $model->setData(array_merge($generalData, array('id' => $model->getId())));
310
+
311
+ /**
312
+ * We need to assign options directly via setter methods in Smartassistant_Smartassistant_Model_Export
313
+ */
314
+ $model->setDays(isset($data['days']) ? $data['days'] : array());
315
+ $model->setHours(isset($data['hours']) ? $data['hours'] : array());
316
+
317
+ $model->save();
318
+ $model->assignFieldsMap($data['map']);
319
+ $model->saveRules($data['rule']['conditions']);
320
+
321
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('smartassistant')->__('Success'));
322
+ $this->redirect($model->getId());
323
+ }
324
+
325
+ /**
326
+ * Redirecting
327
+ *
328
+ * @param int $id Export ID
329
+ * @param boolean $back Flag
330
+ * @return void
331
+ */
332
+ private function redirect($id = null, $back = false, $runLoader = false)
333
+ {
334
+ if ($id !== null && ($back || $this->getRequest()->getParam('back'))) {
335
+ $params = array('id' => $id);
336
+ if ($runLoader) {
337
+ $params['run'] = true;
338
+ }
339
+ if (($tab=Mage::app()->getRequest()->getParam('tab', null)) !== null) {
340
+ $params['tab'] = $tab;
341
+ }
342
+ $this->getResponse()->setRedirect($this->getUrl('*/*/edit', $params));
343
+ } else {
344
+ $this->getResponse()->setRedirect($this->getUrl('*/*/index'));
345
+ }
346
+ return;
347
+ }
348
+
349
+ /**
350
+ * Load model class for given ID or create new model (if $createNew is true)
351
+ *
352
+ * @param int $id
353
+ * @param boolean $createNew
354
+ * @param string $modelClass
355
+ * @return mixed
356
+ */
357
+ private function loadCurrentModelInstance($id, $createNew = true, $modelClass = 'smartassistant/export')
358
+ {
359
+ $model = Mage::getModel($modelClass)->load($id);
360
+ if ($model->isEmpty() && $createNew) {
361
+ return Mage::getModel($modelClass);
362
+ } elseif (! $model->isEmpty()) {
363
+ return $model;
364
+ } else {
365
+ return null;
366
+ }
367
+ }
368
+
369
+ protected function _isAllowed()
370
+ {
371
+ return true;
372
+ return parent::_isAllowed();
373
+ }
374
+ }
app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/PanelController.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Adminhtml_Smartassistant_PanelController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ if ($this->isAllowed() && ($url=$this->getPanelLink()) !== null) {
8
+ $this->getResponse()->setRedirect($url);
9
+ return;
10
+ }
11
+
12
+ Mage::getSingleton('core/session')->addError(Mage::helper('smartassistant')->__('Unable to redirect'));
13
+ $this->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('/'));
14
+ }
15
+
16
+ private function isAllowed()
17
+ {
18
+ $accountId = Mage::getStoreConfig('smartassistant/auth/account_id');
19
+ $accountPassword = Mage::getStoreConfig('smartassistant/auth/account_password');
20
+ $oemUser = Mage::getSingleton('admin/session')->getUser()->getUsername();
21
+
22
+ return (! empty($accountId) && ! empty($accountPassword) && ! empty($oemUser));
23
+ }
24
+
25
+ private function encrypt($input)
26
+ {
27
+ $originalPath = get_include_path();
28
+ $file = dirname(__FILE__) . '/../../../secret/oem.public.key';
29
+ $publicKey = file_get_contents($file);
30
+
31
+ set_include_path(rtrim(Mage::getBaseDir('lib'), '/') . '/phpseclib');
32
+ $rsa = new Crypt_RSA();
33
+ $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
34
+ $rsa->loadKey($publicKey);
35
+ $ciphertext = $rsa->encrypt($input);
36
+ $ciphertext = base64_encode($ciphertext);
37
+
38
+ set_include_path($originalPath);
39
+ return $ciphertext;
40
+ }
41
+
42
+ private function getPanelLink()
43
+ {
44
+ $accountId = Mage::getStoreConfig('smartassistant/auth/account_id');
45
+ $accountPassword = Mage::getStoreConfig('smartassistant/auth/account_password');
46
+ $oemUser = Mage::getSingleton('admin/session')->getUser()->getUsername();
47
+ $platformUrl = Mage::getStoreConfig('smartassistant/advisor/platformUrl');
48
+
49
+ if (empty($accountId) || empty($accountPassword) || empty($oemUser)) {
50
+ return null;
51
+ }
52
+
53
+ $oem = $this->encrypt(json_encode(array(
54
+ 'accountId' => $accountId,
55
+ 'accountPassword' => $accountPassword,
56
+ 'oemUser' => $oemUser,
57
+ 'oemPartner' => 'Magento',
58
+ )));
59
+
60
+ return $platformUrl . $oem;
61
+ }
62
+
63
+ protected function _isAllowed()
64
+ {
65
+ return true;
66
+ }
67
+ }
app/code/community/Smartassistant/Smartassistant/controllers/Adminhtml/Smartassistant/TasksController.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_Adminhtml_Smartassistant_TasksController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout();
8
+ $this->_setActiveMenu('catalog');
9
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
10
+ $this->_addContent($this->getLayout()->createBlock('smartassistant/adminhtml_tasks'));
11
+ $this->renderLayout();
12
+ }
13
+
14
+ public function previewAction()
15
+ {
16
+ $this->_title($this->__('smartassistans'))->_title($this->__('Task preview'));
17
+ $this->loadLayout();
18
+ $this->_setActiveMenu('catalog');
19
+ $this->_addContent($this->getLayout()->createBlock('smartassistant/adminhtml_tasks_preview'));
20
+ $this->renderLayout();
21
+ }
22
+
23
+ public function statsAction()
24
+ {
25
+ $this->loadLayout();
26
+ $block = $this->getLayout()->createBlock('smartassistant/adminhtml_taskStats');
27
+ $block->setTaskId(Mage::app()->getRequest()->getParam('id', null));
28
+ $this->getResponse()->clearHeaders();
29
+ $this->getResponse()->setBody($block->toHtml());
30
+ }
31
+
32
+ private function loadCurrentModelInstance($id, $modelClass = 'smartassistant/task')
33
+ {
34
+ $model = Mage::getModel($modelClass)->load($id);
35
+ if ($model->isEmpty()) {
36
+ return Mage::getModel($modelClass);
37
+ } else {
38
+ return $model;
39
+ }
40
+ }
41
+
42
+ protected function _isAllowed()
43
+ {
44
+ return true;
45
+ }
46
+ }
app/code/community/Smartassistant/Smartassistant/controllers/SmartassistantController.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Smartassistant_Smartassistant_SmartassistantController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Run cron action
7
+ * - if executed with GET: ?force=1 it will ignore configuration cron enable/disable settings
8
+ */
9
+ public function cronAction()
10
+ {
11
+ $force = Mage::app()->getRequest()->getParam('force', false);
12
+ $generator = Mage::getModel('smartassistant/generator');
13
+ $generator->scheduleRun($force);
14
+ }
15
+ }
app/code/community/Smartassistant/Smartassistant/etc/adminhtml.xml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <menu>
4
+ <catalog>
5
+ <children>
6
+ <smartassistant module="smartassistant">
7
+ <title>SMARTASSISTANT</title>
8
+ <action>adminhtml/smartassistant_export</action>
9
+ <sort_order>1000</sort_order>
10
+
11
+ <children>
12
+ <export module="smartassistant">
13
+ <title>Export CSV</title>
14
+ <action>adminhtml/smartassistant_export</action>
15
+ <sort_order>10</sort_order>
16
+ </export>
17
+ <tasks module="smartassistant">
18
+ <title>Tasks list</title>
19
+ <action>adminhtml/smartassistant_tasks</action>
20
+ <sort_order>20</sort_order>
21
+ </tasks>
22
+ <panel module="smartassistant">
23
+ <title>Advisor configurator</title>
24
+ <action>adminhtml/smartassistant_panel</action>
25
+ <sort_order>30</sort_order>
26
+ </panel>
27
+ </children>
28
+ </smartassistant>
29
+ </children>
30
+ </catalog>
31
+ </menu>
32
+ <acl>
33
+ <resources>
34
+ <all>
35
+ <title>Allow Everything</title>
36
+ </all>
37
+ <admin>
38
+ <children>
39
+ <system module="smartassistant">
40
+ <children>
41
+ <config>
42
+ <children>
43
+ <smartassistant translate="title" module="smartassistant">
44
+ <title>Smartassistant</title>
45
+ <sort_order>99</sort_order>
46
+ </smartassistant>
47
+ </children>
48
+ </config>
49
+ </children>
50
+ </system>
51
+ </children>
52
+ </admin>
53
+ </resources>
54
+ </acl>
55
+ <layout>
56
+ <updates>
57
+ <smartassistant>
58
+ <file>smartassistant.xml</file>
59
+ </smartassistant>
60
+ </updates>
61
+ </layout>
62
+ </config>
app/code/community/Smartassistant/Smartassistant/etc/config.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Smartassistant_Smartassistant>
5
+ <version>1.0.0</version>
6
+ </Smartassistant_Smartassistant>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <smartassistant>
11
+ <class>Smartassistant_Smartassistant_Block</class>
12
+ </smartassistant>
13
+ </blocks>
14
+ <helpers>
15
+ <smartassistant>
16
+ <class>Smartassistant_Smartassistant_Helper</class>
17
+ </smartassistant>
18
+ </helpers>
19
+ <models>
20
+ <smartassistant>
21
+ <class>Smartassistant_Smartassistant_Model</class>
22
+ <resourceModel>smartassistant_mysql4</resourceModel>
23
+ </smartassistant>
24
+ <smartassistant_mysql4>
25
+ <class>Smartassistant_Smartassistant_Model_Mysql4</class>
26
+ <deprecatedNode>smartassistant_mysql4</deprecatedNode>
27
+ <entities>
28
+ <export>
29
+ <table>smartassistant_export</table>
30
+ </export>
31
+ <exportfield>
32
+ <table>smartassistant_exportfield</table>
33
+ </exportfield>
34
+ <scheduledtask>
35
+ <table>smartassistant_scheduled_tasks</table>
36
+ </scheduledtask>
37
+ <rule>
38
+ <table>smartassistant_rule</table>
39
+ </rule>
40
+ <task>
41
+ <table>smartassistant_task</table>
42
+ </task>
43
+ <task_status>
44
+ <table>smartassistant_task_status</table>
45
+ </task_status>
46
+ <task_config>
47
+ <table>smartassistant_task_config</table>
48
+ </task_config>
49
+ <task_log>
50
+ <table>smartassistant_task_log</table>
51
+ </task_log>
52
+ </entities>
53
+ </smartassistant_mysql4>
54
+ </models>
55
+ <resources>
56
+ <smartassistant_setup>
57
+ <setup>
58
+ <module>Smartassistant_Smartassistant</module>
59
+ </setup>
60
+ <connection>
61
+ <use>core_setup</use>
62
+ </connection>
63
+ </smartassistant_setup>
64
+ </resources>
65
+ </global>
66
+ <admin>
67
+ <routers>
68
+ <adminhtml>
69
+ <args>
70
+ <modules>
71
+ <smartassistant before="Mage_Adminhtml">Smartassistant_Smartassistant_Adminhtml</smartassistant>
72
+ </modules>
73
+ </args>
74
+ </adminhtml>
75
+ </routers>
76
+ </admin>
77
+ <frontend>
78
+ <layout>
79
+ <updates>
80
+ <smartassistant>
81
+ <file>smartassistant.xml</file>
82
+ </smartassistant>
83
+ </updates>
84
+ </layout>
85
+ <routers>
86
+ <smartassistant>
87
+ <use>standard</use>
88
+ <args>
89
+ <module>Smartassistant_Smartassistant</module>
90
+ <frontName>smartassistant</frontName>
91
+ </args>
92
+ </smartassistant>
93
+ </routers>
94
+ </frontend>
95
+ <default>
96
+ <smartassistant>
97
+ <advisor>
98
+ <enable>1</enable>
99
+ <contextPath>https://st.smartassistant.com/advisor-fe-web</contextPath>
100
+ <platformUrl>https://st.smartassistant.com/configurator/auth?oem=</platformUrl>
101
+ </advisor>
102
+ <ftp>
103
+ <port>21</port>
104
+ <pasivemode>1</pasivemode>
105
+ </ftp>
106
+ <general>
107
+ <cron>1</cron>
108
+ <useShell>1</useShell>
109
+ </general>
110
+ </smartassistant>
111
+ </default>
112
+ <crontab>
113
+ <jobs>
114
+ <smartassistant_scheduled_actions>
115
+ <schedule>
116
+ <cron_expr>*/5 * * * *</cron_expr>
117
+ </schedule>
118
+ <run>
119
+ <model>smartassistant/generator::scheduleRun</model>
120
+ </run>
121
+ </smartassistant_scheduled_actions>
122
+ </jobs>
123
+ </crontab>
124
+ </config>
app/code/community/Smartassistant/Smartassistant/etc/system.xml ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <smartassistant translate="label">
5
+ <label>SMARTASSISTANT configuration</label>
6
+ <tab>general</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>1000</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <auth>
14
+ <label>SMARTASSISTANT credentials</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <account_id>
22
+ <label>Account ID</label>
23
+ <comment><![CDATA[The value of this property you should receive via e-mail after <a href="https://st.smartassistant.com/configurator/register/Magento" target="_blank">registration</a>.]]></comment>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>0</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </account_id>
30
+ <account_password>
31
+ <label>Account password</label>
32
+ <comment><![CDATA[Password set in <a href="https://st.smartassistant.com/configurator/register/Magento" target="_blank">registration</a> process.]]></comment>
33
+ <frontend_type>password</frontend_type>
34
+ <sort_order>2</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </account_password>
39
+ </fields>
40
+ </auth>
41
+ <advisor module="smartassistant">
42
+ <label>Advisor configuration</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>2</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ <fields>
49
+ <enable>
50
+ <label>Enable</label>
51
+ <comment><![CDATA[Enable/Disable advisor widget]]></comment>
52
+ <frontend_type>select</frontend_type>
53
+ <source_model>adminhtml/system_config_source_yesno</source_model>
54
+ <sort_order>1</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>0</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </enable>
59
+ <contextPath>
60
+ <label>Context path</label>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>1</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </contextPath>
67
+ <platformUrl>
68
+ <label>Platform URL</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>3</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </platformUrl>
75
+ </fields>
76
+ </advisor>
77
+ <ftp module="smartassistant">
78
+ <label>FTP configuration</label>
79
+ <frontend_type>text</frontend_type>
80
+ <sort_order>3</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ <fields>
85
+ <host>
86
+ <label>Host</label>
87
+ <frontend_type>text</frontend_type>
88
+ <sort_order>1</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </host>
93
+ <user>
94
+ <label>User</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>2</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ </user>
101
+ <password>
102
+ <label>Password</label>
103
+ <frontend_type>password</frontend_type>
104
+ <sort_order>3</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ </password>
109
+ <path>
110
+ <label>Path</label>
111
+ <frontend_type>text</frontend_type>
112
+ <sort_order>4</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ </path>
117
+ <pasivemode>
118
+ <label>Passive mode</label>
119
+ <frontend_type>select</frontend_type>
120
+ <source_model>adminhtml/system_config_source_yesno</source_model>
121
+ <sort_order>5</sort_order>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ </pasivemode>
126
+ <port>
127
+ <label>Port</label>
128
+ <frontend_type>text</frontend_type>
129
+ <sort_order>6</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>1</show_in_website>
132
+ <show_in_store>1</show_in_store>
133
+ <comment><![CDATA[(Default port for FTP is 21)]]></comment>
134
+ </port>
135
+ </fields>
136
+ </ftp>
137
+ <general module="smartassistant">
138
+ <label>Export settings</label>
139
+ <frontend_type>text</frontend_type>
140
+ <sort_order>4</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <show_in_store>1</show_in_store>
144
+ <fields>
145
+ <cron>
146
+ <label>Auto sending</label>
147
+ <comment><![CDATA[Auto sending<br />Enable/Disable cron operations for this module.<br />If is set to "No", the module will not perform any automatic generation.]]></comment>
148
+ <frontend_type>select</frontend_type>
149
+ <source_model>adminhtml/system_config_source_yesno</source_model>
150
+ <sort_order>1</sort_order>
151
+ <show_in_default>1</show_in_default>
152
+ <show_in_website>0</show_in_website>
153
+ <show_in_store>0</show_in_store>
154
+ </cron>
155
+ <useShell>
156
+ <label>Use shell</label>
157
+ <comment><![CDATA[If is set to "No", the module will generate files via standard HTTP process. If set to "Yes", the module will use shell script to generate files.]]></comment>
158
+ <frontend_type>select</frontend_type>
159
+ <source_model>adminhtml/system_config_source_yesno</source_model>
160
+ <sort_order>2</sort_order>
161
+ <show_in_default>1</show_in_default>
162
+ <show_in_website>0</show_in_website>
163
+ <show_in_store>0</show_in_store>
164
+ </useShell>
165
+ </fields>
166
+ </general>
167
+ </groups>
168
+ </smartassistant>
169
+ </sections>
170
+ </config>
app/code/community/Smartassistant/Smartassistant/etc/widget.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <widgets>
3
+ <smartassistant_widget type="smartassistant/widget" translate="smartassistant" module="smartassistant">
4
+ <name>SMARTASSISTANT widget</name>
5
+ <description>Allows you to put SMARTASSISTANT code to your site</description>
6
+ <parameters>
7
+ <code>
8
+ <label>Advisor code</label>
9
+ <description>See your advisor code at SMARTASSISTANT Integrate page</description>
10
+ <visible>1</visible>
11
+ <required>1</required>
12
+ <type>text</type>
13
+ </code>
14
+ <uc>
15
+ <label>Unique</label>
16
+ <visible>1</visible>
17
+ <required>1</required>
18
+ <type>smartassistant/adminhtml_renderer_widget</type>
19
+ </uc>
20
+ </parameters>
21
+ </smartassistant_widget>
22
+ </widgets>
app/code/community/Smartassistant/Smartassistant/secret/oem.public.key ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ MIIBCgKCAQEA3sKlUZRlSLYTe0XBcP+wAZtR+oJUxFlLV0KYuo/3XXZvxWd1KBIz
2
+ eRc5mdeWZbb+Dur6up1xilFd7824HNFamzbDEfc9Q6vlJ1m4i1u51tDJFaThwOg7
3
+ UPUGjqH5T8jW4SaNHUUZBAW7YPgyBQOaPS/cvj3J366hpMj133WGJcwmcOi1NQPj
4
+ H8C/3mcxLRcOfgx8fWhJrTHCHt3i4BHqw8z70TztKNJJ6Lit/aag6nZoispu4FTj
5
+ zYxkPMuA1m6Ze1kP665p5OaRX7N2/etDQQvZIJrCZ1CTIiTlLg1oDEmMK023Hqdt
6
+ sw0lJHtO9EiYawbkXHhq3UL+z91Opt6xdQIDAQAB
app/code/community/Smartassistant/Smartassistant/sql/smartassistant_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_exportconfig')}");
7
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_export')}");
8
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_exportfield')}");
9
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_rule')}");
10
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_task_status')}");
11
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_task')}");
12
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_task_config')}");
13
+ $installer->run("DROP TABLE IF EXISTS {$this->getTable('smartassistant_task_log')}");
14
+
15
+ $installer->run("
16
+ CREATE TABLE {$this->getTable('smartassistant_export')} (
17
+ `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
18
+ `store_id` INT(11) UNSIGNED NOT NULL,
19
+ `name` VARCHAR(256) NOT NULL,
20
+ `filename` VARCHAR(256) NOT NULL,
21
+ `days` TEXT DEFAULT NULL,
22
+ `hours` TEXT DEFAULT NULL,
23
+ `autogenerate` BOOLEAN NOT NULL DEFAULT TRUE,
24
+ `autosend` BOOLEAN NOT NULL DEFAULT TRUE
25
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
26
+
27
+ CREATE TABLE {$this->getTable('smartassistant_exportfield')} (
28
+ `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
29
+ `export_id` INT(11) UNSIGNED NOT NULL,
30
+ `fieldname` VARCHAR(256) NOT NULL,
31
+ `attribute_code` VARCHAR(256) NOT NULL,
32
+ `enabled` BOOLEAN NOT NULL,
33
+ `when_empty` VARCHAR(256) NOT NULL,
34
+ `position` INT(11) UNSIGNED NOT NULL DEFAULT 1
35
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
36
+
37
+ CREATE TABLE IF NOT EXISTS {$this->getTable('smartassistant_rule')} (
38
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
39
+ `export_id` int(10) unsigned NOT NULL,
40
+ `conditions_serialized` mediumtext NOT NULL,
41
+ `actions_serialized` mediumtext NOT NULL
42
+ ) ENGINE=InnoDB CHARSET=utf8 AUTO_INCREMENT=26;
43
+
44
+ CREATE TABLE IF NOT EXISTS {$this->getTable('smartassistant_task_status')} (
45
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
46
+ `name` VARCHAR(256) NOT NULL,
47
+ `display` VARCHAR(256) NOT NULL
48
+ ) ENGINE=InnoDB CHARSET=utf8 AUTO_INCREMENT=1;
49
+
50
+ CREATE TABLE IF NOT EXISTS {$this->getTable('smartassistant_task')} (
51
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
52
+ `status_id` VARCHAR(256),
53
+ `time` VARCHAR(256),
54
+ `progress` INT NOT NULL DEFAULT 0,
55
+ `items` INT NOT NULL DEFAULT 0
56
+ ) ENGINE=InnoDB CHARSET=utf8 AUTO_INCREMENT=1;
57
+
58
+ CREATE TABLE IF NOT EXISTS {$this->getTable('smartassistant_task_config')} (
59
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
60
+ `export_id` INT NOT NULL,
61
+ `task_id` INT NOT NULL,
62
+ `status_id` VARCHAR(256),
63
+ `generate` BOOLEAN NOT NULL,
64
+ `send` BOOLEAN NOT NULL,
65
+ `progress` INT NOT NULL DEFAULT 0,
66
+ `items` INT NOT NULL DEFAULT 0
67
+ ) ENGINE=InnoDB CHARSET=utf8 AUTO_INCREMENT=1;
68
+
69
+ INSERT INTO {$this->getTable('smartassistant_task_status')}
70
+ (`id`, `name`, `display`)
71
+ VALUES
72
+ (1, 'Waiting', ''),
73
+ (2, 'Inicjalizowanie', ''),
74
+ (3, 'Generation in process', ''),
75
+ (4, 'Generation is finished', ''),
76
+ (5, 'Generated', ''),
77
+ (6, 'Send', ''),
78
+ (7, 'Failed', '');
79
+
80
+ CREATE TABLE IF NOT EXISTS {$this->getTable('smartassistant_task_log')} (
81
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
82
+ `type` INT NOT NULL DEFAULT 1,
83
+ `task_id` INT NOT NULL,
84
+ `task_config_id` INT NOT NULL,
85
+ `message` TEXT,
86
+ `datetime` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
87
+ ) ENGINE=InnoDB CHARSET=utf8 AUTO_INCREMENT=1;
88
+ ");
89
+
90
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/smartassistant.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_smartassistant_export_edit>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>smartassistant/smartassistant.js</name>
8
+ </action>
9
+ <action method="addItem">
10
+ <type>skin_css</type>
11
+ <name>smartassistant/smartassistant.css</name>
12
+ </action>
13
+ </reference>
14
+ </adminhtml_smartassistant_export_edit>
15
+ </layout>
app/design/adminhtml/default/default/template/smartassistant/export/loader.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php if ($this->getRunLoader()) { ?>
3
+ <script type="text/javascript">
4
+ document.observe("dom:loaded", function() {
5
+ SmartassistantStatus.start(
6
+ '<?php echo MAge::helper('adminhtml')->getUrl('*/*/stats', array('id' => Mage::app()->getRequest()->getParam('id'))); ?>'
7
+ );
8
+ });
9
+ </script>
10
+ <?php } ?>
11
+ <div id="smartassistant-loader-wrapper">
12
+ <div id="smartassistant_loader" style="display:none;">
13
+ <p class="loader" id="loading_mask_loader">
14
+ <img src="/skin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="Loading...">
15
+ <br>
16
+ <div id="task-stats-container"></div>
17
+ </p>
18
+ <button type="button" onclick="SmartassistantStatus.stop();">
19
+ <?php echo Mage::helper('smartassistant')->__('Close'); ?>
20
+ </button>
21
+ </div>
22
+ </div>
app/design/adminhtml/default/default/template/smartassistant/export/mapping.phtml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $map = $this->getMap();
3
+ ?>
4
+ <div class="entry-edit-head">
5
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('smartassistant')->__('Attributes naming') ?></h4>
6
+ <div class="form-buttons"></div>
7
+ </div>
8
+ <div class="fieldset mfe-mapping" id="content">
9
+ <div class="grid">
10
+ <table id="mapping-table" cellspacing="0" cellpadding="0" class="data" style="width:100%;">
11
+ <thead>
12
+ <tr class="headings">
13
+ <th width="50"></th>
14
+ <th width="180"><?php echo $this->__('Field Name')?></th>
15
+ <th width="80"><?php echo $this->__('Attribute')?></th>
16
+ <th width="80"><?php echo $this->__('Enabled')?></th>
17
+ <th width="80"><?php echo $this->__('When empty')?></th>
18
+ <th width="50"></th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <?php foreach ($map as $item) { ?>
23
+ <tr>
24
+ <td>
25
+ <button type="button" onclick="SmartassistantMap.up(this);" class="button"><span><span><?php echo $this->__('↑')?></span></span></button>
26
+ <button type="button" onclick="SmartassistantMap.down(this);" class="button"><span><span><?php echo $this->__('↓')?></span></span></button>
27
+ </td>
28
+ <td>
29
+ <input type="hidden" name="map[id][<?php echo $item->getId(); ?>]" value="<?php echo $item->getId(); ?>" />
30
+ <input type="text" class="input-text fieldname-entry required-entry" name="map[fieldname][<?php echo $item->getId(); ?>]" value="<?php echo $item->getFieldname(); ?>" />
31
+ </td>
32
+ <td>
33
+ <?php echo Mage::helper('smartassistant')->getProductAttributesSelectHtml('map[attribute_code]['.$item->getId().']', $item->getAttributeCode()); ?>
34
+ </td>
35
+ <td>
36
+ <select name="map[enabled][<?php echo $item->getId(); ?>]" style="width:100%;">
37
+ <option value="1" <?php echo $item->getEnabled() ? 'selected="selected"' : ''; ?>><?php echo $this->__('Yes'); ?></option>
38
+ <option value="0" <?php echo $item->getEnabled() ? '' : 'selected="selected"'; ?>><?php echo $this->__('No'); ?></option>
39
+ </select>
40
+ </td>
41
+ <td>
42
+ <input type="text" class="input-text" name="map[when_empty][<?php echo $item->getId(); ?>]" value="<?php echo $item->getWhenEmpty(); ?>" />
43
+ </td>
44
+ <td>
45
+ <button type="button" onclick="SmartassistantMap.remove(this);" class="button"><span><span><?php echo $this->__('✖') ?></span></span></button>
46
+ </td>
47
+ </tr>
48
+ <?php } ?>
49
+ </tbody>
50
+ <tfoot>
51
+ <tr class="pattern hidden-row">
52
+ <td>
53
+ <button type="button" onclick="SmartassistantMap.up(this);" class="button"><span><span><?php echo $this->__('↑')?></span></span></button>
54
+ <button type="button" onclick="SmartassistantMap.down(this);" class="button"><span><span><?php echo $this->__('↓')?></span></span></button>
55
+ </td>
56
+ <td>
57
+ <input type="hidden" name="map[id][]" value="" />
58
+ <input type="text" class="input-text fieldname-entry" name="map[fieldname][]" value="" />
59
+ </td>
60
+ <td>
61
+ <?php echo Mage::helper('smartassistant')->getProductAttributesSelectHtml('map[attribute_code][]', ''); ?>
62
+ </td>
63
+ <td>
64
+ <select name="map[enabled][]" style="width:100%;">
65
+ <option value="1"><?php echo $this->__('Yes'); ?></option>
66
+ <option value="0"><?php echo $this->__('No'); ?></option>
67
+ </select>
68
+ </td>
69
+ <td>
70
+ <input type="text" class="input-text" name="map[when_empty][]" value="" />
71
+ </td>
72
+ <td>
73
+ <button type="button" onclick="SmartassistantMap.remove(this);" class="button"><span><span><?php echo $this->__('✖') ?></span></span></button>
74
+ </td>
75
+ </tr>
76
+ </tfoot>
77
+ </table>
78
+ <p style="margin-top:10px;">
79
+ <button type="button" onclick="SmartassistantMap.add();" class="button"><span><span><?php echo $this->__('Add Row') ?></span></span></button>
80
+ </p>
81
+ </div>
82
+ </div>
app/design/adminhtml/default/default/template/smartassistant/tasks/preview.phtml ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $task = $this->getTask();
3
+ $configs = $task->getTaskConfigs();
4
+ ?>
5
+
6
+ <div class="content-header">
7
+ <h3 class="icon-head">
8
+ <?php echo Mage::helper('smartassistant')->__('Task preview'); ?>
9
+ </h3>
10
+ <p class="form-buttons">
11
+ <button title="Back" type="button" class="scalable back" onclick="setLocation('<?php echo $this->getBackUrl(); ?>')" style="">
12
+ <span><span><span>Back</span></span></span>
13
+ </button>
14
+ </p>
15
+ </div>
16
+
17
+
18
+ <?php if ($this->getTask()->getStatusId() != Smartassistant_Smartassistant_Model_Task_Status::FINISHED ) { ?>
19
+ <script type="text/javascript">
20
+ (function() {
21
+ var interval = <?php echo $this->getTaskRefreshInterval(); ?>;
22
+ setInterval(function(){
23
+ new Ajax.Request('<?php echo $this->getStatusUrl(); ?>', {
24
+ method: 'get',
25
+ parameters: 'id=<?php echo $this->getTaskId(); ?>',
26
+ onCreate: function(request) {
27
+ Ajax.Responders.unregister(varienLoaderHandler.handler);
28
+ },
29
+ onSuccess: function(transport) {
30
+ $('task-stats-container').replace(transport.responseText);
31
+ }
32
+ });
33
+ }, interval);
34
+ })();
35
+ </script>
36
+ <?php } ?>
37
+
38
+ <style type="text/css">
39
+ .task-clear {
40
+ clear:both;
41
+ }
42
+ .task-part {
43
+ width:50%;
44
+ float:left;
45
+ }
46
+ .task-stats-container .task-details {
47
+ padding-right: 1%;
48
+ width: 49%;
49
+ }
50
+ .task-stats-container .task-log {
51
+ float:right;
52
+ }
53
+ </style>
54
+
55
+ <div class="task-stats-container">
56
+ <div class="task-part task-details">
57
+ <h4><?php echo Mage::helper('smartassistant')->__('Task'); ?> <?php echo $task->getTime(); ?> (<?php echo $task->getStatus()->getName(); ?>)</h4>
58
+ <br />
59
+ <div class="grid">
60
+ <table cellspacing="0" cellpadding="0" class="data">
61
+ <thead>
62
+ <tr class="headings">
63
+ <th width="50"><?php echo Mage::helper('smartassistant')->__('Config name');?></th>
64
+ <th width="50"><?php echo Mage::helper('smartassistant')->__('Generation');?></th>
65
+ <th width="50"><?php echo Mage::helper('smartassistant')->__('Send to FTP');?></th>
66
+ <th width="50"><?php echo Mage::helper('smartassistant')->__('Items amount');?></th>
67
+ <th width="50"><?php echo Mage::helper('smartassistant')->__('Status');?></th>
68
+ </tr>
69
+ </thead>
70
+ <tbody>
71
+ <?php foreach ($configs as $config) { ?>
72
+ <tr>
73
+ <td><?php echo $config->getConfig()->getName() ?></td>
74
+ <td><?php echo ($config->getGenerate() ? Mage::helper('smartassistant')->__('Yes') : Mage::helper('smartassistant')->__('No')) ?></td>
75
+ <td><?php echo ($config->getSend() ? Mage::helper('smartassistant')->__('Yes') : Mage::helper('smartassistant')->__('No')) ?></td>
76
+ <td><?php echo $config->getItems() ?></td>
77
+ <td><?php echo $config->getStatus()->getName() ?></td>
78
+ </tr>
79
+ <?php } ?>
80
+ </tbody>
81
+ </table>
82
+ </div>
83
+ </div>
84
+ <div class="task-part task-log">
85
+ <h4><?php echo Mage::helper('smartassistant')->__('Log of task');?> <?php echo $task->getTime();?></h4>
86
+ <?php echo $this->getStatsBlock()->toHtml(); ?>
87
+ </div>
88
+ <div class="task-clear"></div>
89
+ </div>
90
+
91
+
app/design/adminhtml/default/default/template/smartassistant/tasks/stats.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $stats = $this->getStats(); ?>
2
+
3
+ <div id="task-stats-container">
4
+ <?php foreach ($stats as $stat) { ?>
5
+
6
+ <br />
7
+
8
+ <div style="font-weight:bold;">
9
+ <?php echo $stat['status']['export_name']; ?>:
10
+ <?php echo $stat['status']['progress']; ?> / <?php echo $stat['status']['amount']; ?>
11
+ (<?php echo $stat['status']['status']; ?>)
12
+ </div>
13
+ <div>
14
+ <?php foreach ($stat['log'] as $log) { ?>
15
+ <strong><?php echo $log['datetime']; ?></strong>
16
+ <?php echo $log['message']; ?>
17
+ <br />
18
+ <?php } ?>
19
+ </div>
20
+ <?php } ?>
21
+ </div>
app/design/frontend/base/default/layout/smartassistant.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="before_body_end">
5
+ <block type="core/text" name="smartassistant_js_all">
6
+ <action method="setText"><text><![CDATA[<script src="//st.smartassistant.com/advisor-fe-web/assets/js-nwd/smartassistant.nwd.all.js"></script>]]></text></action>
7
+ </block>
8
+ <block type="core/text" name="smartassistant_js_advisor">
9
+ <action method="setText"><text><![CDATA[<script src="//st.smartassistant.com/advisor-fe-web/custom-javascript?advisorCode=DD1KF7Rb"></script>]]></text></action>
10
+ </block>
11
+ <block type="core/text" name="smartassistant_css_advisor">
12
+ <action method="setText"><text><![CDATA[<link rel="stylesheet" type="text/css" href="//st.smartassistant.com/advisor-fe-web/css-design?advisorCode=DD1KF7Rb" media="all" />]]></text></action>
13
+ </block>
14
+ </reference>
15
+ </default>
16
+ </layout>
app/etc/modules/Smartassistant_Smartassistant.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Smartassistant_Smartassistant>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Smartassistant_Smartassistant>
8
+ </modules>
9
+ </config>
app/locale/en_US/Smartassistant_Smartassistant.csv ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Id is invalid","Id is invalid"
2
+ "Unable to find model for given id","Unable to find model for given id"
3
+ "Unable to find export for given configuration","Unable to find export for given configuration"
4
+ "Unable remove this model","Unable remove this model"
5
+ "Unable to run task. Check if exec() function is enabled on your environment", "Unable to run task. Check if exec() function is enabled on your environment"
6
+ "Success","Success"
7
+ "FTP server is unreachable","FTP server is unreachable"
8
+ "Sending to FTP...","Sending to FTP..."
9
+ "Unable to send file to FTP server. Check access permissions on server","Unable to send file to FTP server. Check access permissions on server"
10
+ "Generate...","Generate..."
11
+ "%s products were found","%s products were found"
12
+ "Export file exists.","Export file exists."
13
+ "Unable to connect with FTP server. Check access FTP configuration","Unable to connect with FTP server. Check access FTP configuration"
14
+ "Display","Display"
15
+ "Action","Action"
16
+ "Time","Time"
17
+ "Configs amount","Configs amount"
18
+ "Status","Status"
19
+ "ID","ID"
20
+ "Task preview", "Task preview"
21
+ "Starting to generate...", "Starting to generate..."
22
+ "Export file exists. It will be replaced", "Export file exists. It will be replaced"
23
+ "Can not remove export file. Generation stoped. Check file permissions to: %s", "Can not remove export file. Generation stoped. Check file permissions to: %s"
24
+ "File sent to FTP server.", "File sent to FTP server."
25
+ "Configs", "Configs"
26
+ "Config name", "Config name"
27
+ "Generation", "Generation"
28
+ "Send to FTP", "Send to FTP"
29
+ "Items amount", "Items amount"
30
+ "Status", "Status"
31
+ "Yes", "Yes"
32
+ "No", "No"
33
+ "SMARTASSISTANT tasks", "SMARTASSISTANT tasks"
34
+ "SMARTASSISTANT CSV configurations", "SMARTASSISTANT CSV configurations"
35
+ "Add configuration", "Add configuration"
36
+ "Name", "Name"
37
+ "Filename", "Filename"
38
+ "Website", "Website"
39
+ "Is active", "Is active"
40
+ "Edit", "Edit"
41
+ "Save configuration", "Save configuration"
42
+ "Delete configuration", "Delete configuration"
43
+ "Save And Continue Edit", "Save And Continue Edit"
44
+ "Generate & send", "Generate & send"
45
+ "Edit export", "Edit export"
46
+ "Export information", "Export information"
47
+ "General", "General"
48
+ "Rules", "Rules"
49
+ "Conditions", "Conditions"
50
+ "Content settings", "Content settings"
51
+ "Scheduled tasks", "Scheduled tasks"
52
+ "Informations", "Informations"
53
+ "Synchronization", "Synchronization"
54
+ "Store", "Store"
55
+ "Schedule", "Schedule"
56
+ "Autogenerate", "Autogenerate"
57
+ "Days", "Days"
58
+ "Conditions", "Conditions"
59
+ "Conditions (leave blank for all products)", "Conditions (leave blank for all products)"
60
+ "Last generated", "Last generated"
61
+ "Generate", "Generate"
62
+ "Send to Server", "Send to Server"
63
+ "Download file", "Download file"
64
+ "Download", "Download"
65
+ "Send", "Send"
66
+ "Post", "Post"
67
+ "Fields configuration", "Fields configuration"
68
+ "Product Id", "Product Id"
69
+ "Is In Stock", "Is In Stock"
70
+ "Qty", "Qty"
71
+ "Image", "Image"
72
+ "Category Name", "Category Name"
73
+ "Category Id", "Category Id"
74
+ "Final Price", "Final Price"
75
+ "Store Price", "Store Price"
76
+ "Custom Attributes", "Custom Attributes"
77
+ "Mapping", "Mapping"
78
+ "Amasty Meta Tags", "Amasty Meta Tags"
79
+ "Primary Attributes", "Primary Attributes"
80
+ "Stock Attributes", "Stock Attributes"
81
+ "Prices & Taxes", "Prices & Taxes"
82
+ "Images", "Images"
83
+ "Category", "Category"
84
+ "Others Attributes", "Others Attributes"
85
+ "Generation is finished", "Generation is finished"
86
+ "Passive mode", "Passive mode"
87
+ "Port", "Port"
88
+ "Path", "Path"
89
+ "Password", "Password"
90
+ "User", "User"
91
+ "Host", "Host"
92
+ "Ftp configuration", "Ftp configuration"
93
+ "Context path", "Context path"
94
+ "Enable", "Enable"
95
+ "Advisor configuration", "Advisor configuration"
96
+ "Advenced", "Advenced"
97
+ "Auto sending", "Auto sending"
98
+ "Use shell", "Use shell"
99
+ "SMARTASSISTANT configuration", "SMARTASSISTANT configuration"
100
+ "Enable/Disable advisor widget", "Enable/Disable advisor widget"
101
+ "Attributes naming", "Attributes naming"
102
+ "Attributes settings", "Attributes settings"
103
+ "Filename to be sent to FTP", "Filename to be sent to FTP"
104
+ "Name allows you to identify the export", "Name allows you to identify the export"
105
+ "General export information", "General export information"
106
+ "No export", "No export"
107
+ "Information", "Information"
108
+ "Export generation", "Export generation"
109
+ "Export settings", "Export settings"
110
+ "Auto sending<br />Enable/Disable cron operations for this module.<br />If is set to "No", the module will not perform any automatic generation.", "Auto sending<br />Enable/Disable cron operations for this module.<br />If is set to "No", the module will not perform any automatic generation."
111
+ "Unable to redirect", "Unable to redirect"
112
+ "Generation in process...", "Generation in process..."
113
+ "General settings", "General settings"
114
+ "Advisor configurator", "Advisor configurator"
package.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Smartassistant_Integration_Tool</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This Module provide synchronization with SMARTASSISTANT product advisor configurator.</summary>
10
+ <description>This extension provides integration with SMARTASSISTANT Platform and gives you access to the WYSIWYG SMARTASSISTANT product advisor configurator. &#xD;
11
+ SMARTASSISTANT Platform is a SaaS-solution that facilitates the fast setup and integration of interactive product advisors. The extension improves the customer experience and purchase decision journey on Magento e-commerce sites as it enables merchants to help their customers with the selection of products or services that fits their individual needs best.&#xD;
12
+ &#xD;
13
+ The extension is free to download and install.</description>
14
+ <notes>This extension provides integration with SMARTASSISTANT Platform and gives you access to the WYSIWYG SMARTASSISTANT product advisor configurator. &#xD;
15
+ SMARTASSISTANT Platform is a SaaS-solution that facilitates the fast setup and integration of interactive product advisors. The extension improves the customer experience and purchase decision journey on Magento e-commerce sites as it enables merchants to help their customers with the selection of products or services that fits their individual needs best.&#xD;
16
+ &#xD;
17
+ The extension is free to download and install.</notes>
18
+ <authors><author><name>SMARTASSISTANT</name><user>jwojciechowski</user><email>j.wojciechowski@smartassistant.com</email></author></authors>
19
+ <date>2015-12-31</date>
20
+ <time>09:47:07</time>
21
+ <contents><target name="mageetc"><dir name="modules"><file name="Smartassistant_Smartassistant.xml" hash="3ab8eedf451de42032aa228aad546d8e"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Smartassistant_Smartassistant.csv" hash="9368cdd744d6025074ff6a02d1b8fee0"/></dir></target><target name="magecommunity"><dir name="Smartassistant"><dir><dir name="Smartassistant"><dir name="Block"><dir name="Adminhtml"><dir name="Export"><dir name="Edit"><file name="BaseTab.php" hash="b47e7d827f0c34428a2ed632f398f7cc"/><file name="Form.php" hash="fa8c975ae30fc6dabb8a1fbc0a9292eb"/><dir name="Tab"><file name="Fields.php" hash="c351bc6a9a2b034679946cd4ec74f2ce"/><file name="General.php" hash="64b6823c5b593ba4a18eab66d496e8e2"/><file name="Info.php" hash="081597a358376bf4bb254da6227c6d12"/><file name="Rules.php" hash="c474252bc165bab8902775018966d39e"/><file name="ScheduledTasks.php" hash="7a87c02b5af1025fa0fc563434ce0b7b"/><file name="Synchronization.php" hash="ef9fc31ae1ae6560e41188e18d9ca1d5"/></dir><file name="Tabs.php" hash="9b9094777040cfb1e907edbeab7a4f24"/></dir><file name="Edit.php" hash="9039c886ea7059aaf2e047968bdc46f0"/><file name="Grid.php" hash="9736cf59eafa2540641fca0af5663d8a"/></dir><file name="Export.php" hash="cee0b7ecca4756ee25e9df6d3505b3ac"/><dir name="Renderer"><file name="Fieldsmap.php" hash="1b308557cf6c43bdc649d5278f572d0e"/><file name="Widget.php" hash="9a0dfc4f94b4cccba4fec9dc8e389af9"/></dir><file name="TaskStats.php" hash="0fe2e0637880f58d716eb1641ec476aa"/><dir name="Tasks"><file name="Grid.php" hash="70e704efafbc03172001e14b45ad961e"/><file name="Preview.php" hash="0fe364a2c3a80890ca314d26d377ccbc"/></dir><file name="Tasks.php" hash="dbd796a366d3ed7795826758e22a360f"/></dir><file name="Widget.php" hash="1a709efd3a144d4564c1270ade6ec1c3"/></dir><dir name="Helper"><file name="Attribute.php" hash="573988816f54cb0ffb17198779117fe9"/><file name="CliRunner.php" hash="ea0d8a0d159d14d996d7e8a0b5eba18f"/><file name="Data.php" hash="5795c3c69e603fd8847725dcbf8251a7"/><file name="Exception.php" hash="c62e505d67c795e4741b2a2e0292a7ed"/><file name="Filesystem.php" hash="912f21bfeffdbaa8ebbeb7b0586254b3"/><file name="FtpConnector.php" hash="15a9577606344a76690c399e9662754a"/></dir><dir name="Model"><dir name="Core"><file name="CollectionIterator.php" hash="95474a76a136907b311562797f81a2d0"/></dir><file name="Export.php" hash="0be7a8823789eb94b7f01fbf60821003"/><file name="Exportfield.php" hash="2c82c671237b46e99f65df6e1117498f"/><file name="Generator.php" hash="55b769739184caccfea681ddcd1bdcfa"/><dir name="Mysql4"><dir name="Export"><file name="Collection.php" hash="2240c9c4c4638a4e5c27f0c8c52b03df"/></dir><file name="Export.php" hash="e1e53d188b28da990d5977e725aea0d8"/><dir name="Exportfield"><file name="Collection.php" hash="8d18e714eb133b03a335b1c63b284f28"/></dir><file name="Exportfield.php" hash="99a096772205370584e6b2d88d06619a"/><dir name="Rule"><file name="Collection.php" hash="6153c378b073674b0a78293ce49a9491"/></dir><file name="Rule.php" hash="eb36f6fe2923e290c483d04864758ec9"/><dir name="Task"><file name="Collection.php" hash="0a0863e25a5c009f8d7a215a5310f243"/><dir name="Config"><file name="Collection.php" hash="35cc2c312e01f49b3e98ceafdf6bb920"/></dir><file name="Config.php" hash="cbfa8240ab04e050fa18c7ac2b7bc7b6"/><dir name="Log"><file name="Collection.php" hash="bb1e7881eb18aac170a5cee0870f5c26"/></dir><file name="Log.php" hash="5faa71492885ec49e73e34b63ba04791"/><dir name="Status"><file name="Collection.php" hash="c239bf7b486ca663749920fdaf893688"/></dir><file name="Status.php" hash="6f13e0178e4e36772bbc72669e081d92"/></dir><file name="Task.php" hash="531df348de86f16fd6b9124c4b87b802"/></dir><dir name="Rule"><dir name="Condition"><file name="Combine.php" hash="6106bd24d9c58938a2a7136eced6f6c7"/><file name="Product.php" hash="650ad4fc505d0faeee1c1037469560ce"/></dir></dir><file name="Rule.php" hash="47661cf6d0e62122145cfd105d59648f"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Day.php" hash="0038b20ab1281a4b696041eace0bc9e3"/><file name="Ftpmodes.php" hash="9e4a1cb11228cfaedaf7e10a137d956a"/><file name="Time.php" hash="af7917b0f9211931ca6f6f2b32ec0f0d"/></dir></dir></dir><dir name="Task"><file name="Config.php" hash="5f80bbd454c4eeabce24761f46d99da7"/><file name="Log.php" hash="5481159dcd2a64441027da19e61f2f59"/><dir name="Mysql4"><dir name="Config"><file name="Collection.php" hash="d2740fcf0231410ba25c595aaff948db"/></dir><file name="Config.php" hash="1d8f0daeffc99a55c53cf604809af873"/><dir name="Status"><file name="Collection.php" hash="490c58e802ffc5560d4243c1fc9b8dbc"/></dir><file name="Status.php" hash="826189724f1240dceffa709eaf534106"/></dir><file name="Status.php" hash="4c2b7616be8cf824b8fffe6f2d102369"/></dir><file name="Task.php" hash="677998382de93ed9c89632ad452d4411"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Smartassistant"><file name="ExportController.php" hash="7cba38d62d24b25cc9aa9d2087e1dbe4"/><file name="PanelController.php" hash="bc05b0effb1f0e00d76d1f1dba475c56"/><file name="TasksController.php" hash="04671fc83b7d748effa3f6956bfaabd5"/></dir></dir><file name="SmartassistantController.php" hash="e9de3170be3117cd62a65c5dbca01820"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4a9423a5ef8dad70fc2e6d5d6e523d48"/><file name="config.xml" hash="3c77606af87d7ef8509760470b5d705d"/><file name="system.xml" hash="3f3536cca89ba0763eedb40447cfccdc"/><file name="widget.xml" hash="e53e1aec564f1c72bbee805e0cd0abf7"/></dir><dir name="secret"><file name="oem.public.key" hash="b2f935735822acf93a7c6a6275fb01e1"/></dir><dir name="sql"><dir name="smartassistant_setup"><file name="mysql4-install-1.0.0.php" hash="d4169a4b997bede2814cf1e2db68f6b0"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="smartassistant"><dir><dir name="export"><file name="loader.phtml" hash="5cccee6adc4aef4c0f41cd78ec133b41"/><file name="mapping.phtml" hash="ea425a43f0c2e00969f1ac13158a943a"/></dir><dir name="tasks"><file name="preview.phtml" hash="cf581aeb15840a68d94f22d7a8ff4887"/><file name="stats.phtml" hash="b194fed7025fa3b83efa8551bff929f9"/></dir></dir></dir></dir><dir name="layout"><file name="smartassistant.xml" hash="7a1d777b942b7ff46ba5716b677edb04"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="smartassistant.xml" hash="fece5dd9f68ee3284891b2471f881ed5"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="smartassistant"><file name="smartassistant.css" hash="d4de11279f7971ce73e64b072fd625b3"/><file name="smartassistant.js" hash="d0c1131a43250fe11d2c015a20b50550"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="smartassistant"><file name="logo.png" hash="8621ebe301af8f40df71fd14b34fd825"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="shell"><file name="smartassistant.php" hash="5bd7cf374bc62086491381d4ddd49347"/></dir></target></contents>
22
+ <compatible/>
23
+ <dependencies><required><php><min>1.7.0</min><max>1.9.2</max></php></required></dependencies>
24
+ </package>
shell/smartassistant.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'abstract.php';
4
+
5
+ class Smartassistant_Shell_ExportCli extends Mage_Shell_Abstract
6
+ {
7
+ private $_time = 36000;
8
+
9
+ private $_classPointer = 'run';
10
+
11
+ private $_paramsSeparator = ';';
12
+
13
+ public function run()
14
+ {
15
+ set_time_limit($this->_time);
16
+
17
+ if ($this->getArg($this->_classPointer)) {
18
+ $parts = explode('/', $this->getArg($this->_classPointer));
19
+ $type = array_shift($parts);
20
+ $method = array_pop($parts);
21
+ $class = implode('/', $parts);
22
+ $args = $this->getArgs();
23
+ $response = $this->fire($type, $class, $method, $args);
24
+ die($response);
25
+ } elseif ($this->getArg('ping')) {
26
+ echo '1';
27
+ } else {
28
+ echo $this->usageHelp();
29
+ }
30
+ }
31
+
32
+ private function fire($type, $class, $method, $args)
33
+ {
34
+ if ($type == 'model') {
35
+ $object = Mage::getModel($class);
36
+ $response = call_user_func_array(array($object, $method), $args);
37
+ } elseif ($type == 'helper') {
38
+ $object = Mage::helper($class);
39
+ $response = call_user_func_array(array($object, $method), $args);
40
+ } else {
41
+ $response = false;
42
+ }
43
+ return $response;
44
+ }
45
+
46
+ public function usageHelp()
47
+ {
48
+ return <<<USAGE
49
+
50
+ Usage: php -f smartassistant.php -- [options]
51
+
52
+ --generate all Generate all
53
+ --generate <id> Generate ID <id>
54
+
55
+ USAGE;
56
+ }
57
+
58
+ protected function getArgs()
59
+ {
60
+ $args = $this->_args;
61
+ unset($args[$this->_classPointer]);
62
+ foreach ($args as &$arg) {
63
+ if (strpos($arg, $this->_paramsSeparator)) {
64
+ $arg = explode($this->_paramsSeparator, $arg);
65
+ }
66
+ }
67
+ return $args;
68
+ }
69
+
70
+ protected function _parseArgs()
71
+ {
72
+ $current = null;
73
+ foreach ($_SERVER['argv'] as $arg) {
74
+ $match = array();
75
+ if (preg_match('#^--([\w\d_-]{1,})$#', $arg, $match) || preg_match('#^-([\w\d_]{1,})$#', $arg, $match)) {
76
+ $current = $match[1];
77
+ $this->_args[$current] = true;
78
+ } else {
79
+ if ($current) {
80
+ $this->_args[$current] = $arg;
81
+ $current = null;
82
+ } else if (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
83
+ $this->_args[$match[1]] = true;
84
+ }
85
+ }
86
+ }
87
+ return $this;
88
+ }
89
+ }
90
+
91
+ $shell = new Smartassistant_Shell_ExportCli();
92
+ $shell->run();
skin/adminhtml/default/default/smartassistant/smartassistant.css ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .hidden-row {
2
+ display: none;
3
+ }
4
+ #smartassistant-loader-wrapper {
5
+ position:relative;
6
+ }
7
+ #smartassistant_loader {
8
+ position:absolute;
9
+ top: 30%;
10
+ left: 27%;
11
+ color:#d85909;
12
+ font-size:1.1em;
13
+ font-weight:bold;
14
+ text-align:left;
15
+ opacity:0.80;
16
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; /* IE8 */
17
+ z-index:500;
18
+ width:400px;
19
+ border:2px solid #f1af73;
20
+ background:#fff4e9;
21
+ padding:15px;
22
+ }
23
+ #smartassistant_loader .loader {
24
+ width:100%;
25
+ color:#d85909;
26
+ font-weight:bold;
27
+ text-align:center;
28
+ z-index:1000;
29
+ }
30
+
31
+ .task-stats-container {
32
+ }
33
+ .task-stats-container:nth-child(odd) {
34
+ background-color:#dadfe0;
35
+ }
36
+ .task-clear {
37
+ clear:both;
38
+ }
39
+ .task-part {
40
+ width:50%;
41
+ float:left;
42
+ }
43
+ .task-stats-container .task-details {
44
+ padding-right: 1%;
45
+ width: 49%;
46
+ }
47
+ .task-stats-container .task-log {
48
+ float:right;
49
+ }
skin/adminhtml/default/default/smartassistant/smartassistant.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var SmartassistantMap = {
2
+ up: function(e) {
3
+ SmartassistantMap.move(e, 'up');
4
+ },
5
+ down: function(e) {
6
+ SmartassistantMap.move(e, 'down');
7
+ },
8
+ remove: function(e) {
9
+ e.ancestors()[1].remove();
10
+ },
11
+ add: function(e) {
12
+ var trNode = $$('#mapping-table tfoot tr').first().cloneNode(true);
13
+ trNode.toggleClassName('hidden-row');
14
+
15
+ var n=Math.floor(Math.random()*11);
16
+ var k = Math.floor(Math.random()* 1000000);
17
+ var unique = String.fromCharCode(n) + k;
18
+
19
+ var fieldNameNode = $(trNode).select('.fieldname-entry')[0];
20
+ $(fieldNameNode).addClassName("required-entry");
21
+ $(fieldNameNode).setAttribute('id', unique);
22
+
23
+ $$('#mapping-table tbody').last().insert(trNode);
24
+ },
25
+ move: function (e, direction) {
26
+ var row = e.ancestors()[1];
27
+ var table = row.parentNode;
28
+
29
+ index = table.select('tr').indexOf(row);
30
+
31
+ var prev = ((index > 0) ? index - 1 : 1);
32
+ var next = table.select('tr').length - 2;
33
+
34
+ if (index < table.select('tr').length - 1) {
35
+ next = index + 1;
36
+ }
37
+
38
+ prevli = table.select('tr')[prev];
39
+ nextli = table.select('tr')[next];
40
+
41
+ row.remove();
42
+
43
+ if (direction == 'up') {
44
+ prevli.insert({before : row});
45
+ } else if (direction == 'down') {
46
+ nextli.insert({after : row});
47
+ }
48
+ }
49
+ };
50
+
51
+ var SmartassistantStatus = {
52
+ 'content' : null,
53
+ 'loader' : null,
54
+ 'interval' : 5000,
55
+ 'time' : null,
56
+ 'start' : function(url) {
57
+ SmartassistantStatus.loader = $('smartassistant_loader');
58
+ if (SmartassistantStatus.loader) {
59
+ SmartassistantStatus.loader.show();
60
+ }
61
+ SmartassistantStatus.update(url);
62
+ },
63
+ 'update' : function(url) {
64
+ new Ajax.Request(url, {
65
+ method: 'get',
66
+ onCreate: function(request) {
67
+ Ajax.Responders.unregister(varienLoaderHandler.handler);
68
+ },
69
+ onSuccess: function(transport) {
70
+ $('task-stats-container').replace(transport.responseJSON.html);
71
+ if (! transport.responseJSON.finished) {
72
+ SmartassistantStatus.time = setTimeout(function() {
73
+ SmartassistantStatus.update(url);
74
+ }, SmartassistantStatus.interval);
75
+ } else {
76
+ $('loading_mask_loader').remove();
77
+ }
78
+ }
79
+ });
80
+ },
81
+ 'stop' : function() {
82
+ SmartassistantStatus.loader.hide();
83
+ clearTimeout(SmartassistantStatus.time);
84
+ }
85
+ };
86
+
skin/frontend/base/default/images/smartassistant/logo.png ADDED
Binary file