Exemple #1
0
 public function parseResults(LoopResult $loopResult)
 {
     $country = $this->getCurrentCountry();
     $state = $this->getCurrentState();
     $cart = $this->request->getSession()->getSessionCart($this->dispatcher);
     $virtual = $cart->isVirtual();
     /** @var Module $deliveryModule */
     foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
         $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule($country, $deliveryModule, $state);
         if (null === $areaDeliveryModule && false === $virtual) {
             continue;
         }
         /** @var DeliveryModuleInterface $moduleInstance */
         $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
         if (true === $virtual && false === $moduleInstance->handleVirtualProductDelivery() && false === $this->getBackendContext()) {
             continue;
         }
         $loopResultRow = new LoopResultRow($deliveryModule);
         try {
             // Check if module is valid, by calling isValidDelivery(),
             // or catching a DeliveryException.
             if ($moduleInstance->isValidDelivery($country)) {
                 $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($country));
                 $loopResultRow->set('ID', $deliveryModule->getId())->set('CODE', $deliveryModule->getCode())->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))->set('POSTAGE', $postage->getAmount())->set('POSTAGE_TAX', $postage->getAmountTax())->set('POSTAGE_UNTAXED', $postage->getAmount() - $postage->getAmountTax())->set('POSTAGE_TAX_RULE_TITLE', $postage->getTaxRuleTitle());
                 $this->addOutputFields($loopResultRow, $deliveryModule);
                 $loopResult->addRow($loopResultRow);
             }
         } catch (DeliveryException $ex) {
             // Module is not available
         }
     }
     return $loopResult;
 }
 /**
  * Return the first area that matches the given  country for the given module
  * @param Country $country
  * @param BaseModule $module
  * @return Area|null
  */
 public function getAreaForCountry(Country $country)
 {
     $area = null;
     if (null !== ($areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule($country, $this->getModuleModel()))) {
         $area = $areaDeliveryModule->getArea();
     }
     return $area;
 }
 public function removeArea(ShippingZoneRemoveAreaEvent $event)
 {
     $areaDelivery = AreaDeliveryModuleQuery::create()->filterByAreaId($event->getAreaId())->filterByDeliveryModuleId($event->getShippingZoneId())->findOne();
     if ($areaDelivery) {
         $areaDelivery->delete();
     } else {
         throw new \RuntimeException(sprintf('areaDeliveryModule not found with area_id = %d and delivery_module_id = %d', $event->getAreaId(), $event->getShippingZoneId()));
     }
 }
Exemple #4
0
 public function parseResults(LoopResult $loopResult)
 {
     $cart = $this->getCurrentRequest()->getSession()->getSessionCart($this->dispatcher);
     $address = $this->getDeliveryAddress();
     $country = $this->getCurrentCountry();
     if (null === $country) {
         if ($address !== null) {
             $country = $address->getCountry();
         } else {
             $country = CountryQuery::create()->findOneByByDefault(true);
         }
     }
     $state = $this->getCurrentState();
     if (null === $state) {
         if ($address !== null) {
             $state = $address->getState();
         }
     }
     $virtual = $cart->isVirtual();
     /** @var Module $deliveryModule */
     foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
         $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule($country, $deliveryModule, $state);
         if (null === $areaDeliveryModule && false === $virtual) {
             continue;
         }
         /** @var DeliveryModuleInterface $moduleInstance */
         $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
         if (true === $virtual && false === $moduleInstance->handleVirtualProductDelivery() && false === $this->getBackendContext()) {
             continue;
         }
         $loopResultRow = new LoopResultRow($deliveryModule);
         try {
             // Check if module is valid, by calling isValidDelivery(),
             // or catching a DeliveryException.
             /** @var CartModel $cart */
             $cart->getAddressDeliveryId();
             $deliveryPostageEvent = new DeliveryPostageEvent($moduleInstance, $cart, $address, $country, $state);
             $this->dispatcher->dispatch(TheliaEvents::MODULE_DELIVERY_GET_POSTAGE, $deliveryPostageEvent);
             if ($deliveryPostageEvent->isValidModule()) {
                 $postage = $deliveryPostageEvent->getPostage();
                 $loopResultRow->set('ID', $deliveryModule->getId())->set('CODE', $deliveryModule->getCode())->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))->set('POSTAGE', $postage->getAmount())->set('POSTAGE_TAX', $postage->getAmountTax())->set('POSTAGE_UNTAXED', $postage->getAmount() - $postage->getAmountTax())->set('POSTAGE_TAX_RULE_TITLE', $postage->getTaxRuleTitle())->set('DELIVERY_DATE', $deliveryPostageEvent->getDeliveryDate());
                 // add additional data if it exists
                 if ($deliveryPostageEvent->hasAdditionalData()) {
                     foreach ($deliveryPostageEvent->getAdditionalData() as $key => $value) {
                         $loopResultRow->set($key, $value);
                     }
                 }
                 $this->addOutputFields($loopResultRow, $deliveryModule);
                 $loopResult->addRow($loopResultRow);
             }
         } catch (DeliveryException $ex) {
             // Module is not available
         }
     }
     return $loopResult;
 }
