diff --git a/local/modules/Recettes/Config/routing.xml b/local/modules/Recettes/Config/routing.xml index cd283f27..056eb3cd 100644 --- a/local/modules/Recettes/Config/routing.xml +++ b/local/modules/Recettes/Config/routing.xml @@ -20,8 +20,9 @@ Recettes\Controller\BackController::searchProduct - - Recettes\Controller\BackController::searchCombination + + Recettes\Controller\BackController::addProduct + \d+ diff --git a/local/modules/Recettes/Controller/BackController.php b/local/modules/Recettes/Controller/BackController.php index c38ca624..5db8e09d 100755 --- a/local/modules/Recettes/Controller/BackController.php +++ b/local/modules/Recettes/Controller/BackController.php @@ -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 ]); } - */ + } diff --git a/local/modules/Recettes/I18n/fr_FR.php b/local/modules/Recettes/I18n/fr_FR.php index 6b3a5363..0e94af20 100644 --- a/local/modules/Recettes/I18n/fr_FR.php +++ b/local/modules/Recettes/I18n/fr_FR.php @@ -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', ); diff --git a/local/modules/Recettes/templates/backOffice/default/ajax/related-products.html b/local/modules/Recettes/templates/backOffice/default/ajax/related-products.html index 6a3b926e..a821ca1c 100644 --- a/local/modules/Recettes/templates/backOffice/default/ajax/related-products.html +++ b/local/modules/Recettes/templates/backOffice/default/ajax/related-products.html @@ -1,15 +1,22 @@ +{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"} + {assign var="recipe_id" value="$ID"} + +{/loop} + - - {loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"} - {assign var="recipe_id" value="$ID"} - {/loop} - + + {intl l="Product" d="recettes"} + {intl l="Quantity needed" d="recettes"} + {intl l="Quantity proposed" d="recettes"} + + {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} {$TITLE} - {$UNITY} + {$QUANTITY_NEEDED} {$QUANTITY_PROPOSED} + {$UNITY} @@ -26,22 +33,31 @@ {/elseloop} - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + Choix de la déclinaison + + + + + + + + + + + + + + diff --git a/local/modules/Recettes/templates/backOffice/default/ajax/steps.html b/local/modules/Recettes/templates/backOffice/default/ajax/steps.html index e69de29b..7c380804 100644 --- a/local/modules/Recettes/templates/backOffice/default/ajax/steps.html +++ b/local/modules/Recettes/templates/backOffice/default/ajax/steps.html @@ -0,0 +1,16 @@ + + + + + {intl l="Step" d="recettes"} + {intl l="Detail" d="recettes"} + + + {loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id} + + {$STEP} + {$DESCRIPTION} + + {/loop} + + \ No newline at end of file diff --git a/local/modules/Recettes/templates/backOffice/default/recette-tab-js.html b/local/modules/Recettes/templates/backOffice/default/recette-tab-js.html index 3b53cd0b..cc84971e 100644 --- a/local/modules/Recettes/templates/backOffice/default/recette-tab-js.html +++ b/local/modules/Recettes/templates/backOffice/default/recette-tab-js.html @@ -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($('').val("").text("Choisissez une déclinaison")); + + item.combinations.forEach(function(key, value) { + for (var id in key) { + $('#select-combination') + .append($('').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'); }); diff --git a/local/modules/Recettes/templates/backOffice/default/recette-tab.html b/local/modules/Recettes/templates/backOffice/default/recette-tab.html index f7776e2c..91ba7c2b 100644 --- a/local/modules/Recettes/templates/backOffice/default/recette-tab.html +++ b/local/modules/Recettes/templates/backOffice/default/recette-tab.html @@ -8,126 +8,124 @@ {assign var="other_ingredients" value=$OTHER_INGREDIENTS} {/loop} - - - {form name="recette_create_form"} - + + {form name="recette_create_form"} + - {form_hidden_fields form=$form} + {form_hidden_fields form=$form} - {form_field form=$form field="content_id"} - + {form_field form=$form field="content_id"} + + {/form_field} + + + + {form_field form=$form field="title"} + + + {intl l=$label d='recettes'} + {if $required}*{/if} + + +   + + {form_error form=$form field="title"}{$message}{/form_error} {/form_field} - - - {form_field form=$form field="title"} - + {form_field form=$form field="summary"} + + + {intl l=$label d='recettes'} + + {if $required}*{/if} + {$summary} + + {form_error form=$form field="summary"}{$message}{/form_error} + {/form_field} + + + {form_field form=$form field="difficulty"} + {intl l=$label d='recettes'} {if $required}*{/if} - -   + + Facile + Moyen + Difficile + - {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"} - - - {intl l=$label d='recettes'} - - {if $required}*{/if} - {$summary} - - {form_error form=$form field="summary"}{$message}{/form_error} - {/form_field} - - - {form_field form=$form field="difficulty"} - - - {intl l=$label d='recettes'} - {if $required}*{/if} - - - Facile - Moyen - Difficile - - - {form_error form=$form field="difficulty"}{$message}{/form_error} - {/form_field} - - {form_field form=$form field="people"} - - - {intl l=$label d='recettes'} - {if $required}*{/if} - -   - - {form_error form=$form field="people"}{$message}{/form_error} - {/form_field} - - - - {form_field form=$form field="preparation_time"} - - - {intl l=$label d='recettes'} - {if $required}*{/if} - -   - {$label_attr.help} - - {form_error form=$form field="preparation_time"}{$message}{/form_error} - {/form_field} - - - {form_field form=$form field="cooking_time"} - - - {intl l=$label d='recettes'} - {if $required}*{/if} - -   - {$label_attr.help} - - {form_error form=$form field="cooking_time"}{$message}{/form_error} - {/form_field} - - - {form_field form=$form field="other_ingredients"} - + {form_field form=$form field="people"} + {intl l=$label d='recettes'} {if $required}*{/if} - {if $required}*{/if} - {$other_ingredients} +   - {form_error form=$form field="other_ingredients"}{$message}{/form_error} + {form_error form=$form field="people"}{$message}{/form_error} {/form_field} - - Produits attachés - - {include file="ajax/related-products.html" content_id=$content_id} + + {form_field form=$form field="preparation_time"} + + + {intl l=$label d='recettes'} + {if $required}*{/if} + +   + {$label_attr.help} - - Etapes de la recette - - {include file="ajax/steps.html"} + {form_error form=$form field="preparation_time"}{$message}{/form_error} + {/form_field} + + + {form_field form=$form field="cooking_time"} + + + {intl l=$label d='recettes'} + {if $required}*{/if} + +   + {$label_attr.help} + {form_error form=$form field="cooking_time"}{$message}{/form_error} + {/form_field} - - {intl l="Save" d="recettes"} + {form_field form=$form field="other_ingredients"} + + + {intl l=$label d='recettes'} + {if $required}*{/if} + + {if $required}*{/if} + {$other_ingredients} - - {/form} + {form_error form=$form field="other_ingredients"}{$message}{/form_error} + {/form_field} + + + Produits attachés + + {include file="ajax/related-products.html" content_id=$content_id} + + + Etapes de la recette + + {include file="ajax/steps.html" content_id=$content_id} + + + + + {intl l="Save recipe" d="recettes"} + + + {/form} \ No newline at end of file diff --git a/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css b/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css index 75844d0f..a2b898d5 100644 --- a/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css +++ b/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css @@ -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; diff --git a/templates/frontOffice/custom/assets/dist/img/218x146.png b/templates/frontOffice/custom/assets/dist/img/218x146.png index 6e964a2c..07f043b1 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/218x146.png and b/templates/frontOffice/custom/assets/dist/img/218x146.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/280x196.png b/templates/frontOffice/custom/assets/dist/img/280x196.png index 592012de..0df3c940 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/280x196.png and b/templates/frontOffice/custom/assets/dist/img/280x196.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/email/header.jpg b/templates/frontOffice/custom/assets/dist/img/email/header.jpg index 8cdff684..c80e1652 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/email/header.jpg and b/templates/frontOffice/custom/assets/dist/img/email/header.jpg differ diff --git a/templates/frontOffice/custom/assets/dist/img/email/logo.png b/templates/frontOffice/custom/assets/dist/img/email/logo.png index 8f14ec09..6cb56aea 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/email/logo.png and b/templates/frontOffice/custom/assets/dist/img/email/logo.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/favicon.png b/templates/frontOffice/custom/assets/dist/img/favicon.png index e481a99d..5669f3e7 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/favicon.png and b/templates/frontOffice/custom/assets/dist/img/favicon.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/flags/logo-npdc.png b/templates/frontOffice/custom/assets/dist/img/flags/logo-npdc.png index 402458a3..c02e3d5f 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/flags/logo-npdc.png and b/templates/frontOffice/custom/assets/dist/img/flags/logo-npdc.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/logo.png b/templates/frontOffice/custom/assets/dist/img/logo.png index 8f14ec09..6cb56aea 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/logo.png and b/templates/frontOffice/custom/assets/dist/img/logo.png differ diff --git a/templates/frontOffice/custom/assets/dist/img/product/1/118x85.png b/templates/frontOffice/custom/assets/dist/img/product/1/118x85.png index eb018927..cf9e98b4 100644 Binary files a/templates/frontOffice/custom/assets/dist/img/product/1/118x85.png and b/templates/frontOffice/custom/assets/dist/img/product/1/118x85.png differ