示例#1
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $paidStatusId = OrderStatusQuery::create()->filterByCode(OrderStatus::CODE_PAID)->select('Id')->findOne();
     if ($order->hasVirtualProduct() && $event->getStatus() == $paidStatusId) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'mail_virtualproduct'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Virtual product download message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Virtual product download message no contact email customer_id", $customer->getId());
         }
     }
 }
示例#2
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $Predict = new Predict();
     if ($order->isSent() && $order->getDeliveryModuleId() == $Predict->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_predict')->findOne();
             if (false === $message) {
                 throw new \Exception(Translator::getInstance()->trans("Failed to load message '%mail_tpl_name'.", ["%mail_tpl_name" => "mail_predict"], Predict::MESSAGE_DOMAIN));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Predict shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Predict shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 /**
  * Save the attribute combinations for the order from our cart item attribute combinations.
  *
  * @param OrderEvent $event
  *
  * @throws PropelException
  */
 public function createOrderProductAttributeCombinations(OrderEvent $event)
 {
     $legacyCartItemAttributeCombinations = LegacyCartItemAttributeCombinationQuery::create()->findByCartItemId($event->getCartItemId());
     // works with Thelia 2.2
     if (method_exists($event, 'getId')) {
         $orderProductId = $event->getId();
     } else {
         // Thelia 2.1 however does not provides the order product id in the event
         // Since the order contains potentially identical (for Thelia) cart items that are only differentiated
         // by the cart item attribute combinations that we are storing ourselves, we cannot use information
         // such as PSE id to cross reference the cart item we are given to the order product that was created from
         // it (as far as I can tell).
         // So we will ASSUME that the order product with the higher id is the one created from this cart item.
         // This is PROBABLY TRUE on a basic Thelia install with no modules messing with the cart and orders in a way
         // that create additional order products, BUT NOT IN GENERAL !
         // This also assumes that ids are generated incrementally, which is NOT GUARANTEED (but true for MySQL
         // with default settings).
         // The creation date was previously used but is even less reliable.
         // FIXME: THIS IS NOT A SANE WAY TO DO THIS
         $orderProductId = OrderProductQuery::create()->orderById(Criteria::DESC)->findOne()->getId();
     }
     $lang = $this->request->getSession()->getLang();
     /** @var LegacyCartItemAttributeCombination $legacyCartItemAttributeCombination */
     foreach ($legacyCartItemAttributeCombinations as $legacyCartItemAttributeCombination) {
         /** @var Attribute $attribute */
         $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $legacyCartItemAttributeCombination->getAttributeId());
         /** @var AttributeAv $attributeAv */
         $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $legacyCartItemAttributeCombination->getAttributeAvId());
         (new OrderProductAttributeCombination())->setOrderProductId($orderProductId)->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save();
     }
 }
示例#4
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_localpickup')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_localpickup'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $store = ConfigQuery::create();
                 $country = CountryQuery::create()->findPk($store->read("store_country"));
                 $country = CountryI18nQuery::create()->filterById($country->getId())->findOneByLocale($order->getLang()->getLocale())->getTitle();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('store_name', $store->read("store_name"));
                 $this->parser->assign('store_address1', $store->read("store_address1"));
                 $this->parser->assign('store_address2', $store->read("store_address2"));
                 $this->parser->assign('store_address3', $store->read("store_address3"));
                 $this->parser->assign('store_zipcode', $store->read("store_zipcode"));
                 $this->parser->assign('store_city', $store->read("store_city"));
                 $this->parser->assign('store_country', $country);
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
示例#5
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_colissimo')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'order_confirmation'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::getStoreName());
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 /**
  * Checks if we are the payment module for the order, and if the order is paid,
  * then send a confirmation email to the customer.
  *
  * @params OrderEvent $order
  */
 public function update_status(OrderEvent $event)
 {
     $payzen = new Payzen();
     if ($event->getOrder()->isPaid() && $payzen->isPaymentModuleFor($event->getOrder())) {
         $contact_email = ConfigQuery::read('store_email', false);
         Tlog::getInstance()->debug("Sending confirmation email from store contact e-mail {$contact_email}");
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName(Payzen::CONFIRMATION_MESSAGE_NAME)->findOne();
             if (false === $message) {
                 throw new \Exception(sprintf("Failed to load message '%s'.", Payzen::CONFIRMATION_MESSAGE_NAME));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->getMailer()->send($instance);
             Tlog::getInstance()->debug("Confirmation email sent to customer " . $customer->getEmail());
         }
     } else {
         Tlog::getInstance()->debug("No confirmation email sent (order not paid, or not the proper payement module.");
     }
 }
