Recettes : c'est bon sur l'ajout des produits, on ataque la liste des étapes

This commit is contained in:
2021-05-08 10:02:07 +02:00
parent 5e1fe56d56
commit 9a57b8f701
16 changed files with 246 additions and 178 deletions

View File

@@ -20,8 +20,9 @@
<route id="recipe.search_product" path="/admin/module/Recettes/search-product">
<default key="_controller">Recettes\Controller\BackController::searchProduct</default>
</route>
<route id="recipe.search_combination" path="/admin/module/Recettes/search-combination">
<default key="_controller">Recettes\Controller\BackController::searchCombination</default>
<route id="recipe.add_product" path="/admin/module/Recettes/add-product/{contentId}">
<default key="_controller">Recettes\Controller\BackController::addProduct</default>
<requirement key="contentId">\d+</requirement>
</route>
</routes>

View File

@@ -19,12 +19,18 @@ use Thelia\Core\Event\Content\ContentUpdateEvent;
use Thelia\Core\HttpFoundation\JsonResponse;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Form\BaseForm;
use Thelia\Model\AttributeAvI18n;
use Thelia\Model\AttributeAvI18nQuery;
use Thelia\Model\AttributeCombinationQuery;
use Thelia\Model\AttributeI18n;
use Thelia\Model\AttributeI18nQuery;
use Thelia\Model\AttributeQuery;
use Thelia\Model\ContentI18nQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductQuery;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Tools\URL;
@@ -37,9 +43,7 @@ class BackController extends BaseAdminController
public function saveRecipe(Request $request)
{
$error = "";
$con = Propel::getConnection();
$nouvelleRecette = false;
$form = new RecetteCreateForm($request);
try {
@@ -88,10 +92,40 @@ class BackController extends BaseAdminController
{
RecipeProductsQuery::create()->filterByRecipeId($recipeId)->filterByPseId($pseId)->delete();
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "#recipe"));
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "?current_tab=recipe"));
}
public function getData($product_id)
{
$locale = $this->getCurrentEditionLocale();
$combinations = [];
$con = Propel::getConnection();
$pse = ProductSaleElementsQuery::create()
->filterByProductId($product_id)
->find($con);
foreach ($pse as $pseItem)
{
$combinationsArray = AttributeCombinationQuery::create()
->filterByProductSaleElements($pseItem)
->find($con);
foreach ($combinationsArray as $combination) {
$pseId = $pseItem->getId();
$label = AttributeAvI18nQuery::create()
->filterByLocale($locale)
->findOneById($combination->getAttributeAvId())
->getTitle();
array_push($combinations, [$pseId => $label]);
}
}
return $combinations;
}
public function searchProduct()
{
$locale = $this->getCurrentEditionLocale();
@@ -115,17 +149,13 @@ class BackController extends BaseAdminController
foreach ($data as $item) {
$combinations = AttributeCombinationQuery::create()
->filterByProductSaleElementsId($item->getId())
$item
$combinations = self::getData($item['product.id']);
$result[] = [
'id' => $item[ProductTableMap::COL_ID],
'ref' => $item[ProductTableMap::COL_REF],
'title' => $item['title'],
'combinations' => []
'combinations' => $combinations,
];
}
}
@@ -133,27 +163,22 @@ class BackController extends BaseAdminController
return JsonResponse::create($result);
}
public function searchCombination()
{
$locale = $this->getCurrentEditionLocale();
$ref = $this->getRequest()->get('query', null);
$result = [];
return JsonResponse::create($result);
}
/*
public function addProduct($contentId)
{
$productId = (int) $this->getRequest()->get('product_id');
$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 AgendaRelatedProduct())
->setProductId($productId)
->setContentId($contentId)
(new RecipeProducts())
->setRecipeId($recipeId)
->setPseId($pseId)
->setQuantity($quantityNeeded)
->setNbOfProducts($quantityProposed)
->save();
return $this->render('ajax/related-products', [ 'content_id' => $contentId ]);
}
*/
}

View File

