Ajout et config du module Chronopost
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Form;
|
||||
|
||||
use ChronopostHomeDelivery\ChronopostHomeDelivery;
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryDeliveryModeQuery;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\AreaQuery;
|
||||
|
||||
class ChronopostHomeDeliveryAddPriceForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("area", "integer", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyAreaExist")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("delivery_mode", "integer", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyDeliveryModeExist")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("weight", "number", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyValidWeight")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("price", "number", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyValidPrice")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("franco", "number", array())
|
||||
;
|
||||
}
|
||||
|
||||
public function verifyAreaExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$area = AreaQuery::create()->findPk($value);
|
||||
if (null === $area) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This area doesn't exists.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyDeliveryModeExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$mode = ChronopostHomeDeliveryDeliveryModeQuery::create()->findPk($value);
|
||||
if (null === $mode) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This delivery mode doesn't exists.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidWeight($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The weight value is not valid.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
|
||||
if ($value < 0) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The weight value must be superior to 0.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidPrice($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "chronopost_home_delivery_price_create";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Form;
|
||||
|
||||
|
||||
use ChronopostHomeDelivery\Config\ChronopostHomeDeliveryConst;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
class ChronopostHomeDeliveryConfigurationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$config = ChronopostHomeDeliveryConst::getConfig();
|
||||
|
||||
$this->formBuilder
|
||||
|
||||
/** Chronopost basic informations */
|
||||
->add(
|
||||
ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_CODE_CLIENT,
|
||||
"text",
|
||||
[
|
||||
'required' => true,
|
||||
'data' => $config[ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_CODE_CLIENT],
|
||||
'label' => Translator::getInstance()->trans("Chronopost client ID"),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
],
|
||||
'attr' => [
|
||||
'placeholder' => Translator::getInstance()->trans("Your Chronopost client ID"),
|
||||
],
|
||||
]
|
||||
)
|
||||
->add(ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_PASSWORD,
|
||||
"text",
|
||||
[
|
||||
'required' => true,
|
||||
'data' => $config[ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_PASSWORD],
|
||||
'label' => Translator::getInstance()->trans("Chronopost password"),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
],
|
||||
'attr' => [
|
||||
'placeholder' => Translator::getInstance()->trans("Your Chronopost password"),
|
||||
],
|
||||
]
|
||||
)
|
||||
;
|
||||
|
||||
/** Delivery types */
|
||||
foreach (ChronopostHomeDeliveryConst::getDeliveryTypesStatusKeys() as $deliveryTypeName => $statusKey) {
|
||||
$this->formBuilder
|
||||
->add($statusKey,
|
||||
"checkbox",
|
||||
[
|
||||
'required' => false,
|
||||
'data' => (bool)$config[$statusKey],
|
||||
'label' => Translator::getInstance()->trans("\"" . $deliveryTypeName . "\" Delivery (Code : " . ChronopostHomeDeliveryConst::CHRONOPOST_HOME_DELIVERY_DELIVERY_CODES[$deliveryTypeName] . ")"),
|
||||
'label_attr' => [
|
||||
'for' => 'title',
|
||||
],
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/** BUILDFORM END */
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "chronopost_home_delivery_configuration_form";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Form;
|
||||
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
class ChronopostHomeDeliveryFreeShippingForm extends BaseForm
|
||||
{
|
||||
/**
|
||||
* @return null|void
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"delivery_mode",
|
||||
"integer"
|
||||
)
|
||||
->add(
|
||||
"freeshipping",
|
||||
"checkbox",
|
||||
[
|
||||
'label'=>Translator::getInstance()->trans("Activate free shipping: ")
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of you form. This name must be unique
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "chronopost_home_delivery_freeshipping";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace ChronopostHomeDelivery\Form;
|
||||
|
||||
|
||||
use ChronopostHomeDelivery\ChronopostHomeDelivery;
|
||||
use ChronopostHomeDelivery\Model\ChronopostHomeDeliveryDeliveryModeQuery;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\AreaQuery;
|
||||
|
||||
class ChronopostHomeDeliveryUpdatePriceForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("area", "integer", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyAreaExist")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("delivery_mode", "integer", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyDeliveryModeExist")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("weight", "number", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
)
|
||||
))
|
||||
->add("price", "number", array(
|
||||
"constraints" => array(
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\Callback(array(
|
||||
"methods" => array(
|
||||
array($this,
|
||||
"verifyValidPrice")
|
||||
)
|
||||
))
|
||||
)
|
||||
))
|
||||
->add("franco", "number", array())
|
||||
;
|
||||
}
|
||||
|
||||
public function verifyAreaExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$area = AreaQuery::create()->findPk($value);
|
||||
if (null === $area) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This area doesn't exists.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyDeliveryModeExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$mode = ChronopostHomeDeliveryDeliveryModeQuery::create()->findPk($value);
|
||||
if (null === $mode) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This delivery mode doesn't exists.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidPrice($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], ChronopostHomeDelivery::DOMAIN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "chronopost_home_delivery_price_create";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user