Correction de quelques bogues dans Recettes (backOffice)
This commit is contained in:
@@ -23,9 +23,10 @@
|
||||
<default key="_controller">Recettes\Controller\BackController::searchProduct</default>
|
||||
</route>
|
||||
|
||||
<route id="recipe.add_product" path="/admin/module/Recettes/add-product/{contentId}">
|
||||
<route id="recipe.add_product" path="/admin/module/Recettes/add-product/{contentId}/{recipeId}">
|
||||
<default key="_controller">Recettes\Controller\BackController::addProduct</default>
|
||||
<requirement key="contentId">\d+</requirement>
|
||||
<requirement key="recipeId">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="recipe.add_step" path="/admin/module/Recettes/add-step" methods="post">
|
||||
|
||||
@@ -165,11 +165,10 @@ class BackController extends BaseAdminController
|
||||
}
|
||||
|
||||
|
||||
public function addProduct($contentId)
|
||||
public function addProduct($contentId, $recipeId)
|
||||
{
|
||||
$pseId = (int) $this->getRequest()->get('pse_id');
|
||||
$quantityNeeded = (string) $this->getRequest()->get('quantity_needed');
|
||||
$recipeId = (int) $this->getRequest()->get('recipe_id');
|
||||
$quantityProposed = (int) $this->getRequest()->get('quantity_proposed');
|
||||
|
||||
(new RecipeProducts())
|
||||
@@ -179,7 +178,7 @@ class BackController extends BaseAdminController
|
||||
->setNbOfProducts($quantityProposed)
|
||||
->save();
|
||||
|
||||
return $this->render('includes/related-products', [ 'content_id' => $contentId ]);
|
||||
return $this->render('includes/related-products', [ 'recipe_id' => $recipeId, 'content_id' => $contentId ]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace Recettes\EventListener;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Recettes\Model\RecipeProductsQuery;
|
||||
use Recettes\Model\RecipeQuery;
|
||||
use Recettes\Model\RecipeStepsQuery;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Action\BaseAction;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\Event\ContentEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
|
||||
@@ -36,26 +38,35 @@ class ContentListener extends BaseAction implements EventSubscriberInterface
|
||||
$con = Propel::getConnection();
|
||||
|
||||
$contentId = $this->request->request->get('content_id');
|
||||
$recipeId = RecipeQuery::create()
|
||||
->findOneByContentId($contentId)
|
||||
->getId();
|
||||
try {
|
||||
$recipe = RecipeQuery::create()
|
||||
->findOneByContentId($contentId);
|
||||
if ($recipe)
|
||||
$recipeId = $recipe->getId();
|
||||
else
|
||||
return;
|
||||
|
||||
if ($recipeId)
|
||||
{
|
||||
RecipeStepsQuery::create()
|
||||
->filterByRecipeId($recipeId)
|
||||
->find($con)
|
||||
->delete();
|
||||
if ($recipeId)
|
||||
{
|
||||
RecipeStepsQuery::create()
|
||||
->filterByRecipeId($recipeId)
|
||||
->find($con)
|
||||
->delete();
|
||||
|
||||
RecipeProductsQuery::create()
|
||||
->filterByRecipeId($recipeId)
|
||||
->find($con)
|
||||
->delete();
|
||||
RecipeProductsQuery::create()
|
||||
->filterByRecipeId($recipeId)
|
||||
->find($con)
|
||||
->delete();
|
||||
|
||||
RecipeQuery::create()
|
||||
->findOneByContentId($contentId)
|
||||
->delete();
|
||||
RecipeQuery::create()
|
||||
->findOneByContentId($contentId)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Tlog::getInstance()->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,16 @@ class RecetteCreateForm extends BaseForm
|
||||
"content_id",
|
||||
"integer",
|
||||
[
|
||||
"constraints" => [ new NotBlank() ]
|
||||
"constraints" => [ new NotBlank() ],
|
||||
"required" => true
|
||||
]
|
||||
)
|
||||
->add(
|
||||
"recipe_id",
|
||||
"integer",
|
||||
[
|
||||
"constraints" => [ new NotBlank() ],
|
||||
"required" => true
|
||||
]
|
||||
)
|
||||
->add(
|
||||
|
||||
@@ -22,7 +22,7 @@ use Thelia\Model\ProductSaleElementsQuery;
|
||||
*/
|
||||
class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
public $countable = false;
|
||||
public $countable = true;
|
||||
public $timestampable = false;
|
||||
public $versionable = false;
|
||||
|
||||
@@ -83,9 +83,10 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
$products = RecipeProductsQuery::create();
|
||||
|
||||
if (null != $recipeId = $this->getRecipeId()) {
|
||||
if (null != $recipeId = $this->getRecipeId())
|
||||
$products->filterByRecipeId($recipeId);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
@@ -57,9 +57,11 @@ class StepsLoop extends BaseLoop implements PropelSearchLoopInterface
|
||||
{
|
||||
$steps = RecipeStepsQuery::create();
|
||||
|
||||
if (null != $id = $this->getRecipeId()) {
|
||||
if (null != $id = $this->getRecipeId())
|
||||
$steps->filterByRecipeId($id);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
|
||||
$steps->orderByStep();
|
||||
|
||||
return $steps;
|
||||
|
||||
@@ -5,19 +5,22 @@
|
||||
<th colspan="2">{intl l="Quantity proposed" d="recettes"}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{loop type="recipe_products" name="products-loop" recipe_id=$recipe_id}
|
||||
{loop type="product" visible="*" name="related-product" id=$PRODUCT_ID}
|
||||
<tr>
|
||||
<td>{$TITLE}<input type="hidden" value="{$PSE_ID}"</input></td>
|
||||
<td>{$QUANTITY_NEEDED}</td>
|
||||
<td>{$QUANTITY_PROPOSED}</td>
|
||||
<td>{$UNITY}</td>
|
||||
<td class="text-center">
|
||||
<a href="{url path='/admin/module/Recettes/remove-product/%recipeId/%pseId/%contentId' recipeId=$recipe_id pseId=$PSE_ID contentId=$content_id}" class="delete-product"><i class="glyphicon glyphicon-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{ifloop rel="products-loop"}
|
||||
{loop type="recipe_products" name="products-loop" recipe_id=$recipe_id}
|
||||
{loop type="product" visible="*" name="related-product" id=$PRODUCT_ID}
|
||||
<tr>
|
||||
<td>{$TITLE}<input type="hidden" value="{$PSE_ID}"</input></td>
|
||||
<td>{$QUANTITY_NEEDED}</td>
|
||||
<td>{$QUANTITY_PROPOSED}</td>
|
||||
<td>{$UNITY}</td>
|
||||
<td class="text-center">
|
||||
<a href="{url path='/admin/module/Recettes/remove-product/%recipeId/%pseId/%contentId' recipeId=$recipe_id pseId=$PSE_ID contentId=$content_id}" class="delete-product"><i class="glyphicon glyphicon-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{/loop}
|
||||
{/loop}
|
||||
{/loop}
|
||||
{/ifloop}
|
||||
{elseloop rel="products-loop"}
|
||||
<tr>
|
||||
<td colspan="99">
|
||||
@@ -51,7 +54,7 @@
|
||||
<input class="form-control" type="text" id="quantity_proposed" autocomplete="off" placeholder="Quantité proposée, en fonction de la déclinaison">
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="{url path='/admin/module/Recettes/add-product/%contentId' contentId=$content_id}" class="btn btn-sm btn-primary add-product"><i class="glyphicon glyphicon-plus-sign"></i></a>
|
||||
<a href="{url path='/admin/module/Recettes/add-product/%contentId/%recipeId' contentId=$content_id recipeId=$recipe_id}" class="btn btn-sm btn-primary add-product"><i class="glyphicon glyphicon-plus-sign"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
{form_field form=$form field="content_id"}
|
||||
<input type="hidden" name="{$name}" value="{$content_id}">
|
||||
{/form_field}
|
||||
<input type="hidden" class="form-control" name="recipe_id" value="{$recipe_id}">
|
||||
{form_field form=$form field="recipe_id"}
|
||||
<input type="hidden" class="form-control" name="{$name}" value="{$recipe_id}">
|
||||
{/form_field}
|
||||
<br>
|
||||
<div class="col-md-8">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user