validateForm($form); $data = $formValidate->getData(); $contentId = $data['content_id']; $title = $data['title']; $summary = $data['summary']; $difficulty = $data['difficulty']; $numberPeople = $data['people']; $preparationTime = $data['preparation_time']; $cookingTime = $data['cooking_time']; $otherIngredients = $data['other_ingredients']; if (null !== $title && null !== $contentId && null !== $difficulty && null !== $numberPeople && null !== $preparationTime) { $recipe = RecipeQuery::create()->findOneByContentId($contentId); if (null === $recipe) $recipe = new Recipe(); else $recipeId = $recipe->getId(); $recipe->setContentId($contentId); $recipe->setSummary($summary); $recipe->setTitle($title); $recipe->setDifficulty($difficulty); $recipe->setPeople($numberPeople); $recipe->setPreparationTime($preparationTime); $recipe->setCookingTime($cookingTime); $recipe->setOtherIngredients($otherIngredients); $recipe->save($con); $con->commit(); return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "#recipe")); } } catch (\Exception $e) { $error = $e->getMessage(); } return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content")); } public function removeProduct($recipeId, $pseId, $contentId) { RecipeProductsQuery::create()->filterByRecipeId($recipeId)->filterByPseId($pseId)->delete(); return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "#recipe")); } public function searchProduct() { $locale = $this->getCurrentEditionLocale(); $ref = $this->getRequest()->get('query', null); $result = []; if (! empty($ref)) { $data = ProductQuery::create() ->filterByRef("%$ref%", Criteria::LIKE) ->orderByRef() ->useI18nQuery($locale) ->withColumn(ProductI18nTableMap::COL_TITLE, 'title') ->endUse() ->limit(15) ->select([ ProductTableMap::COL_ID, ProductTableMap::COL_REF, 'title' ]) ->find(); foreach ($data as $item) { $combinations = AttributeCombinationQuery::create() ->filterByProductSaleElementsId($item->getId()) $item $result[] = [ 'id' => $item[ProductTableMap::COL_ID], 'ref' => $item[ProductTableMap::COL_REF], 'title' => $item['title'], 'combinations' => [] ]; } } 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'); (new AgendaRelatedProduct()) ->setProductId($productId) ->setContentId($contentId) ->save(); return $this->render('ajax/related-products', [ 'content_id' => $contentId ]); } */ }