示例#7
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === DpdClassic::getModuleId()) {
         if ($event->getOrder()->getStatusId() === DpdClassic::STATUS_SENT) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_dpdclassic')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_dpdclassic'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('order_date', $order->getCreatedAt());
                 $this->parser->assign('update_date', $order->getUpdatedAt());
                 $this->parser->assign('package', $order->getDeliveryRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
 public function export()
 {
     if (null !== ($response = $this->checkAuth([AdminResources::MODULE, AdminResources::ORDER], ['Predict'], AccessManager::VIEW))) {
         return $response;
     }
     $orders = PredictQuery::getOrders();
     $export = new PredictExport();
     $export_data = "";
     /**
      * Validate the form and checks which order(s) must be exported
      */
     try {
         $form = new ExportForm($this->getRequest());
         $vform = $this->validateForm($form, "post");
         $entries = array();
         /** @var \Thelia\Model\Order $order */
         foreach ($orders as $order) {
             if ($vform->get("order_" . $order->getId())->getData()) {
                 $entries[] = $entry = new ExportEntry($order, $vform->get("guaranty_" . $order->getId())->getData());
                 $export->addEntry($entry);
             }
         }
         /**
          * Be sure that the export is done before updating the order status
          */
         $export_data = $export->doExport();
         $status = null;
         switch ($vform->get("new_status")->getData()) {
             case "processing":
                 $status = OrderStatus::CODE_PROCESSING;
                 break;
             case "sent":
                 $status = OrderStatus::CODE_SENT;
                 break;
         }
         if ($status !== null) {
             /**
              *  If the current user doesn't have the right to edit orders, return an error
              */
             if (null !== ($response = $this->checkAuth([AdminResources::ORDER], [], AccessManager::UPDATE))) {
                 return $response;
             }
             /**
              * Get status ID
              */
             $status_id = OrderStatusQuery::create()->findOneByCode($status)->getId();
             /** @var ExportEntry $entry */
             foreach ($entries as $entry) {
                 $event = new OrderEvent($entry->getOrder());
                 $event->setStatus($status_id);
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             }
         }
     } catch (\Exception $e) {
         return $this->render("module-configure", ["module_code" => "Predict", "tab" => "export", "error_message" => $e->getMessage()]);
     }
     return $this->createResponse($export_data);
 }
 /**
  * @param OrderEvent $event
  *
  * Check if we're the payment module, and send the payment confirmation email to the customer if it's the case.
  */
 public function sendConfirmationEmail(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Cheque::getModuleId()) {
         if ($event->getOrder()->isPaid(true)) {
             $order = $event->getOrder();
             $this->mailer->sendEmailToCustomer('order_confirmation_cheque', $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
     }
 }
示例#10
0
 /**
  * @throws \Exception
  */
 public function receiveResponse()
 {
     $request = $this->getRequest();
     $order_id = $request->get('reference');
     if (is_numeric($order_id)) {
         $order_id = (int) $order_id;
     }
     /*
      * Configure log output
      */
     $log = Tlog::getInstance();
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
     $log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, THELIA_ROOT . "log" . DS . "log-cmcic.txt");
     $log->info("accessed");
     $order = OrderQuery::create()->findPk($order_id);
     /*
      * Retrieve HMac for CGI2
      */
     $config = Config::read(CmCIC::JSON_CONFIG_PATH);
     $hashable = sprintf(CmCIC::CMCIC_CGI2_FIELDS, $config['CMCIC_TPE'], $request->get('date'), $request->get('montant'), $request->get('reference'), $request->get('texte-libre'), $config['CMCIC_VERSION'], $request->get('code-retour'), $request->get('cvx'), $request->get('vld'), $request->get('brand'), $request->get('status3ds'), $request->get('numauto'), $request->get('motifrefus'), $request->get('originecb'), $request->get('bincb'), $request->get('hpancb'), $request->get('ipclient'), $request->get('originetr'), $request->get('veres'), $request->get('pares'));
     $mac = CmCIC::computeHmac($hashable, CmCIC::getUsableKey($config["CMCIC_KEY"]));
     $response = CmCIC::CMCIC_CGI2_MACNOTOK . $hashable;
     if ($mac === strtolower($request->get('MAC'))) {
         $code = $request->get("code-retour");
         $msg = null;
         $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID);
         $event = new OrderEvent($order);
         $event->setStatus($status->getId());
         switch ($code) {
             case "payetest":
                 $msg = "The test payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "paiement":
                 $msg = "The payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "Annulation":
                 $msg = "Error during the paiement: " . $this->getRequest()->get("motifrefus");
                 break;
             default:
                 $log->error("Error while receiving response from CMCIC: code-retour not valid");
                 throw new \Exception(Translator::getInstance()->trans("An error occured, no valid code-retour"));
         }
         if (!empty($msg)) {
             $log->info($msg);
         }
         $response = CmCIC::CMCIC_CGI2_MACOK;
     }
     /*
      * Get log back to previous state
      */
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
     return Response::create(sprintf(CmCIC::CMCIC_CGI2_RECEIPT, $response), 200, array("Content-type" => "text/plain", "Pragma" => "nocache"));
 }
示例#11
0
 /**
  * Send the confirmation message only if the order is paid.
  *
  * @param OrderEvent $event
  */
 public function checkSendOrderConfirmationMessageToCustomer(OrderEvent $event)
 {
     if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
         $paybox = new Paybox();
         if ($paybox->isPaymentModuleFor($event->getOrder())) {
             if (!$event->getOrder()->isPaid()) {
                 $event->stopPropagation();
             }
         }
     }
 }
示例#12
0
 /**
  * Coupon consuming
  */
 public function consumeAction()
 {
     $this->checkCartNotEmpty();
     $message = false;
     $couponCodeForm = $this->createForm(FrontForm::COUPON_CONSUME);
     try {
         $form = $this->validateForm($couponCodeForm, 'post');
         $couponCode = $form->get('coupon-code')->getData();
         if (null === $couponCode || empty($couponCode)) {
             $message = true;
             throw new \Exception($this->getTranslator()->trans('Coupon code can\'t be empty', [], Front::MESSAGE_DOMAIN));
         }
         $couponConsumeEvent = new CouponConsumeEvent($couponCode);
         // Dispatch Event to the Action
         $this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $couponConsumeEvent);
         /* recalculate postage amount */
         $order = $this->getSession()->getOrder();
         if (null !== $order) {
             $deliveryModule = $order->getModuleRelatedByDeliveryModuleId();
             $deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
             if (null !== $deliveryModule && null !== $deliveryAddress) {
                 $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
                 $orderEvent = new OrderEvent($order);
                 try {
                     $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($deliveryAddress->getCountry()));
                     $orderEvent->setPostage($postage->getAmount());
                     $orderEvent->setPostageTax($postage->getAmountTax());
                     $orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
                     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
                 } catch (DeliveryException $ex) {
                     // The postage has been chosen, but changes dues to coupon causes an exception.
                     // Reset the postage data in the order
                     $orderEvent->setDeliveryModule(0);
                     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
                 }
             }
         }
         return $this->generateSuccessRedirect($couponCodeForm);
     } catch (FormValidationException $e) {
         $message = $this->getTranslator()->trans('Please check your coupon code: %message', ["%message" => $e->getMessage()], Front::MESSAGE_DOMAIN);
     } catch (UnmatchableConditionException $e) {
         $message = $this->getTranslator()->trans('You should <a href="%sign">sign in</a> or <a href="%register">register</a> to use this coupon', ['%sign' => $this->retrieveUrlFromRouteId('customer.login.view'), '%register' => $this->retrieveUrlFromRouteId('customer.create.view')], Front::MESSAGE_DOMAIN);
     } catch (PropelException $e) {
         $this->getParserContext()->setGeneralError($e->getMessage());
     } catch (\Exception $e) {
         $message = $this->getTranslator()->trans('Sorry, an error occurred: %message', ["%message" => $e->getMessage()], Front::MESSAGE_DOMAIN);
     }
     if ($message !== false) {
         Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
         $couponCodeForm->setErrorMessage($message);
         $this->getParserContext()->addForm($couponCodeForm)->setGeneralError($message);
     }
     return $this->generateErrorRedirect($couponCodeForm);
 }
示例#13
0
 /**
  * Send email to notify customer that files for virtual products are available
  *
  * @param OrderEvent $event
  * @throws \Exception
  */
 public function sendEmail(OrderEvent $event)
 {
     $order = $event->getOrder();
     // Be sure that we have a document to download
     $virtualProductCount = OrderProductQuery::create()->filterByOrderId($order->getId())->filterByVirtual(true)->filterByVirtualDocument(null, Criteria::NOT_EQUAL)->count();
     if ($virtualProductCount > 0) {
         $customer = $order->getCustomer();
         $this->mailer->sendEmailToCustomer('mail_virtualproduct', $customer, ['customer_id' => $customer->getId(), 'order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt()]);
     } else {
         Tlog::getInstance()->warning("Virtual product download message not sent to customer: there's nothing to downnload");
     }
 }
 public function trackOrder(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $order = $event->getPlacedOrder();
     $taxTotal = 0;
     foreach ($order->getOrderProducts() as $orderProduct) {
         $product = ProductQuery::create()->findPk($orderProduct->getVirtualColumn('product_id'));
         $defaultCategory = CategoryQuery::create()->findPk($product->getDefaultCategoryId());
         $taxTotal += $orderProduct->getVirtualColumn('TOTAL_TAX');
         $this->tracker->addEcommerceItem($orderProduct->getProductSaleElementsRef() || $orderProduct->getProductRef() || $orderProduct->getId() || $orderProduct->getProductSaleElementsId(), $orderProduct->getTitle(), $defaultCategory->getTitle(), $orderProduct->getPrice(), $orderProduct->getQuantity());
     }
     $this->tracker->doTrackEcommerceOrder($order->getRef(), $order->getTotalAmount($taxTotal, true, true), $order->getTotalAmount($taxTotal, false, true), $taxTotal, $order->getPostage() + $order->getPostageTax(), $order->getDiscount());
 }
示例#15
0
 public function saveComment(OrderEvent $orderEvent)
 {
     $comment = $this->request->getSession()->get('order-comment');
     $order = $orderEvent->getOrder();
     $orderId = $order->getId();
     if ($orderId != null && $comment != null) {
         $orderComment = new OrderComment();
         $orderComment->setOrderId($orderId);
         $orderComment->setComment($comment);
         $orderComment->save();
         $this->request->getSession()->set('order-comment', '');
     }
 }
 public function verifyCreditUsage(OrderEvent $event)
 {
     $session = $this->request->getSession();
     if ($session->get('creditAccount.used') == 1) {
         $customer = $event->getOrder()->getCustomer();
         $amount = $session->get('creditAccount.amount');
         $creditEvent = new CreditAccountEvent($customer, $amount * -1, $event->getOrder()->getId());
         $creditEvent->setWhoDidIt(Translator::getInstance()->trans('Customer', [], CreditAccount::DOMAIN))->setOrderId($event->getOrder()->getId());
         $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         $session->set('creditAccount.used', 0);
         $session->set('creditAccount.amount', 0);
     }
 }
 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()]);
             }
         }
     }
 }
