diff --git a/Controllers/Backend/AfterbuyConnector.php b/Controllers/Backend/AfterbuyConnector.php new file mode 100755 index 0000000..e5cecb1 --- /dev/null +++ b/Controllers/Backend/AfterbuyConnector.php @@ -0,0 +1,44 @@ +container->get('viaeb_shopware_afterbuy.services.read_data.external.connection_test_service'); + $response = $testService->get(array()); + + if(array_key_exists('AfterbuyTimeStamp', $response['Result'])) { + $this->view->assign([ + 'success' => true, + ]); + + return; + } + + if(array_key_exists('ErrorList', $response['Result']) && array_key_exists('Error', $response['Result']['ErrorList'])) { + + if(array_key_exists('ErrorDescription', $response['Result']['ErrorList']['Error'])) { + $error = $response['Result']['ErrorList']['Error']['ErrorDescription']; + } + else { + $error = ''; + + foreach($response['Result']['ErrorList']['Error'] as $element) { + $error .= $element['ErrorDescription']; + } + } + + $this->view->assign([ + 'success' => false, + 'data' => [ + 'error' => $error, + ], + ]); + + return; + } + } +} diff --git a/Resources/menu.xml b/Resources/menu.xml new file mode 100644 index 0000000..c3c9280 --- /dev/null +++ b/Resources/menu.xml @@ -0,0 +1,22 @@ + + + + + AfterbuyConnector + + + ConfigurationMenu + + + TestConnection + + + AfterbuyConnector + testConnection + sprite-box + + + + + \ No newline at end of file diff --git a/Resources/services.xml b/Resources/services.xml index b6689fd..6414835 100755 --- a/Resources/services.xml +++ b/Resources/services.xml @@ -14,6 +14,14 @@ + + + %viaeb_shopware_afterbuy.plugin_dir% + + + + + @@ -78,6 +86,11 @@ + + + + + diff --git a/Resources/views/backend/afterbuy_connector/app.js b/Resources/views/backend/afterbuy_connector/app.js new file mode 100755 index 0000000..10a3927 --- /dev/null +++ b/Resources/views/backend/afterbuy_connector/app.js @@ -0,0 +1,51 @@ +Ext.define('Shopware.apps.AfterbuyConnector', { + + extend: 'Enlight.app.SubApplication', + + /** + * The name of the module. Used for internal purpose + * @string + */ + name:'Shopware.apps.AfterbuyConnector', + + + launch: function() { + var me = this; + + + Ext.Ajax.request({ + url: '{url controller=AfterbuyConnector action=testConnection}', + success: function(response) { + + var status = JSON.parse(response.responseText); + + if(status.success == true) { + Shopware.Notification.createGrowlMessage( + '{s namespace="backend/afterbuy" name="success"}Erfolg{/s}', + '{s namespace="backend/afterbuy" name="connection"}Verbindung erfolgreich hergestellt{/s}', + 'Afterbuy Conncetor' + ); + } + else { + Shopware.Notification.createGrowlMessage( + '{s namespace="backend/afterbuy" name="error"}Fehler{/s}', + status.data.error, + 'Afterbuy Conncetor' + ); + } + }, + failure: function() { + Shopware.Notification.createGrowlMessage( + '{s namespace="backend/afterbuy" name="error"}Error{/s}', + 'Unbekannter Fehler beim Testen der Verbindung', + 'Afterbuy Conncetor' + ); + } + }); + + } +}); + + + + diff --git a/Services/ReadData/External/ConnectionTestService.php b/Services/ReadData/External/ConnectionTestService.php new file mode 100644 index 0000000..a793c35 --- /dev/null +++ b/Services/ReadData/External/ConnectionTestService.php @@ -0,0 +1,53 @@ +read($filter); + + return $this->transform($data); + } + + /** + * transforms api input into valueObject (targetEntity) + * + * @param array $data + * + * @return array|null + */ + public function transform(array $data) + { + return $data; + } + + + /** + * provides api data. dummy data as used here can be used in tests + * + * @param array $filter + * + * @return array + */ + public function read(array $filter) + { + /** @var ApiClient $api */ + $api = new ApiClient($this->apiConfig); + $response = $api->getAfterbuyTime(); + + return $response; + } +} diff --git a/Subscriber/TemplateRegistration.php b/Subscriber/TemplateRegistration.php new file mode 100755 index 0000000..9688401 --- /dev/null +++ b/Subscriber/TemplateRegistration.php @@ -0,0 +1,43 @@ +pluginDirectory = $pluginDirectory; + $this->templateManager = $templateManager; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return [ + 'Enlight_Controller_Action_PreDispatch' => 'onPreDispatch', + ]; + } + + public function onPreDispatch(\Enlight_Event_EventArgs $args) + { + $this->templateManager->addTemplateDir($this->pluginDirectory . '/Resources/views'); + } +} \ No newline at end of file