-
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.
Merge pull request #16 from ThomasDaSilva/main
Tax Rule Option + fix translation + hide password feature
- Loading branch information
Showing
10 changed files
with
186 additions
and
32 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
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
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,56 @@ | ||
<?php | ||
|
||
namespace ChronopostPickupPoint\Controller; | ||
|
||
use ChronopostPickupPoint\ChronopostPickupPoint; | ||
use ChronopostPickupPoint\Form\ChronopostPickupPointTaxRuleForm; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Thelia\Controller\Admin\BaseAdminController; | ||
use Thelia\Core\Security\AccessManager; | ||
use Thelia\Core\Security\Resource\AdminResources; | ||
use Thelia\Core\Translation\Translator; | ||
use Thelia\Form\Exception\FormValidationException; | ||
use Thelia\Tools\URL; | ||
|
||
#[Route('/admin/module/ChronopostPickupPoint/tax_rule', name: 'chronopost_pickup_point_tax_rule_')] | ||
class ChronopostPickupPointTaxRuleController extends BaseAdminController | ||
{ | ||
#[Route('/save', name: 'save')] | ||
public function saveTaxRule() | ||
{ | ||
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ChronopostPickupPoint::DOMAIN_NAME, AccessManager::UPDATE)) { | ||
return $response; | ||
} | ||
|
||
$taxRuleForm = $this->createForm(ChronopostPickupPointTaxRuleForm::getName()); | ||
|
||
$message = false; | ||
|
||
$url = '/admin/module/ChronopostPickupPoint'; | ||
|
||
try { | ||
$form = $this->validateForm($taxRuleForm); | ||
|
||
// Get the form field values | ||
$data = $form->getData(); | ||
|
||
ChronopostPickupPoint::setConfigValue(ChronopostPickupPoint::CHRONOPOST_TAX_RULE_ID, $data["tax_rule_id"]); | ||
|
||
} catch (FormValidationException $ex) { | ||
$message = $this->createStandardFormValidationErrorMessage($ex); | ||
} catch (\Exception $ex) { | ||
$message = $ex->getMessage(); | ||
} | ||
|
||
if ($message !== false) { | ||
$this->setupFormErrorContext( | ||
Translator::getInstance()->trans('Error', [], ChronopostPickupPoint::DOMAIN_NAME), | ||
$message, | ||
$taxRuleForm, | ||
$ex | ||
); | ||
} | ||
|
||
return $this->generateRedirect(URL::getInstance()->absoluteUrl($url, [ 'current_tab' => 'tax_rule'])); | ||
} | ||
} |
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
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,49 @@ | ||
<?php | ||
|
||
namespace ChronopostPickupPoint\Form; | ||
|
||
use ChronopostPickupPoint\ChronopostPickupPoint; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Thelia\Core\HttpFoundation\Request; | ||
use Thelia\Core\Translation\Translator; | ||
use Thelia\Form\BaseForm; | ||
use Thelia\Model\TaxRuleI18nQuery; | ||
|
||
class ChronopostPickupPointTaxRuleForm extends BaseForm | ||
{ | ||
protected function buildForm(): void | ||
{ | ||
$this->formBuilder | ||
->add("tax_rule_id", | ||
ChoiceType::class, | ||
[ | ||
'data' => (int)ChronopostPickupPoint::getConfigValue(ChronopostPickupPoint::CHRONOPOST_TAX_RULE_ID), | ||
'choices' => $this->getTaxRules(), | ||
'label' => Translator::getInstance()->trans('Tax Rule', [], ChronopostPickupPoint::DOMAIN_NAME), | ||
] | ||
); | ||
} | ||
|
||
private function getTaxRules(): array | ||
{ | ||
$res = []; | ||
|
||
/** @var Request $request */ | ||
$request = $this->request; | ||
|
||
$lang = $request->getSession()?->getAdminEditionLang(); | ||
|
||
$taxRules = TaxRuleI18nQuery::create() | ||
->filterByLocale($lang->getLocale()) | ||
->find(); | ||
|
||
$res[Translator::getInstance()->trans('Default Tax rule', [], ChronopostPickupPoint::DOMAIN_NAME)] = null; | ||
|
||
foreach ($taxRules as $taxRule) | ||
{ | ||
$res[$taxRule->getTitle()] = $taxRule->getId(); | ||
} | ||
|
||
return $res; | ||
} | ||
} |
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,6 @@ | ||
<?php | ||
|
||
return array( | ||
'Chronopost Tax Rule configuration' => 'Configuration des Règles de taxes Chronopost', | ||
'Tax Rule' => 'Règles de taxes', | ||
); |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
return array( | ||
// 'an english string' => 'La traduction française de la chaine', | ||
'Default Tax rule' => 'Règles de taxes par défaut', | ||
'Tax Rule' => 'Règles de taxes', | ||
); |
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
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
Oops, something went wrong.