manu le bossu's backup
This commit is contained in:
@@ -23,10 +23,12 @@
|
|||||||
|
|
||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
use Thelia\Core\HttpFoundation\Session\Session;
|
use Thelia\Core\HttpFoundation\Session\Session;
|
||||||
|
use Thelia\Form\CartAdd;
|
||||||
use Thelia\Model\CartQuery;
|
use Thelia\Model\CartQuery;
|
||||||
use Thelia\Model\Cart as CartModel;
|
use Thelia\Model\Cart as CartModel;
|
||||||
use Thelia\Model\Customer;
|
use Thelia\Model\Customer;
|
||||||
@@ -42,9 +44,33 @@ class Cart implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function addArticle(ActionEvent $event)
|
public function addArticle(ActionEvent $event)
|
||||||
{
|
{
|
||||||
|
$request = $event->getRequest();
|
||||||
|
|
||||||
|
if ($request->isMethod("post")) {
|
||||||
|
$cartAdd = new CartAdd($request);
|
||||||
|
} else {
|
||||||
|
$cartAdd = new CartAdd(
|
||||||
|
$request,
|
||||||
|
"form",
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'csrf_protection' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $cartAdd->getForm();
|
||||||
|
|
||||||
|
$form->bind($request);
|
||||||
|
|
||||||
|
if($form->isValid()) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var_dump($form->createView());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Delete specify article present into cart
|
* Delete specify article present into cart
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
<parameters>
|
<parameters>
|
||||||
<parameter key="thelia.actionEvent" type="collection">
|
<parameter key="thelia.actionEvent" type="collection">
|
||||||
<parameter key="addArticle">Thelia\Core\Event\CartEvent</parameter>
|
|
||||||
<parameter key="modifyArticle">Thelia\Core\Event\CartEvent</parameter>
|
|
||||||
<parameter key="deleteArticle">Thelia\Core\Event\CartEvent</parameter>
|
|
||||||
</parameter>
|
</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
|
|||||||
@@ -66,19 +66,22 @@ abstract class BaseForm {
|
|||||||
$options["attr"]["thelia_name"] = $this->getName();
|
$options["attr"]["thelia_name"] = $this->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->formBuilder = Forms::createFormFactoryBuilder()
|
$builder = Forms::createFormFactoryBuilder()
|
||||||
->addExtension(new HttpFoundationExtension())
|
->addExtension(new HttpFoundationExtension());
|
||||||
->addExtension(
|
if(!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
|
||||||
|
$builder->addExtension(
|
||||||
new CsrfExtension(
|
new CsrfExtension(
|
||||||
new SessionCsrfProvider(
|
new SessionCsrfProvider(
|
||||||
$request->getSession(),
|
$request->getSession(),
|
||||||
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
|
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
|
}
|
||||||
|
$this->formBuilder = $builder
|
||||||
->addExtension(new ValidatorExtension($validator))
|
->addExtension(new ValidatorExtension($validator))
|
||||||
->getFormFactory()
|
->getFormFactory()
|
||||||
->createNamedBuilder($this->getName(), $type, $data, $options);
|
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->buildForm();
|
$this->buildForm();
|
||||||
@@ -91,6 +94,13 @@ abstract class BaseForm {
|
|||||||
$this->form = $this->formBuilder->getForm();
|
$this->form = $this->formBuilder->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function cleanOptions($options)
|
||||||
|
{
|
||||||
|
unset($options["csrf_protection"]);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the absolute URL to redirect the user to if the form is successfully processed.
|
* Returns the absolute URL to redirect the user to if the form is successfully processed.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ class CartAdd extends BaseForm
|
|||||||
new Constraints\Callback(array(
|
new Constraints\Callback(array(
|
||||||
"methods" => array($this, "checkStock")
|
"methods" => array($this, "checkStock")
|
||||||
)),
|
)),
|
||||||
new Constraints\GreaterThanOrEqual(0)
|
new Constraints\GreaterThanOrEqual(array(
|
||||||
|
"value" => 0
|
||||||
|
))
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add("append", "hidden")
|
->add("append", "hidden")
|
||||||
|
|||||||
33
core/lib/Thelia/Tests/Form/CartAddTest.php
Normal file
33
core/lib/Thelia/Tests/Form/CartAddTest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?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 Thelia\Tests\Form;
|
||||||
|
|
||||||
|
|
||||||
|
class CartAddTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testSimpleAddingToCart()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user