/** * @Route("/attend/{id}", name="event_event_attend") */ public function attendAction(\Club\EventBundle\Entity\Event $event) { try { $this->get('club_event.event')->validateAttend($event, $this->getUser()); if ($event->getPrice() > 0) { $prod = new \Club\ShopBundle\Entity\CartProduct(); $prod->setPrice($event->getPrice()); $prod->setType('event'); $prod->setProductName(sprintf("Event: %s, #%d", $event->getEventName(), $event->getId())); $this->get('cart')->getCurrent()->addToCart($prod); return $this->redirect($this->generateUrl('shop_checkout')); } else { $this->get('club_event.event')->attend($event, $this->getUser()); $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('Your changes are saved.')); } } catch (\Club\EventBundle\Exception\AttendNotAvailableException $e) { $this->get('session')->getFlashBag()->add('error', $e->getMessage()); } catch (\Club\EventBundle\Exception\EventException $e) { $this->get('session')->getFlashBag()->add('error', $e->getMessage()); } catch (\Doctrine\DBAL\DBALException $e) { if (preg_match("/Duplicate entry/", $e->getMessage())) { $this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('You are already subscribed')); } else { throw $e; } } return $this->redirect($this->generateUrl('event_event')); }
protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $product = $em->find('ClubShopBundle:Product', $input->getArgument('product')); $location = $em->find('ClubUserBundle:Location', $input->getArgument('location')); $payment = $em->find('ClubShopBundle:PaymentMethod', 1); $fh = fopen($input->getArgument('file'), 'r'); while (!feof($fh)) { $member_number = trim(fgets($fh, 1024)); if (strlen($member_number) > 0) { $user = $em->getRepository('ClubUserBundle:User')->findOneBy(array('member_number' => $member_number)); if (!$user) { throw new \Exception('No such user: '******'order'); $order->createSimpleOrder($user, $location); $cart_prod = new \Club\ShopBundle\Entity\CartProduct(); $cart_prod->setType('subscription'); $cart_prod->setQuantity(1); $cart_prod->setPrice($product->getPrice()); $cart_prod->setProductName($product->getProductName()); $cart_prod->setProduct($product); foreach ($product->getProductAttributes() as $attr) { $product_attr = new \Club\ShopBundle\Entity\CartProductAttribute(); $product_attr->setCartProduct($cart_prod); $product_attr->setValue($attr->getValue()); $product_attr->setAttributeName($attr->getAttribute()); $cart_prod->addCartProductAttribute($product_attr); } $order->addCartProduct($cart_prod); $order->save(); $p = new \Club\ShopBundle\Entity\PurchaseLog(); $p->setAmount($order->getOrder()->getAmountLeft() * 100); $p->setCurrency('DKK'); $p->setAccepted(true); $p->setOrder($order->getOrder()); $p->setPaymentMethod($payment); $em->persist($p); $order->makePayment($p); $em->flush(); } } $em->flush(); }
public function onTeamPenalty(\Club\TaskBundle\Event\FilterTaskEvent $event) { if (!$this->penalty_enabled) { return; } $schedules = $this->em->getRepository('ClubTeamBundle:Schedule')->getNotProcessed(); foreach ($schedules as $schedule) { foreach ($schedule->getUsers() as $user) { if (!$user->getConfirmed()) { $product = new \Club\ShopBundle\Entity\CartProduct(); $product->setPrice($schedule->getPenalty()); $product->setQuantity(1); $product->setType('team_fee'); $product->setProductName($this->penalty_product_name); $this->order->createSimpleOrder($user->getUser(), $schedule->getLocation()); $this->order->addSimpleProduct($product); $this->order->save(); } } $schedule->setProcessed(true); $this->em->persist($schedule); } $this->em->flush(); }
public function addToCart() { $product = new \Club\ShopBundle\Entity\CartProduct(); $product->setPrice($this->container->getParameter('club_booking.guest_price')); $product->setQuantity(1); $product->setType('guest_booking'); $product->setProductName($this->translator->trans('Guest booking') . ', #' . $this->booking->getId()); $cart = $this->container->get('cart'); $cart->getCurrent()->addToCart($product); }
public function updateShipping() { foreach ($this->cart->getCartProducts() as $cart_prod) { if ($cart_prod->getType() == 'shipping') { $this->em->remove($cart_prod); } } $this->em->flush(); if ($this->cart->getShipping()->getPrice() > 0) { $prod = new \Club\ShopBundle\Entity\CartProduct(); $prod->setType('shipping'); $prod->setPrice($this->cart->getShipping()->getPrice()); $prod->setProductName(sprintf('Shipping: %s', $this->cart->getShipping()->getShippingName())); $this->addToCart($prod); } }
private function addProductToCart(\Club\ShopBundle\Entity\Product $product) { $this->checkLocation($product); $trigger = 0; // check if its already in the cart foreach ($this->cart->getCartProducts() as $prod) { if ($prod->getProduct()->getId() == $product->getId()) { $prod = $this->modifyQuantity($prod); $trigger = 1; } } if (!$trigger) { $op = new \Club\ShopBundle\Entity\CartProduct(); $op->setCart($this->cart); $op->setProduct($product); $op->setProductName($product->getProductName()); $op->setPrice($product->getSpecialPrice()); $op->setVatRate($product->getVat()->getRate()); $op->setQuantity(1); $op->setType('product'); foreach ($product->getProductAttributes() as $attr) { $opa = new \Club\ShopBundle\Entity\CartProductAttribute(); $opa->setCartProduct($op); $opa->setValue($attr->getValue()); $opa->setAttributeName($attr->getAttribute()->getAttributeName()); $op->addCartProductAttribute($opa); } $this->updateProductToCart($op); } }