Exemple #5
0
 public function parseResults(LoopResult $loopResult)
 {
     $countryId = $this->getCountry();
     if (null !== $countryId) {
         $country = CountryQuery::create()->findPk($countryId);
         if (null === $country) {
             throw new \InvalidArgumentException('Cannot found country id: `' . $countryId . '` in delivery loop');
         }
     } else {
         $country = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
     }
     /** @var Module $deliveryModule */
     foreach ($loopResult->getResultDataCollection() as $deliveryModule) {
         $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule($country, $deliveryModule);
         if (null === $areaDeliveryModule) {
             continue;
         }
         $loopResultRow = new LoopResultRow($deliveryModule);
         /** @var DeliveryModuleInterface $moduleInstance */
         $moduleInstance = $deliveryModule->getModuleInstance($this->container);
         if (false === $moduleInstance instanceof DeliveryModuleInterface) {
             throw new \RuntimeException(sprintf("delivery module %s is not a Thelia\\Module\\DeliveryModuleInterface", $deliveryModule->getCode()));
         }
         try {
             // Check if module is valid, by calling isValidDelivery(),
             // or catching a DeliveryException.
             if ($moduleInstance->isValidDelivery($country)) {
                 $postage = $moduleInstance->getPostage($country);
                 $loopResultRow->set('ID', $deliveryModule->getId())->set('TITLE', $deliveryModule->getVirtualColumn('i18n_TITLE'))->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO'))->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION'))->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM'))->set('POSTAGE', $postage);
                 $loopResult->addRow($loopResultRow);
             }
         } catch (DeliveryException $ex) {
             // Module is not available
         }
     }
     return $loopResult;
 }
Exemple #6
0
 /**
  * set delivery address
  * set delivery module
  */
 public function deliver()
 {
     $this->checkAuth();
     $this->checkCartNotEmpty();
     $message = false;
     $orderDelivery = $this->createForm(FrontForm::ORDER_DELIVER);
     try {
         $form = $this->validateForm($orderDelivery, "post");
         $deliveryAddressId = $form->get("delivery-address")->getData();
         $deliveryModuleId = $form->get("delivery-module")->getData();
         $deliveryAddress = AddressQuery::create()->findPk($deliveryAddressId);
         $deliveryModule = ModuleQuery::create()->findPk($deliveryModuleId);
         /* check that the delivery address belongs to the current customer */
         if ($deliveryAddress->getCustomerId() !== $this->getSecurityContext()->getCustomerUser()->getId()) {
             throw new \Exception($this->getTranslator()->trans("Delivery address does not belong to the current customer", [], Front::MESSAGE_DOMAIN));
         }
         /* check that the delivery module fetches the delivery address area */
         if (null === AreaDeliveryModuleQuery::create()->findByCountryAndModule($deliveryAddress->getCountry(), $deliveryModule)) {
             throw new \Exception($this->getTranslator()->trans("Delivery module cannot be use with selected delivery address", [], Front::MESSAGE_DOMAIN));
         }
         /* get postage amount */
         $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
         $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($deliveryAddress->getCountry()));
         $orderEvent = $this->getOrderEvent();
         $orderEvent->setDeliveryAddress($deliveryAddressId);
         $orderEvent->setDeliveryModule($deliveryModuleId);
         $orderEvent->setPostage($postage->getAmount());
         $orderEvent->setPostageTax($postage->getAmountTax());
         $orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
         $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent);
         $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
         $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
         return $this->generateRedirectFromRoute("order.invoice");
     } catch (FormValidationException $e) {
         $message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
     } catch (PropelException $e) {
         $this->getParserContext()->setGeneralError($e->getMessage());
     } catch (\Exception $e) {
         $message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
     }
     if ($message !== false) {
         Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
         $orderDelivery->setErrorMessage($message);
         $this->getParserContext()->addForm($orderDelivery)->setGeneralError($message);
     }
 }
 /**
  * Returns a new ChildAreaDeliveryModuleQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildAreaDeliveryModuleQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof \Thelia\Model\AreaDeliveryModuleQuery) {
         return $criteria;
     }
     $query = new \Thelia\Model\AreaDeliveryModuleQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 protected function getShippings($country)
 {
     $search = ModuleQuery::create()->filterByActivate(1)->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL)->find();
     if (null === $country) {
         throw new \Exception($this->getTranslator()->trans('Target country not defined for GoogleShopping', [], GoogleShopping::DOMAIN_NAME));
     }
     $deliveries = array();
     /** @var Module $deliveryModule */
     foreach ($search as $deliveryModule) {
         $areaDeliveryModule = AreaDeliveryModuleQuery::create()->findByCountryAndModule($country, $deliveryModule);
         if (null === $areaDeliveryModule) {
             continue;
         }
         $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
         if ($moduleInstance->isValidDelivery($country)) {
             $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($country));
             $deliveries[$deliveryModule->getTitle()] = $postage;
         }
     }
     return $deliveries;
 }
Exemple #9
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Module is new, it will return
  * an empty collection; or if this Module has previously
  * been saved, it will retrieve related AreaDeliveryModules from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Module.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return Collection|ChildAreaDeliveryModule[] List of ChildAreaDeliveryModule objects
  */
 public function getAreaDeliveryModulesJoinArea($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildAreaDeliveryModuleQuery::create(null, $criteria);
     $query->joinWith('Area', $joinBehavior);
     return $this->getAreaDeliveryModules($query, $con);
 }
Exemple #10
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see AreaDeliveryModule::setDeleted()
  * @see AreaDeliveryModule::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(AreaDeliveryModuleTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAreaDeliveryModuleQuery::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 AreaDeliveryModule or Criteria object.
  *
  * @param mixed               $criteria Criteria or AreaDeliveryModule 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(AreaDeliveryModuleTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from AreaDeliveryModule object
     }
     if ($criteria->containsKey(AreaDeliveryModuleTableMap::ID) && $criteria->keyContainsValue(AreaDeliveryModuleTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AreaDeliveryModuleTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AreaDeliveryModuleQuery::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;
 }