Ajout du module CustomDelivery v 1.0.7 (avant le AbstractDeliveryModuleWithState)
This commit is contained in:
130
local/modules/CustomDelivery/Form/ConfigurationForm.php
Normal file
130
local/modules/CustomDelivery/Form/ConfigurationForm.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
namespace CustomDelivery\Form;
|
||||
|
||||
use CustomDelivery\CustomDelivery;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\Base\TaxRuleQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigurationForm
|
||||
* @package VirtualProductGereso\Form
|
||||
* @author Julien Chanséaume <julien@thelia.net>
|
||||
*/
|
||||
class ConfigurationForm extends BaseForm
|
||||
{
|
||||
public function checkTaxRuleId($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (0 !== intval($value)) {
|
||||
if (null === TaxRuleQuery::create()->findPk($value)) {
|
||||
$context->addViolation(
|
||||
$this->trans(
|
||||
"The Tax Rule id '%id' doesn't exist",
|
||||
[
|
||||
"%id" => $value,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "customdelivery-configuration-form";
|
||||
}
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$form = $this->formBuilder;
|
||||
|
||||
$config = CustomDelivery::getConfig();
|
||||
|
||||
$form
|
||||
->add(
|
||||
"url",
|
||||
"text",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
],
|
||||
'data' => $config['url'],
|
||||
'label' => $this->trans("Tracking URL"),
|
||||
'label_attr' => [
|
||||
'for' => "url",
|
||||
'help' => $this->trans(
|
||||
"The tracking URL. %ID% will be replaced by the tracking number entered in the order"
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"method",
|
||||
"choice",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
],
|
||||
"choices" => [
|
||||
CustomDelivery::METHOD_PRICE_WEIGHT => $this->trans("Price and weight"),
|
||||
CustomDelivery::METHOD_PRICE => $this->trans("Price"),
|
||||
CustomDelivery::METHOD_WEIGHT => $this->trans("Weight"),
|
||||
],
|
||||
'data' => $config['method'],
|
||||
'label' => $this->trans("Method"),
|
||||
'label_attr' => [
|
||||
'for' => "method",
|
||||
'help' => $this->trans(
|
||||
"The method used to select the right slice."
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"tax",
|
||||
"tax_rule_id",
|
||||
[
|
||||
"constraints" => [
|
||||
new Callback([
|
||||
"methods" => [
|
||||
[$this, "checkTaxRuleId"]
|
||||
]
|
||||
])
|
||||
],
|
||||
'required' => false,
|
||||
'data' => $config['tax'],
|
||||
'label' => $this->trans("Tax rule"),
|
||||
'label_attr' => [
|
||||
'for' => "method",
|
||||
'help' => $this->trans(
|
||||
"The tax rule used to calculate postage taxes."
|
||||
)
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function trans($id, array $parameters = [])
|
||||
{
|
||||
return $this->translator->trans($id, $parameters, CustomDelivery::MESSAGE_DOMAIN);
|
||||
}
|
||||
}
|
||||
92
local/modules/CustomDelivery/Form/SliceForm.php
Normal file
92
local/modules/CustomDelivery/Form/SliceForm.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
namespace CustomDelivery\Form;
|
||||
|
||||
use CustomDelivery\CustomDelivery;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
/**
|
||||
* Class SliceForm
|
||||
* @package VirtualProductGereso\Form
|
||||
* @author Julien Chanséaume <julien@thelia.net>
|
||||
*/
|
||||
class SliceForm extends BaseForm
|
||||
{
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "customdelivery-configuration-form";
|
||||
}
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$form = $this->formBuilder;
|
||||
|
||||
$config = CustomDelivery::getConfig();
|
||||
|
||||
$form
|
||||
->add(
|
||||
"id",
|
||||
"number",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
],
|
||||
'label' => $this->trans("Id")
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"area",
|
||||
"area_id",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
],
|
||||
'label' => $this->trans("Area"),
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"priceMax",
|
||||
"float",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
],
|
||||
'label' => $this->trans("Area"),
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"weightMax",
|
||||
"float",
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
],
|
||||
'label' => $this->trans("Area"),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function trans($id, array $parameters = [])
|
||||
{
|
||||
return $this->translator->trans($id, $parameters, CustomDelivery::MESSAGE_DOMAIN);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user