Commit du module Colissimo
This commit is contained in:
105
local/modules/SoColissimo/Form/AddPriceForm.php
Normal file
105
local/modules/SoColissimo/Form/AddPriceForm.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
|
||||
use SoColissimo\Model\SocolissimoDeliveryModeQuery;
|
||||
use SoColissimo\SoColissimo;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\AreaQuery;
|
||||
|
||||
class AddPriceForm 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.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyDeliveryModeExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$mode = SocolissimoDeliveryModeQuery::create()->findPk($value);
|
||||
if (null === $mode) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This delivery mode doesn't exists.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidWeight($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The weight value is not valid.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
|
||||
if ($value < 0) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The weight value must be superior to 0.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidPrice($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "socolissimo_price_create";
|
||||
}
|
||||
}
|
||||
144
local/modules/SoColissimo/Form/ConfigureSoColissimo.php
Normal file
144
local/modules/SoColissimo/Form/ConfigureSoColissimo.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
|
||||
use SoColissimo\SoColissimo;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Url;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigureSoColissimo
|
||||
* @package SoColissimo\Form
|
||||
* @author Thelia <info@thelia.net>
|
||||
*/
|
||||
class ConfigureSoColissimo extends BaseForm
|
||||
{
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$translator = Translator::getInstance();
|
||||
$this->formBuilder
|
||||
->add(
|
||||
'accountnumber',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [new NotBlank()],
|
||||
'data' => ConfigQuery::read('socolissimo_login'),
|
||||
'label' => $translator->trans("Account number", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'accountnumber']
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'password',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [new NotBlank()],
|
||||
'data' => ConfigQuery::read('socolissimo_pwd'),
|
||||
'label' => $translator->trans("Password", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'password']
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'url_prod',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new Url([
|
||||
'protocols' => ['https', 'http']
|
||||
])
|
||||
],
|
||||
'data' => ConfigQuery::read('socolissimo_url_prod'),
|
||||
'label' => $translator->trans("Colissimo URL prod", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'socolissimo_url_prod']
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'url_test',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new Url([
|
||||
'protocols' => ['https', 'http']
|
||||
])
|
||||
],
|
||||
'data' => ConfigQuery::read('socolissimo_url_test'),
|
||||
'label' => $translator->trans("Colissimo URL test", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'socolissimo_url_test']
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'test_mode',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [new NotBlank()],
|
||||
'data' => ConfigQuery::read('socolissimo_test_mode'),
|
||||
'label' => $translator->trans("Test mode", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'test_mode']
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'google_map_key',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [],
|
||||
'data' => ConfigQuery::read('socolissimo_google_map_key'),
|
||||
'label' => $translator->trans("Google map API key", [], SoColissimo::DOMAIN),
|
||||
'label_attr' => ['for' => 'google_map_key']
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "configuresocolissimo";
|
||||
}
|
||||
}
|
||||
120
local/modules/SoColissimo/Form/ExportOrder.php
Normal file
120
local/modules/SoColissimo/Form/ExportOrder.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use SoColissimo\SoColissimo;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\Base\OrderQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
|
||||
/**
|
||||
* Class ExportOrder
|
||||
* @package SoColissimo\Form
|
||||
* @author Thelia <info@thelia.net>
|
||||
*/
|
||||
class ExportOrder extends BaseForm
|
||||
{
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$status = OrderStatusQuery::create()
|
||||
->filterByCode(
|
||||
array(
|
||||
OrderStatus::CODE_PAID,
|
||||
OrderStatus::CODE_PROCESSING,
|
||||
OrderStatus::CODE_SENT
|
||||
),
|
||||
Criteria::IN
|
||||
)
|
||||
->find()
|
||||
->toArray("code")
|
||||
;
|
||||
$query = OrderQuery::create()
|
||||
->filterByDeliveryModuleId(SoColissimo::getModCode())
|
||||
->filterByStatusId(array($status['paid']['Id'], $status['processing']['Id']), Criteria::IN)
|
||||
->find();
|
||||
|
||||
$this->formBuilder
|
||||
->add('new_status_id', 'choice',array(
|
||||
'label' => Translator::getInstance()->trans('server'),
|
||||
'choices' => array(
|
||||
"nochange" => Translator::getInstance()->trans("Do not change"),
|
||||
"processing" => Translator::getInstance()->trans("Set orders status as processing"),
|
||||
"sent" => Translator::getInstance()->trans("Set orders status as sent")
|
||||
),
|
||||
'required' => 'true',
|
||||
'expanded'=>true,
|
||||
'multiple'=>false,
|
||||
'data'=>'nochange'
|
||||
)
|
||||
);
|
||||
/** @var \Thelia\Model\Order $order */
|
||||
foreach ($query as $order) {
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"order_".$order->getId(),
|
||||
"checkbox",
|
||||
[
|
||||
'label'=>$order->getRef(),
|
||||
'label_attr'=>['for'=>'export_'.$order->getId()]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"order_weight_".$order->getId(),
|
||||
'number'
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "exportsocolissimoorder";
|
||||
}
|
||||
|
||||
}
|
||||
70
local/modules/SoColissimo/Form/FreeShipping.php
Normal file
70
local/modules/SoColissimo/Form/FreeShipping.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
|
||||
use SoColissimo\Model\SocolissimoFreeshippingQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
class FreeShipping extends BaseForm
|
||||
{
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("delivery_mode", "integer")
|
||||
->add("freeshipping", "checkbox", array(
|
||||
'label'=>Translator::getInstance()->trans("Activate free shipping: ")
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "socolissimofreeshipping";
|
||||
}
|
||||
|
||||
}
|
||||
37
local/modules/SoColissimo/Form/ImportForm.php
Normal file
37
local/modules/SoColissimo/Form/ImportForm.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
|
||||
use SoColissimo\SoColissimo;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
/**
|
||||
* Class ImportForm
|
||||
* @package SoColissimo\Form
|
||||
* @author Etienne Perriere - OpenStudio <eperriere@openstudio.fr>
|
||||
*/
|
||||
class ImportForm extends BaseForm
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'import_form';
|
||||
}
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
'import_file', 'file',
|
||||
[
|
||||
'label' => Translator::getInstance()->trans('Select file to import', [], SoColissimo::DOMAIN),
|
||||
'constraints' => [
|
||||
new Constraints\NotBlank(),
|
||||
new Constraints\File(['mimeTypes' => ['text/csv', 'text/plain']])
|
||||
],
|
||||
'label_attr' => ['for' => 'import_file']
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
88
local/modules/SoColissimo/Form/UpdatePriceForm.php
Normal file
88
local/modules/SoColissimo/Form/UpdatePriceForm.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace SoColissimo\Form;
|
||||
|
||||
use SoColissimo\Model\SocolissimoDeliveryModeQuery;
|
||||
use SoColissimo\SoColissimo;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Model\AreaQuery;
|
||||
|
||||
class UpdatePriceForm 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.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyDeliveryModeExist($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$mode = SocolissimoDeliveryModeQuery::create()->findPk($value);
|
||||
if (null === $mode) {
|
||||
$context->addViolation(Translator::getInstance()->trans("This delivery mode doesn't exists.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyValidPrice($value, ExecutionContextInterface $context)
|
||||
{
|
||||
if (!preg_match("#^\d+\.?\d*$#", $value)) {
|
||||
$context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], SoColissimo::DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "socolissimo_price_create";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user