示例#18
0
 /**
  * Coupon consuming
  */
 public function consumeAction()
 {
     $this->checkAuth();
     $this->checkCartNotEmpty();
     $message = false;
     $couponCodeForm = new CouponCode($this->getRequest());
     try {
         $form = $this->validateForm($couponCodeForm, 'post');
         $couponCode = $form->get('coupon-code')->getData();
         if (null === $couponCode || empty($couponCode)) {
             $message = true;
             throw new \Exception('Coupon code can\'t be empty');
         }
         $couponConsumeEvent = new CouponConsumeEvent($couponCode);
         // Dispatch Event to the Action
         $this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $couponConsumeEvent);
         /* recalculate postage amount */
         $order = $this->getSession()->getOrder();
         if (null !== $order) {
             $deliveryModule = $order->getModuleRelatedByDeliveryModuleId();
             $deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
             if (null !== $deliveryModule && null !== $deliveryAddress) {
                 $moduleInstance = $deliveryModule->getModuleInstance($this->container);
                 $orderEvent = new OrderEvent($order);
                 try {
                     $postage = $moduleInstance->getPostage($deliveryAddress->getCountry());
                     $orderEvent->setPostage($postage);
                     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
                 } catch (DeliveryException $ex) {
                     // The postage has been chosen, but changes dues to coupon causes an exception.
                     // Reset the postage data in the order
                     $orderEvent->setDeliveryModule(0);
                     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
                 }
             }
         }
         return $this->generateSuccessRedirect($couponCodeForm);
     } catch (FormValidationException $e) {
         $message = sprintf('Please check your coupon code: %s', $e->getMessage());
     } catch (PropelException $e) {
         $this->getParserContext()->setGeneralError($e->getMessage());
     } catch (\Exception $e) {
         $message = sprintf('Sorry, an error occurred: %s', $e->getMessage());
     }
     if ($message !== false) {
         Tlog::getInstance()->error(sprintf("Error during order delivery process : %s. Exception was %s", $message, $e->getMessage()));
         $couponCodeForm->setErrorMessage($message);
         $this->getParserContext()->addForm($couponCodeForm)->setGeneralError($message);
     }
 }
示例#19
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid() && $order->getPaymentModuleId() == Atos::getModuleId()) {
         if (Atos::getConfigValue('send_payment_confirmation_message')) {
             $this->mailer->sendEmailToCustomer(Atos::CONFIRMATION_MESSAGE_NAME, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
         // Send confirmation email if required.
         if (Atos::getConfigValue('send_confirmation_message_only_if_paid')) {
             $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
         }
         Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
     }
 }
示例#20
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->mailer->sendEmailToCustomer('mail_colissimo', $customer, ['customer_id' => $customer->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
示例#21
0
 /**
  * @depends testCreate
  *
  * @param OrderModel $order
  */
 public function testUpdateDeliveryRef(OrderModel $order)
 {
     $deliveryRef = uniqid('DELREF');
     $this->orderEvent->setDeliveryRef($deliveryRef);
     $this->orderEvent->setOrder($order);
     $this->orderAction->updateDeliveryRef($this->orderEvent);
     $this->assertEquals($deliveryRef, $this->orderEvent->getOrder()->getDeliveryRef());
     $this->assertEquals($deliveryRef, OrderQuery::create()->findPk($order->getId())->getDeliveryRef());
 }
 /**
  * Update order's delivery ref
  *
  * @param string    $deliveryRef
  * @param string    $orderRef
  * @param int       $i
  */
 public function importDeliveryRef($deliveryRef, $orderRef, &$i)
 {
     // Check if the order exists
     if (null !== ($order = OrderQuery::create()->findOneByRef($orderRef))) {
         $event = new OrderEvent($order);
         // Check if delivery refs are different
         if ($order->getDeliveryRef() != $deliveryRef) {
             $event->setDeliveryRef($deliveryRef);
             $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event);
             $sentStatusId = OrderStatusQuery::create()->filterByCode('sent')->select('ID')->findOne();
             // Set 'sent' order status if not already sent
             if ($sentStatusId != null && $order->getStatusId() != $sentStatusId) {
                 $event->setStatus($sentStatusId);
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             }
             $i++;
         }
     }
 }
 /**
  * Update order's delivery ref
  *
  * @param string    $deliveryRef
  * @param string    $orderRef
  * @param int       $i
  */
 public function importDeliveryRef($deliveryRef, $orderRef, &$i)
 {
     // Get order
     $order = OrderQuery::create()->findOneByRef($orderRef);
     // Check if the order exists
     if ($order !== null) {
         $event = new OrderEvent($order);
         // Check if delivery refs are different
         if ($order->getDeliveryRef() != $deliveryRef) {
             $event->setDeliveryRef($deliveryRef);
             $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event);
             // Set 'sent' order status if not already sent
             if ($order->getStatusId() != DpdPickup::STATUS_SENT) {
                 $event->setStatus(DpdPickup::STATUS_SENT);
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             }
             $i++;
         }
     }
 }
示例#24
0
 public function updateCreditAccount(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid(true)) {
         $total = $order->getTotalAmount();
         $loyaltySlice = LoyaltyQuery::create()->filterByMin($total, Criteria::LESS_EQUAL)->filterByMax($total, Criteria::GREATER_EQUAL)->findOne();
         if ($loyaltySlice) {
             $amount = $loyaltySlice->getAmount();
             $creditEvent = new CreditAccountEvent($order->getCustomer(), $amount, $order->getId());
             $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         }
     } else {
         // Remove any credited amount
         $entryList = CreditAmountHistoryQuery::create()->findByOrderId($order->getId());
         /** @var CreditAmountHistory $entry */
         foreach ($entryList as $entry) {
             $creditEvent = new CreditAccountEvent($order->getCustomer(), -$entry->getAmount(), $order->getId());
             $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         }
     }
 }
