/** * Save slice * * @return \Thelia\Core\HttpFoundation\Response */ public function deleteAction() { $response = $this->checkAuth([], ['customdelivery'], AccessManager::DELETE); if (null !== $response) { return $response; } $this->checkXmlHttpRequest(); $responseData = ["success" => false, "message" => '', "slice" => null]; $response = null; try { $requestData = $this->getRequest()->request; if (0 !== ($id = intval($requestData->get('id', 0)))) { $slice = CustomDeliverySliceQuery::create()->findPk($id); $slice->delete(); $responseData['success'] = true; } else { $responseData['message'] = $this->getTranslator()->trans('The slice has not been deleted', [], CustomDelivery::MESSAGE_DOMAIN); } } catch (\Exception $e) { $responseData['message'] = $e->getMessage(); } return $this->jsonResponse(json_encode($responseData)); }
/** * Performs an INSERT on the database, given a CustomDeliverySlice or Criteria object. * * @param mixed $criteria Criteria or CustomDeliverySlice 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(CustomDeliverySliceTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from CustomDeliverySlice object } if ($criteria->containsKey(CustomDeliverySliceTableMap::ID) && $criteria->keyContainsValue(CustomDeliverySliceTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CustomDeliverySliceTableMap::ID . ')'); } // Set the correct dbName $query = CustomDeliverySliceQuery::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 Cart $cart * @param $areaId * @return |null */ protected function getSlicePostage(Cart $cart, Country $country) { $config = self::getConfig(); $currency = $cart->getCurrency(); $areaId = $country->getAreaId(); $query = CustomDeliverySliceQuery::create()->filterByAreaId($areaId); if ($config['method'] != CustomDelivery::METHOD_PRICE) { $query->filterByWeightMax($cart->getWeight(), Criteria::GREATER_THAN); $query->orderByWeightMax(Criteria::ASC); } if ($config['method'] != CustomDelivery::METHOD_WEIGHT) { $total = $cart->getTotalAmount(); // convert amount to the default currency if (0 == $currency->getByDefault()) { $total = $total / $currency->getRate(); } $query->filterByPriceMax($total, Criteria::GREATER_THAN); $query->orderByPriceMax(Criteria::ASC); } $slice = $query->findOne(); $postage = null; if (null !== $slice) { $postage = new OrderPostage(); if (0 == $currency->getByDefault()) { $price = $slice->getPrice() * $currency->getRate(); } else { $price = $slice->getPrice(); } $price = round($price, 2); $postage->setAmount($price); $postage->setAmountTax(0); // taxed amount if (0 !== $config['tax']) { $taxRuleI18N = I18n::forceI18nRetrieving($this->getRequest()->getSession()->getLang()->getLocale(), 'TaxRule', $config['tax']); $taxRule = TaxRuleQuery::create()->findPk($config['tax']); if (null !== $taxRule) { $taxCalculator = new Calculator(); $taxCalculator->loadTaxRuleWithoutProduct($taxRule, $country); $postage->setAmount(round($taxCalculator->getTaxedPrice($price), 2)); $postage->setAmountTax($postage->getAmount() - $price); $postage->setTaxRuleTitle($taxRuleI18N->getTitle()); } } } return $postage; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see CustomDeliverySlice::setDeleted() * @see CustomDeliverySlice::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(CustomDeliverySliceTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildCustomDeliverySliceQuery::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; } }