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} - + + + + + + {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} - + + @@ -26,22 +33,31 @@ {/elseloop} - - - - - - - - - - + + + + + + + + + + + + + +
{intl l="Product" d="recettes"}{intl l="Quantity needed" d="recettes"}{intl l="Quantity proposed" d="recettes"}
{$TITLE}{$UNITY}{$QUANTITY_NEEDED} {$QUANTITY_PROPOSED}{$UNITY}
- -
- -
- - - -
+ +
+ +
+ + + +
+ + + +
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 @@ + + + + + + + + + {loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id} + + + + + {/loop} + +
{intl l="Step" d="recettes"}{intl l="Detail" d="recettes"}
{$STEP}{$DESCRIPTION}
\ 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($('