public function onCriteriaSearchSearchPage(HookRenderEvent $event)
 {
     $request = $this->getRequest();
     $params['category_id'] = $event->getArgument('category_id');
     $categorieTaxeRule = CriteriaSearchCategoryTaxRuleQuery::create()->findOneByCategoryId($params['category_id']);
     //Enable price filter only if a tax rule is chosen for this category
     if (null !== $categorieTaxeRule && null !== $categorieTaxeRule->getTaxRuleId()) {
         $params['price_filter'] = CriteriaSearch::getConfigValue('price_filter');
     }
     $params['brand_filter'] = CriteriaSearch::getConfigValue('brand_filter');
     $params['new_filter'] = CriteriaSearch::getConfigValue('new_filter');
     $params['promo_filter'] = CriteriaSearch::getConfigValue('promo_filter');
     $params['stock_filter'] = CriteriaSearch::getConfigValue('stock_filter');
     $this->criteriaSearchHandler->getLoopParamsFromQuery($params, $request);
     if (null !== $params['category_id']) {
         $categoryProductMaxPrice = ProductPriceQuery::create()->useProductSaleElementsQuery()->useProductQuery()->useProductCategoryQuery()->filterByCategoryId($params['category_id'])->endUse()->endUse()->endUse()->select('price')->orderBy('price', Criteria::DESC)->limit(1)->findOne();
         $params['max_price_filter'] = ceil($categoryProductMaxPrice / 10) * 10;
         if ($params['max_price_filter'] > 0) {
             $params['value_price_filter'] = [];
             $priceSlice = $params['max_price_filter'] / 4;
             for ($i = 0; $i <= $params['max_price_filter']; $i = $i + $priceSlice) {
                 $params['value_price_filter'][] = $i;
             }
         }
     }
     $event->add($this->render('criteria-search/search-page.html', $params));
 }
 public function onCategoryTabContent(HookRenderEvent $event)
 {
     $categoryTaxeRule = CriteriaSearchCategoryTaxRuleQuery::create()->findOneByCategoryId($event->getArgument('id'));
     if (null !== $categoryTaxeRule) {
         $params['taxe_rule_id'] = $categoryTaxeRule->getTaxRuleId();
     }
     $params['category_id'] = $event->getArgument('id');
     $event->add($this->render('criteria-search/category/category-edit.html', $params));
 }
 public function setCategoryTaxRule()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('CriteriaSearch'), AccessManager::UPDATE))) {
         return $response;
     }
     try {
         $searchCategoryTaxRule = CriteriaSearchCategoryTaxRuleQuery::create()->filterByCategoryId($this->getRequest()->get('category_id'))->findOneOrCreate();
         $searchCategoryTaxRule->setTaxRuleId($this->getRequest()->get('tax_rule_id'))->save();
     } catch (\Exception $e) {
         return new JsonResponse($e->getMessage(), 500);
     }
 }
 /**
  * Performs an INSERT on the database, given a CriteriaSearchCategoryTaxRule or Criteria object.
  *
  * @param mixed               $criteria Criteria or CriteriaSearchCategoryTaxRule object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(CriteriaSearchCategoryTaxRuleTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from CriteriaSearchCategoryTaxRule object
     }
     if ($criteria->containsKey(CriteriaSearchCategoryTaxRuleTableMap::ID) && $criteria->keyContainsValue(CriteriaSearchCategoryTaxRuleTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . CriteriaSearchCategoryTaxRuleTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = CriteriaSearchCategoryTaxRuleQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see CriteriaSearchCategoryTaxRule::setDeleted()
  * @see CriteriaSearchCategoryTaxRule::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(CriteriaSearchCategoryTaxRuleTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCriteriaSearchCategoryTaxRuleQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }