Пример #1
0
 protected function buildForm()
 {
     $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING, OrderStatus::CODE_SENT), Criteria::IN)->find()->toArray("code");
     $query = OrderQuery::create()->filterByDeliveryModuleId(FreeShipping::getModuleId())->filterByStatusId(array($status['paid']['Id'], $status['processing']['Id']), Criteria::IN)->find();
     $this->formBuilder->add('new_status_id', 'choice', array('label' => Translator::getInstance()->trans('server'), 'choices' => array("nochange" => Translator::getInstance()->trans("Do not change"), "processing" => Translator::getInstance()->trans("Set orders status as processing"), "sent" => Translator::getInstance()->trans("Set orders status as sent")), 'required' => 'true', 'expanded' => true, 'multiple' => false, 'data' => 'nochange'));
     /** @var \Thelia\Model\Order $order */
     foreach ($query as $order) {
         $this->formBuilder->add("order_" . $order->getId(), "checkbox", array('label' => $order->getRef(), 'label_attr' => array('for' => 'export_' . $order->getId())));
     }
 }
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === FreeShipping::getModuleId()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::getStoreEmail();
             if ($contact_email) {
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->mailer->sendEmailToCustomer(FreeShipping::MESSAGE_SEND_CONFIRMATION, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'customer_id' => $customer->getId(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             }
         }
     }
 }
Пример #3
0
 public function buildModelCriteria()
 {
     $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING), Criteria::IN)->find()->toArray("code");
     $query = OrderQuery::create()->filterByDeliveryModuleId(FreeShipping::getModuleId())->filterByStatusId(array($status[OrderStatus::CODE_PAID]['Id'], $status[OrderStatus::CODE_PROCESSING]['Id']), Criteria::IN);
     return $query;
 }
Пример #4
0
 public function export()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('FreeShipping'), 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(FreeShipping::getModuleId())->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 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(), $customer->getEmail(), $weight, $store_name)));
                 /**
                  * 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"));
 }