示例#25
0
 /**
  * @param  OrderEvent                                     $event
  * @throws \Thelia\Form\Exception\FormValidationException
  */
 public function cellphoneCheck(OrderEvent $event)
 {
     if (Predict::getModuleId() === $event->getDeliveryModule()) {
         $cellphone = $this->request->request->get("predict_cellphone");
         $cellphone = str_replace(array(' ', '.', '-', ',', ';', '/', '\\', '(', ')'), '', $cellphone);
         $partial_number = "";
         if (empty($cellphone) || !preg_match('#^[0|\\+33][6-7]([0-9]{8})$#', $cellphone, $partial_number)) {
             throw new FormValidationException(Translator::getInstance()->trans("You must give a cellphone number in order to use Predict services", [], Predict::MESSAGE_DOMAIN));
         }
         $cellphone = str_replace("+33", "0", $cellphone);
         $banned_cellphones = array('00000000', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678', '23456789', '98765432');
         if (in_array($partial_number[1], $banned_cellphones)) {
             throw new FormValidationException(Translator::getInstance()->trans("This phone number is not valid", [], Predict::MESSAGE_DOMAIN));
         }
         /** @var \Thelia\Model\Customer $customer */
         $customer = $this->getRequest()->getSession()->getCustomerUser();
         $address = $customer->getDefaultAddress();
         $addressEvent = new AddressCreateOrUpdateEvent($address->getLabel(), $address->getTitleId(), $address->getFirstname(), $address->getLastname(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $address->getCountryId(), $cellphone, $address->getPhone(), $address->getCompany());
         $addressEvent->setAddress($address);
         $dispatcher = $event->getDispatcher();
         $dispatcher->dispatch(TheliaEvents::ADDRESS_UPDATE, $addressEvent);
     }
 }
示例#26
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Paypal::getModCode()) {
         if ($event->getOrder()->isPaid()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('payment_confirmation_paypal')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'payment_confirmation_paypal'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
示例#27
0
 public function exportAction()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('Colissimo'), AccessManager::UPDATE))) {
         return $response;
     }
     $form = new FormExport($this->getRequest());
     try {
         $exportForm = $this->validateForm($form);
         // Get new status
         $status_id = $exportForm->get('status_id')->getData();
         $status = OrderStatusQuery::create()->filterByCode($status_id)->findOne();
         // Get Colissimo orders
         $orders = ColissimoQuery::getOrders()->find();
         $export = "";
         $store_name = ConfigQuery::getStoreName();
         /** @var $order \Thelia\Model\Order */
         foreach ($orders as $order) {
             $value = $exportForm->get('order_' . $order->getId())->getData();
             if ($value) {
                 // Get order information
                 $customer = $order->getCustomer();
                 $locale = $order->getLang()->getLocale();
                 $address = $order->getOrderAddressRelatedByDeliveryOrderAddressId();
                 $country = CountryQuery::create()->findPk($address->getCountryId());
                 $country->setLocale($locale);
                 $customerTitle = CustomerTitleQuery::create()->findPk($address->getCustomerTitleId());
                 $customerTitle->setLocale($locale);
                 $weight = $exportForm->get('order_weight_' . $order->getId())->getData();
                 if ($weight == 0) {
                     /** @var \Thelia\Model\OrderProduct $product */
                     foreach ($order->getOrderProducts() as $product) {
                         $weight += (double) $product->getWeight();
                     }
                 }
                 /**
                  * 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;
                     }
                 }
                 // Cellphone
                 $cellphone = $customer->getDefaultAddress()->getCellphone();
                 if (empty($cellphone)) {
                     $cellphone = $customer->getDefaultAddress()->getCellphone();
                     if (empty($cellphone)) {
                         $cellphone = self::DEFAULT_CELLPHONE;
                     }
                 }
                 $export .= "\"" . $order->getRef() . "\";\"" . $address->getLastname() . "\";\"" . $address->getFirstname() . "\";\"" . $address->getAddress1() . "\";\"" . $address->getAddress2() . "\";\"" . $address->getAddress3() . "\";\"" . $address->getZipcode() . "\";\"" . $address->getCity() . "\";\"" . $country->getIsoalpha2() . "\";\"" . $phone . "\";\"" . $cellphone . "\";\"" . $weight . "\";\"" . $customer->getEmail() . "\";\"\";\"" . $store_name . "\";\"DOM\";\r\n";
                 if ($status) {
                     $event = new OrderEvent($order);
                     $event->setStatus($status->getId());
                     $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 }
             }
         }
         return Response::create(utf8_decode($export), 200, array("Content-Encoding" => "ISO-8889-1", "Content-Type" => "application/csv-tab-delimited-table", "Content-disposition" => "filename=export.csv"));
     } catch (FormValidationException $e) {
         $this->setupFormErrorContext(Translator::getInstance()->trans("colissimo expeditor export", [], Colissimo::DOMAIN_NAME), $e->getMessage(), $form, $e);
         return $this->render("module-configure", array("module_code" => "Colissimo"));
     }
 }
示例#28
0
 protected function afterModifyCart()
 {
     /* recalculate postage amount */
     $order = $this->getSession()->getOrder();
     if (null !== $order) {
         $deliveryModule = $order->getModuleRelatedByDeliveryModuleId();
         $deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
         if (null !== $deliveryModule && null !== $deliveryAddress) {
             $moduleInstance = $deliveryModule->getDeliveryModuleInstance($this->container);
             $orderEvent = new OrderEvent($order);
             try {
                 $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($deliveryAddress->getCountry()));
                 $orderEvent->setPostage($postage->getAmount());
                 $orderEvent->setPostageTax($postage->getAmountTax());
                 $orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle());
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent);
             } catch (DeliveryException $ex) {
                 // The postage has been chosen, but changes in the cart causes an exception.
                 // Reset the postage data in the order
                 $orderEvent->setDeliveryModule(0);
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent);
             }
         }
     }
 }
示例#29
0
 public function setOrderDelivery(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() == TNTFrance::getModuleId()) {
         // we have the order id
         $data = TNTFrance::getExtraOrderData($event->getOrder()->getCartId());
         TNTFrance::setExtraOrderData($event->getOrder()->getId(), $data, false);
     }
 }
示例#30
0
 public function updateDeliveryRef($order_id)
 {
     if (null !== ($response = $this->checkAuth(AdminResources::ORDER, array(), AccessManager::UPDATE))) {
         return $response;
     }
     $message = null;
     try {
         $order = OrderQuery::create()->findPk($order_id);
         $deliveryRef = $this->getRequest()->get("delivery_ref");
         if (null === $order) {
             throw new \InvalidArgumentException("The order you want to update status does not exist");
         }
         $event = new OrderEvent($order);
         $event->setDeliveryRef($deliveryRef);
         $this->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     $params = array();
     if ($message) {
         $params["update_status_error_message"] = $message;
     }
     $params["tab"] = $this->getRequest()->get("tab", 'bill');
     return $this->generateRedirectFromRoute("admin.order.update.view", $params, ['order_id' => $order_id]);
 }