/**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $query = OrderAddressSocolissimoQuery::create();
     if (!is_null($id = $this->getId())) {
         $query->filterById(intval($id));
     }
     return $query;
 }
Example #2
0
 public function export()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE))) {
         return $response;
     }
     $csv = new CSV(self::CSV_SEPARATOR);
     try {
         $form = new ExportOrder($this->getRequest());
         $vform = $this->validateForm($form);
         // Check status_id
         $status_id = $vform->get("new_status_id")->getData();
         if (!preg_match("#^nochange|processing|sent\$#", $status_id)) {
             throw new Exception("Bad value for new_status_id field");
         }
         $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING, OrderStatus::CODE_SENT), Criteria::IN)->find()->toArray("code");
         $query = OrderQuery::create()->filterByDeliveryModuleId(SoColissimo::getModCode())->filterByStatusId(array($status[OrderStatus::CODE_PAID]['Id'], $status[OrderStatus::CODE_PROCESSING]['Id']), Criteria::IN)->find();
         // check form && exec csv
         /** @var \Thelia\Model\Order $order */
         foreach ($query as $order) {
             $value = $vform->get('order_' . $order->getId())->getData();
             // If checkbox is checked
             if ($value) {
                 /**
                  * Retrieve user with the order
                  */
                 $customer = $order->getCustomer();
                 /**
                  * Retrieve address with the order
                  */
                 $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId());
                 if ($address === null) {
                     throw new Exception("Could not find the order's invoice address");
                 }
                 /**
                  * Retrieve country with the address
                  */
                 $country = CountryQuery::create()->findPk($address->getCountryId());
                 if ($country === null) {
                     throw new Exception("Could not find the order's country");
                 }
                 /**
                  * Retrieve Title
                  */
                 $title = CustomerTitleI18nQuery::create()->filterById($customer->getTitleId())->findOneByLocale($this->getSession()->getAdminEditionLang()->getLocale());
                 /**
                  * Get user's phone & cellphone
                  * First get invoice address phone,
                  * If empty, try to get default address' phone.
                  * If still empty, set default value
                  */
                 $phone = $address->getPhone();
                 if (empty($phone)) {
                     $phone = $customer->getDefaultAddress()->getPhone();
                     if (empty($phone)) {
                         $phone = self::DEFAULT_PHONE;
                     }
                 }
                 /**
                  * Cellp
                  */
                 $cellphone = $customer->getDefaultAddress()->getCellphone();
                 if (empty($cellphone)) {
                     $cellphone = self::DEFAULT_CELLPHONE;
                 }
                 /**
                  * Compute package weight
                  */
                 $weight = 0;
                 /** @var \Thelia\Model\OrderProduct $product */
                 foreach ($order->getOrderProducts() as $product) {
                     $weight += (double) $product->getWeight();
                 }
                 /**
                  * Get relay ID
                  */
                 $relay_id = OrderAddressSocolissimoQuery::create()->findPk($order->getDeliveryOrderAddressId());
                 if ($relay_id === null) {
                     throw new Exception("Invalid order " . $order->getRef() . ", no relay id found");
                 }
                 /**
                  * Get store's name
                  */
                 $store_name = ConfigQuery::read("store_name");
                 /**
                  * Write CSV line
                  */
                 $csv->addLine(CSVLine::create(array($address->getFirstname(), $address->getLastname(), $address->getCompany(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $country->getIsoalpha2(), $phone, $cellphone, $order->getRef(), $title->getShort(), $relay_id->getCode() == 0 ? '' : $relay_id->getCode(), $customer->getEmail(), $weight, $store_name, $relay_id->getType())));
                 /**
                  * Then update order's status if necessary
                  */
                 if ($status_id == "processing") {
                     $event = new OrderEvent($order);
                     $event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']);
                     $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 } elseif ($status_id == "sent") {
                     $event = new OrderEvent($order);
                     $event->setStatus($status[OrderStatus::CODE_SENT]['Id']);
                     $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 }
             }
         }
     } catch (\Exception $e) {
         return Response::create($e->getMessage(), 500);
     }
     return Response::create(utf8_decode($csv->parse()), 200, array("Content-Encoding" => "ISO-8889-1", "Content-Type" => "application/csv-tab-delimited-table", "Content-disposition" => "filename=export.csv"));
 }
 /**
  * Performs an INSERT on the database, given a OrderAddressSocolissimo or Criteria object.
  *
  * @param mixed               $criteria Criteria or OrderAddressSocolissimo 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(OrderAddressSocolissimoTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from OrderAddressSocolissimo object
     }
     // Set the correct dbName
     $query = OrderAddressSocolissimoQuery::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 OrderAddressSocolissimo::setDeleted()
  * @see OrderAddressSocolissimo::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(OrderAddressSocolissimoTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildOrderAddressSocolissimoQuery::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;
     }
 }