manu le bossu's backup

This commit is contained in:
Manuel Raynaud
2013-07-30 09:04:41 +02:00
parent 85007b54c5
commit 651f191314
5 changed files with 78 additions and 9 deletions

View File

@@ -23,10 +23,12 @@
namespace Thelia\Action;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Form\CartAdd;
use Thelia\Model\CartQuery;
use Thelia\Model\Cart as CartModel;
use Thelia\Model\Customer;
@@ -42,9 +44,33 @@ class Cart implements EventSubscriberInterface
*/
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

View File

@@ -6,9 +6,7 @@
<parameters>
<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>
</parameters>

View File

@@ -66,19 +66,22 @@ abstract class BaseForm {
$options["attr"]["thelia_name"] = $this->getName();
}
$this->formBuilder = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->addExtension(
$builder = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension());
if(!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension(
new CsrfExtension(
new SessionCsrfProvider(
$request->getSession(),
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
)
)
)
);
}
$this->formBuilder = $builder
->addExtension(new ValidatorExtension($validator))
->getFormFactory()
->createNamedBuilder($this->getName(), $type, $data, $options);
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
;
$this->buildForm();
@@ -91,6 +94,13 @@ abstract class BaseForm {
$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.
*

View File

@@ -79,7 +79,9 @@ class CartAdd extends BaseForm
new Constraints\Callback(array(
"methods" => array($this, "checkStock")
)),
new Constraints\GreaterThanOrEqual(0)
new Constraints\GreaterThanOrEqual(array(
"value" => 0
))
)
))
->add("append", "hidden")

View 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()
{
}
}