@@ -8,7 +8,7 @@ return array(
'Number of people' => 'Nombre de couverts',
'Product' => 'Produit',
'Quantity' => 'Quantité',
'Summary' => 'Détail',
'Summary' => 'Petit résumé de la recette',
'Other ingredients' => 'Ingrédients supplémentaires',
'Ingredients' => 'Ingrédients',
'Ingredient' => 'Nos produits',
@@ -22,4 +22,5 @@ return array(
'Some products may not be in stock' => '* ce produit n\'est plus en stock, désolé',
'Name' => 'Notre recette',
'Created on' => 'Rédigée le',
'Save recipe' => 'Sauvegarder la recette',
);

View File

@@ -1,15 +1,22 @@
{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"}
{assign var="recipe_id" value="$ID"}
<input type="hidden" id="recipe_id" value="{$ID}">
{/loop}
<table class="table table-condensed">
{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"}
{assign var="recipe_id" value="$ID"}
{/loop}
<thead>
<th>{intl l="Product" d="recettes"}</th>
<th>{intl l="Quantity needed" d="recettes"}</th>
<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}
{loop type="product" visible="*" name="related-product" id=$PRODUCT_ID}
<tr>
<td>{$TITLE}<input type="hidden" value="{$PSE_ID}"</input></td>
<td>{$UNITY}</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>
@@ -26,22 +33,31 @@
</tr>
{/elseloop}
<tr>
<td colspan="3">
<input class="form-control" type="text" id="product_ref" autocomplete="off" data-content-id="{$recipe_id}" placeholder="Indiquez une référence de produit">
</td>
</tr>
<tr>
<td colspan="3">
<input class="form-control" type="text" id="pse_id" autocomplete="off" data-content-id="{$pse_id}" placeholder="Choisissez une déclinaison">
</td>
</tr>
<tr>
<td colspan="2">
<input class="form-control" type="text" id="quantity" autocomplete="off" placeholder="Saisir une quantité">
</td>
<td class="text-center">
<a href="{url path='/admin/module/Recettes/add-product/%recipeId' recipeId=$recipe_id}" class="btn btn-sm btn-primary add-product"><i class="glyphicon glyphicon-plus-sign"></i></a>
</td>
</tr>
<tr>
<td colspan="3">
<input class="form-control" type="text" id="product_ref" autocomplete="off" data-content-id="{$recipe_id}" placeholder="Saisir une référence de produit">
</td>
</tr>
<tr>
<td colspan="3">
<input class="form-control" type="text" id="quantity_needed" autocomplete="off" placeholder="Quantité nécessaire (texte libre)">
</td>
</tr>
<tr>
<td colspan="3">
<label class="control-label">Choix de la déclinaison</label>
<input type="hidden" id="combinations" name="combinations" value="---">
<select id="select-combination" name="select-combination" class="form-control input-sm pse-option">
</select>
</td>
</tr>
<tr>
<td colspan="2">
<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>
</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,16 @@
<input type="hidden" id="recipe_id" value="{$recipe_id}">
<table class="table table-condensed">
<thead>
<th>{intl l="Step" d="recettes"}</th>
<th colspan="2">{intl l="Detail" d="recettes"}</th>
</thead>
<tbody>
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
<tr>
<td>{$STEP}</td>
<td>{$DESCRIPTION}</td>
</tr>
{/loop}
</tbody>
</table>

View File

@@ -24,46 +24,53 @@
},
afterSelect: function (item) {
this.$element[0].value = item.title
$('#product_ref').data('product-id', item.id);
$("#pse_id").attr('disabled', null);
}
});
$("#select-combination").attr('disabled', null);
$("#quantity_needed").attr('disabled', null);
$('#pse_id').typeahead({
source: function (query, process) {
return $.getJSON(
'{url path="/admin/module/Recettes/search-combination"}',
{
query: query
},
function (data) {
process(data)
$('#select-combination')
.empty()
.append($('<option>').val("").text("Choisissez une déclinaison"));
item.combinations.forEach(function(key, value) {
for (var id in key) {
$('#select-combination')
.append($('<option>').val(id).text(key[id]));
}
);
},
displayText: function (item) {
return item.title
},
afterSelect: function (item) {
this.$element[0].value = item.title
$('#product_ref').data('product-id', item.id);
$("#pse_id").attr('disabled', null);
});
}
});
$('#select-combination').change(function() {
var option = $("#select-combination option:selected").val();
if (option != "") {
$("#quantity_proposed").attr('disabled', null);
$('#product_ref').data('pse-id', option);
}
else
$("#quantity_proposed").attr('disabled', 'disabled');
});
$('#quantity_proposed').change(function() {
if ($('#quantity_proposed').val() <= 0) {
alert("Veuillez saisir une quantité positive.");
$("#quantity_proposed").attr('disabled', null);
}
else
$(".add-product").attr('disabled', null);
});
}
$(document).on('click', '.add-product', function(event) {
event.preventDefault();
$('#related-products-block').load(
$(this).attr('href'),
{
product_id: $('#product_ref').data('product-id')
quantity_needed: $('#quantity_needed').val(),
pse_id: $('#product_ref').data('pse-id'),
quantity_proposed: $('#quantity_proposed').val(),
recipe_id : $("#recipe_id").val()
},
function() {
setupTypeAhead();
@@ -73,8 +80,11 @@
setupTypeAhead();
$("#pse_id").attr('disabled', 'disabled');
$("#quantity").attr('disabled', 'disabled');
// Par défaut, les champs de saisie du produit sont désactivés.
$("#quantity_needed").attr('disabled', 'disabled');
$("#select-combination").attr('disabled', 'disabled');
$("#quantity_proposed").attr('disabled', 'disabled');
$(".add-product").attr('disabled', 'disabled');
});

View File

@@ -8,126 +8,124 @@
{assign var="other_ingredients" value=$OTHER_INGREDIENTS}
{/loop}
<div id="wrapper" class="container">
<div class="row">
{form name="recette_create_form"}
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form}>
<div class="form-container">
{form name="recette_create_form"}
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form} class="clearfix">
{form_hidden_fields form=$form}
{form_hidden_fields form=$form}
{form_field form=$form field="content_id"}
<input type="hidden" name="{$name}" value="{$content_id}">
{form_field form=$form field="content_id"}
<input type="hidden" name="{$name}" value="{$content_id}">
{/form_field}
<br>
<div class="col-md-8">
{form_field form=$form field="title"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control large" name="{$name}" value="{$title}" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="title"}{$message}{/form_error}
{/form_field}
<br>
<div class="col-md-8">
{form_field form=$form field="title"}
<div class="form-group form-inline">
{form_field form=$form field="summary"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
</label>
{if $required}<span class="required">*</span>{/if}
<textarea id="summary" name="{$name}" rows="10" class="form-control wysiwyg">{$summary}</textarea>
</div>
{form_error form=$form field="summary"}{$message}{/form_error}
{/form_field}
<div class="row">
{form_field form=$form field="difficulty"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control large" name="{$name}" value="{$title}" {if $required}required{/if} />&nbsp
<select id="{$label_attr.for}" name="{$name}">
<option value="0" {if $difficulty eq 0}selected{/if}>Facile</option>
<option value="1" {if $difficulty eq 1}selected{/if}>Moyen</option>
<option value="2" {if $difficulty eq 2}selected{/if}>Difficile</option>
</select>
</div>
{form_error form=$form field="title"}{$message}{/form_error}
{form_error form=$form field="difficulty"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="summary"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
</label>
{if $required}<span class="required">*</span>{/if}
<textarea id="summary" name="{$name}" rows="10" class="form-control wysiwyg">{$summary}</textarea>
</div>
{form_error form=$form field="summary"}{$message}{/form_error}
{/form_field}
<div class="row">
{form_field form=$form field="difficulty"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<select id="{$label_attr.for}" name="{$name}">
<option value="0" {if $difficulty eq 0}selected{/if}>Facile</option>
<option value="1" {if $difficulty eq 1}selected{/if}>Moyen</option>
<option value="2" {if $difficulty eq 2}selected{/if}>Difficile</option>
</select>
</div>
{form_error form=$form field="difficulty"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="people"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" value="{$people}" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="people"}{$message}{/form_error}
{/form_field}
</div>
<div class="row">
{form_field form=$form field="preparation_time"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$preparation_time}" {if $required}required{/if} />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
{form_error form=$form field="preparation_time"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="cooking_time"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$cooking_time}" {if $required}required{/if} />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
{form_error form=$form field="cooking_time"}{$message}{/form_error}
{/form_field}
</div>
{form_field form=$form field="other_ingredients"}
<div class="form-group form-inline">
{form_field form=$form field="people"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
{if $required}<span class="required">*</span>{/if}
<textarea id="attr-recipe" name="{$name}" rows="10" class="form-control wysiwyg">{$other_ingredients}</textarea>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" value="{$people}" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="other_ingredients"}{$message}{/form_error}
{form_error form=$form field="people"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-4 form-group">
<label class="control-label">Produits attachés</label>
<div id="related-products-block">
{include file="ajax/related-products.html" content_id=$content_id}
<div class="row">
{form_field form=$form field="preparation_time"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$preparation_time}" {if $required}required{/if} />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
<br>
<label class="control-label">Etapes de la recette</label>
<div id="steps-block">
{include file="ajax/steps.html"}
{form_error form=$form field="preparation_time"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="cooking_time"}
<div class="col-md-6 form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$cooking_time}" {if $required}required{/if} />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
{form_error form=$form field="cooking_time"}{$message}{/form_error}
{/form_field}
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">{intl l="Save" d="recettes"}</button>
{form_field form=$form field="other_ingredients"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
{if $required}<span class="required">*</span>{/if}
<textarea id="attr-recipe" name="{$name}" rows="10" class="form-control wysiwyg">{$other_ingredients}</textarea>
</div>
</form>
{/form}
{form_error form=$form field="other_ingredients"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-4 form-group">
<label class="control-label">Produits attachés</label>
<div id="related-products-block">
{include file="ajax/related-products.html" content_id=$content_id}
</div>
<br>
<label class="control-label">Etapes de la recette</label>
<div id="steps-block">
{include file="ajax/steps.html" content_id=$content_id}
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">{intl l="Save recipe" d="recettes"}</button>
</div>
</form>
{/form}
</div>

View File

@@ -132,6 +132,7 @@ td.table-liste-recettes-image {
text-align: right;
width: auto;
vertical-align: middle !important;
margin: auto;
}
.table-liste-recettes-image img {
width: 65px;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB