Recettes : presque OK sur addToCart
This commit is contained in:
@@ -5,10 +5,11 @@
|
|||||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
<route id="recipe.save" path="/admin/module/Recettes/save" methods="post">
|
<route id="recipe.save" path="/admin/module/Recettes/save" methods="post">
|
||||||
<default key="_controller">Recettes\Controller\MainController::saveRecipe</default>
|
<default key="_controller">Recettes\Controller\BackController::saveRecipe</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
<route id="recipe.addtocart" path="/admin/module/Recettes/addtocart" methods="post">
|
<route id="recipe.addtocart" path="/admin/module/Recettes/addtocart" methods="post">
|
||||||
<default key="_controller">Recettes\Controller\MainController::addToCart</default>
|
<default key="_controller">Recettes\Controller\FrontController::addToCart</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
</routes>
|
</routes>
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ use Thelia\Tools\URL;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MainController
|
* Class BackController
|
||||||
* @package Recettes\Controller
|
* @package Recettes\Controller
|
||||||
*/
|
*/
|
||||||
class MainController extends BaseAdminController
|
class BackController extends BaseAdminController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function saveRecipe(Request $request)
|
public function saveRecipe(Request $request)
|
||||||
@@ -99,9 +99,4 @@ class MainController extends BaseAdminController
|
|||||||
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content"));
|
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addToCart(Request $request)
|
|
||||||
{
|
|
||||||
$order = $request->getSession()->getOrder();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
54
local/modules/Recettes/Controller/FrontController.php
Executable file
54
local/modules/Recettes/Controller/FrontController.php
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Recettes\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Thelia\Controller\Front\BaseFrontController;
|
||||||
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
|
use Thelia\Core\Event\Cart\CartEvent;
|
||||||
|
use Thelia\Exception\TheliaProcessException;
|
||||||
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FrontController
|
||||||
|
* @package Recettes\Controller
|
||||||
|
*/
|
||||||
|
class FrontController extends BaseFrontController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function addToCart(Request $request)
|
||||||
|
{
|
||||||
|
$parameters = $request->request;
|
||||||
|
$dispatcher = $this->getDispatcher();
|
||||||
|
$produitsHorsStock = false;
|
||||||
|
|
||||||
|
foreach ($parameters as $key=>$value) {
|
||||||
|
$string = explode("-", $key);
|
||||||
|
$pseId = $string[1];;
|
||||||
|
$qty = $string[3];
|
||||||
|
|
||||||
|
$productId = ProductSaleElementsQuery::create()->findOneById($pseId)->getProductId();
|
||||||
|
$stock = ProductSaleElementsQuery::create()->findOneById($pseId)->getQuantity();
|
||||||
|
|
||||||
|
if ($stock > 0) {
|
||||||
|
$eventAjout = new CartEvent($request->getSession()->getSessionCart($dispatcher));
|
||||||
|
$eventAjout
|
||||||
|
->setQuantity($qty)
|
||||||
|
->setProduct($productId)
|
||||||
|
->setProductSaleElementsId($pseId);
|
||||||
|
|
||||||
|
$dispatcher->dispatch(TheliaEvents::CART_ADDITEM, $eventAjout);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$produitsHorsStock = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $produitsHorsStock)
|
||||||
|
return new RedirectResponse(URL::getInstance()->absoluteUrl('/cart'));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,17 @@
|
|||||||
namespace Recettes\Loop;
|
namespace Recettes\Loop;
|
||||||
|
|
||||||
use Recettes\Model\RecipeProductsQuery;
|
use Recettes\Model\RecipeProductsQuery;
|
||||||
|
use Thelia\Action\AttributeAv;
|
||||||
use Thelia\Core\Template\Element\BaseLoop;
|
use Thelia\Core\Template\Element\BaseLoop;
|
||||||
use Thelia\Core\Template\Element\LoopResult;
|
use Thelia\Core\Template\Element\LoopResult;
|
||||||
use Thelia\Core\Template\Element\LoopResultRow;
|
use Thelia\Core\Template\Element\LoopResultRow;
|
||||||
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
|
||||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||||
|
use Thelia\Model\AttributeAvI18nQuery;
|
||||||
|
use Thelia\Model\AttributeCombinationQuery;
|
||||||
|
use Thelia\Model\AttributeI18n;
|
||||||
|
use Thelia\Model\AttributeI18nQuery;
|
||||||
use Thelia\Model\ProductI18nQuery;
|
use Thelia\Model\ProductI18nQuery;
|
||||||
use Thelia\Model\ProductSaleElementsQuery;
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
|
||||||
@@ -33,6 +38,8 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
|
|||||||
|
|
||||||
$pse = ProductSaleElementsQuery::create()->findOneById($product->getPseId());
|
$pse = ProductSaleElementsQuery::create()->findOneById($product->getPseId());
|
||||||
$productLabel = ProductI18nQuery::create()->findOneById($pse->getProductId())->getTitle();
|
$productLabel = ProductI18nQuery::create()->findOneById($pse->getProductId())->getTitle();
|
||||||
|
$attributeCombination = AttributeCombinationQuery::create()->findOneByProductSaleElementsId($product->getPseId());
|
||||||
|
$unity = AttributeAvI18nQuery::create()->findOneById($attributeCombination->getAttributeAvId())->getTitle();
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow($product);
|
$loopResultRow = new LoopResultRow($product);
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
@@ -41,6 +48,7 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
|
|||||||
->set("PRODUCT_LABEL", $productLabel)
|
->set("PRODUCT_LABEL", $productLabel)
|
||||||
->set("QUANTITY_NEEDED", $product->getQuantity())
|
->set("QUANTITY_NEEDED", $product->getQuantity())
|
||||||
->set("QUANTITY_PROPOSED", $product->getNbOfProducts())
|
->set("QUANTITY_PROPOSED", $product->getNbOfProducts())
|
||||||
|
->set('UNITY', $unity)
|
||||||
;
|
;
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,3 +79,6 @@ div.entete span b {
|
|||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
.bouton-imprimer {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<span class="difficulte"><b>{intl l='Difficulty' d='recettes'}</b><img src="{image file='assets/img/cellular.svg' source='Recettes'}" alt="Difficulty">{$label_difficulty}</span>
|
<span class="difficulte"><b>{intl l='Difficulty' d='recettes'}</b><img src="{image file='assets/img/cellular.svg' source='Recettes'}" alt="Difficulty">{$label_difficulty}</span>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<form id="form-recette" action="/admin/module/Recettes/addtocart" method="post">
|
<form id="form-recette" action="{url path='/admin/module/Recettes/addtocart'}" method="POST" class="clearfix">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="photo-principale col-md-4">
|
<div class="photo-principale col-md-4">
|
||||||
{loop type="image" name="image-loop" content=$content_id visible=true}
|
{loop type="image" name="image-loop" content=$content_id visible=true}
|
||||||
@@ -67,8 +67,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="cellule-large">{$PRODUCT_LABEL}</td>
|
<td class="cellule-large">{$PRODUCT_LABEL}</td>
|
||||||
<td class="cellule-etroite">{$QUANTITY_NEEDED}</td>
|
<td class="cellule-etroite">{$QUANTITY_NEEDED}</td>
|
||||||
<td class="cellule-etroite">{$QUANTITY_PROPOSED}<input type="hidden" id="quantity-{$PSE_ID}" value="{$QUANTITY_PROPOSED}"></td>
|
<td class="cellule-etroite">{$QUANTITY_PROPOSED} ({$UNITY})</td>
|
||||||
<td class="cellule-etroite"><input type="checkbox" id="product-{$PSE_ID}" name="selected-product" class="cellule-checkbox"></td>
|
<td class="cellule-etroite"><input type="checkbox" name="pseid-{$PSE_ID}-qty-{$QUANTITY_PROPOSED}" class="cellule-checkbox"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{/loop}
|
||||||
<tr>
|
<tr>
|
||||||
@@ -101,6 +101,9 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
</article>
|
</article>
|
||||||
<br>
|
<br>
|
||||||
|
<button type="button" class="btn btn-primary bouton-imprimer">{intl l="Print recipe" d="recettes"}</button>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/block}
|
{/block}
|
||||||
@@ -114,7 +117,7 @@
|
|||||||
|
|
||||||
$("#form-recette").off('submit').submit(function(ev) {
|
$("#form-recette").off('submit').submit(function(ev) {
|
||||||
|
|
||||||
if ($('input[name=selected-product]:checked').length === 0) {
|
if ($('input[name*=pseid-]:checked').length === 0) {
|
||||||
alert("Vous n'avez choisi aucun produit à rajouter dans votre panier.");
|
alert("Vous n'avez choisi aucun produit à rajouter dans votre panier.");
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user