-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WIP - Handle configuration module to save and display the form
- Loading branch information
1 parent
a9a4b43
commit 6d8ccce
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* 2018-2024 Alma SAS. | ||
* | ||
* THE MIT LICENSE | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
* | ||
* @author Alma SAS <[email protected]> | ||
* @copyright 2018-2024 Alma SAS | ||
* @license https://opensource.org/licenses/MIT The MIT License | ||
*/ | ||
|
||
namespace Alma\PrestaShop\Exceptions; | ||
|
||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
class AlmaFormConfigurationException extends AlmaException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* 2018-2024 Alma SAS. | ||
* | ||
* THE MIT LICENSE | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
* | ||
* @author Alma SAS <[email protected]> | ||
* @copyright 2018-2024 Alma SAS | ||
* @license https://opensource.org/licenses/MIT The MIT License | ||
*/ | ||
|
||
namespace Alma\Prestashop\Services; | ||
|
||
use Alma\PrestaShop\Exceptions\AlmaApiKeyException; | ||
use Alma\PrestaShop\Factories\ClientFactory; | ||
use Alma\PrestaShop\Forms\ApiAdminFormBuilder; | ||
use Alma\PrestaShop\Logger; | ||
use Alma\PrestaShop\Model\AlmaApiKeyModel; | ||
use Alma\PrestaShop\Proxy\ToolsProxy; | ||
|
||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
class AlmaConfigurationService | ||
{ | ||
/** | ||
* @var \Alma\PrestaShop\Model\AlmaApiKeyModel | ||
*/ | ||
private $almaApiKeyModel; | ||
/** | ||
* @var \Alma\PrestaShop\Proxy\ToolsProxy|mixed|null | ||
*/ | ||
private $toolsProxy; | ||
|
||
public function __construct( | ||
$almaApiKeyModel = null, | ||
$toolsProxy = null, | ||
$clientFactory = null | ||
) { | ||
if (!$almaApiKeyModel) { | ||
$almaApiKeyModel = new AlmaApiKeyModel(); | ||
} | ||
$this->almaApiKeyModel = $almaApiKeyModel; | ||
|
||
if (!$toolsProxy) { | ||
$toolsProxy = new ToolsProxy(); | ||
} | ||
$this->toolsProxy = $toolsProxy; | ||
|
||
if (!$clientFactory) { | ||
$clientFactory = new ClientFactory(); | ||
} | ||
} | ||
|
||
public function saveConfiguration() | ||
{ | ||
try { | ||
$currentMode = $this->toolsProxy->getValue(ApiAdminFormBuilder::ALMA_API_MODE); | ||
$this->almaApiKeyModel->checkActiveApiKey($currentMode); | ||
} catch (AlmaApiKeyException $e) { | ||
Logger::instance()->error($e->getMessage()); | ||
} | ||
} | ||
|
||
public function getConfiguration() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* 2018-2024 Alma SAS. | ||
* | ||
* THE MIT LICENSE | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
* | ||
* @author Alma SAS <[email protected]> | ||
* @copyright 2018-2024 Alma SAS | ||
* @license https://opensource.org/licenses/MIT The MIT License | ||
*/ | ||
|
||
namespace Alma\PrestaShop\Tests\Unit\Services; | ||
|
||
use Alma\PrestaShop\Model\AlmaApiKeyModel; | ||
use Alma\Prestashop\Services\AlmaConfigurationService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AlmaConfigurationServiceTest extends TestCase | ||
{ | ||
/** | ||
* @var AlmaConfigurationService | ||
*/ | ||
protected $almaconfigurationService; | ||
|
||
public function setUp() | ||
{ | ||
$this->almaApiKeyModel = $this->createMock(AlmaApiKeyModel::class); | ||
$this->almaconfigurationService = new AlmaConfigurationService( | ||
$this->almaApiKeyModel | ||
); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$this->almaApiKeyModel = null; | ||
} | ||
|
||
public function testSaveConfiguration() | ||
{ | ||
} | ||
} |