Example #1
0
 public function buildModelCriteria()
 {
     $productId = $this->getProductId();
     $search = DigressivePriceQuery::create();
     if (!is_null($productId)) {
         $search->filterByProductId($productId);
     }
     return $search;
 }
 /**
  * @param $value
  * @param $isUpdating
  * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
  */
 public function inRangeQuery($value, $isUpdating)
 {
     // Check if the value is between FROM and TO quantities of an existing digressive price of the current product
     $digressivePricesQuery = DigressivePriceQuery::create()->filterByProductId($this->getForm()->getData()['productId'])->filterByQuantityFrom($value, Criteria::LESS_EQUAL)->filterByQuantityTo($value, Criteria::GREATER_EQUAL);
     // If it's an update, don't check itself
     if ($isUpdating) {
         $digressivePricesQuery->filterById($this->getForm()->getData()['id'], Criteria::NOT_IN);
     }
     return $digressivePricesQuery->find();
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see DigressivePrice::setDeleted()
  * @see DigressivePrice::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(DigressivePriceTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildDigressivePriceQuery::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;
     }
 }
 /**
  * Performs an INSERT on the database, given a DigressivePrice or Criteria object.
  *
  * @param mixed               $criteria Criteria or DigressivePrice 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(DigressivePriceTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from DigressivePrice object
     }
     if ($criteria->containsKey(DigressivePriceTableMap::ID) && $criteria->keyContainsValue(DigressivePriceTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . DigressivePriceTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = DigressivePriceQuery::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;
 }
 /**
  * @param DigressivePriceIdEvent $event
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function deleteDigressivePrice(DigressivePriceIdEvent $event)
 {
     DigressivePriceQuery::create()->filterById($event->getId())->delete();
 }