[12/05/2025] Un peu de paramétrage, notamment les frais de port gratuits en fonction de certains seuils

This commit is contained in:
2025-05-12 17:02:55 +02:00
parent 49b1a63ecc
commit 5826bd7942
105 changed files with 18596 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
<?php
namespace ColissimoPickupPoint\Form;
use ColissimoPickupPoint\ColissimoPickupPoint;
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('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.", [], ColissimoPickupPoint::DOMAIN));
}
}
public function verifyValidWeight($value, ExecutionContextInterface $context)
{
if (!preg_match("#^\d+\.?\d*$#", $value)) {
$context->addViolation(Translator::getInstance()->trans("The weight value is not valid.", [], ColissimoPickupPoint::DOMAIN));
}
if ($value < 0) {
$context->addViolation(Translator::getInstance()->trans("The weight value must be superior to 0.", [], ColissimoPickupPoint::DOMAIN));
}
}
public function verifyValidPrice($value, ExecutionContextInterface $context)
{
if (!preg_match("#^\d+\.?\d*$#", $value)) {
$context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], ColissimoPickupPoint::DOMAIN));
}
}
public function getName()
{
return 'colissimo_pickup_point_price_slices_create';
}
}

View File

@@ -0,0 +1,121 @@
<?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 ColissimoPickupPoint\Form;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
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 ConfigureColissimoPickupPoint
* @package ColissimoPickupPoint\Form
* @author Thelia <info@thelia.net>
*/
class ConfigureColissimoPickupPoint 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(
ColissimoPickupPoint::COLISSIMO_USERNAME,
TextType::class,
[
'constraints' => [new NotBlank()],
'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME),
'label' => $translator->trans('Account number', [], ColissimoPickupPoint::DOMAIN),
'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_USERNAME]
]
)
->add(
ColissimoPickupPoint::COLISSIMO_PASSWORD,
TextType::class,
[
'constraints' => [new NotBlank()],
'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD),
'label' => $translator->trans('Password', [], ColissimoPickupPoint::DOMAIN),
'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_PASSWORD]
]
)
->add(
ColissimoPickupPoint::COLISSIMO_ENDPOINT,
TextType::class,
[
'constraints' => [
new NotBlank(),
new Url([
'protocols' => ['https', 'http']
])
],
'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_ENDPOINT),
'label' => $translator->trans('Colissimo URL prod', [], ColissimoPickupPoint::DOMAIN),
'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_ENDPOINT]
]
)
->add(
ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY,
TextType::class,
[
'constraints' => [],
'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY),
'label' => $translator->trans('Google map API key', [], ColissimoPickupPoint::DOMAIN),
'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY]
]
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'configurecolissimopickuppoint';
}
}

View File

@@ -0,0 +1,121 @@
<?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 ColissimoPickupPoint\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Thelia\Form\BaseForm;
use Thelia\Model\Base\OrderQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Order;
use Thelia\Model\OrderStatusQuery;
use Thelia\Model\OrderStatus;
/**
* Class ExportOrder
* @package ColissimoPickupPoint\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(ColissimoPickupPoint::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 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 'exportcolissimopickuppointorder';
}
}

View File

@@ -0,0 +1,88 @@
<?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 ColissimoPickupPoint\Form;
use ColissimoPickupPoint\ColissimoPickupPoint;
use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
class FreeShippingForm 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(
'freeshipping',
CheckboxType::class,
[
'label' => Translator::getInstance()->trans('Activate free shipping: ', [], ColissimoPickupPoint::DOMAIN)
]
)
->add(
'freeshipping_from',
NumberType::class,
[
'required' => false,
'label' => Translator::getInstance()->trans("Free shipping from: ", [], ColissimoPickupPoint::DOMAIN),
'data' => ColissimoPickupPointFreeshippingQuery::create()->findOneById(1)->getFreeshippingFrom(),
'scale' => 2,
]
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'colissimopickuppointfreeshipping';
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace ColissimoPickupPoint\Form;
use ColissimoPickupPoint\ColissimoPickupPoint;
use Symfony\Component\Validator\Constraints;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
/**
* Class ImportForm
* @package ColissimoPickupPoint\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', [], ColissimoPickupPoint::DOMAIN),
'constraints' => [
new Constraints\NotBlank(),
new Constraints\File(['mimeTypes' => ['text/csv', 'text/plain']])
],
'label_attr' => ['for' => 'import_file']
]
);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace ColissimoPickupPoint\Form;
use ColissimoPickupPoint\ColissimoPickupPoint;
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('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.", [], ColissimoPickupPoint::DOMAIN));
}
}
public function verifyValidPrice($value, ExecutionContextInterface $context)
{
if (!preg_match("#^\d+\.?\d*$#", $value)) {
$context->addViolation(Translator::getInstance()->trans('The price value is not valid.', [], ColissimoPickupPoint::DOMAIN));
}
}
public function getName()
{
return 'colissimo_pickup_point_price_slices_create';
}
}