/** * this method returns a Propel ModelCriteria * * @return \Propel\Runtime\ActiveQuery\ModelCriteria */ public function buildModelCriteria() { $search = TntPriceWeightQuery::create(); if (null !== ($areaId = $this->getAreaId())) { $search->filterByAreaId($areaId, Criteria::IN); } if (null !== ($tntProductCodes = $this->getTntProductCode())) { $search->filterByTntProductCode(explode(',', $tntProductCodes), Criteria::IN); } if (null != ($orderBys = $this->getOrderBy())) { foreach ($orderBys as $orderBy) { switch ($orderBy) { case "id": $search->orderById(); break; case "area_id": $search->orderByAreaId(); break; case "tnt_product_code": $search->orderByTntProductCode(); break; case "tnt_product_label": $search->orderByTntProductLabel(); break; } } } return $search; }
public function saveAction() { $errorMessage = null; $current_tab = $this->getRequest()->get('current_tab'); if ($current_tab != "weight") { return parent::saveAction(); } $form = new TNTPriceWeightForm($this->getRequest()); try { $formValidate = $this->validateForm($form); TNTFrance::setConfigValue(TNTFranceConfigValue::FREE_SHIPPING, $formValidate->get(TNTFranceConfigValue::FREE_SHIPPING)->getData() ? $formValidate->get(TNTFranceConfigValue::FREE_SHIPPING)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_FUEL, $formValidate->get(TNTFranceConfigValue::SURCHARGE_FUEL)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_FUEL)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE, $formValidate->get(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE, $formValidate->get(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, $formValidate->get(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK, $formValidate->get(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION, $formValidate->get(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE, $formValidate->get(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY, $formValidate->get(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING, $formValidate->get(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING)->getData() : 0); //Save the contracted rates $prices = $formValidate->get(TNTFranceConfigValue::PRICE_ONE_KG)->getData(); $priceKgSups = $formValidate->get(TNTFranceConfigValue::PRICE_KG_SUP)->getData(); foreach ($prices as $id => $price) { if (null != ($tntPriceWeight = TntPriceWeightQuery::create()->findPk($id))) { $tntPriceWeight->setPrice($price); if (is_array($priceKgSups) && array_key_exists($id, $priceKgSups)) { $tntPriceWeight->setPriceKgSup($priceKgSups[$id]); } $tntPriceWeight->save(); } } } catch (FormValidationException $ex) { // Invalid data entered $errorMessage = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], [], TNTFrance::MESSAGE_DOMAIN); } if (null !== $errorMessage) { // Mark the form as with error $form->setErrorMessage($errorMessage); // Send the form and the error to the parser $this->getParserContext()->addForm($form)->setGeneralError($errorMessage); } else { $this->getParserContext()->set("success", true); } return $this->defaultAction(); }
/** * Performs an INSERT on the database, given a TntPriceWeight or Criteria object. * * @param mixed $criteria Criteria or TntPriceWeight 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(TntPriceWeightTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from TntPriceWeight object } if ($criteria->containsKey(TntPriceWeightTableMap::ID) && $criteria->keyContainsValue(TntPriceWeightTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . TntPriceWeightTableMap::ID . ')'); } // Set the correct dbName $query = TntPriceWeightQuery::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 TntPriceWeight::setDeleted() * @see TntPriceWeight::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(TntPriceWeightTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildTntPriceWeightQuery::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; } }