diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi.php new file mode 100644 index 0000000..c92e11f --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi.php @@ -0,0 +1,38 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi extends Mage_Adminhtml_Block_Widget_Grid_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + $this->_controller = 'adminhtml_chatbotapi'; + $this->_blockGroup = 'werules_chatbot'; + parent::__construct(); + $this->_headerText = Mage::helper('werules_chatbot')->__('ChatbotAPI'); + $this->_updateButton('add', 'label', Mage::helper('werules_chatbot')->__('Add ChatbotAPI')); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit.php new file mode 100644 index 0000000..3b45ebd --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit.php @@ -0,0 +1,78 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit extends Mage_Adminhtml_Block_Widget_Form_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->_blockGroup = 'werules_chatbot'; + $this->_controller = 'adminhtml_chatbotapi'; + $this->_updateButton( + 'save', + 'label', + Mage::helper('werules_chatbot')->__('Save ChatbotAPI') + ); + $this->_updateButton( + 'delete', + 'label', + Mage::helper('werules_chatbot')->__('Delete ChatbotAPI') + ); + $this->_addButton( + 'saveandcontinue', + array( + 'label' => Mage::helper('werules_chatbot')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save', + ), + -100 + ); + $this->_formScripts[] = " + function saveAndContinueEdit() { + editForm.submit($('edit_form').action+'back/edit/'); + } + "; + } + + /** + * get the edit form header + * + * @access public + * @return string + */ + public function getHeaderText() + { + if (Mage::registry('current_chatbotapi') && Mage::registry('current_chatbotapi')->getId()) { + return Mage::helper('werules_chatbot')->__( + "Edit ChatbotAPI '%s'", + $this->escapeHtml(Mage::registry('current_chatbotapi')->getChatbotapiId()) + ); + } else { + return Mage::helper('werules_chatbot')->__('Add ChatbotAPI'); + } + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Form.php new file mode 100644 index 0000000..00222f7 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Form.php @@ -0,0 +1,49 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form( + array( + 'id' => 'edit_form', + 'action' => $this->getUrl( + '*/*/save', + array( + 'id' => $this->getRequest()->getParam('id') + ) + ), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ) + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Form.php new file mode 100644 index 0000000..7d93b60 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Form.php @@ -0,0 +1,222 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tab_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setHtmlIdPrefix('chatbotapi_'); + $form->setFieldNameSuffix('chatbotapi'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'chatbotapi_form', + array('legend' => Mage::helper('werules_chatbot')->__('ChatbotAPI')) + ); + + $fieldset->addField( + 'chatbotapi_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('ChatbotAPI ID'), + 'name' => 'chatbotapi_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'hash_key', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Hash Key'), + 'name' => 'hash_key', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'logged', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Logged?'), + 'name' => 'logged', + 'required' => true, + 'class' => 'required-entry', + + 'values'=> array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Yes'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('No'), + ), + ), + ) + ); + + $fieldset->addField( + 'enabled', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Enabled?'), + 'name' => 'enabled', + 'required' => true, + 'class' => 'required-entry', + + 'values'=> array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Yes'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('No'), + ), + ), + ) + ); + + $fieldset->addField( + 'chatbot_type', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Chatbot Type'), + 'name' => 'chatbot_type', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'chat_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Chat ID'), + 'name' => 'chat_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'conversation_state', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Conversation State'), + 'name' => 'conversation_state', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'fallback_qty', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Fallback Quantity'), + 'name' => 'fallback_qty', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'chatbotuser_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Chatbotuser ID'), + 'name' => 'chatbotuser_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'last_command_details', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Last Command Details'), + 'name' => 'last_command_details', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + $fieldset->addField( + 'status', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'name' => 'status', + 'values' => array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Enabled'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('Disabled'), + ), + ), + ) + ); + if (Mage::app()->isSingleStoreMode()) { + $fieldset->addField( + 'store_id', + 'hidden', + array( + 'name' => 'stores[]', + 'value' => Mage::app()->getStore(true)->getId() + ) + ); + Mage::registry('current_chatbotapi')->setStoreId(Mage::app()->getStore(true)->getId()); + } + $formValues = Mage::registry('current_chatbotapi')->getDefaultValues(); + if (!is_array($formValues)) { + $formValues = array(); + } + if (Mage::getSingleton('adminhtml/session')->getChatbotapiData()) { + $formValues = array_merge($formValues, Mage::getSingleton('adminhtml/session')->getChatbotapiData()); + Mage::getSingleton('adminhtml/session')->setChatbotapiData(null); + } elseif (Mage::registry('current_chatbotapi')) { + $formValues = array_merge($formValues, Mage::registry('current_chatbotapi')->getData()); + } + $form->setValues($formValues); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Stores.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Stores.php new file mode 100644 index 0000000..59134c9 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tab/Stores.php @@ -0,0 +1,55 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tab_Stores extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tab_Stores + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setFieldNameSuffix('chatbotapi'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'chatbotapi_stores_form', + array('legend' => Mage::helper('werules_chatbot')->__('Store views')) + ); + $field = $fieldset->addField( + 'store_id', + 'multiselect', + array( + 'name' => 'stores[]', + 'label' => Mage::helper('werules_chatbot')->__('Store Views'), + 'title' => Mage::helper('werules_chatbot')->__('Store Views'), + 'required' => true, + 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true), + ) + ); + $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element'); + $field->setRenderer($renderer); + $form->addValues(Mage::registry('current_chatbotapi')->getData()); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tabs.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tabs.php new file mode 100644 index 0000000..7165389 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Edit/Tabs.php @@ -0,0 +1,82 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs +{ + /** + * Initialize Tabs + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('chatbotapi_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(Mage::helper('werules_chatbot')->__('ChatbotAPI')); + } + + /** + * before render html + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Edit_Tabs + */ + protected function _beforeToHtml() + { + $this->addTab( + 'form_chatbotapi', + array( + 'label' => Mage::helper('werules_chatbot')->__('ChatbotAPI'), + 'title' => Mage::helper('werules_chatbot')->__('ChatbotAPI'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_chatbotapi_edit_tab_form' + ) + ->toHtml(), + ) + ); + if (!Mage::app()->isSingleStoreMode()) { + $this->addTab( + 'form_store_chatbotapi', + array( + 'label' => Mage::helper('werules_chatbot')->__('Store views'), + 'title' => Mage::helper('werules_chatbot')->__('Store views'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_chatbotapi_edit_tab_stores' + ) + ->toHtml(), + ) + ); + } + return parent::_beforeToHtml(); + } + + /** + * Retrieve chatbotapi entity + * + * @access public + * @return Werules_Chatbot_Model_Chatbotapi + */ + public function getChatbotapi() + { + return Mage::registry('current_chatbotapi'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Grid.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Grid.php new file mode 100644 index 0000000..dc87b3d --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotapi/Grid.php @@ -0,0 +1,368 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * constructor + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('chatbotapiGrid'); + $this->setDefaultSort('entity_id'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + $this->setUseAjax(true); + } + + /** + * prepare collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('werules_chatbot/chatbotapi') + ->getCollection(); + + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * prepare grid collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid + */ + protected function _prepareColumns() + { + $this->addColumn( + 'entity_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Id'), + 'index' => 'entity_id', + 'type' => 'number' + ) + ); + $this->addColumn( + 'chatbotapi_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('ChatbotAPI ID'), + 'align' => 'left', + 'index' => 'chatbotapi_id', + ) + ); + + $this->addColumn( + 'status', + array( + 'header' => Mage::helper('werules_chatbot')->__('Status'), + 'index' => 'status', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ); + $this->addColumn( + 'hash_key', + array( + 'header' => Mage::helper('werules_chatbot')->__('Hash Key'), + 'index' => 'hash_key', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'logged', + array( + 'header' => Mage::helper('werules_chatbot')->__('Logged?'), + 'index' => 'logged', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ); + $this->addColumn( + 'enabled', + array( + 'header' => Mage::helper('werules_chatbot')->__('Enabled?'), + 'index' => 'enabled', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ); + $this->addColumn( + 'chatbot_type', + array( + 'header' => Mage::helper('werules_chatbot')->__('Chatbot Type'), + 'index' => 'chatbot_type', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'chat_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Chat ID'), + 'index' => 'chat_id', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'conversation_state', + array( + 'header' => Mage::helper('werules_chatbot')->__('Conversation State'), + 'index' => 'conversation_state', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'fallback_qty', + array( + 'header' => Mage::helper('werules_chatbot')->__('Fallback Quantity'), + 'index' => 'fallback_qty', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'chatbotuser_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Chatbotuser ID'), + 'index' => 'chatbotuser_id', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'last_command_details', + array( + 'header' => Mage::helper('werules_chatbot')->__('Last Command Details'), + 'index' => 'last_command_details', + 'type'=> 'text', + + ) + ); + if (!Mage::app()->isSingleStoreMode() && !$this->_isExport) { + $this->addColumn( + 'store_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Store Views'), + 'index' => 'store_id', + 'type' => 'store', + 'store_all' => true, + 'store_view' => true, + 'sortable' => false, + 'filter_condition_callback'=> array($this, '_filterStoreCondition'), + ) + ); + } + $this->addColumn( + 'created_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Created at'), + 'index' => 'created_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'updated_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Updated at'), + 'index' => 'updated_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'action', + array( + 'header' => Mage::helper('werules_chatbot')->__('Action'), + 'width' => '100', + 'type' => 'action', + 'getter' => 'getId', + 'actions' => array( + array( + 'caption' => Mage::helper('werules_chatbot')->__('Edit'), + 'url' => array('base'=> '*/*/edit'), + 'field' => 'id' + ) + ), + 'filter' => false, + 'is_system' => true, + 'sortable' => false, + ) + ); + $this->addExportType('*/*/exportCsv', Mage::helper('werules_chatbot')->__('CSV')); + $this->addExportType('*/*/exportExcel', Mage::helper('werules_chatbot')->__('Excel')); + $this->addExportType('*/*/exportXml', Mage::helper('werules_chatbot')->__('XML')); + return parent::_prepareColumns(); + } + + /** + * prepare mass action + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid + */ + protected function _prepareMassaction() + { + $this->setMassactionIdField('entity_id'); + $this->getMassactionBlock()->setFormFieldName('chatbotapi'); + $this->getMassactionBlock()->addItem( + 'delete', + array( + 'label'=> Mage::helper('werules_chatbot')->__('Delete'), + 'url' => $this->getUrl('*/*/massDelete'), + 'confirm' => Mage::helper('werules_chatbot')->__('Are you sure?') + ) + ); + $this->getMassactionBlock()->addItem( + 'status', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change status'), + 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)), + 'additional' => array( + 'status' => array( + 'name' => 'status', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ) + ) + ); + $this->getMassactionBlock()->addItem( + 'logged', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change Logged?'), + 'url' => $this->getUrl('*/*/massLogged', array('_current'=>true)), + 'additional' => array( + 'flag_logged' => array( + 'name' => 'flag_logged', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Logged?'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ) + ) + ); + $this->getMassactionBlock()->addItem( + 'enabled', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change Enabled?'), + 'url' => $this->getUrl('*/*/massEnabled', array('_current'=>true)), + 'additional' => array( + 'flag_enabled' => array( + 'name' => 'flag_enabled', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Enabled?'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ) + ) + ); + return $this; + } + + /** + * get the row url + * + * @access public + * @param Werules_Chatbot_Model_Chatbotapi + * @return string + */ + public function getRowUrl($row) + { + return $this->getUrl('*/*/edit', array('id' => $row->getId())); + } + + /** + * get the grid url + * + * @access public + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/grid', array('_current'=>true)); + } + + /** + * after collection load + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid + */ + protected function _afterLoadCollection() + { + $this->getCollection()->walk('afterLoad'); + parent::_afterLoadCollection(); + } + + /** + * filter store column + * + * @access protected + * @param Werules_Chatbot_Model_Resource_Chatbotapi_Collection $collection + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Werules_Chatbot_Block_Adminhtml_Chatbotapi_Grid + */ + protected function _filterStoreCondition($collection, $column) + { + if (!$value = $column->getFilter()->getValue()) { + return; + } + $collection->addStoreFilter($value); + return $this; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser.php new file mode 100644 index 0000000..4719691 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser.php @@ -0,0 +1,39 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser extends Mage_Adminhtml_Block_Widget_Grid_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + $this->_controller = 'adminhtml_chatbotuser'; + $this->_blockGroup = 'werules_chatbot'; + parent::__construct(); + $this->_headerText = Mage::helper('werules_chatbot')->__('ChatbotUser'); + $this->_updateButton('add', 'label', Mage::helper('werules_chatbot')->__('Add ChatbotUser')); + + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit.php new file mode 100644 index 0000000..3483865 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit.php @@ -0,0 +1,78 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit extends Mage_Adminhtml_Block_Widget_Form_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->_blockGroup = 'werules_chatbot'; + $this->_controller = 'adminhtml_chatbotuser'; + $this->_updateButton( + 'save', + 'label', + Mage::helper('werules_chatbot')->__('Save ChatbotUser') + ); + $this->_updateButton( + 'delete', + 'label', + Mage::helper('werules_chatbot')->__('Delete ChatbotUser') + ); + $this->_addButton( + 'saveandcontinue', + array( + 'label' => Mage::helper('werules_chatbot')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save', + ), + -100 + ); + $this->_formScripts[] = " + function saveAndContinueEdit() { + editForm.submit($('edit_form').action+'back/edit/'); + } + "; + } + + /** + * get the edit form header + * + * @access public + * @return string + */ + public function getHeaderText() + { + if (Mage::registry('current_chatbotuser') && Mage::registry('current_chatbotuser')->getId()) { + return Mage::helper('werules_chatbot')->__( + "Edit ChatbotUser '%s'", + $this->escapeHtml(Mage::registry('current_chatbotuser')->getChatbotuserId()) + ); + } else { + return Mage::helper('werules_chatbot')->__('Add ChatbotUser'); + } + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Form.php new file mode 100644 index 0000000..5e5392c --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Form.php @@ -0,0 +1,49 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form( + array( + 'id' => 'edit_form', + 'action' => $this->getUrl( + '*/*/save', + array( + 'id' => $this->getRequest()->getParam('id') + ) + ), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ) + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Form.php new file mode 100644 index 0000000..db70834 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Form.php @@ -0,0 +1,172 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tab_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setHtmlIdPrefix('chatbotuser_'); + $form->setFieldNameSuffix('chatbotuser'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'chatbotuser_form', + array('legend' => Mage::helper('werules_chatbot')->__('ChatbotUser')) + ); + + $fieldset->addField( + 'chatbotuser_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('ChatbotUser ID'), + 'name' => 'chatbotuser_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'session_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Session ID'), + 'name' => 'session_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'enable_promotional_messages', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Enable Promotional Messages'), + 'name' => 'enable_promotional_messages', + 'required' => true, + 'class' => 'required-entry', + + 'values'=> array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Yes'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('No'), + ), + ), + ) + ); + + $fieldset->addField( + 'enable_support', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Enable Support'), + 'name' => 'enable_support', + 'required' => true, + 'class' => 'required-entry', + + 'values'=> array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Yes'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('No'), + ), + ), + ) + ); + + $fieldset->addField( + 'admin', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Is Admin?'), + 'name' => 'admin', + 'required' => true, + 'class' => 'required-entry', + + 'values'=> array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Yes'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('No'), + ), + ), + ) + ); + $fieldset->addField( + 'status', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'name' => 'status', + 'values' => array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Enabled'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('Disabled'), + ), + ), + ) + ); + if (Mage::app()->isSingleStoreMode()) { + $fieldset->addField( + 'store_id', + 'hidden', + array( + 'name' => 'stores[]', + 'value' => Mage::app()->getStore(true)->getId() + ) + ); + Mage::registry('current_chatbotuser')->setStoreId(Mage::app()->getStore(true)->getId()); + } + $formValues = Mage::registry('current_chatbotuser')->getDefaultValues(); + if (!is_array($formValues)) { + $formValues = array(); + } + if (Mage::getSingleton('adminhtml/session')->getChatbotuserData()) { + $formValues = array_merge($formValues, Mage::getSingleton('adminhtml/session')->getChatbotuserData()); + Mage::getSingleton('adminhtml/session')->setChatbotuserData(null); + } elseif (Mage::registry('current_chatbotuser')) { + $formValues = array_merge($formValues, Mage::registry('current_chatbotuser')->getData()); + } + $form->setValues($formValues); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Stores.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Stores.php new file mode 100644 index 0000000..4b65cf3 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tab/Stores.php @@ -0,0 +1,55 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tab_Stores extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tab_Stores + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setFieldNameSuffix('chatbotuser'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'chatbotuser_stores_form', + array('legend' => Mage::helper('werules_chatbot')->__('Store views')) + ); + $field = $fieldset->addField( + 'store_id', + 'multiselect', + array( + 'name' => 'stores[]', + 'label' => Mage::helper('werules_chatbot')->__('Store Views'), + 'title' => Mage::helper('werules_chatbot')->__('Store Views'), + 'required' => true, + 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true), + ) + ); + $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element'); + $field->setRenderer($renderer); + $form->addValues(Mage::registry('current_chatbotuser')->getData()); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tabs.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tabs.php new file mode 100644 index 0000000..e330782 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Edit/Tabs.php @@ -0,0 +1,82 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs +{ + /** + * Initialize Tabs + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('chatbotuser_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(Mage::helper('werules_chatbot')->__('ChatbotUser')); + } + + /** + * before render html + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Edit_Tabs + */ + protected function _beforeToHtml() + { + $this->addTab( + 'form_chatbotuser', + array( + 'label' => Mage::helper('werules_chatbot')->__('ChatbotUser'), + 'title' => Mage::helper('werules_chatbot')->__('ChatbotUser'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_chatbotuser_edit_tab_form' + ) + ->toHtml(), + ) + ); + if (!Mage::app()->isSingleStoreMode()) { + $this->addTab( + 'form_store_chatbotuser', + array( + 'label' => Mage::helper('werules_chatbot')->__('Store views'), + 'title' => Mage::helper('werules_chatbot')->__('Store views'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_chatbotuser_edit_tab_stores' + ) + ->toHtml(), + ) + ); + } + return parent::_beforeToHtml(); + } + + /** + * Retrieve chatbotuser entity + * + * @access public + * @return Werules_Chatbot_Model_Chatbotuser + */ + public function getChatbotuser() + { + return Mage::registry('current_chatbotuser'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Grid.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Grid.php new file mode 100644 index 0000000..0ebb52a --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Chatbotuser/Grid.php @@ -0,0 +1,347 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * constructor + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('chatbotuserGrid'); + $this->setDefaultSort('entity_id'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + $this->setUseAjax(true); + } + + /** + * prepare collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('werules_chatbot/chatbotuser') + ->getCollection(); + + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * prepare grid collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid + */ + protected function _prepareColumns() + { + $this->addColumn( + 'entity_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Id'), + 'index' => 'entity_id', + 'type' => 'number' + ) + ); + $this->addColumn( + 'chatbotuser_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('ChatbotUser ID'), + 'align' => 'left', + 'index' => 'chatbotuser_id', + ) + ); + + $this->addColumn( + 'status', + array( + 'header' => Mage::helper('werules_chatbot')->__('Status'), + 'index' => 'status', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ); + $this->addColumn( + 'session_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Session ID'), + 'index' => 'session_id', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'enable_promotional_messages', + array( + 'header' => Mage::helper('werules_chatbot')->__('Enable Promotional Messages'), + 'index' => 'enable_promotional_messages', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ); + $this->addColumn( + 'enable_support', + array( + 'header' => Mage::helper('werules_chatbot')->__('Enable Support'), + 'index' => 'enable_support', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ); + $this->addColumn( + 'admin', + array( + 'header' => Mage::helper('werules_chatbot')->__('Is Admin?'), + 'index' => 'admin', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ); + if (!Mage::app()->isSingleStoreMode() && !$this->_isExport) { + $this->addColumn( + 'store_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Store Views'), + 'index' => 'store_id', + 'type' => 'store', + 'store_all' => true, + 'store_view' => true, + 'sortable' => false, + 'filter_condition_callback'=> array($this, '_filterStoreCondition'), + ) + ); + } + $this->addColumn( + 'created_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Created at'), + 'index' => 'created_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'updated_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Updated at'), + 'index' => 'updated_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'action', + array( + 'header' => Mage::helper('werules_chatbot')->__('Action'), + 'width' => '100', + 'type' => 'action', + 'getter' => 'getId', + 'actions' => array( + array( + 'caption' => Mage::helper('werules_chatbot')->__('Edit'), + 'url' => array('base'=> '*/*/edit'), + 'field' => 'id' + ) + ), + 'filter' => false, + 'is_system' => true, + 'sortable' => false, + ) + ); + $this->addExportType('*/*/exportCsv', Mage::helper('werules_chatbot')->__('CSV')); + $this->addExportType('*/*/exportExcel', Mage::helper('werules_chatbot')->__('Excel')); + $this->addExportType('*/*/exportXml', Mage::helper('werules_chatbot')->__('XML')); + return parent::_prepareColumns(); + } + + /** + * prepare mass action + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid + */ + protected function _prepareMassaction() + { + $this->setMassactionIdField('entity_id'); + $this->getMassactionBlock()->setFormFieldName('chatbotuser'); + $this->getMassactionBlock()->addItem( + 'delete', + array( + 'label'=> Mage::helper('werules_chatbot')->__('Delete'), + 'url' => $this->getUrl('*/*/massDelete'), + 'confirm' => Mage::helper('werules_chatbot')->__('Are you sure?') + ) + ); + $this->getMassactionBlock()->addItem( + 'status', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change status'), + 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)), + 'additional' => array( + 'status' => array( + 'name' => 'status', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ) + ) + ); + $this->getMassactionBlock()->addItem( + 'enable_promotional_messages', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change Enable Promotional Messages'), + 'url' => $this->getUrl('*/*/massEnablePromotionalMessages', array('_current'=>true)), + 'additional' => array( + 'flag_enable_promotional_messages' => array( + 'name' => 'flag_enable_promotional_messages', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Enable Promotional Messages'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ) + ) + ); + $this->getMassactionBlock()->addItem( + 'enable_support', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change Enable Support'), + 'url' => $this->getUrl('*/*/massEnableSupport', array('_current'=>true)), + 'additional' => array( + 'flag_enable_support' => array( + 'name' => 'flag_enable_support', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Enable Support'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ) + ) + ); + $this->getMassactionBlock()->addItem( + 'admin', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change Is Admin?'), + 'url' => $this->getUrl('*/*/massAdmin', array('_current'=>true)), + 'additional' => array( + 'flag_admin' => array( + 'name' => 'flag_admin', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Is Admin?'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Yes'), + '0' => Mage::helper('werules_chatbot')->__('No'), + ) + + ) + ) + ) + ); + return $this; + } + + /** + * get the row url + * + * @access public + * @param Werules_Chatbot_Model_Chatbotuser + * @return string + */ + public function getRowUrl($row) + { + return $this->getUrl('*/*/edit', array('id' => $row->getId())); + } + + /** + * get the grid url + * + * @access public + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/grid', array('_current'=>true)); + } + + /** + * after collection load + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid + */ + protected function _afterLoadCollection() + { + $this->getCollection()->walk('afterLoad'); + parent::_afterLoadCollection(); + } + + /** + * filter store column + * + * @access protected + * @param Werules_Chatbot_Model_Resource_Chatbotuser_Collection $collection + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Werules_Chatbot_Block_Adminhtml_Chatbotuser_Grid + */ + protected function _filterStoreCondition($collection, $column) + { + if (!$value = $column->getFilter()->getValue()) { + return; + } + $collection->addStoreFilter($value); + return $this; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message.php new file mode 100644 index 0000000..f59cacd --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message.php @@ -0,0 +1,39 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message extends Mage_Adminhtml_Block_Widget_Grid_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + $this->_controller = 'adminhtml_message'; + $this->_blockGroup = 'werules_chatbot'; + parent::__construct(); + $this->_headerText = Mage::helper('werules_chatbot')->__('Message'); + $this->_updateButton('add', 'label', Mage::helper('werules_chatbot')->__('Add Message')); + + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit.php new file mode 100644 index 0000000..ce62c2d --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit.php @@ -0,0 +1,78 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Edit extends Mage_Adminhtml_Block_Widget_Form_Container +{ + /** + * constructor + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->_blockGroup = 'werules_chatbot'; + $this->_controller = 'adminhtml_message'; + $this->_updateButton( + 'save', + 'label', + Mage::helper('werules_chatbot')->__('Save Message') + ); + $this->_updateButton( + 'delete', + 'label', + Mage::helper('werules_chatbot')->__('Delete Message') + ); + $this->_addButton( + 'saveandcontinue', + array( + 'label' => Mage::helper('werules_chatbot')->__('Save And Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save', + ), + -100 + ); + $this->_formScripts[] = " + function saveAndContinueEdit() { + editForm.submit($('edit_form').action+'back/edit/'); + } + "; + } + + /** + * get the edit form header + * + * @access public + * @return string + */ + public function getHeaderText() + { + if (Mage::registry('current_message') && Mage::registry('current_message')->getId()) { + return Mage::helper('werules_chatbot')->__( + "Edit Message '%s'", + $this->escapeHtml(Mage::registry('current_message')->getMessageId()) + ); + } else { + return Mage::helper('werules_chatbot')->__('Add Message'); + } + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Form.php new file mode 100644 index 0000000..dccc8e8 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Form.php @@ -0,0 +1,49 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Edit_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Edit_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form( + array( + 'id' => 'edit_form', + 'action' => $this->getUrl( + '*/*/save', + array( + 'id' => $this->getRequest()->getParam('id') + ) + ), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ) + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Form.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Form.php new file mode 100644 index 0000000..870e811 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Form.php @@ -0,0 +1,216 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Edit_Tab_Form + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setHtmlIdPrefix('message_'); + $form->setFieldNameSuffix('message'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'message_form', + array('legend' => Mage::helper('werules_chatbot')->__('Message')) + ); + + $fieldset->addField( + 'sender_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Sender ID'), + 'name' => 'sender_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'content', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Content'), + 'name' => 'content', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'status', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'name' => 'status', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'direction', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Direction'), + 'name' => 'direction', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'chat_message_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Chat Message ID'), + 'name' => 'chat_message_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'chatbot_type', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Chatbot Type'), + 'name' => 'chatbot_type', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'content_type', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Content Type'), + 'name' => 'content_type', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'message_payload', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Message Payload'), + 'name' => 'message_payload', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'sent_at', + 'date', + array( + 'label' => Mage::helper('werules_chatbot')->__('Sent At'), + 'name' => 'sent_at', + 'required' => true, + 'class' => 'required-entry', + + 'image' => $this->getSkinUrl('images/grid-cal.gif'), + 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), + ) + ); + + $fieldset->addField( + 'current_command_details', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Current Command Details'), + 'name' => 'current_command_details', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + + $fieldset->addField( + 'message_id', + 'text', + array( + 'label' => Mage::helper('werules_chatbot')->__('Message ID'), + 'name' => 'message_id', + 'required' => true, + 'class' => 'required-entry', + + ) + ); + $fieldset->addField( + 'status', + 'select', + array( + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'name' => 'status', + 'values' => array( + array( + 'value' => 1, + 'label' => Mage::helper('werules_chatbot')->__('Enabled'), + ), + array( + 'value' => 0, + 'label' => Mage::helper('werules_chatbot')->__('Disabled'), + ), + ), + ) + ); + if (Mage::app()->isSingleStoreMode()) { + $fieldset->addField( + 'store_id', + 'hidden', + array( + 'name' => 'stores[]', + 'value' => Mage::app()->getStore(true)->getId() + ) + ); + Mage::registry('current_message')->setStoreId(Mage::app()->getStore(true)->getId()); + } + $formValues = Mage::registry('current_message')->getDefaultValues(); + if (!is_array($formValues)) { + $formValues = array(); + } + if (Mage::getSingleton('adminhtml/session')->getMessageData()) { + $formValues = array_merge($formValues, Mage::getSingleton('adminhtml/session')->getMessageData()); + Mage::getSingleton('adminhtml/session')->setMessageData(null); + } elseif (Mage::registry('current_message')) { + $formValues = array_merge($formValues, Mage::registry('current_message')->getData()); + } + $form->setValues($formValues); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Stores.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Stores.php new file mode 100644 index 0000000..cb4ebca --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tab/Stores.php @@ -0,0 +1,55 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Edit_Tab_Stores extends Mage_Adminhtml_Block_Widget_Form +{ + /** + * prepare the form + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Edit_Tab_Stores + */ + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + $form->setFieldNameSuffix('message'); + $this->setForm($form); + $fieldset = $form->addFieldset( + 'message_stores_form', + array('legend' => Mage::helper('werules_chatbot')->__('Store views')) + ); + $field = $fieldset->addField( + 'store_id', + 'multiselect', + array( + 'name' => 'stores[]', + 'label' => Mage::helper('werules_chatbot')->__('Store Views'), + 'title' => Mage::helper('werules_chatbot')->__('Store Views'), + 'required' => true, + 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true), + ) + ); + $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element'); + $field->setRenderer($renderer); + $form->addValues(Mage::registry('current_message')->getData()); + return parent::_prepareForm(); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tabs.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tabs.php new file mode 100644 index 0000000..db6325c --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Edit/Tabs.php @@ -0,0 +1,82 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs +{ + /** + * Initialize Tabs + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('message_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(Mage::helper('werules_chatbot')->__('Message')); + } + + /** + * before render html + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Edit_Tabs + */ + protected function _beforeToHtml() + { + $this->addTab( + 'form_message', + array( + 'label' => Mage::helper('werules_chatbot')->__('Message'), + 'title' => Mage::helper('werules_chatbot')->__('Message'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_message_edit_tab_form' + ) + ->toHtml(), + ) + ); + if (!Mage::app()->isSingleStoreMode()) { + $this->addTab( + 'form_store_message', + array( + 'label' => Mage::helper('werules_chatbot')->__('Store views'), + 'title' => Mage::helper('werules_chatbot')->__('Store views'), + 'content' => $this->getLayout()->createBlock( + 'werules_chatbot/adminhtml_message_edit_tab_stores' + ) + ->toHtml(), + ) + ); + } + return parent::_beforeToHtml(); + } + + /** + * Retrieve message entity + * + * @access public + * @return Werules_Chatbot_Model_Message + */ + public function getMessage() + { + return Mage::registry('current_message'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Grid.php b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Grid.php new file mode 100644 index 0000000..6ba3e11 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Adminhtml/Message/Grid.php @@ -0,0 +1,329 @@ +. + */ + +class Werules_Chatbot_Block_Adminhtml_Message_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + /** + * constructor + * + * @access public + */ + public function __construct() + { + parent::__construct(); + $this->setId('messageGrid'); + $this->setDefaultSort('entity_id'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + $this->setUseAjax(true); + } + + /** + * prepare collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Grid + */ + protected function _prepareCollection() + { + $collection = Mage::getModel('werules_chatbot/message') + ->getCollection(); + + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * prepare grid collection + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Grid + */ + protected function _prepareColumns() + { + $this->addColumn( + 'entity_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Id'), + 'index' => 'entity_id', + 'type' => 'number' + ) + ); + $this->addColumn( + 'message_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Message ID'), + 'align' => 'left', + 'index' => 'message_id', + ) + ); + + $this->addColumn( + 'status', + array( + 'header' => Mage::helper('werules_chatbot')->__('Status'), + 'index' => 'status', + 'type' => 'options', + 'options' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ); + $this->addColumn( + 'sender_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Sender ID'), + 'index' => 'sender_id', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'content', + array( + 'header' => Mage::helper('werules_chatbot')->__('Content'), + 'index' => 'content', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'status', + array( + 'header' => Mage::helper('werules_chatbot')->__('Status'), + 'index' => 'status', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'direction', + array( + 'header' => Mage::helper('werules_chatbot')->__('Direction'), + 'index' => 'direction', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'chat_message_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Chat Message ID'), + 'index' => 'chat_message_id', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'chatbot_type', + array( + 'header' => Mage::helper('werules_chatbot')->__('Chatbot Type'), + 'index' => 'chatbot_type', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'content_type', + array( + 'header' => Mage::helper('werules_chatbot')->__('Content Type'), + 'index' => 'content_type', + 'type'=> 'number', + + ) + ); + $this->addColumn( + 'message_payload', + array( + 'header' => Mage::helper('werules_chatbot')->__('Message Payload'), + 'index' => 'message_payload', + 'type'=> 'text', + + ) + ); + $this->addColumn( + 'sent_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Sent At'), + 'index' => 'sent_at', + 'type'=> 'datetime', + + ) + ); + $this->addColumn( + 'current_command_details', + array( + 'header' => Mage::helper('werules_chatbot')->__('Current Command Details'), + 'index' => 'current_command_details', + 'type'=> 'text', + + ) + ); + if (!Mage::app()->isSingleStoreMode() && !$this->_isExport) { + $this->addColumn( + 'store_id', + array( + 'header' => Mage::helper('werules_chatbot')->__('Store Views'), + 'index' => 'store_id', + 'type' => 'store', + 'store_all' => true, + 'store_view' => true, + 'sortable' => false, + 'filter_condition_callback'=> array($this, '_filterStoreCondition'), + ) + ); + } + $this->addColumn( + 'created_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Created at'), + 'index' => 'created_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'updated_at', + array( + 'header' => Mage::helper('werules_chatbot')->__('Updated at'), + 'index' => 'updated_at', + 'width' => '120px', + 'type' => 'datetime', + ) + ); + $this->addColumn( + 'action', + array( + 'header' => Mage::helper('werules_chatbot')->__('Action'), + 'width' => '100', + 'type' => 'action', + 'getter' => 'getId', + 'actions' => array( + array( + 'caption' => Mage::helper('werules_chatbot')->__('Edit'), + 'url' => array('base'=> '*/*/edit'), + 'field' => 'id' + ) + ), + 'filter' => false, + 'is_system' => true, + 'sortable' => false, + ) + ); + $this->addExportType('*/*/exportCsv', Mage::helper('werules_chatbot')->__('CSV')); + $this->addExportType('*/*/exportExcel', Mage::helper('werules_chatbot')->__('Excel')); + $this->addExportType('*/*/exportXml', Mage::helper('werules_chatbot')->__('XML')); + return parent::_prepareColumns(); + } + + /** + * prepare mass action + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Grid + */ + protected function _prepareMassaction() + { + $this->setMassactionIdField('entity_id'); + $this->getMassactionBlock()->setFormFieldName('message'); + $this->getMassactionBlock()->addItem( + 'delete', + array( + 'label'=> Mage::helper('werules_chatbot')->__('Delete'), + 'url' => $this->getUrl('*/*/massDelete'), + 'confirm' => Mage::helper('werules_chatbot')->__('Are you sure?') + ) + ); + $this->getMassactionBlock()->addItem( + 'status', + array( + 'label' => Mage::helper('werules_chatbot')->__('Change status'), + 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)), + 'additional' => array( + 'status' => array( + 'name' => 'status', + 'type' => 'select', + 'class' => 'required-entry', + 'label' => Mage::helper('werules_chatbot')->__('Status'), + 'values' => array( + '1' => Mage::helper('werules_chatbot')->__('Enabled'), + '0' => Mage::helper('werules_chatbot')->__('Disabled'), + ) + ) + ) + ) + ); + return $this; + } + + /** + * get the row url + * + * @access public + * @param Werules_Chatbot_Model_Message + * @return string + */ + public function getRowUrl($row) + { + return $this->getUrl('*/*/edit', array('id' => $row->getId())); + } + + /** + * get the grid url + * + * @access public + * @return string + */ + public function getGridUrl() + { + return $this->getUrl('*/*/grid', array('_current'=>true)); + } + + /** + * after collection load + * + * @access protected + * @return Werules_Chatbot_Block_Adminhtml_Message_Grid + */ + protected function _afterLoadCollection() + { + $this->getCollection()->walk('afterLoad'); + parent::_afterLoadCollection(); + } + + /** + * filter store column + * + * @access protected + * @param Werules_Chatbot_Model_Resource_Message_Collection $collection + * @param Mage_Adminhtml_Block_Widget_Grid_Column $column + * @return Werules_Chatbot_Block_Adminhtml_Message_Grid + */ + protected function _filterStoreCondition($collection, $column) + { + if (!$value = $column->getFilter()->getValue()) { + return; + } + $collection->addStoreFilter($value); + return $this; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Index.php b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Index.php new file mode 100644 index 0000000..3fe6aa0 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Index.php @@ -0,0 +1,116 @@ +. + */ + +class Werules_Chatbot_Block_Webhook_Index extends Mage_Core_Block_Template +{ + protected $_helper; + protected $_chatbotAPI; + protected $_messageModel; + protected $_request; + protected $_define; +// protected $_cronWorker; + + public function _construct() + { + $this->_helper = Mage::helper('werules_chatbot'); + $this->_chatbotAPI = Mage::getModel('werules_chatbot/chatbotapi'); + $this->_messageModel = Mage::getModel('werules_chatbot/message'); + $this->_request = $this->getRequest(); + $this->_define = new Werules_Chatbot_Helper_Define; + } + + protected function createMessageObject($apiModel){} // TODO + public function processRequest(){} // TODO + + protected function checkEndpointSecretKey() + { + $urlKey = $this->_request->getParam('endpoint'); + $customKey = $this->getConfigValue('werules_chatbot_general/general/custom_key'); + if ($urlKey == $customKey) + return true; + + return false; + } + + public function requestHandler() + { + $enabled = $this->getConfigValue('werules_chatbot_general/general/enable'); + if ($enabled != $this->_define->ENABLED) + return $this->getJsonErrorResponse(); + + $correctKey = $this->checkEndpointSecretKey(); + if ($correctKey) + $result = $this->processRequest(); + else + $result = $this->getJsonErrorResponse(); + + return $result; + } + + protected function messageHandler($messageObject) + { + $messageModel = $this->_helper->createIncomingMessage($messageObject); + if ($messageModel->getMessageId()) + { + $messageQueueMode = $this->_helper->getQueueMessageMode(); + if (($messageQueueMode == $this->_define->QUEUE_NONE) || ($messageQueueMode == $this->_define->QUEUE_NON_RESTRICTIVE)) + { + $outgoingMessages = $this->_helper->processIncomingMessage($messageModel); + foreach ($outgoingMessages as $outgoingMessage) + { + $result = $this->_helper->processOutgoingMessage($outgoingMessage); + } + } + else if (($messageQueueMode == $this->_define->QUEUE_RESTRICTIVE) || ($messageQueueMode == $this->_define->QUEUE_SIMPLE_RESTRICTIVE)) + { + $result = $this->_helper->processIncomingMessageQueueBySenderId($messageModel->getSenderId()); + if ($result) + $result = $this->_helper->processOutgoingMessageQueueBySenderId($messageModel->getSenderId()); + } + } + else + return $this->_helper->getJsonErrorResponse(); + + return $this->getJsonSuccessResponse(); + } + + public function getConfigValue($code) + { + return $this->_helper->getConfigValue($code); + } + + protected function getJsonErrorResponse() + { + return $this->_helper->getJsonErrorResponse(); + } + + protected function getJsonSuccessResponse() + { + return $this->_helper->getJsonSuccessResponse(); + } + + protected function logPostData($data, $file = 'werules_chatbot.log') + { + $postLog = ($this->getConfigValue('werules_chatbot_general/general/enable_post_log') == $this->_define->ENABLED); + if ($postLog) + $this->_helper->logger($data, $file); + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Messenger.php b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Messenger.php new file mode 100644 index 0000000..7d14dca --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Messenger.php @@ -0,0 +1,99 @@ +. + */ + +class Werules_Chatbot_Block_Webhook_Messenger extends Werules_Chatbot_Block_Webhook_Index +{ + public function processRequest() + { + $challenge_hub = $this->getConfigValue('werules_chatbot_messenger/general/enable_hub_challenge'); + if ($challenge_hub == $this->_define->ENABLED) + { + $hub_token = $this->getConfigValue('werules_chatbot_general/general/custom_key'); + $verification_hub = $this->getVerificationHub($hub_token); + if ($verification_hub) + $result = $verification_hub; + else + $result = __("Please check your Hub Verify Token."); + } + else // process message + { + $messengerInstance = $this->getMessengerInstance(); + if (!$messengerInstance->getPostData()) + return $this->getJsonErrorResponse(); + + $this->logPostData($messengerInstance->getPostData(), 'werules_chatbot_messenger.log'); + + $messageObject = $this->createMessageObject($messengerInstance); + if (isset($messageObject->content)) + $result = $this->messageHandler($messageObject); + else + $result = $this->getJsonSuccessResponse(); // return success to avoid receiving the same message again + } + + return $result; + } + + protected function getMessengerInstance() + { + $api_token = $this->_helper->getConfigValue('werules_chatbot_messenger/general/api_key'); + $messenger = $this->_chatbotAPI->initMessengerAPI($api_token); + return $messenger; + } + + protected function createMessageObject($messenger) + { + $messageObject = new stdClass(); + if ($messenger->Text()) + $content = $messenger->Text(); + else + $content = $messenger->getPostbackTitle(); + if (!$content) + return $messageObject; + + $messageObject->senderId = $messenger->ChatID(); + $messageObject->content = $content; + $messageObject->status = $this->_define->PROCESSING; + $messageObject->direction = $this->_define->INCOMING; + $messageObject->chatType = $this->_define->MESSENGER_INT; // TODO + $messageObject->contentType = $this->_define->CONTENT_TEXT; // TODO + $messageObject->currentCommandDetails = $this->_define->CURRENT_COMMAND_DETAILS_DEFAULT; // TODO + $messageObject->messagePayload = $this->getMessengerPayload($messenger); // TODO + $messageObject->chatMessageId = $messenger->MessageID(); + if ($messenger->getMessageTimestamp()) + $messageObject->sentAt = substr($messenger->getMessageTimestamp(), 0, 10); + else + $messageObject->sentAt = time(); + $datetime = date('Y-m-d H:i:s'); + $messageObject->createdAt = $datetime; + $messageObject->updatedAt = $datetime; + + return $messageObject; + } + + protected function getMessengerPayload($messenger) + { + $payload = $messenger->getPostbackPayload(); + if (!$payload) + $payload = $messenger->getQuickReplyPayload(); + + return $payload; + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Telegram.php b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Telegram.php new file mode 100644 index 0000000..72380d3 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Block/Webhook/Telegram.php @@ -0,0 +1,25 @@ +. + */ + +class Werules_Chatbot_Block_Webhook_Telegram extends Werules_Chatbot_Block_Webhook_Index +{ + +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Controller/Adminhtml/Chatbot.php b/Magento1/app/code/community/Werules/Chatbot/Controller/Adminhtml/Chatbot.php new file mode 100644 index 0000000..fa4862f --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Controller/Adminhtml/Chatbot.php @@ -0,0 +1,57 @@ +. + */ + +class Werules_Chatbot_Controller_Adminhtml_Chatbot extends Mage_Adminhtml_Controller_Action +{ + /** + * upload file and get the uploaded name + * + * @access public + * @param string $input + * @param string $destinationFolder + * @param array $data + * @return string + */ + protected function _uploadAndGetName($input, $destinationFolder, $data) + { + try { + if (isset($data[$input]['delete'])) { + return ''; + } else { + $uploader = new Varien_File_Uploader($input); + $uploader->setAllowRenameFiles(true); + $uploader->setFilesDispersion(true); + $uploader->setAllowCreateFolders(true); + $result = $uploader->save($destinationFolder); + return $result['file']; + } + } catch (Exception $e) { + if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) { + throw $e; + } else { + if (isset($data[$input]['value'])) { + return $data[$input]['value']; + } + } + } + return ''; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Helper/Data.php b/Magento1/app/code/community/Werules/Chatbot/Helper/Data.php new file mode 100644 index 0000000..fd2e9da --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Helper/Data.php @@ -0,0 +1,159 @@ +. + */ + +class Werules_Chatbot_Helper_Data extends Mage_Core_Helper_Abstract +{ + protected $storeManager; + protected $_messageModelFactory; + protected $_messageModel; + protected $_chatbotAPIFactory; + protected $_chatbotUserFactory; + protected $_serializer; + protected $_categoryHelper; + protected $_categoryFactory; + protected $_categoryCollectionFactory; + protected $_orderCollectionFactory; + protected $_productCollection; + protected $_customerRepositoryInterface; + protected $_quoteModel; + protected $_configWriter; + protected $_imageHelper; + protected $_stockRegistry; + protected $_stockFilter; + protected $_priceHelper; + + // not from construct parameters + protected $_define; + protected $_messageQueueMode; + protected $_configPrefix; + protected $_commandsList; + protected $_completeCommandsList; + protected $_currentCommand; + protected $_messagePayload; + protected $_chatbotAPIModel; + + public function __construct() + { + $this->_serializer = Mage::helper('core/unserializeArray'); // ->unserialize((string)$serializedValue); // fix magento unserializing bug +// $this->storeManager = $storeManager; + $this->_messageModel = Mage::getModel('werules_chatbot/message'); // TODO + $this->_messageModelFactory = Mage::getModel('werules_chatbot/message'); // TODO + $this->_chatbotAPIFactory = Mage::getModel('werules_chatbot/chatbotapi'); // TODO + $this->_chatbotUserFactory = Mage::getModel('werules_chatbot/chatbotuser'); // TODO + $this->_define = new Werules_Chatbot_Helper_Define; + } + public function convertOptions($options) + { + $converted = array(); + foreach ($options as $option) { + if (isset($option['value']) && !is_array($option['value']) && + isset($option['label']) && !is_array($option['label'])) { + $converted[$option['value']] = $option['label']; + } + } + return $converted; + } + + public function createIncomingMessage($messageObject) + { + $this->logger('messageObject -> '); + $this->logger($messageObject); + $incomingMessage = $this->_messageModelFactory; + if (isset($messageObject->senderId)) + { + $incomingMessage->setSenderId($messageObject->senderId); + $incomingMessage->setContent($messageObject->content); + $incomingMessage->setChatbotType($messageObject->chatType); + $incomingMessage->setContentType($messageObject->contentType); + $incomingMessage->setCurrentCommandDetails($messageObject->currentCommandDetails); + $incomingMessage->setStatus($messageObject->status); + $incomingMessage->setDirection($messageObject->direction); + $incomingMessage->setMessagePayload($messageObject->messagePayload); + $incomingMessage->setChatMessageId($messageObject->chatMessageId); + $incomingMessage->setSentAt($messageObject->sentAt); + $incomingMessage->setCreatedAt($messageObject->createdAt); + $incomingMessage->setUpdatedAt($messageObject->updatedAt); + $incomingMessage->save(); + } + + return $incomingMessage; + } + + public function getQueueMessageMode() + { + if (isset($this->_messageQueueMode)) + return $this->_messageQueueMode; + + $this->_messageQueueMode = $this->getConfigValue('werules_chatbot_general/general/message_queue_mode'); + return $this->_messageQueueMode; + } + + public function processIncomingMessage($message) // TODO_NOW + { + return array(); + } + + public function processOutgoingMessage($outgoingMessage) // TODO_NOW + { + return array(); + } + + public function processIncomingMessageQueueBySenderId($senderId) // TODO_NOW + { + return array(); + } + + public function processOutgoingMessageQueueBySenderId($senderId) // TODO_NOW + { + return array(); + } + + public function logger($text, $file = 'werules_chatbot.log') + { + Mage::log($text, null, $file); + } + + public function getConfigValue($field) + { + return Mage::getStoreConfig($field); + } + + public function getJsonSuccessResponse() + { + return $this->getJsonResponse(true); + } + + public function getJsonErrorResponse() + { + return $this->getJsonResponse(false); + } + + private function getJsonResponse($success) + { + header_remove('Content-Type'); // TODO + header('Content-Type: application/json'); // TODO + if ($success) + $result = array('status' => 'success', 'success' => true); + else + $result = array('status' => 'error', 'success' => false); + return json_encode($result); + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Helper/Define.php b/Magento1/app/code/community/Werules/Chatbot/Helper/Define.php new file mode 100644 index 0000000..b8831cf --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Helper/Define.php @@ -0,0 +1,99 @@ +. + */ + +class Werules_Chatbot_Helper_Define +{ + public $MESSENGER_INT = 0; + public $TELEGRAM_INT = 1; + public $NOT_PROCESSED = 0; + public $PROCESSING = 1; + public $PROCESSED = 2; + public $INCOMING = 0; + public $OUTGOING = 1; + public $DISABLED = 0; + public $ENABLED = 1; + public $NOT_LOGGED = 0; + public $NOT_ADMIN = 0; + public $ADMIN = 1; + public $LOGGED = 1; + public $SECONDS_IN_HOUR = 3600; + public $SECONDS_IN_MINUTE = 60; + public $DEFAULT_MIN_CONFIDENCE = 0.7; + public $BREAK_LINE = '\n'; // chr(10) + public $QUEUE_PROCESSING_LIMIT = 180;//$SECONDS_IN_MINUTE * 3; + + // commands + public $START_COMMAND_ID = 0; + public $LIST_CATEGORIES_COMMAND_ID = 1; + public $SEARCH_COMMAND_ID = 2; + public $LOGIN_COMMAND_ID = 3; + public $LIST_ORDERS_COMMAND_ID = 4; + public $REORDER_COMMAND_ID = 5; + public $ADD_TO_CART_COMMAND_ID = 6; + public $CHECKOUT_COMMAND_ID = 7; + public $CLEAR_CART_COMMAND_ID = 8; + public $TRACK_ORDER_COMMAND_ID = 9; + public $SUPPORT_COMMAND_ID = 10; + public $SEND_EMAIL_COMMAND_ID = 11; + public $CANCEL_COMMAND_ID = 12; + public $HELP_COMMAND_ID = 13; + public $ABOUT_COMMAND_ID = 14; + public $LOGOUT_COMMAND_ID = 15; + public $REGISTER_COMMAND_ID = 16; + public $LIST_MORE_COMMAND_ID = 17; + public $LAST_COMMAND_DETAILS_DEFAULT = '{"last_command_parameter":"","last_command_text":"","last_conversation_state":0,"last_listed_quantity":0}'; +// array( +// 'last_command_parameter' => '', +// 'last_command_text' => '', +// 'last_conversation_state' => 0, +// 'last_listed_quantity' => 0, +// ); + public $CURRENT_COMMAND_DETAILS_DEFAULT = '[]'; +// json_encode(array()) + + // message content types + public $CONTENT_TEXT = 0; + public $QUICK_REPLY = 1; + public $IMAGE_WITH_TEXT = 2; + public $IMAGE_WITH_OPTIONS = 3; + public $RECEIPT_LAYOUT = 4; + public $LIST_WITH_IMAGE = 5; + public $TEXT_WITH_OPTIONS = 6; + + // conversation states + public $CONVERSATION_STARTED = 0; + public $CONVERSATION_LIST_CATEGORIES = 1; + public $CONVERSATION_SEARCH = 2; + public $CONVERSATION_EMAIL = 3; + public $CONVERSATION_TRACK_ORDER = 4; + + // API + public $MAX_MESSAGE_ELEMENTS = 7; + + // MESSAGE QUEUE MODES + public $QUEUE_NONE = 0; + public $QUEUE_SIMPLE_RESTRICTIVE = 1; + public $QUEUE_RESTRICTIVE = 2; + public $QUEUE_NON_RESTRICTIVE = 3; + + public $DONT_CLEAR_MESSAGE_QUEUE = 0; + public $CLEAR_MESSAGE_QUEUE = 1; +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php b/Magento1/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php new file mode 100644 index 0000000..41596c2 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php @@ -0,0 +1,55 @@ +. + */ + +// this class is used to replace Magento own class that contains a glitch +class Werules_Chatbot_Model_Adminhtml_Serialized extends Mage_Adminhtml_Model_System_Config_Backend_Serialized +{ + protected function _afterLoad() + { + if (!is_array($this->getValue())) { + $serializedValue = $this->getValue(); + $unserializedValue = false; + if ($serializedValue) { + try { + $unserializedValue = Mage::helper('core/unserializeArray') + ->unserialize((string)$serializedValue); // fix magento unserializing bug + } catch (Exception $e) { + Mage::logException($e); + } + } + $this->setValue($unserializedValue); + } + } + + protected function _beforeSave() + { + $value = $this->getValue(); + if (is_array($value)) { + unset($value['__empty']); + } + $this->setValue($value); + + if (is_array($this->getValue())) + { + $this->setValue(serialize($this->getValue())); + } + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Api/Messenger.php b/Magento1/app/code/community/Werules/Chatbot/Model/Api/Messenger.php new file mode 100644 index 0000000..47eb917 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Api/Messenger.php @@ -0,0 +1,442 @@ + + * TODO: + * https://developers.facebook.com/docs/messenger-platform/send-api-reference/buy-button + * https://developers.facebook.com/docs/messenger-platform/send-api-reference/url-button + * https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment + * https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions + * https://developers.facebook.com/docs/messenger-platform/send-api-reference/errors + */ + +/** + * Magento Chatbot Integration + * Copyright (C) 2018 + * + * This file is part of Werules/Chatbot. + * + * Werules/Chatbot is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +class Werules_Chatbot_Model_Api_Messenger { + + private $bot_token; + private $api_version = "v2.11"; + private $data; + + /// Class constructor + public function __construct($bot_token) { + $this->bot_token = $bot_token; + $this->data = $this->getPostData(); + } + + /// Verify webhook + public function verifyWebhook($hub_token) { + if (isset($this->data['hub_verify_token'])) + { + if ($this->data['hub_verify_token'] == $hub_token) { + if (isset($this->data['hub_challenge'])) + return $this->data['hub_challenge']; + } + } + + return ''; + } + + /// Do requests to Messenger Bot API + public function endpoint($api, array $content, $post = true) { + $url = 'https://graph.facebook.com/' . $this->api_version . '/' . $api . '?access_token=' . $this->bot_token; + if ($post) + $reply = $this->sendAPIRequest($url, $content); + else + $reply = $this->sendAPIRequest($url, array(), false); + return json_decode($reply, true); + } + + public function respondSuccess() { + http_response_code(200); + return json_encode(array("status" => "success")); + } + + // send chat action + // sender_action: + // mark_seen + // typing_on + // typing_off + public function sendChatAction($chat_id, $action) { + return $this->endpoint("me/messages", array( + 'recipient' => array( + 'id' => $chat_id + ), + 'sender_action' => $action + ) + ); + } + + // send message +// https://developers.facebook.com/docs/messenger-platform/send-api-reference#request + public function sendMessage($chat_id, $text) { + return $this->endpoint("me/messages", array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'text' => $text + ) + ) + ); + } + +// sendGenericTemplate +// $button = array( +// array( +// 'type' => 'web_url', +// 'url' => 'URL_HERE', +// 'title' => 'TITLE_HERE' +// ), +// array( +// 'type' => 'web_url', +// 'url' => 'URL_HERE', +// 'title' => 'TITLE_HERE' +// ), +// ... +// ); +// $elements = array( +// array( +// 'title' => 'TITLE_TEXT_HERE', +// 'item_url' => 'ITEM_URL_HERE', +// 'image_url' => 'IMAGE_URL_HERE', +// 'subtitle' => 'SUBTITLE_HERE', +// 'buttons' => $buttons +// ) +// ); +// https://developers.facebook.com/docs/messenger-platform/send-api-reference#request + public function sendGenericTemplate($chat_id, array $elements) { + return $this->endpoint("me/messages", array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'attachment' => array( + 'type' => 'template', + 'payload' => array( + 'template_type' => 'generic', + 'elements' => $elements + ) + ) + ) + ) + ); + } + +// https://developers.facebook.com/docs/messenger-platform/send-messages/template/list#example_request +// $elements = array( +// array( +// 'title' => 'Classic T-Shirt Collection', +// 'subtitle' => 'See all our colors 1', +// 'image_url' => 'https://mysite.com/image/toy_1.jpg', +// 'buttons' => array( +// array( +// 'title' => 'View', +// 'type' => 'web_url', +// 'url' => 'https://mysite.com/' +// ) +// ) +// ), +// array( +// 'title' => 'Classic White T-Shirt', +// 'subtitle' => 'See all our colors', +// 'default_action' => array( +// 'type' => 'web_url', +// 'url' => 'https://mysite.com/' +// ) +// ), +// array( +// 'title' => 'Classic Blue T-Shirt', +// 'image_url' => 'https://mysite.com/image/toy_1.jpg', +// 'subtitle' => '100% Cotton, 200% Comfortable', +// 'default_action' => array( +// 'type' => 'web_url', +// 'url' => 'https://mysite.com/' +// ), +// 'buttons' => array( +// array( +// 'title' => 'Shop Now', +// 'type' => 'web_url', +// 'url' => 'https://mysite.com/' +// ) +// ) +// ) +// ); +// $buttons = array( +// array( +// 'title' => 'View More', +// 'type' => 'postback', +// 'payload' => 'payload', +// ) + +// ); + + public function sendListTemplate($chat_id, array $elements, array $buttons = array(), $top_element = 'compact') { + return $this->endpoint("me/messages", array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'attachment' => array( + 'type' => 'template', + 'payload' => array( + 'template_type' => 'list', + 'top_element_style' => $top_element, + 'elements' => $elements, + 'buttons' => $buttons + ) + ) + ) + ) + ); + } + + // send quick reply +// $replies = array( +// array( +// 'content_type' => 'text', +// 'title' => 'TITLE_HERE', +// 'payload' => 'DEVELOPER_CUSTOM_PAYLOAD_HERE' +// ), +// array( +// 'content_type' => 'text', +// 'title' => 'TITLE_HERE', +// 'payload' => 'DEVELOPER_CUSTOM_PAYLOAD_HERE' +// ), +// ... +// ); +// https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies + public function sendQuickReply($chat_id, $text, array $replies) { + return $this->endpoint("me/messages", array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'text' => $text, + 'quick_replies' => $replies + ) + ) + ); + } + + // send button +// $buttons = array( +// array( +// 'type' => 'web_url', +// 'url' => 'URL_HERE', +// 'title' => 'TITLE_HERE' +// ), +// array( +// 'type' => 'web_url', +// 'url' => 'URL_HERE', +// 'title' => 'TITLE_HERE' +// ), +// ... +// ); +// https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template +// https://developers.facebook.com/docs/messenger-platform/send-api-reference/share-button <- works only with sendGenericTemplate + public function sendButtonTemplate($chat_id, $text, array $buttons) { + return $this->endpoint("me/messages", + array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'attachment' => array( + 'type' => 'template', + 'payload' => array( + 'template_type' => 'button', + 'text' => $text, + 'buttons' => $buttons + ) + ) + ) + ) + ); + } + + // send elements +// $elements = array( +// array( +// 'title' => 'TITLE_TEXT_HERE', +// 'item_url' => 'ITEM_URL_HERE', +// 'image_url' => 'IMAGE_URL_HERE', +// 'subtitle' => 'SUBTITLE_HERE', +// 'buttons' => $buttons +// ) +// ); +// https://developers.facebook.com/docs/messenger-platform/send-api-reference/receipt-template + public function sendReceiptTemplate($chat_id, array $payload) { + return $this->endpoint("me/messages", + array( + 'recipient' => array( + 'id' => $chat_id + ), + 'message' => array( + 'attachment' => array( + 'type' => 'template', + 'payload' => $payload + ) + ) + ) + ); + } + + /// Get the text of the current message + public function Text() { + if (isset($this->data["entry"][0]["messaging"][0]["message"]["text"])) + return $this->data["entry"][0]["messaging"][0]["message"]["text"]; + + return ''; + } + + /// Get the userdata who sent the message + public function UserData($chat_id) { + return $this->endpoint($chat_id, array(), false); + } + + /// Get the chat_id of the current message + public function ChatID() { + if (isset($this->data["entry"][0]['messaging'][0]['sender']['id'])) + return $this->data['entry'][0]['messaging'][0]['sender']['id']; + + return ''; + } + + /// Get the recipient_id of the current message + public function RecipientID() { + if (isset($this->data["entry"][0]['messaging'][0]['recipient']['id'])) + return $this->data['entry'][0]['messaging'][0]['recipient']['id']; + + return ''; + } + + /// Get m.me ref type + public function getReferralType() { + if (isset($this->data["entry"][0]["messaging"][0]["referral"]["type"])) + return $this->data["entry"][0]["messaging"][0]["referral"]["type"]; + + return ''; + } + + /// Get m.me ref data + public function getReferralRef() { + if (isset($this->data["entry"][0]["messaging"][0]["referral"]["ref"])) + return $this->data["entry"][0]["messaging"][0]["referral"]["ref"]; + + return ''; + } + + /// Get postback payload + public function getPostbackPayload() { + if (isset($this->data["entry"][0]["messaging"][0]["postback"]["payload"])) + return $this->data["entry"][0]["messaging"][0]["postback"]["payload"]; + + return ''; + } + + /// Get postback title + public function getPostbackTitle() { + if (isset($this->data["entry"][0]["messaging"][0]["postback"]["title"])) + return $this->data["entry"][0]["messaging"][0]["postback"]["title"]; + + return ''; + } + + /// Get quickreply payload + public function getQuickReplyPayload() { + if (isset($this->data["entry"][0]["messaging"][0]["message"]["quick_reply"]["payload"])) + return $this->data["entry"][0]["messaging"][0]["message"]["quick_reply"]["payload"]; + + return ''; + } + + /// Get message timestamp + public function getMessageTimestamp() { + if (isset($this->data["entry"][0]["time"])) + return $this->data["entry"][0]["time"]; + + return ''; + } + + /// Get the message_id of the current message + public function MessageID() { + if (isset($this->data["entry"][0]["messaging"][0]["message"]["mid"])) + return $this->data["entry"][0]["messaging"][0]["message"]["mid"]; + + return ''; + } + + /// Get the is_echo of the current message + public function getEcho() { + if (isset($this->data["entry"][0]["messaging"][0]["message"]["is_echo"])) + return $this->data["entry"][0]["messaging"][0]["message"]["is_echo"]; + + return ''; + } + + /// Get the app_id of the current message + public function getAppId() { + if (isset($this->data["entry"][0]["messaging"][0]["message"]["app_id"])) + return $this->data["entry"][0]["messaging"][0]["message"]["app_id"]; + + return ''; + } + + private function sendAPIRequest($url, array $content, $post = true, $response = true) { + $ch = curl_init($url); + if ($post) { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content)); + } + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + if ($response) + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + curl_close($ch); + return $result; + } + + /// Get the data of the current message + public function getPostData() { + if (!($this->data)) { + $rawData = file_get_contents("php://input"); + if ($rawData) + return json_decode($rawData, true); + else + return $_REQUEST; + } else { + return $this->data; + } + } +} + +// Helper for Uploading file using CURL +if (!function_exists('curl_file_create')) { + + function curl_file_create($filename, $mimetype = '', $postname = '') { + return "@$filename;filename=" + . ($postname ? : basename($filename)) + . ($mimetype ? ";type=$mimetype" : ''); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Api/witAI.php b/Magento1/app/code/community/Werules/Chatbot/Model/Api/witAI.php new file mode 100644 index 0000000..bdb86f1 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Api/witAI.php @@ -0,0 +1,67 @@ +. +*/ + +class Werules_Chatbot_Model_Api_witAI extends Mage_Core_Model_Mysql4_Abstract { + + protected $_token; + protected $_version = '11/12/2017'; + //protected $_data; + + /// Class constructor + public function __construct($token) { + $this->_token = $token; + } + + function getTextResponse($query) { + $options = array( + 'http' => array( + 'method' => 'GET', + 'header' => "Authorization: Bearer " . $this->_token . "\r\n" + ) + ); + $content = "&q=" . urlencode($query); + return $this->getWitAIResponse("message", $content, $options); + } + + function getAudioResponse($audioFile) { + $options = array( + 'http' => array( + 'method' => 'POST', + 'header' => "Authorization: Bearer " . $this->_token . "\n" . + "Content-Type: audio/mpeg3" . "\r\n", + 'content' => file_get_contents($audioFile) + ) + ); + return $this->getWitAIResponse("speech", "", $options); + } + + function getWitAIResponse($endPoint, $content, $options) { + $context = stream_context_create($options); + $url = 'https://api.wit.ai/' . $endPoint . '?v=' . $this->_version . $content; + $result = file_get_contents($url, false, $context); + $result = json_decode($result, true); + + if ($result) + return $result; + + return null; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotapi.php b/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotapi.php new file mode 100644 index 0000000..58138f1 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotapi.php @@ -0,0 +1,107 @@ +. + */ + +class Werules_Chatbot_Model_Chatbotapi extends Mage_Core_Model_Abstract +{ + /** + * Entity code. + * Can be used as part of method name for entity processing + */ + const ENTITY = 'werules_chatbot_chatbotapi'; + const CACHE_TAG = 'werules_chatbot_chatbotapi'; + + /** + * Prefix of model events names + * + * @var string + */ + protected $_eventPrefix = 'werules_chatbot_chatbotapi'; + + /** + * Parameter name in event + * + * @var string + */ + protected $_eventObject = 'chatbotapi'; + + /** + * constructor + * + * @access public + * @return void + + */ + public function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/chatbotapi'); + } + + /** + * before save chatbotapi + * + * @access protected + * @return Werules_Chatbot_Model_Chatbotapi + + */ + protected function _beforeSave() + { + parent::_beforeSave(); + $now = Mage::getSingleton('core/date')->gmtDate(); + if ($this->isObjectNew()) { + $this->setCreatedAt($now); + } + $this->setUpdatedAt($now); + return $this; + } + + /** + * save chatbotapi relation + * + * @access public + * @return Werules_Chatbot_Model_Chatbotapi + + */ + protected function _afterSave() + { + return parent::_afterSave(); + } + + /** + * get default values + * + * @access public + * @return array + + */ + public function getDefaultValues() + { + $values = array(); + $values['status'] = 1; + return $values; + } + + // CUSTOM FUNCTIONS + public function initMessengerAPI($bot_token) // TODO TODO TODO + { + return new Werules_Chatbot_Model_Api_Messenger($bot_token); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotuser.php b/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotuser.php new file mode 100644 index 0000000..bd8848d --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Chatbotuser.php @@ -0,0 +1,102 @@ +. + */ + +class Werules_Chatbot_Model_Chatbotuser extends Mage_Core_Model_Abstract +{ + /** + * Entity code. + * Can be used as part of method name for entity processing + */ + const ENTITY = 'werules_chatbot_chatbotuser'; + const CACHE_TAG = 'werules_chatbot_chatbotuser'; + + /** + * Prefix of model events names + * + * @var string + */ + protected $_eventPrefix = 'werules_chatbot_chatbotuser'; + + /** + * Parameter name in event + * + * @var string + */ + protected $_eventObject = 'chatbotuser'; + + /** + * constructor + * + * @access public + * @return void + + */ + public function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/chatbotuser'); + } + + /** + * before save chatbotuser + * + * @access protected + * @return Werules_Chatbot_Model_Chatbotuser + + */ + protected function _beforeSave() + { + parent::_beforeSave(); + $now = Mage::getSingleton('core/date')->gmtDate(); + if ($this->isObjectNew()) { + $this->setCreatedAt($now); + } + $this->setUpdatedAt($now); + return $this; + } + + /** + * save chatbotuser relation + * + * @access public + * @return Werules_Chatbot_Model_Chatbotuser + + */ + protected function _afterSave() + { + return parent::_afterSave(); + } + + /** + * get default values + * + * @access public + * @return array + + */ + public function getDefaultValues() + { + $values = array(); + $values['status'] = 1; + return $values; + } + +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php new file mode 100644 index 0000000..1495704 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php @@ -0,0 +1,27 @@ +. + */ + +class Werules_Chatbot_Model_Cron +{ + public function execute(){ + //do something + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Message.php b/Magento1/app/code/community/Werules/Chatbot/Model/Message.php new file mode 100644 index 0000000..6061a35 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Message.php @@ -0,0 +1,102 @@ +. + */ + +class Werules_Chatbot_Model_Message extends Mage_Core_Model_Abstract +{ + /** + * Entity code. + * Can be used as part of method name for entity processing + */ + const ENTITY = 'werules_chatbot_message'; + const CACHE_TAG = 'werules_chatbot_message'; + + /** + * Prefix of model events names + * + * @var string + */ + protected $_eventPrefix = 'werules_chatbot_message'; + + /** + * Parameter name in event + * + * @var string + */ + protected $_eventObject = 'message'; + + /** + * constructor + * + * @access public + * @return void + + */ + public function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/message'); + } + + /** + * before save message + * + * @access protected + * @return Werules_Chatbot_Model_Message + + */ + protected function _beforeSave() + { + parent::_beforeSave(); + $now = Mage::getSingleton('core/date')->gmtDate(); + if ($this->isObjectNew()) { + $this->setCreatedAt($now); + } + $this->setUpdatedAt($now); + return $this; + } + + /** + * save message relation + * + * @access public + * @return Werules_Chatbot_Model_Message + + */ + protected function _afterSave() + { + return parent::_afterSave(); + } + + /** + * get default values + * + * @access public + * @return array + + */ + public function getDefaultValues() + { + $values = array(); + $values['status'] = 1; + return $values; + } + +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi.php new file mode 100644 index 0000000..783c1aa --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi.php @@ -0,0 +1,132 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Chatbotapi extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * constructor + * + * @access public + + */ + public function _construct() + { + $this->_init('werules_chatbot/chatbotapi', 'entity_id'); + } + + /** + * Get store ids to which specified item is assigned + * + * @access public + * @param int $chatbotapiId + * @return array + + */ + public function lookupStoreIds($chatbotapiId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('werules_chatbot/chatbotapi_store'), 'store_id') + ->where('chatbotapi_id = ?', (int)$chatbotapiId); + return $adapter->fetchCol($select); + } + + /** + * Perform operations after object load + * + * @access public + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Chatbotapi + + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + if ($object->getId()) { + $stores = $this->lookupStoreIds($object->getId()); + $object->setData('store_id', $stores); + } + return parent::_afterLoad($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Werules_Chatbot_Model_Chatbotapi $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($object->getStoreId()) { + $storeIds = array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId()); + $select->join( + array('chatbot_chatbotapi_store' => $this->getTable('werules_chatbot/chatbotapi_store')), + $this->getMainTable() . '.entity_id = chatbot_chatbotapi_store.chatbotapi_id', + array() + ) + ->where('chatbot_chatbotapi_store.store_id IN (?)', $storeIds) + ->order('chatbot_chatbotapi_store.store_id DESC') + ->limit(1); + } + return $select; + } + + /** + * Assign chatbotapi to store views + * + * @access protected + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Chatbotapi + + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $oldStores = $this->lookupStoreIds($object->getId()); + $newStores = (array)$object->getStores(); + if (empty($newStores)) { + $newStores = (array)$object->getStoreId(); + } + $table = $this->getTable('werules_chatbot/chatbotapi_store'); + $insert = array_diff($newStores, $oldStores); + $delete = array_diff($oldStores, $newStores); + if ($delete) { + $where = array( + 'chatbotapi_id = ?' => (int) $object->getId(), + 'store_id IN (?)' => $delete + ); + $this->_getWriteAdapter()->delete($table, $where); + } + if ($insert) { + $data = array(); + foreach ($insert as $storeId) { + $data[] = array( + 'chatbotapi_id' => (int) $object->getId(), + 'store_id' => (int) $storeId + ); + } + $this->_getWriteAdapter()->insertMultiple($table, $data); + } + return parent::_afterSave($object); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi/Collection.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi/Collection.php new file mode 100644 index 0000000..bde2618 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotapi/Collection.php @@ -0,0 +1,134 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Chatbotapi_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + protected $_joinedFields = array(); + + /** + * constructor + * + * @access public + * @return void + + */ + protected function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/chatbotapi'); + $this->_map['fields']['store'] = 'store_table.store_id'; + } + + /** + * Add filter by store + * + * @access public + * @param int|Mage_Core_Model_Store $store + * @param bool $withAdmin + * @return Werules_Chatbot_Model_Resource_Chatbotapi_Collection + + */ + public function addStoreFilter($store, $withAdmin = true) + { + if (!isset($this->_joinedFields['store'])) { + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } + if (!is_array($store)) { + $store = array($store); + } + if ($withAdmin) { + $store[] = Mage_Core_Model_App::ADMIN_STORE_ID; + } + $this->addFilter('store', array('in' => $store), 'public'); + $this->_joinedFields['store'] = true; + } + return $this; + } + + /** + * Join store relation table if there is store filter + * + * @access protected + * @return Werules_Chatbot_Model_Resource_Chatbotapi_Collection + + */ + protected function _renderFiltersBefore() + { + if ($this->getFilter('store')) { + $this->getSelect()->join( + array('store_table' => $this->getTable('werules_chatbot/chatbotapi_store')), + 'main_table.entity_id = store_table.chatbotapi_id', + array() + ) + ->group('main_table.entity_id'); + /* + * Allow analytic functions usage because of one field grouping + */ + $this->_useAnalyticFunction = true; + } + return parent::_renderFiltersBefore(); + } + + /** + * get chatbotapis as array + * + * @access protected + * @param string $valueField + * @param string $labelField + * @param array $additional + * @return array + + */ + protected function _toOptionArray($valueField='entity_id', $labelField='chatbotapi_id', $additional=array()) + { + return parent::_toOptionArray($valueField, $labelField, $additional); + } + + /** + * get options hash + * + * @access protected + * @param string $valueField + * @param string $labelField + * @return array + + */ + protected function _toOptionHash($valueField='entity_id', $labelField='chatbotapi_id') + { + return parent::_toOptionHash($valueField, $labelField); + } + + /** + * Get SQL for get record count. + * Extra GROUP BY strip added. + * + * @access public + * @return Varien_Db_Select + + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + $countSelect->reset(Zend_Db_Select::GROUP); + return $countSelect; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser.php new file mode 100644 index 0000000..dbf8b4b --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser.php @@ -0,0 +1,132 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Chatbotuser extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * constructor + * + * @access public + + */ + public function _construct() + { + $this->_init('werules_chatbot/chatbotuser', 'entity_id'); + } + + /** + * Get store ids to which specified item is assigned + * + * @access public + * @param int $chatbotuserId + * @return array + + */ + public function lookupStoreIds($chatbotuserId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('werules_chatbot/chatbotuser_store'), 'store_id') + ->where('chatbotuser_id = ?', (int)$chatbotuserId); + return $adapter->fetchCol($select); + } + + /** + * Perform operations after object load + * + * @access public + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Chatbotuser + + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + if ($object->getId()) { + $stores = $this->lookupStoreIds($object->getId()); + $object->setData('store_id', $stores); + } + return parent::_afterLoad($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Werules_Chatbot_Model_Chatbotuser $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($object->getStoreId()) { + $storeIds = array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId()); + $select->join( + array('chatbot_chatbotuser_store' => $this->getTable('werules_chatbot/chatbotuser_store')), + $this->getMainTable() . '.entity_id = chatbot_chatbotuser_store.chatbotuser_id', + array() + ) + ->where('chatbot_chatbotuser_store.store_id IN (?)', $storeIds) + ->order('chatbot_chatbotuser_store.store_id DESC') + ->limit(1); + } + return $select; + } + + /** + * Assign chatbotuser to store views + * + * @access protected + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Chatbotuser + + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $oldStores = $this->lookupStoreIds($object->getId()); + $newStores = (array)$object->getStores(); + if (empty($newStores)) { + $newStores = (array)$object->getStoreId(); + } + $table = $this->getTable('werules_chatbot/chatbotuser_store'); + $insert = array_diff($newStores, $oldStores); + $delete = array_diff($oldStores, $newStores); + if ($delete) { + $where = array( + 'chatbotuser_id = ?' => (int) $object->getId(), + 'store_id IN (?)' => $delete + ); + $this->_getWriteAdapter()->delete($table, $where); + } + if ($insert) { + $data = array(); + foreach ($insert as $storeId) { + $data[] = array( + 'chatbotuser_id' => (int) $object->getId(), + 'store_id' => (int) $storeId + ); + } + $this->_getWriteAdapter()->insertMultiple($table, $data); + } + return parent::_afterSave($object); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser/Collection.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser/Collection.php new file mode 100644 index 0000000..9c79a2c --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Chatbotuser/Collection.php @@ -0,0 +1,134 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Chatbotuser_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + protected $_joinedFields = array(); + + /** + * constructor + * + * @access public + * @return void + + */ + protected function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/chatbotuser'); + $this->_map['fields']['store'] = 'store_table.store_id'; + } + + /** + * Add filter by store + * + * @access public + * @param int|Mage_Core_Model_Store $store + * @param bool $withAdmin + * @return Werules_Chatbot_Model_Resource_Chatbotuser_Collection + + */ + public function addStoreFilter($store, $withAdmin = true) + { + if (!isset($this->_joinedFields['store'])) { + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } + if (!is_array($store)) { + $store = array($store); + } + if ($withAdmin) { + $store[] = Mage_Core_Model_App::ADMIN_STORE_ID; + } + $this->addFilter('store', array('in' => $store), 'public'); + $this->_joinedFields['store'] = true; + } + return $this; + } + + /** + * Join store relation table if there is store filter + * + * @access protected + * @return Werules_Chatbot_Model_Resource_Chatbotuser_Collection + + */ + protected function _renderFiltersBefore() + { + if ($this->getFilter('store')) { + $this->getSelect()->join( + array('store_table' => $this->getTable('werules_chatbot/chatbotuser_store')), + 'main_table.entity_id = store_table.chatbotuser_id', + array() + ) + ->group('main_table.entity_id'); + /* + * Allow analytic functions usage because of one field grouping + */ + $this->_useAnalyticFunction = true; + } + return parent::_renderFiltersBefore(); + } + + /** + * get chatbotusers as array + * + * @access protected + * @param string $valueField + * @param string $labelField + * @param array $additional + * @return array + + */ + protected function _toOptionArray($valueField='entity_id', $labelField='chatbotuser_id', $additional=array()) + { + return parent::_toOptionArray($valueField, $labelField, $additional); + } + + /** + * get options hash + * + * @access protected + * @param string $valueField + * @param string $labelField + * @return array + + */ + protected function _toOptionHash($valueField='entity_id', $labelField='chatbotuser_id') + { + return parent::_toOptionHash($valueField, $labelField); + } + + /** + * Get SQL for get record count. + * Extra GROUP BY strip added. + * + * @access public + * @return Varien_Db_Select + + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + $countSelect->reset(Zend_Db_Select::GROUP); + return $countSelect; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message.php new file mode 100644 index 0000000..a295cad --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message.php @@ -0,0 +1,132 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Message extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * constructor + * + * @access public + + */ + public function _construct() + { + $this->_init('werules_chatbot/message', 'entity_id'); + } + + /** + * Get store ids to which specified item is assigned + * + * @access public + * @param int $messageId + * @return array + + */ + public function lookupStoreIds($messageId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('werules_chatbot/message_store'), 'store_id') + ->where('message_id = ?', (int)$messageId); + return $adapter->fetchCol($select); + } + + /** + * Perform operations after object load + * + * @access public + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Message + + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + if ($object->getId()) { + $stores = $this->lookupStoreIds($object->getId()); + $object->setData('store_id', $stores); + } + return parent::_afterLoad($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Werules_Chatbot_Model_Message $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($object->getStoreId()) { + $storeIds = array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId()); + $select->join( + array('chatbot_message_store' => $this->getTable('werules_chatbot/message_store')), + $this->getMainTable() . '.entity_id = chatbot_message_store.message_id', + array() + ) + ->where('chatbot_message_store.store_id IN (?)', $storeIds) + ->order('chatbot_message_store.store_id DESC') + ->limit(1); + } + return $select; + } + + /** + * Assign message to store views + * + * @access protected + * @param Mage_Core_Model_Abstract $object + * @return Werules_Chatbot_Model_Resource_Message + + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $oldStores = $this->lookupStoreIds($object->getId()); + $newStores = (array)$object->getStores(); + if (empty($newStores)) { + $newStores = (array)$object->getStoreId(); + } + $table = $this->getTable('werules_chatbot/message_store'); + $insert = array_diff($newStores, $oldStores); + $delete = array_diff($oldStores, $newStores); + if ($delete) { + $where = array( + 'message_id = ?' => (int) $object->getId(), + 'store_id IN (?)' => $delete + ); + $this->_getWriteAdapter()->delete($table, $where); + } + if ($insert) { + $data = array(); + foreach ($insert as $storeId) { + $data[] = array( + 'message_id' => (int) $object->getId(), + 'store_id' => (int) $storeId + ); + } + $this->_getWriteAdapter()->insertMultiple($table, $data); + } + return parent::_afterSave($object); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message/Collection.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message/Collection.php new file mode 100644 index 0000000..031c5fe --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Message/Collection.php @@ -0,0 +1,134 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Message_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + protected $_joinedFields = array(); + + /** + * constructor + * + * @access public + * @return void + + */ + protected function _construct() + { + parent::_construct(); + $this->_init('werules_chatbot/message'); + $this->_map['fields']['store'] = 'store_table.store_id'; + } + + /** + * Add filter by store + * + * @access public + * @param int|Mage_Core_Model_Store $store + * @param bool $withAdmin + * @return Werules_Chatbot_Model_Resource_Message_Collection + + */ + public function addStoreFilter($store, $withAdmin = true) + { + if (!isset($this->_joinedFields['store'])) { + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } + if (!is_array($store)) { + $store = array($store); + } + if ($withAdmin) { + $store[] = Mage_Core_Model_App::ADMIN_STORE_ID; + } + $this->addFilter('store', array('in' => $store), 'public'); + $this->_joinedFields['store'] = true; + } + return $this; + } + + /** + * Join store relation table if there is store filter + * + * @access protected + * @return Werules_Chatbot_Model_Resource_Message_Collection + + */ + protected function _renderFiltersBefore() + { + if ($this->getFilter('store')) { + $this->getSelect()->join( + array('store_table' => $this->getTable('werules_chatbot/message_store')), + 'main_table.entity_id = store_table.message_id', + array() + ) + ->group('main_table.entity_id'); + /* + * Allow analytic functions usage because of one field grouping + */ + $this->_useAnalyticFunction = true; + } + return parent::_renderFiltersBefore(); + } + + /** + * get messages as array + * + * @access protected + * @param string $valueField + * @param string $labelField + * @param array $additional + * @return array + + */ + protected function _toOptionArray($valueField='entity_id', $labelField='message_id', $additional=array()) + { + return parent::_toOptionArray($valueField, $labelField, $additional); + } + + /** + * get options hash + * + * @access protected + * @param string $valueField + * @param string $labelField + * @return array + + */ + protected function _toOptionHash($valueField='entity_id', $labelField='message_id') + { + return parent::_toOptionHash($valueField, $labelField); + } + + /** + * Get SQL for get record count. + * Extra GROUP BY strip added. + * + * @access public + * @return Varien_Db_Select + + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + $countSelect->reset(Zend_Db_Select::GROUP); + return $countSelect; + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Setup.php b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Setup.php new file mode 100644 index 0000000..2cd6495 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Resource/Setup.php @@ -0,0 +1,24 @@ +. + */ + +class Werules_Chatbot_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup +{ +} diff --git a/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotapiController.php b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotapiController.php new file mode 100644 index 0000000..099f396 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotapiController.php @@ -0,0 +1,400 @@ +. + */ + +class Werules_Chatbot_Adminhtml_Chatbot_ChatbotapiController extends Werules_Chatbot_Controller_Adminhtml_Chatbot +{ + /** + * init the chatbotapi + * + * @access protected + * @return Werules_Chatbot_Model_Chatbotapi + */ + protected function _initChatbotapi() + { + $chatbotapiId = (int) $this->getRequest()->getParam('id'); + $chatbotapi = Mage::getModel('werules_chatbot/chatbotapi'); + if ($chatbotapiId) { + $chatbotapi->load($chatbotapiId); + } + Mage::register('current_chatbotapi', $chatbotapi); + return $chatbotapi; + } + + /** + * default action + * + * @access public + * @return void + + */ + public function indexAction() + { + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('ChatbotAPIs')); + $this->renderLayout(); + } + + /** + * grid action + * + * @access public + * @return void + + */ + public function gridAction() + { + $this->loadLayout()->renderLayout(); + } + + /** + * edit chatbotapi - action + * + * @access public + * @return void + + */ + public function editAction() + { + $chatbotapiId = $this->getRequest()->getParam('id'); + $chatbotapi = $this->_initChatbotapi(); + if ($chatbotapiId && !$chatbotapi->getId()) { + $this->_getSession()->addError( + Mage::helper('werules_chatbot')->__('This chatbotapi no longer exists.') + ); + $this->_redirect('*/*/'); + return; + } + $data = Mage::getSingleton('adminhtml/session')->getChatbotapiData(true); + if (!empty($data)) { + $chatbotapi->setData($data); + } + Mage::register('chatbotapi_data', $chatbotapi); + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('ChatbotAPIs')); + if ($chatbotapi->getId()) { + $this->_title($chatbotapi->getChatbotapiId()); + } else { + $this->_title(Mage::helper('werules_chatbot')->__('Add chatbotapi')); + } + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + $this->renderLayout(); + } + + /** + * new chatbotapi action + * + * @access public + * @return void + + */ + public function newAction() + { + $this->_forward('edit'); + } + + /** + * save chatbotapi - action + * + * @access public + * @return void + + */ + public function saveAction() + { + if ($data = $this->getRequest()->getPost('chatbotapi')) { + try { + $chatbotapi = $this->_initChatbotapi(); + $chatbotapi->addData($data); + $chatbotapi->save(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('ChatbotAPI was successfully saved') + ); + Mage::getSingleton('adminhtml/session')->setFormData(false); + if ($this->getRequest()->getParam('back')) { + $this->_redirect('*/*/edit', array('id' => $chatbotapi->getId())); + return; + } + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + Mage::getSingleton('adminhtml/session')->setChatbotapiData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } catch (Exception $e) { + Mage::logException($e); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was a problem saving the chatbotapi.') + ); + Mage::getSingleton('adminhtml/session')->setChatbotapiData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Unable to find chatbotapi to save.') + ); + $this->_redirect('*/*/'); + } + + /** + * delete chatbotapi - action + * + * @access public + * @return void + + */ + public function deleteAction() + { + if ( $this->getRequest()->getParam('id') > 0) { + try { + $chatbotapi = Mage::getModel('werules_chatbot/chatbotapi'); + $chatbotapi->setId($this->getRequest()->getParam('id'))->delete(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('ChatbotAPI was successfully deleted.') + ); + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting chatbotapi.') + ); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + Mage::logException($e); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Could not find chatbotapi to delete.') + ); + $this->_redirect('*/*/'); + } + + /** + * mass delete chatbotapi - action + * + * @access public + * @return void + + */ + public function massDeleteAction() + { + $chatbotapiIds = $this->getRequest()->getParam('chatbotapi'); + if (!is_array($chatbotapiIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotapis to delete.') + ); + } else { + try { + foreach ($chatbotapiIds as $chatbotapiId) { + $chatbotapi = Mage::getModel('werules_chatbot/chatbotapi'); + $chatbotapi->setId($chatbotapiId)->delete(); + } + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('Total of %d chatbotapis were successfully deleted.', count($chatbotapiIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting chatbotapis.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass status change - action + * + * @access public + * @return void + + */ + public function massStatusAction() + { + $chatbotapiIds = $this->getRequest()->getParam('chatbotapi'); + if (!is_array($chatbotapiIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotapis.') + ); + } else { + try { + foreach ($chatbotapiIds as $chatbotapiId) { + $chatbotapi = Mage::getSingleton('werules_chatbot/chatbotapi')->load($chatbotapiId) + ->setStatus($this->getRequest()->getParam('status')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotapis were successfully updated.', count($chatbotapiIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotapis.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass Logged? change - action + * + * @access public + * @return void + + */ + public function massLoggedAction() + { + $chatbotapiIds = $this->getRequest()->getParam('chatbotapi'); + if (!is_array($chatbotapiIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotapis.') + ); + } else { + try { + foreach ($chatbotapiIds as $chatbotapiId) { + $chatbotapi = Mage::getSingleton('werules_chatbot/chatbotapi')->load($chatbotapiId) + ->setLogged($this->getRequest()->getParam('flag_logged')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotapis were successfully updated.', count($chatbotapiIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotapis.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass Enabled? change - action + * + * @access public + * @return void + + */ + public function massEnabledAction() + { + $chatbotapiIds = $this->getRequest()->getParam('chatbotapi'); + if (!is_array($chatbotapiIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotapis.') + ); + } else { + try { + foreach ($chatbotapiIds as $chatbotapiId) { + $chatbotapi = Mage::getSingleton('werules_chatbot/chatbotapi')->load($chatbotapiId) + ->setEnabled($this->getRequest()->getParam('flag_enabled')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotapis were successfully updated.', count($chatbotapiIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotapis.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * export as csv - action + * + * @access public + * @return void + + */ + public function exportCsvAction() + { + $fileName = 'chatbotapi.csv'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotapi_grid') + ->getCsv(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as MsExcel - action + * + * @access public + * @return void + + */ + public function exportExcelAction() + { + $fileName = 'chatbotapi.xls'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotapi_grid') + ->getExcelFile(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as xml - action + * + * @access public + * @return void + + */ + public function exportXmlAction() + { + $fileName = 'chatbotapi.xml'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotapi_grid') + ->getXml(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * Check if admin has permissions to visit related pages + * + * @access protected + * @return boolean + + */ + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('system/config/werules_chatbot/chatbotapi'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotuserController.php b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotuserController.php new file mode 100644 index 0000000..4d6ba7d --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/ChatbotuserController.php @@ -0,0 +1,437 @@ +. + */ + +class Werules_Chatbot_Adminhtml_Chatbot_ChatbotuserController extends Werules_Chatbot_Controller_Adminhtml_Chatbot +{ + /** + * init the chatbotuser + * + * @access protected + * @return Werules_Chatbot_Model_Chatbotuser + */ + protected function _initChatbotuser() + { + $chatbotuserId = (int) $this->getRequest()->getParam('id'); + $chatbotuser = Mage::getModel('werules_chatbot/chatbotuser'); + if ($chatbotuserId) { + $chatbotuser->load($chatbotuserId); + } + Mage::register('current_chatbotuser', $chatbotuser); + return $chatbotuser; + } + + /** + * default action + * + * @access public + * @return void + + */ + public function indexAction() + { + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('ChatbotUsers')); + $this->renderLayout(); + } + + /** + * grid action + * + * @access public + * @return void + + */ + public function gridAction() + { + $this->loadLayout()->renderLayout(); + } + + /** + * edit chatbotuser - action + * + * @access public + * @return void + + */ + public function editAction() + { + $chatbotuserId = $this->getRequest()->getParam('id'); + $chatbotuser = $this->_initChatbotuser(); + if ($chatbotuserId && !$chatbotuser->getId()) { + $this->_getSession()->addError( + Mage::helper('werules_chatbot')->__('This chatbotuser no longer exists.') + ); + $this->_redirect('*/*/'); + return; + } + $data = Mage::getSingleton('adminhtml/session')->getChatbotuserData(true); + if (!empty($data)) { + $chatbotuser->setData($data); + } + Mage::register('chatbotuser_data', $chatbotuser); + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('ChatbotUsers')); + if ($chatbotuser->getId()) { + $this->_title($chatbotuser->getChatbotuserId()); + } else { + $this->_title(Mage::helper('werules_chatbot')->__('Add chatbotuser')); + } + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + $this->renderLayout(); + } + + /** + * new chatbotuser action + * + * @access public + * @return void + + */ + public function newAction() + { + $this->_forward('edit'); + } + + /** + * save chatbotuser - action + * + * @access public + * @return void + + */ + public function saveAction() + { + if ($data = $this->getRequest()->getPost('chatbotuser')) { + try { + $chatbotuser = $this->_initChatbotuser(); + $chatbotuser->addData($data); + $chatbotuser->save(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('ChatbotUser was successfully saved') + ); + Mage::getSingleton('adminhtml/session')->setFormData(false); + if ($this->getRequest()->getParam('back')) { + $this->_redirect('*/*/edit', array('id' => $chatbotuser->getId())); + return; + } + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + Mage::getSingleton('adminhtml/session')->setChatbotuserData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } catch (Exception $e) { + Mage::logException($e); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was a problem saving the chatbotuser.') + ); + Mage::getSingleton('adminhtml/session')->setChatbotuserData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Unable to find chatbotuser to save.') + ); + $this->_redirect('*/*/'); + } + + /** + * delete chatbotuser - action + * + * @access public + * @return void + + */ + public function deleteAction() + { + if ( $this->getRequest()->getParam('id') > 0) { + try { + $chatbotuser = Mage::getModel('werules_chatbot/chatbotuser'); + $chatbotuser->setId($this->getRequest()->getParam('id'))->delete(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('ChatbotUser was successfully deleted.') + ); + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting chatbotuser.') + ); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + Mage::logException($e); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Could not find chatbotuser to delete.') + ); + $this->_redirect('*/*/'); + } + + /** + * mass delete chatbotuser - action + * + * @access public + * @return void + + */ + public function massDeleteAction() + { + $chatbotuserIds = $this->getRequest()->getParam('chatbotuser'); + if (!is_array($chatbotuserIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotusers to delete.') + ); + } else { + try { + foreach ($chatbotuserIds as $chatbotuserId) { + $chatbotuser = Mage::getModel('werules_chatbot/chatbotuser'); + $chatbotuser->setId($chatbotuserId)->delete(); + } + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('Total of %d chatbotusers were successfully deleted.', count($chatbotuserIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting chatbotusers.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass status change - action + * + * @access public + * @return void + + */ + public function massStatusAction() + { + $chatbotuserIds = $this->getRequest()->getParam('chatbotuser'); + if (!is_array($chatbotuserIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotusers.') + ); + } else { + try { + foreach ($chatbotuserIds as $chatbotuserId) { + $chatbotuser = Mage::getSingleton('werules_chatbot/chatbotuser')->load($chatbotuserId) + ->setStatus($this->getRequest()->getParam('status')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotusers were successfully updated.', count($chatbotuserIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotusers.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass Enable Promotional Messages change - action + * + * @access public + * @return void + + */ + public function massEnablePromotionalMessagesAction() + { + $chatbotuserIds = $this->getRequest()->getParam('chatbotuser'); + if (!is_array($chatbotuserIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotusers.') + ); + } else { + try { + foreach ($chatbotuserIds as $chatbotuserId) { + $chatbotuser = Mage::getSingleton('werules_chatbot/chatbotuser')->load($chatbotuserId) + ->setEnablePromotionalMessages($this->getRequest()->getParam('flag_enable_promotional_messages')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotusers were successfully updated.', count($chatbotuserIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotusers.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass Enable Support change - action + * + * @access public + * @return void + + */ + public function massEnableSupportAction() + { + $chatbotuserIds = $this->getRequest()->getParam('chatbotuser'); + if (!is_array($chatbotuserIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotusers.') + ); + } else { + try { + foreach ($chatbotuserIds as $chatbotuserId) { + $chatbotuser = Mage::getSingleton('werules_chatbot/chatbotuser')->load($chatbotuserId) + ->setEnableSupport($this->getRequest()->getParam('flag_enable_support')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotusers were successfully updated.', count($chatbotuserIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotusers.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass Is Admin? change - action + * + * @access public + * @return void + + */ + public function massAdminAction() + { + $chatbotuserIds = $this->getRequest()->getParam('chatbotuser'); + if (!is_array($chatbotuserIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select chatbotusers.') + ); + } else { + try { + foreach ($chatbotuserIds as $chatbotuserId) { + $chatbotuser = Mage::getSingleton('werules_chatbot/chatbotuser')->load($chatbotuserId) + ->setAdmin($this->getRequest()->getParam('flag_admin')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d chatbotusers were successfully updated.', count($chatbotuserIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating chatbotusers.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * export as csv - action + * + * @access public + * @return void + + */ + public function exportCsvAction() + { + $fileName = 'chatbotuser.csv'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotuser_grid') + ->getCsv(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as MsExcel - action + * + * @access public + * @return void + + */ + public function exportExcelAction() + { + $fileName = 'chatbotuser.xls'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotuser_grid') + ->getExcelFile(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as xml - action + * + * @access public + * @return void + + */ + public function exportXmlAction() + { + $fileName = 'chatbotuser.xml'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_chatbotuser_grid') + ->getXml(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * Check if admin has permissions to visit related pages + * + * @access protected + * @return boolean + + */ + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('system/config/werules_chatbot/chatbotuser'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/MessageController.php b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/MessageController.php new file mode 100644 index 0000000..31d0beb --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/controllers/Adminhtml/Chatbot/MessageController.php @@ -0,0 +1,326 @@ +. + */ + +class Werules_Chatbot_Adminhtml_Chatbot_MessageController extends Werules_Chatbot_Controller_Adminhtml_Chatbot +{ + /** + * init the message + * + * @access protected + * @return Werules_Chatbot_Model_Message + */ + protected function _initMessage() + { + $messageId = (int) $this->getRequest()->getParam('id'); + $message = Mage::getModel('werules_chatbot/message'); + if ($messageId) { + $message->load($messageId); + } + Mage::register('current_message', $message); + return $message; + } + + /** + * default action + * + * @access public + * @return void + */ + public function indexAction() + { + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('Messages')); + $this->renderLayout(); + } + + /** + * grid action + * + * @access public + * @return void + + */ + public function gridAction() + { + $this->loadLayout()->renderLayout(); + } + + /** + * edit message - action + * + * @access public + * @return void + + */ + public function editAction() + { + $messageId = $this->getRequest()->getParam('id'); + $message = $this->_initMessage(); + if ($messageId && !$message->getId()) { + $this->_getSession()->addError( + Mage::helper('werules_chatbot')->__('This message no longer exists.') + ); + $this->_redirect('*/*/'); + return; + } + $data = Mage::getSingleton('adminhtml/session')->getMessageData(true); + if (!empty($data)) { + $message->setData($data); + } + Mage::register('message_data', $message); + $this->loadLayout(); + $this->_title(Mage::helper('werules_chatbot')->__('Chatbot Settings')) + ->_title(Mage::helper('werules_chatbot')->__('Messages')); + if ($message->getId()) { + $this->_title($message->getMessageId()); + } else { + $this->_title(Mage::helper('werules_chatbot')->__('Add message')); + } + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } + $this->renderLayout(); + } + + /** + * new message action + * + * @access public + * @return void + + */ + public function newAction() + { + $this->_forward('edit'); + } + + /** + * save message - action + * + * @access public + * @return void + + */ + public function saveAction() + { + if ($data = $this->getRequest()->getPost('message')) { + try { + $data = $this->_filterDates($data, array('sent_at')); + $message = $this->_initMessage(); + $message->addData($data); + $message->save(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('Message was successfully saved') + ); + Mage::getSingleton('adminhtml/session')->setFormData(false); + if ($this->getRequest()->getParam('back')) { + $this->_redirect('*/*/edit', array('id' => $message->getId())); + return; + } + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + Mage::getSingleton('adminhtml/session')->setMessageData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } catch (Exception $e) { + Mage::logException($e); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was a problem saving the message.') + ); + Mage::getSingleton('adminhtml/session')->setMessageData($data); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Unable to find message to save.') + ); + $this->_redirect('*/*/'); + } + + /** + * delete message - action + * + * @access public + * @return void + + */ + public function deleteAction() + { + if ( $this->getRequest()->getParam('id') > 0) { + try { + $message = Mage::getModel('werules_chatbot/message'); + $message->setId($this->getRequest()->getParam('id'))->delete(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('Message was successfully deleted.') + ); + $this->_redirect('*/*/'); + return; + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting message.') + ); + $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); + Mage::logException($e); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Could not find message to delete.') + ); + $this->_redirect('*/*/'); + } + + /** + * mass delete message - action + * + * @access public + * @return void + + */ + public function massDeleteAction() + { + $messageIds = $this->getRequest()->getParam('message'); + if (!is_array($messageIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select messages to delete.') + ); + } else { + try { + foreach ($messageIds as $messageId) { + $message = Mage::getModel('werules_chatbot/message'); + $message->setId($messageId)->delete(); + } + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('werules_chatbot')->__('Total of %d messages were successfully deleted.', count($messageIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error deleting messages.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * mass status change - action + * + * @access public + * @return void + + */ + public function massStatusAction() + { + $messageIds = $this->getRequest()->getParam('message'); + if (!is_array($messageIds)) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('Please select messages.') + ); + } else { + try { + foreach ($messageIds as $messageId) { + $message = Mage::getSingleton('werules_chatbot/message')->load($messageId) + ->setStatus($this->getRequest()->getParam('status')) + ->setIsMassupdate(true) + ->save(); + } + $this->_getSession()->addSuccess( + $this->__('Total of %d messages were successfully updated.', count($messageIds)) + ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('werules_chatbot')->__('There was an error updating messages.') + ); + Mage::logException($e); + } + } + $this->_redirect('*/*/index'); + } + + /** + * export as csv - action + * + * @access public + * @return void + + */ + public function exportCsvAction() + { + $fileName = 'message.csv'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_message_grid') + ->getCsv(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as MsExcel - action + * + * @access public + * @return void + + */ + public function exportExcelAction() + { + $fileName = 'message.xls'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_message_grid') + ->getExcelFile(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * export as xml - action + * + * @access public + * @return void + + */ + public function exportXmlAction() + { + $fileName = 'message.xml'; + $content = $this->getLayout()->createBlock('werules_chatbot/adminhtml_message_grid') + ->getXml(); + $this->_prepareDownloadResponse($fileName, $content); + } + + /** + * Check if admin has permissions to visit related pages + * + * @access protected + * @return boolean + + */ + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('system/config/werules_chatbot/message'); + } +} diff --git a/Magento1/app/code/community/Werules/Chatbot/controllers/CustomerController.php b/Magento1/app/code/community/Werules/Chatbot/controllers/CustomerController.php new file mode 100644 index 0000000..099c4cd --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/controllers/CustomerController.php @@ -0,0 +1,42 @@ +. + */ + +class Werules_Chatbot_CustomerController extends Mage_Core_Controller_Front_Action{ + public function IndexAction() { + + $this->loadLayout(); + $this->getLayout()->getBlock("head")->setTitle($this->__("Titlename")); + $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs"); + $breadcrumbs->addCrumb("home", array( + "label" => $this->__("Home Page"), + "title" => $this->__("Home Page"), + "link" => Mage::getBaseUrl() + )); + + $breadcrumbs->addCrumb("titlename", array( + "label" => $this->__("Titlename"), + "title" => $this->__("Titlename") + )); + + $this->renderLayout(); + + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/controllers/WebhookController.php b/Magento1/app/code/community/Werules/Chatbot/controllers/WebhookController.php new file mode 100644 index 0000000..caf4cd9 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/controllers/WebhookController.php @@ -0,0 +1,66 @@ +. + */ + +class Werules_Chatbot_WebhookController extends Mage_Core_Controller_Front_Action{ +// public function IndexAction() { +// +// $this->loadLayout(); +// $this->getLayout()->getBlock("head")->setTitle($this->__("Titlename")); +// $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs"); +// $breadcrumbs->addCrumb("home", array( +// "label" => $this->__("Home Page"), +// "title" => $this->__("Home Page"), +// "link" => Mage::getBaseUrl() +// )); +// +// $breadcrumbs->addCrumb("titlename", array( +// "label" => $this->__("Titlename"), +// "title" => $this->__("Titlename") +// )); +// +// $this->renderLayout(); +// +// } + public function IndexAction() + { + $this->loadLayout(); + $this->getLayout()->getBlock('root')->setTemplate("chatbot/index.phtml"); // use root block to output pure values without html tags + $this->renderLayout(); + } + + public function MessengerAction() + { + $this->loadLayout(); + $this->getLayout()->getBlock('root')->setTemplate("chatbot/messenger.phtml"); // use root block to output pure values without html tags + $this->renderLayout(); + } + + public function TelegramAction() + { + $this->loadLayout(); + $this->getLayout()->getBlock('root')->setTemplate("chatbot/telegram.phtml"); // use root block to output pure values without html tags + //$this->getLayout()->getBlock('root')->setTemplate("werules_chatbot_view.phtml")->setTitle(Mage::helper('core')->__('Chatbot')); // use root block to output pure values without html tags + //$this->getLayout()->getBlock('head')->setTitle(Mage::helper('core')->__('Chatbot')); + //$this->getLayout()->getBlock('head')->setTitle($this->__('My Title')); // then this works + //$this->getLayout()->unsetBlock('head'); + $this->renderLayout(); + } +} \ No newline at end of file diff --git a/Magento1/app/code/community/Werules/Chatbot/etc/adminhtml.xml b/Magento1/app/code/community/Werules/Chatbot/etc/adminhtml.xml new file mode 100644 index 0000000..acef8d6 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/etc/adminhtml.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + Chatbot + + + General Settings + + + Messenger Settings + + + Danger Zone + + + + + + + + + + + Chatbot Settings + + + Message + 0 + + + ChatbotUser + 10 + + + ChatbotAPI + 20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Magento1/app/code/community/Werules/Chatbot/etc/config.xml b/Magento1/app/code/community/Werules/Chatbot/etc/config.xml new file mode 100644 index 0000000..4750211 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/etc/config.xml @@ -0,0 +1,140 @@ + + + + + 1.0.0 + + + + + + + + Werules_Chatbot.csv + + + + + + + + chatbot_customer_index.xml + + + + + chatbot_webhook_index.xml + + + + + chatbot_webhook_messenger.xml + + + + + chatbot_webhook_telegram.xml + + + + + + standard + + Werules_Chatbot + chatbot + + + + + + + + + Werules_Chatbot + Werules_Chatbot_Model_Resource_Setup + + + + + + Werules_Chatbot_Block + + + + + Werules_Chatbot_Helper + + + + + Werules_Chatbot_Model + werules_chatbot_resource + + + Werules_Chatbot_Model_Resource + + + werules_chatbot_message
+
+ + werules_chatbot_chatbotuser
+
+ + werules_chatbot_chatbotapi
+
+ + werules_chatbot_message_store
+
+ + werules_chatbot_chatbotuser_store
+
+ + werules_chatbot_chatbotapi_store
+
+
+
+
+
+ + + + + */1 * * * * + + + chatbot/cron::execute + + + + + + + + + werules_chatbot.xml + + + + + + + + Werules_Chatbot.csv + + + + + + + + + + + Werules_Chatbot_Adminhtml + + + + + +
diff --git a/Magento1/app/code/community/Werules/Chatbot/etc/system.xml b/Magento1/app/code/community/Werules/Chatbot/etc/system.xml new file mode 100644 index 0000000..d7a3468 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/etc/system.xml @@ -0,0 +1,394 @@ + + + + + + 50 + + + + + + werules_chatbot + text + 0 + 1 + 1 + 1 + + + + Magento Chatbot v1.0.0 +

To use this module you'll have to use SSL in your store.

+
+ ]]>
+ text + 0 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_enabledisable + 0 + 1 + 1 + 1 + Enable module. + + + + text + 1 + 1 + 1 + 1 + validate-alphanum + Generate +

This is your secret key used for the webhook URL and Facebook Verification Hub. Click here to get instructions on how to configure your endpoint for Messenger or here to configure it for Telegram.

+ ]]>
+
+ + + select + adminhtml/system_config_source_yesno + 2 + 1 + 1 + 1 + Enable listing of categories with no products or unallowed products (this module supports only simple products for now). + + + + + + + select + adminhtml/system_config_source_yesno + 4 + 1 + 1 + 1 + Log will be at root/var/log/. + + + + select + adminhtml/system_config_source_yesno + 5 + 1 + 1 + 1 + Enable wit.ai Natural Language Processor. + + + + 1 + + + text + 6 + 1 + 1 + 1 + wit.ai Server Access Token. + +
+
+
+
+ + + werules_chatbot + text + 1 + 1 + 1 + 1 + + + + Magento Chatbot v1.0.0 +

To use this module you'll have to use SSL in your store.

+
+ ]]>
+ text + 1 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_enabledisable + 0 + 1 + 1 + 1 + Enable Messenger bot. + + + + select + adminhtml/system_config_source_enabledisable + 1 + 1 + 1 + 1 + Enable Hub Challenge verification. + + + + 0 + + + text + 2 + 1 + 1 + 1 + Message to send when bot is disabled. Leave it empty to send no message. Please check the maximum size for messages on Messenger API, otherwise your message might not be sent. + + + + text + 3 + 1 + 1 + 1 + Your Facebook Application ID. + + + + text + 4 + 1 + 1 + 1 + Your page access token. + + + + text + 5 + 1 + 1 + 1 + Facebook page username. If you don't know, leave it blank. + + + + text + 6 + 1 + 1 + 1 + Facebook Page ID. If you don't know, leave it blank and we fill it for you. + + + + select + adminhtml/system_config_source_yesno + 7 + 1 + 1 + 1 + Is this domain whitelisted on Facebook? If not, don't worry, we'll whitelist it for you and update this setting. + + + + select + adminhtml/system_config_source_yesno + 8 + 1 + 1 + 1 + Enable Messenger chat box. + + + + + + text + 11 + 1 + 1 + 1 + First message the bot will send to your client. please check the maximum size for messages on Facebook API, otherwise your message might not be sent. you can use "{customername}" to send the customer name. + + + + select + adminhtml/system_config_source_yesno + 12 + 1 + 1 + 1 + Enable welcome message options. + + + + + + + + + + text + 14 + 1 + 1 + 1 + Message will be sent when customer asks informations about the store. Please check the maximum size for messages on Facebook API, otherwise your message might not be sent. + + + + text + 15 + 1 + 1 + 1 + Message will be sent when customer asks for help. Please check the maximum size for messages on Facebook API, otherwise your message might not be sent. + + + + select + adminhtml/system_config_source_yesno + 16 + 1 + 1 + 1 + Enable command listing when customer ask for help. + + + + + + + select + adminhtml/system_config_source_yesno + 18 + 1 + 1 + 1 + Enable default replies. + + + + + + + + + + select + adminhtml/system_config_source_yesno + 20 + 1 + 1 + 1 + Enable Natural Language Processor replies. + + + + + 1 + + text + 21 + 1 + 1 + 1 + validate-no-html-tags + Natural Language Processor entity prefix is a prefix name to flag that the request is coming from Messenger. + + + + + + + + + + text + 23 + 1 + 1 + 1 + Message will be sent when the bot don't understand customer messages for the Nst time. + + + + text + 24 + 1 + 1 + 1 + input-number validate-number + Number of fallbacks before sending the fallback message. + + +
+
+
+ + + werules_chatbot + text + 2 + 1 + 1 + 1 + + + + Magento Chatbot v1.0.0 +

To use this module you'll have to use SSL in your store.

+

You should only change settings here if you know what you're doing.

+ +
+ ]]>
+ text + 2 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_enabledisable + 0 + 1 + 1 + 1 + Clear message pending list. After changing this value and saving, a process to clear message pending list will be schedule for the next minute. + + + + 1 + + + text + 1 + 1 + 1 + 1 + If you like, you can specify a Sender Chat ID to filter the message clearing process. + + +
+
+
+
+
diff --git a/Magento1/app/code/community/Werules/Chatbot/sql/werules_chatbot_setup/install-1.0.0.php b/Magento1/app/code/community/Werules/Chatbot/sql/werules_chatbot_setup/install-1.0.0.php new file mode 100644 index 0000000..3161e14 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/sql/werules_chatbot_setup/install-1.0.0.php @@ -0,0 +1,510 @@ +. + */ + +$this->startSetup(); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/message')) + ->addColumn( + 'entity_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), + 'Message ID' + ) + ->addColumn( + 'sender_id', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Sender ID' + ) + ->addColumn( + 'content', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Content' + ) + ->addColumn( + 'status', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Status' + ) + ->addColumn( + 'direction', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Direction' + ) + ->addColumn( + 'chat_message_id', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Chat Message ID' + ) + ->addColumn( + 'chatbot_type', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Chatbot Type' + ) + ->addColumn( + 'content_type', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Content Type' + ) + ->addColumn( + 'message_payload', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Message Payload' + ) + ->addColumn( + 'sent_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, 255, + array( + 'nullable' => false, + ), + 'Sent At' + ) + ->addColumn( + 'current_command_details', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Current Command Details' + ) + ->addColumn( + 'message_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Message ID' + ) + ->addColumn( + 'status', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array(), + 'Enabled' + ) + ->addColumn( + 'updated_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'Message Modification Time' + ) + ->addColumn( + 'created_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'Message Creation Time' + ) + ->setComment('Message Table'); +$this->getConnection()->createTable($table); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/chatbotuser')) + ->addColumn( + 'entity_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ChatbotUser ID' + ) + ->addColumn( + 'chatbotuser_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'ChatbotUser ID' + ) + ->addColumn( + 'session_id', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Session ID' + ) + ->addColumn( + 'enable_promotional_messages', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array( + 'nullable' => false, + ), + 'Enable Promotional Messages' + ) + ->addColumn( + 'enable_support', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array( + 'nullable' => false, + ), + 'Enable Support' + ) + ->addColumn( + 'admin', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array( + 'nullable' => false, + ), + 'Is Admin?' + ) + ->addColumn( + 'status', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array(), + 'Enabled' + ) + ->addColumn( + 'updated_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'ChatbotUser Modification Time' + ) + ->addColumn( + 'created_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'ChatbotUser Creation Time' + ) + ->setComment('ChatbotUser Table'); +$this->getConnection()->createTable($table); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/chatbotapi')) + ->addColumn( + 'entity_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ChatbotAPI ID' + ) + ->addColumn( + 'chatbotapi_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'ChatbotAPI ID' + ) + ->addColumn( + 'hash_key', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Hash Key' + ) + ->addColumn( + 'logged', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array( + 'nullable' => false, + ), + 'Logged?' + ) + ->addColumn( + 'enabled', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array( + 'nullable' => false, + ), + 'Enabled?' + ) + ->addColumn( + 'chatbot_type', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Chatbot Type' + ) + ->addColumn( + 'chat_id', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Chat ID' + ) + ->addColumn( + 'conversation_state', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Conversation State' + ) + ->addColumn( + 'fallback_qty', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Fallback Quantity' + ) + ->addColumn( + 'chatbotuser_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, null, + array( + 'nullable' => false, + ), + 'Chatbotuser ID' + ) + ->addColumn( + 'last_command_details', + Varien_Db_Ddl_Table::TYPE_TEXT, 255, + array( + 'nullable' => false, + ), + 'Last Command Details' + ) + ->addColumn( + 'status', + Varien_Db_Ddl_Table::TYPE_SMALLINT, null, + array(), + 'Enabled' + ) + ->addColumn( + 'updated_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'ChatbotAPI Modification Time' + ) + ->addColumn( + 'created_at', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + null, + array(), + 'ChatbotAPI Creation Time' + ) + ->setComment('ChatbotAPI Table'); +$this->getConnection()->createTable($table); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/message_store')) + ->addColumn( + 'message_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'nullable' => false, + 'primary' => true, + ), + 'Message ID' + ) + ->addColumn( + 'store_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'Store ID' + ) + ->addIndex( + $this->getIdxName( + 'werules_chatbot/message_store', + array('store_id') + ), + array('store_id') + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/message_store', + 'message_id', + 'werules_chatbot/message', + 'entity_id' + ), + 'message_id', + $this->getTable('werules_chatbot/message'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/message_store', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', + $this->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Messages To Store Linkage Table'); +$this->getConnection()->createTable($table); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/chatbotuser_store')) + ->addColumn( + 'chatbotuser_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'nullable' => false, + 'primary' => true, + ), + 'ChatbotUser ID' + ) + ->addColumn( + 'store_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'Store ID' + ) + ->addIndex( + $this->getIdxName( + 'werules_chatbot/chatbotuser_store', + array('store_id') + ), + array('store_id') + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/chatbotuser_store', + 'chatbotuser_id', + 'werules_chatbot/chatbotuser', + 'entity_id' + ), + 'chatbotuser_id', + $this->getTable('werules_chatbot/chatbotuser'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/chatbotuser_store', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', + $this->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('ChatbotUsers To Store Linkage Table'); +$this->getConnection()->createTable($table); +$table = $this->getConnection() + ->newTable($this->getTable('werules_chatbot/chatbotapi_store')) + ->addColumn( + 'chatbotapi_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'nullable' => false, + 'primary' => true, + ), + 'ChatbotAPI ID' + ) + ->addColumn( + 'store_id', + Varien_Db_Ddl_Table::TYPE_SMALLINT, + null, + array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'Store ID' + ) + ->addIndex( + $this->getIdxName( + 'werules_chatbot/chatbotapi_store', + array('store_id') + ), + array('store_id') + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/chatbotapi_store', + 'chatbotapi_id', + 'werules_chatbot/chatbotapi', + 'entity_id' + ), + 'chatbotapi_id', + $this->getTable('werules_chatbot/chatbotapi'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey( + $this->getFkName( + 'werules_chatbot/chatbotapi_store', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', + $this->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('ChatbotAPIs To Store Linkage Table'); +$this->getConnection()->createTable($table); +$this->endSetup(); diff --git a/Magento1/app/design/adminhtml/default/default/layout/werules_chatbot.xml b/Magento1/app/design/adminhtml/default/default/layout/werules_chatbot.xml new file mode 100644 index 0000000..2af9118 --- /dev/null +++ b/Magento1/app/design/adminhtml/default/default/layout/werules_chatbot.xml @@ -0,0 +1,104 @@ + + + + + + system/config/werules_chatbot/message + + + + + + + + + + + + + + + + + + system/config/werules_chatbot/message + + + + + + + + + + + + + + system/config/werules_chatbot/chatbotuser + + + + + + + + + + + + + + + + + + system/config/werules_chatbot/chatbotuser + + + + + + + + + + + + + + system/config/werules_chatbot/chatbotapi + + + + + + + + + + + + + + + + + + system/config/werules_chatbot/chatbotapi + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/layout/chatbot_customer_index.xml b/Magento1/app/design/frontend/base/default/layout/chatbot_customer_index.xml new file mode 100644 index 0000000..0d72252 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/layout/chatbot_customer_index.xml @@ -0,0 +1,18 @@ + + + + + + chatbot_settings + chatbot/customer/index + + + + + + + + + + + \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_index.xml b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_index.xml new file mode 100644 index 0000000..af508f5 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_index.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_messenger.xml b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_messenger.xml new file mode 100644 index 0000000..4a0f504 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_messenger.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_telegram.xml b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_telegram.xml new file mode 100644 index 0000000..c76d547 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/layout/chatbot_webhook_telegram.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/template/chatbot/index.phtml b/Magento1/app/design/frontend/base/default/template/chatbot/index.phtml new file mode 100644 index 0000000..126930c --- /dev/null +++ b/Magento1/app/design/frontend/base/default/template/chatbot/index.phtml @@ -0,0 +1,24 @@ +. + */ +// $thisBlock = $this->getLayout()->getBlockSingleton('werules_chatbot/webhook_messenger'); + $thisBlock = $this->getLayout()->createBlock('werules_chatbot/webhook_index'); + echo $thisBlock->requestHandler(); +?> \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/template/chatbot/messenger.phtml b/Magento1/app/design/frontend/base/default/template/chatbot/messenger.phtml new file mode 100644 index 0000000..3b20a19 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/template/chatbot/messenger.phtml @@ -0,0 +1,24 @@ +. + */ +// $thisBlock = $this->getLayout()->getBlockSingleton('werules_chatbot/webhook_messenger'); + $thisBlock = $this->getLayout()->createBlock('werules_chatbot/webhook_messenger'); + echo $thisBlock->requestHandler(); +?> \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/template/chatbot/settings.phtml b/Magento1/app/design/frontend/base/default/template/chatbot/settings.phtml new file mode 100644 index 0000000..2216f7e --- /dev/null +++ b/Magento1/app/design/frontend/base/default/template/chatbot/settings.phtml @@ -0,0 +1,21 @@ +. + */ +?> \ No newline at end of file diff --git a/Magento1/app/design/frontend/base/default/template/chatbot/telegram.phtml b/Magento1/app/design/frontend/base/default/template/chatbot/telegram.phtml new file mode 100644 index 0000000..411afd0 --- /dev/null +++ b/Magento1/app/design/frontend/base/default/template/chatbot/telegram.phtml @@ -0,0 +1,24 @@ +. + */ +// $thisBlock = $this->getLayout()->getBlockSingleton('werules_chatbot/webhook_telegram'); + $thisBlock = $this->getLayout()->createBlock('werules_chatbot/webhook_telegram'); + echo $thisBlock->requestHandler(); +?> \ No newline at end of file diff --git a/Magento1/app/etc/modules/Werules_Chatbot.xml b/Magento1/app/etc/modules/Werules_Chatbot.xml new file mode 100644 index 0000000..2680f6e --- /dev/null +++ b/Magento1/app/etc/modules/Werules_Chatbot.xml @@ -0,0 +1,13 @@ + + + + + true + community + 1.0.0 + + + + + + \ No newline at end of file diff --git a/Magento1/app/locale/en_US/Werules_Chatbot.csv b/Magento1/app/locale/en_US/Werules_Chatbot.csv new file mode 100644 index 0000000..a08fcc1 --- /dev/null +++ b/Magento1/app/locale/en_US/Werules_Chatbot.csv @@ -0,0 +1,205 @@ +"Cancel","Cancel" +"Sorry, no products found for this criteria.","Sorry, no products found for this criteria." +"Sorry, no products found in this category.","Sorry, no products found in this category." +"Please select a category.","Please select a category." +"Sure, send me the name of the product you're looking for.","Sure, send me the name of the product you're looking for" +"Add to cart","Add to cart" +"Visit product's page","Visit product's page" +"Command","Command" +"Enable Command","Enable Command" +"Command Code","Command Code" +"Command Alias (Separated by Comma)","Command Alias (Separated by Comma)" +"Add","Add" +"Enable","Enable" +"List Categories","List Categories" +"List More","List More" +"Search For Product","Search For Product" +"Login","Login" +"List Orders","List Orders" +"Reorder","Reorder" +"Add Product to Cart","Add Product to Cart" +"Checkout on Website","Checkout on Website" +"Clear Cart","Clear Cart" +"Track Order Status","Track Order Status" +"Talk to Support","Talk to Support" +"Send Email","Send Email" +"Help","Help" +"About","About" +"Logout","Logout" +"Register","Register" +"Enable Reply","Enable Reply" +"wit.ai entity","wit.ai entity" +"Acceptable Confidence (%)","Acceptable Confidence (%)" +"Stop Processing","Stop Processing" +"Reply Mode","Reply Mode" +"Reply Text","Reply Text" +"No Reply","No Reply" +"Text Only","Text Only" +"Command Only","Command Only" +"Text and Command","Text and Command" +"Please check your Hub Verify Token.","Please check your Hub Verify Token." +"Mapped Command","Mapped Command" +"Ok, canceled.","Ok, canceled." +"Access %1 to register a new account on our shop.","Access %1 to register a new account on our shop." +"Not informed","Not informed" +"Message from chatbot customer","Message from chatbot customer" +"Customer name","Customer name" +"Message","Message" +"Contacts","Contacts" +"Chatbot","Chatbot" +"Email","Email" +"Contact from chatbot","Contact from chatbot" +"Sure, send me the email content.","Sure, send me the email content." +"Sorry, I wasn't able to send an email this time. Please try again later.","Sorry, I wasn't able to send an email this time. Please try again later." +"Email sent.","Email sent." +"Sorry, I didn't understand that.","Sorry, I didn't understand that." +"You are already logged.","You are already logged." +"You are already registered.","You are already registered." +"Receive Promotional Messages?","Receive Promotional Messages?" +"Enable Messenger?","Enable Messenger?" +"Chatbot Settings","Chatbot Settings" +"Chatbot settings saved successfully.","Chatbot settings saved successfully." +"Something went wrong, please try again.","Something went wrong, please try again." +"You still haven't chat with our Chatbot.","You still haven't chat with our Chatbot." +"You haven't changed any data in the settings.","You haven't changed any data in the settings." +"Invalid URL hash, please try again.","Invalid URL hash, please try again." +"Ok, you're logged out.","Ok, you're logged out." +"This account has no orders.","This account has no orders." +"Ok, send me the order number you're looking for.","Ok, send me the order number you're looking for." +"Sorry, we couldn't find any order with this information.","Sorry, we couldn't find any order with this information." +"Ok, I just add the product to your cart, to checkout send '%1'.","Ok, I just add the product to your cart, to checkout send '%1'." +"Cart cleared.","Cart cleared." +"If you want to reorder one of these orders choose it below.","If you want to reorder one of these orders choose it below." +"All products from order %1 that are in stock were added to your cart.","All products from order %1 that are in stock were added to your cart." +"Your cart is empty.","Your cart is empty." +"Product:","Product:" +"Price:","Price:" +"Quantity:","Quantity:" +"Subtotal:","Subtotal:" +"Subtotal (Tax Incl.):","Subtotal (Tax Incl.):" +"To chat with me, please enable Messenger on your account chatbot settings.","To chat with me, please enable Messenger on your account chatbot settings." +"To list more send '%1'.","To list more send '%1'." +"No more items to list.","No more items to list." +"This category doesn't seems to exist. Please try again.","This category doesn't seems to exist. Please try again." +"Action","Action" +"Add ChatbotAPI","Add ChatbotAPI" +"Add ChatbotUser","Add ChatbotUser" +"Add Message","Add Message" +"An error occurred while updating the chatbotapis.","An error occurred while updating the chatbotapis." +"An error occurred while updating the chatbotusers.","An error occurred while updating the chatbotusers." +"An error occurred while updating the messages.","An error occurred while updating the messages." +"Are you sure?","Are you sure?" +"CSV","CSV" +"Change Enable Promotional Messages","Change Enable Promotional Messages" +"Change Enable Support","Change Enable Support" +"Change Enabled?","Change Enabled?" +"Change Is Admin?","Change Is Admin?" +"Change Logged?","Change Logged?" +"Change status","Change status" +"Chat ID","Chat ID" +"Chat Message ID","Chat Message ID" +"Chatbot Type","Chatbot Type" +"ChatbotAPI ID","ChatbotAPI ID" +"ChatbotAPI was saved","ChatbotAPI was saved" +"ChatbotAPI was successfully deleted.","ChatbotAPI was successfully deleted." +"ChatbotAPI was successfully saved","ChatbotAPI was successfully saved" +"ChatbotAPI","ChatbotAPI" +"ChatbotAPIs","ChatbotAPIs" +"ChatbotUser ID","ChatbotUser ID" +"ChatbotUser was saved","ChatbotUser was saved" +"ChatbotUser was successfully deleted.","ChatbotUser was successfully deleted." +"ChatbotUser was successfully saved","ChatbotUser was successfully saved" +"ChatbotUser","ChatbotUser" +"ChatbotUsers","ChatbotUsers" +"Chatbotuser ID","Chatbotuser ID" +"Content Type","Content Type" +"Content","Content" +"Conversation State","Conversation State" +"Could not find chatbotapi to delete.","Could not find chatbotapi to delete." +"Could not find chatbotuser to delete.","Could not find chatbotuser to delete." +"Could not find message to delete.","Could not find message to delete." +"Created at","Created at" +"Current Command Details","Current Command Details" +"Delete ChatbotAPI","Delete ChatbotAPI" +"Delete ChatbotUser","Delete ChatbotUser" +"Delete Message","Delete Message" +"Delete","Delete" +"Direction","Direction" +"Disabled","Disabled" +"Edit ChatbotAPI '%s'","Edit ChatbotAPI '%s'" +"Edit ChatbotUser '%s'","Edit ChatbotUser '%s'" +"Edit Message '%s'","Edit Message '%s'" +"Edit","Edit" +"Enable Promotional Messages","Enable Promotional Messages" +"Enable Support","Enable Support" +"Enabled","Enabled" +"Enabled?","Enabled?" +"Error saving chatbotapi","Error saving chatbotapi" +"Error saving chatbotuser","Error saving chatbotuser" +"Error saving message","Error saving message" +"Excel","Excel" +"Fallback Quantity","Fallback Quantity" +"Hash Key","Hash Key" +"Home","Home" +"Id","Id" +"Is Admin?","Is Admin?" +"Last Command Details","Last Command Details" +"Logged?","Logged?" +"Message ID","Message ID" +"Message Payload","Message Payload" +"Message was saved","Message was saved" +"Message was successfully deleted.","Message was successfully deleted." +"Message was successfully saved","Message was successfully saved" +"Message","Message" +"Messages","Messages" +"No","No" +"None","None" +"Please select chatbotapis to delete.","Please select chatbotapis to delete." +"Please select chatbotapis.","Please select chatbotapis." +"Please select chatbotusers to delete.","Please select chatbotusers to delete." +"Please select chatbotusers.","Please select chatbotusers." +"Please select messages to delete.","Please select messages to delete." +"Please select messages.","Please select messages." +"Reset","Reset" +"Save And Continue Edit","Save And Continue Edit" +"Save ChatbotAPI","Save ChatbotAPI" +"Save ChatbotUser","Save ChatbotUser" +"Save Message","Save Message" +"Sender ID","Sender ID" +"Sent At","Sent At" +"Session ID","Session ID" +"Status","Status" +"Store views","Store views" +"The chatbotapis has been deleted.","The chatbotapis has been deleted." +"The chatbotusers has been deleted.","The chatbotusers has been deleted." +"The messages has been deleted.","The messages has been deleted." +"There was a problem saving the chatbotapi.","There was a problem saving the chatbotapi." +"There was a problem saving the chatbotuser.","There was a problem saving the chatbotuser." +"There was a problem saving the message.","There was a problem saving the message." +"There was an error deleting chatbotapi.","There was an error deleting chatbotapi." +"There was an error deleting chatbotapis.","There was an error deleting chatbotapis." +"There was an error deleting chatbotuser.","There was an error deleting chatbotuser." +"There was an error deleting chatbotusers.","There was an error deleting chatbotusers." +"There was an error deleting message.","There was an error deleting message." +"There was an error deleting messages.","There was an error deleting messages." +"There was an error updating chatbotapis.","There was an error updating chatbotapis." +"There was an error updating chatbotusers.","There was an error updating chatbotusers." +"There was an error updating messages.","There was an error updating messages." +"This chatbotapi no longer exists.","This chatbotapi no longer exists." +"This chatbotuser no longer exists.","This chatbotuser no longer exists." +"This message no longer exists.","This message no longer exists." +"Total of %d chatbotapis were successfully deleted.","Total of %d chatbotapis were successfully deleted." +"Total of %d chatbotapis were successfully updated.","Total of %d chatbotapis were successfully updated." +"Total of %d chatbotusers were successfully deleted.","Total of %d chatbotusers were successfully deleted." +"Total of %d chatbotusers were successfully updated.","Total of %d chatbotusers were successfully updated." +"Total of %d messages were successfully deleted.","Total of %d messages were successfully deleted." +"Total of %d messages were successfully updated.","Total of %d messages were successfully updated." +"Total of %d record(s) have been deleted.","Total of %d record(s) have been deleted." +"Total of %d record(s) have been updated.","Total of %d record(s) have been updated." +"Unable to find chatbotapi to save.","Unable to find chatbotapi to save." +"Unable to find chatbotuser to save.","Unable to find chatbotuser to save." +"Unable to find message to save.","Unable to find message to save." +"Updated at","Updated at" +"WYSIWYG Editor","WYSIWYG Editor" +"XML","XML" +"Yes","Yes" diff --git a/Magento1/app/locale/pt_BR/Werules_Chatbot.csv b/Magento1/app/locale/pt_BR/Werules_Chatbot.csv new file mode 100644 index 0000000..a276ac2 --- /dev/null +++ b/Magento1/app/locale/pt_BR/Werules_Chatbot.csv @@ -0,0 +1 @@ +"Cancel.","Cancelar." \ No newline at end of file diff --git a/Magento1/app/locale/zh_CN/Werules_Chatbot.csv b/Magento1/app/locale/zh_CN/Werules_Chatbot.csv new file mode 100644 index 0000000..0b573fa --- /dev/null +++ b/Magento1/app/locale/zh_CN/Werules_Chatbot.csv @@ -0,0 +1 @@ +"Cancel.","取消。" \ No newline at end of file diff --git a/Magento1/app/locale/zh_HK/Werules_Chatbot.csv b/Magento1/app/locale/zh_HK/Werules_Chatbot.csv new file mode 100644 index 0000000..0b573fa --- /dev/null +++ b/Magento1/app/locale/zh_HK/Werules_Chatbot.csv @@ -0,0 +1 @@ +"Cancel.","取消。" \ No newline at end of file diff --git a/Magento1/app/locale/zh_TW/Werules_Chatbot.csv b/Magento1/app/locale/zh_TW/Werules_Chatbot.csv new file mode 100644 index 0000000..0b573fa --- /dev/null +++ b/Magento1/app/locale/zh_TW/Werules_Chatbot.csv @@ -0,0 +1 @@ +"Cancel.","取消。" \ No newline at end of file diff --git a/Magento1/js/werules/chatbot/chatbot.js b/Magento1/js/werules/chatbot/chatbot.js new file mode 100644 index 0000000..28a42ed --- /dev/null +++ b/Magento1/js/werules/chatbot/chatbot.js @@ -0,0 +1,50 @@ +// display/hide match mode +function werulesTogleMatchMode(element) +{ + //debugger; + var val = element.value; + var name = element.name; + name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; + var target = document.getElementsByName(name); + if (val === 0) + target[0].disabled = false; + else + target[0].disabled = true; +} + +function werulesTogleEnable(element) +{ + //debugger; + // var val = element.value; + // var name = element.name; + // if (val == 0) + // { + // name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; + // var target = document.getElementsByName(name); + // target[0].disabled = false; + // } + // else + // { + // name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; + // var target = document.getElementsByName(name); + // target[0].disabled = true; + // } +} + +// display/hide reply mode +function werulesTogleReplyMode(element) +{ + //debugger; + var val = element.value; + var name = element.name; + name = name.substr(0, name.lastIndexOf("[")) + "[command_id]"; + var target = document.getElementsByName(name); + if (val === 0) + target[0].disabled = true; + else + { + //target[0].classList.remove("werules-disabled"); + //target[0].style = ""; + target[0].disabled = false; + } +} \ No newline at end of file diff --git a/Magento1/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css b/Magento1/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css new file mode 100644 index 0000000..2b3e611 --- /dev/null +++ b/Magento1/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css @@ -0,0 +1,12 @@ +/*backend css*/ +.werules-disabled-input{ + pointer-events: none; + background-color: #ebebe4; + color: #545454; +} + +.werules-disabled-select{ + pointer-events: none; + background-color: #FFFFFF; + color: #808080; +} \ No newline at end of file diff --git a/Magento1/skin/frontend/base/default/images/werules_chatbot/messenger-icon.png b/Magento1/skin/frontend/base/default/images/werules_chatbot/messenger-icon.png new file mode 100644 index 0000000..611e6d4 Binary files /dev/null and b/Magento1/skin/frontend/base/default/images/werules_chatbot/messenger-icon.png differ