public function printExpedition(TNTFrancePrintExpeditionEvent $event)
 {
     /** @var \Thelia\Model\Order $oldOrder */
     $oldOrder = null;
     $parcelResponses = [];
     foreach ($event->getTntOrderParceResponses() as $key => $tntOrderParcelResponse) {
         $order = $tntOrderParcelResponse->getOrderProduct()->getOrder();
         if (null != $oldOrder && $oldOrder->getId() != $order->getId()) {
             $this->sendEmailFromOrder($oldOrder, $parcelResponses);
             $parcelResponses = [];
         }
         //check if there is many stickers (sequence_number) in the pdf
         $responses = TntOrderParcelResponseQuery::create()->filterByFileName($tntOrderParcelResponse->getFileName())->groupBySequenceNumber()->groupByFileName();
         /** @var \TNTFrance\Model\TntOrderParcelResponse $response */
         foreach ($responses as $response) {
             //Get all the concerned orderProducts
             $listConcernedOrderProduct = TntOrderParcelResponseQuery::create()->useOrderProductQuery()->endUse()->filterByFileName($response->getFileName(), Criteria::LIKE)->groupByOrderProductId()->withColumn(OrderProductTableMap::TITLE, 'order_product_title')->find()->toArray();
             $response->setVirtualColumn('order_products', $listConcernedOrderProduct);
             $parcelResponses[] = $response->toArray();
         }
         if (count($event->getTntOrderParceResponses()) == $key + 1) {
             $this->sendEmailFromOrder($order, $parcelResponses);
         }
     }
 }
 /**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $search = TntOrderParcelResponseQuery::create();
     //Join order_product table
     $orderProductJoin = new Join(TntOrderParcelResponseTableMap::ORDER_PRODUCT_ID, OrderProductTableMap::ID, Criteria::INNER_JOIN);
     $search->addJoinObject($orderProductJoin, 'order_product_join');
     //Join order_product table
     $orderJoin = new Join(OrderProductTableMap::ORDER_ID, OrderTableMap::ID, Criteria::INNER_JOIN);
     $search->addJoinObject($orderJoin, 'order_join');
     if (null !== ($orderProductId = $this->getOrderProductId())) {
         $search->addJoinCondition('order_product_join', 'order_product.id IN (' . implode(',', $orderProductId) . ')');
     }
     if (null !== ($orderId = $this->getOrderId())) {
         $search->addJoinCondition('order_join', 'order.id IN (' . implode(',', $orderId) . ')');
     }
     if (null !== ($id = $this->getId())) {
         $search->filterById($id, Criteria::IN);
     }
     if (null != ($printed = $this->getPrinted())) {
         $search->filterByPrinted($printed, Criteria::EQUAL);
     }
     if (null != ($fileName = $this->getFileName())) {
         $search->filterByFileName($fileName, Criteria::LIKE);
     }
     if (null != ($sequenceNumber = $this->getSequenceNumber())) {
         $search->filterBySequenceNumber($sequenceNumber, Criteria::IN);
     }
     if (null != ($groupBys = $this->getGroupBy())) {
         foreach ($groupBys as $groupBy) {
             switch ($groupBy) {
                 case "id":
                     $search->groupById();
                     break;
                 case "package":
                     $search->groupByFileName();
                     $search->groupBySequenceNumber();
                     break;
                 case "sticker":
                     $search->groupByFileName();
                     break;
                 case "order_product":
                     $search->groupByOrderProductId();
                     break;
             }
         }
     }
     return $search;
 }
Beispiel #3
0
 public function orderNumberPackage($params, $template = null)
 {
     $numberOfPackage = 1;
     $maxWeightPackage = TNTFrance::getConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, 25);
     if (null != ($orderId = $this->getParam($params, "order_id", null))) {
         if (null != ($order = OrderQuery::create()->findPk($orderId))) {
             $orderTotalWeight = 0;
             foreach ($order->getOrderProducts() as $orderProduct) {
                 //Be sure that this orderProduct has no package already
                 if (null == ($tntResponse = TntOrderParcelResponseQuery::create()->findOneByOrderProductId($orderProduct->getId()))) {
                     $orderTotalWeight += $orderProduct->getQuantity() * $orderProduct->getWeight();
                 }
             }
             $numberOfPackage = ceil($orderTotalWeight / $maxWeightPackage);
         }
     }
     return $numberOfPackage;
 }
 public function stickerAction()
 {
     $response = $this->checkAuth(AdminResources::MODULE, TNTFrance::getModuleCode(), AccessManager::UPDATE);
     if (null !== $response) {
         return $response;
     }
     $tntOrderParcelResponseIdList = $this->getRequest()->request->get("tnt-order-parcel-response");
     if ($tntOrderParcelResponseIdList) {
         $tntOrderParcelResponses = TntOrderParcelResponseQuery::create()->findPks($tntOrderParcelResponseIdList);
         $event = new TNTFrancePrintExpeditionEvent($tntOrderParcelResponses);
         $this->dispatch(TNTFranceEvents::TNT_FRANCE_PRINT_EXPEDITION, $event);
         $zipName = "stickers.zip";
         if (file_exists($zipName)) {
             unlink($zipName);
         }
         $zip = new ZipArchive();
         if ($zip->open($zipName, ZipArchive::CREATE) === true) {
             $zip->addEmptyDir('stickers');
             foreach ($event->getTntOrderParceResponses() as $tntOrderParcelResponse) {
                 $fileName = $tntOrderParcelResponse->getOrderProductId() . '.pdf';
                 $filePath = TNTFrance::getUploadDirectory() . $fileName;
                 if (file_exists($filePath)) {
                     $handle = fopen($filePath, 'r');
                     $contents = fread($handle, filesize($filePath));
                     fclose($handle);
                     $zip->addFromString('stickers/' . $fileName, $contents);
                 }
             }
             $zip->close();
             //If no pdf found, zip won't exists
             if (file_exists($zipName)) {
                 if ($downloadZip = fopen($zipName, "r")) {
                     $zipSize = filesize($zipName);
                     header("Content-type: application/zip");
                     header("Content-Disposition: attachment; filename=\"" . $zipName . "\"");
                     header("Content-length: {$zipSize}");
                     header('Content-Transfer-Encoding: binary');
                     echo fpassthru($downloadZip);
                     // deliver the zip file
                 }
                 fclose($downloadZip);
             }
         }
     }
     return $this->redirectToDefaultPage();
 }
 /**
  * Performs an INSERT on the database, given a TntOrderParcelResponse or Criteria object.
  *
  * @param mixed               $criteria Criteria or TntOrderParcelResponse 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(TntOrderParcelResponseTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from TntOrderParcelResponse object
     }
     if ($criteria->containsKey(TntOrderParcelResponseTableMap::ID) && $criteria->keyContainsValue(TntOrderParcelResponseTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . TntOrderParcelResponseTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = TntOrderParcelResponseQuery::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 TntOrderParcelResponse::setDeleted()
  * @see TntOrderParcelResponse::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(TntOrderParcelResponseTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildTntOrderParcelResponseQuery::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;
     }
 }