public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $user = $this->security_context->getToken()->getUser();
     $order = $event->getOrder();
     $vat_account = $this->em->getRepository('ClubUserBundle:LocationConfig')->getObjectByKey('account_default_vat', $user->getLocation());
     foreach ($order->getProducts() as $product) {
         switch ($product->getType()) {
             case 'product':
                 $account = $this->em->getRepository('ClubShopBundle:Product')->getAccount($product->getProduct(), $user->getLocation());
                 break;
             case 'coupon':
                 $account = $this->em->getRepository('ClubUserBundle:LocationConfig')->getObjectByKey('account_default_discount', $user->getLocation());
                 break;
         }
         $ledger = new \Club\AccountBundle\Entity\Ledger();
         $ledger->setValue($product->getPrice());
         $ledger->setNote($product->getQuantity() . 'x ' . $product->getProductName());
         $ledger->setAccount($account);
         $ledger->setUser($order->getUser());
         $this->em->persist($ledger);
         if ($product->getVatRate() > 0) {
             $ledger = new \Club\AccountBundle\Entity\Ledger();
             $ledger->setValue($product->getPrice() * $product->getVatRate() / 100);
             $ledger->setNote('VAT for order ' . $order->getOrderNumber());
             $ledger->setAccount($vat_account);
             $ledger->setUser($order->getUser());
             $this->em->persist($ledger);
         }
     }
     $this->em->flush();
 }
Example #2
0
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     $email = $order->getUser()->getProfile()->getProfileEmail();
     if ($email) {
         $this->clubmaster_mailer->setSubject('Order ' . $order->getOrderNumber())->setTo($email->getEmailAddress())->setBody($this->templating->render('ClubMailBundle:Template:order_new.html.twig', array('order' => $order)))->send();
     }
 }
Example #3
0
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     $status = new \Club\ShopBundle\Entity\OrderStatusHistory();
     $status->setOrder($order);
     $status->setOrderStatus($order->getOrderStatus());
     $this->em->persist($status);
     $this->em->flush();
 }
 public function onOrderPaid(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     foreach ($order->getProducts() as $orderProduct) {
         $product = $orderProduct->getProduct();
         $product->setQuantity($product->getQuantity() - $orderProduct->getQuantity());
         $this->em->persist($product);
     }
     $this->em->flush();
 }
 public function onOrderPaid(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     foreach ($order->getProducts() as $prod) {
         if ($prod->getType() == 'subscription') {
             $this->createSubscription($order, $prod);
         }
     }
     $this->em->flush();
 }
 public function onOrderChange(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     if (!$this->em->getRepository('ClubShopBundle:Order')->isFirstAccepted($order)) {
         return;
     }
     $email = $order->getUser()->getProfile()->getProfileEmail();
     if ($email) {
         $this->clubmaster_mailer->setSubject('Order ' . $order->getOrderNumber())->setTo($email->getEmailAddress())->setBody($this->templating->render('ClubMailBundle:Template:order_accepted.html.twig', array('order' => $order)))->send();
     }
 }
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     if (!$this->container->getParameter('club_mail.mail_on_order_confirm')) {
         return false;
     }
     $order = $event->getOrder();
     $email = $order->getUser()->getProfile()->getProfileEmail();
     if ($email) {
         $this->clubmaster_mailer->init()->setSpool(false)->setSubject('Order ' . $order->getOrderNumber())->setFrom()->setTo($email->getEmailAddress())->setBody($this->templating->render('ClubMailBundle:Template:order_new.html.twig', array('order' => $order)))->send();
     }
 }
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     $status = new \Club\ShopBundle\Entity\OrderStatusHistory();
     $status->setOrder($order);
     $status->setOrderStatus($order->getOrderStatus());
     $this->em->persist($status);
     $this->em->flush();
     if ($order->getAmountLeft() == 0) {
         $this->club_shop_order->setOrder($order)->setPaid();
     }
 }
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     $user = $this->security_context->getToken()->getUser();
     $log = new \Club\LogBundle\Entity\Log();
     $log->setEvent('onShopOrder');
     $log->setSeverity('informational');
     $log->setUser($user);
     $log->setLogType('general');
     $log->setLog('Created a new order #' . $order->getId());
     $this->em->persist($log);
     $this->em->flush();
 }
Example #10
0
 public function onOrderPaid(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     foreach ($event->getOrder()->getOrderProducts() as $product) {
         if ($product->getType() == 'event') {
             if (preg_match("/#(\\d+)\$/", $product->getProductName(), $o)) {
                 $e = $this->em->find('ClubEventBundle:Event', $o[1]);
                 if ($e) {
                     $this->event->attend($e, $event->getOrder()->getUser());
                 }
             }
         }
     }
 }
 public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     $log = new \Club\LogBundle\Entity\Log();
     $log->setEvent('onShopOrder');
     $log->setSeverity('informational');
     $log->setLogType('shop');
     $log->setLog('Created a new order #' . $order->getId());
     if ($this->security_context->getToken() && $this->security_context->isGranted('IS_AUTHENTICATED_FULLY')) {
         $log->setUser($this->security_context->getToken()->getUser());
     }
     $this->em->persist($log);
     $this->em->flush();
 }
Example #12
0
 public function onOrderPaid(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     foreach ($event->getOrder()->getOrderProducts() as $product) {
         if ($product->getType() == 'guest_booking') {
             if (preg_match("/#(\\d+)\$/", $product->getProductName(), $o)) {
                 $booking = $this->em->find('ClubBookingBundle:Booking', $o[1]);
                 if ($booking) {
                     $status = $this->container->get('club_booking.booking')->getConfirmStatus($booking->getFirstDate());
                     $booking->setStatus($status);
                     $this->club_booking->setBooking($booking);
                     $this->club_booking->save();
                 }
             }
         }
     }
 }
 public function onOrderChange(\Club\ShopBundle\Event\FilterOrderEvent $event)
 {
     $order = $event->getOrder();
     if (!$this->em->getRepository('ClubShopBundle:Order')->isFirstAccepted($order)) {
         return;
     }
     foreach ($order->getProducts() as $product) {
         if (count($product->getOrderProductAttributes())) {
             $res = array();
             foreach ($product->getOrderProductAttributes() as $attr) {
                 $res[$attr->getAttributeName()] = $attr;
             }
             $subscription = new \Club\ShopBundle\Entity\Subscription();
             $subscription->setOrder($order);
             $subscription->setOrderProduct($product);
             $subscription->setUser($order->getUser());
             $subscription->setActive(1);
             $subscription->setType('subscription');
             $start_date = isset($res['StartDate']) ? new \DateTime($res['StartDate']->getValue()) : new \DateTime();
             if (isset($res['StartDate'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('StartDate');
                 $sub_attr->setValue($res['StartDate']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
                 $date = new \DateTime($res['StartDate']->getValue());
                 if ($date->getTimestamp() > time()) {
                     $start_date = $date;
                 } elseif (isset($res['AutoRenewal'])) {
                     if ($res['AutoRenewal']->getValue() == 'A') {
                         $start_date = new \DateTime();
                     } elseif ($res['AutoRenewal']->getValue() == 'Y') {
                         $start_date = new \DateTime(date('Y-m-d', mktime(0, 0, 0, $date->format('n'), $date->format('j'), date('Y'))));
                         if ($start_date->getTimestamp() < time()) {
                             $start_date->add(new \DateInterval('P1Y'));
                         }
                     }
                 }
             }
             $subscription->setStartDate($start_date);
             if (isset($res['ExpireDate'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('ExpireDate');
                 $sub_attr->setValue($res['ExpireDate']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
                 $subscription->setExpireDate(new \DateTime($res['ExpireDate']->getValue()));
                 if (isset($res['AutoRenewal'])) {
                     if ($res['AutoRenewal']->getValue() == 'Y') {
                         $date1 = new \DateTime($res['StartDate']->getValue());
                         $interval = $date1->diff(new \DateTime($res['ExpireDate']->getValue()));
                         $expire_date = new \DateTime($start_date->format('Y-m-d'));
                         $expire_date->add($interval);
                         $subscription->setExpireDate($expire_date);
                     }
                 }
             }
             if (isset($res['Month'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('Month');
                 $sub_attr->setValue($res['Month']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
                 $expire_date = new \DateTime($subscription->getStartDate()->format('Y-m-d'));
                 $expire_date->add(new \DateInterval('P' . $res['Month']->getValue() . 'M'));
                 $subscription->setExpireDate($expire_date);
             }
             if (isset($res['Ticket'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('Ticket');
                 $sub_attr->setValue($res['Ticket']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
                 $subscription->setType('ticket');
             }
             if (isset($res['AutoRenewal'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('AutoRenewal');
                 $sub_attr->setValue($res['AutoRenewal']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
             }
             if (isset($res['Lifetime'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('Lifetime');
                 $sub_attr->setValue($res['Lifetime']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
             }
             if (isset($res['AllowedPauses'])) {
                 $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                 $sub_attr->setSubscription($subscription);
                 $sub_attr->setAttributeName('AllowedPauses');
                 $sub_attr->setValue($res['AllowedPauses']->getValue());
                 $subscription->addSubscriptionAttributes($sub_attr);
                 $this->em->persist($sub_attr);
             }
             if (isset($res['Location'])) {
                 $locations = preg_split("/,/", $res['Location']->getValue());
                 foreach ($locations as $location) {
                     $sub_attr = new \Club\ShopBundle\Entity\SubscriptionAttribute();
                     $sub_attr->setSubscription($subscription);
                     $sub_attr->setAttributeName('Location');
                     $sub_attr->setValue($location);
                     $subscription->addSubscriptionAttributes($sub_attr);
                     $this->em->persist($sub_attr);
                 }
             }
             $this->em->persist($subscription);
         }
     }
     $this->em->flush();
 }