/** * @EXT\Route( * "/product/{product}/infos", * name="product_infos", * options={"expose"=true} * ) * * @return Response */ public function productInfosAction(Product $product) { $priceSolutions = $product->getPriceSolutions(); $solutionsDatas = array(); foreach ($priceSolutions as $solution) { $solutionsDatas[] = array('id' => $solution->getId(), 'duration' => $solution->getMonthDuration(), 'price' => $solution->getPrice()); } $datas = array('details' => $product->getDetails(), 'priceSolutions' => $solutionsDatas); return new JsonResponse($datas, 200); }
/** * @EXT\Route( * "/payment/workspace/submit/order/{order}/product/{product}", * name="workspace_product_payment_submit" * ) * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true}) * @return Response */ public function addOrderToChartAction(Order $order, Product $product) { $chart = $order->getChart(); //check it wasn't already submitted if (false) { $content = $this->renderView('FormaLibreInvoiceBundle:errors:orderAlreadySubmitedException.html.twig'); return new Response($content); } if ($this->session->has('form_price_data')) { $priceSolution = $this->session->get('form_price_data'); $this->session->remove('form_price_data'); $priceSolution = $this->em->getRepository('FormaLibreInvoiceBundle:PriceSolution')->find($priceSolution->getId()); } $form = $this->createForm(new SharedWorkspaceForm($product)); $form->handleRequest($this->request); if ($form->isValid()) { //do that stuff here if (!$this->authorization->isGranted('ROLE_USER')) { $this->session->set('form_price_data', $form->get('price')->getData()); $redirectRoute = $this->router->generate('workspace_product_payment_submit', array('order' => $order->getId(), 'product' => $product->getId(), 'chart' => $chart->getId())); $this->session->set('redirect_route', $redirectRoute); $route = $this->router->generate('claro_security_login', array()); return new RedirectResponse($route); } $priceSolution = $form->get('price')->getData(); } $order->setChart($chart); $order->setProduct($product); $chart->setOwner($this->tokenStorage->getToken()->getUser()); $chart->setIpAdress($_SERVER['REMOTE_ADDR']); $order->setPriceSolution($priceSolution); $order->setChart($chart); if ($this->swsManager->hasFreeTestMonth($chart->getOwner())) { $order->setHasDiscount(true); $this->swsManager->useFreeTestMonth($chart->getOwner()); } $this->em->persist($chart); $this->em->persist($order); $this->em->flush(); return new RedirectResponse($this->router->generate('chart_payment_confirm', array('chart' => $order->getChart()->getId()), true)); throw new \Exception('Errors were found: ' . $form->getErrorsAsString()); }
private function createSupportCreditsProducts() { $this->log('Creating support credits products...'); $pack20 = $this->productRepo->findOneByCode('SUPPORT_CREDITS_PACK_20'); if (is_null($pack20)) { $pack20 = new Product(); $pack20->setCode('SUPPORT_CREDITS_PACK_20'); $pack20->setType('SUPPORT_CREDITS'); $details = array('name' => 'Pack 20', 'nb_credits' => 20, 'nb_hours' => 4, 'saving' => 0); $pack20->setDetails($details); $pack20->setIsActivated(true); $priceSolution = new PriceSolution(); $priceSolution->setPrice(250); $priceSolution->setProduct($pack20); $this->om->persist($priceSolution); $pack20->addPriceSolution($priceSolution); $this->om->persist($pack20); } $pack50 = $this->productRepo->findOneByCode('SUPPORT_CREDITS_PACK_50'); if (is_null($pack50)) { $pack50 = new Product(); $pack50->setCode('SUPPORT_CREDITS_PACK_50'); $pack50->setType('SUPPORT_CREDITS'); $details = array('name' => 'Pack 50', 'nb_credits' => 50, 'nb_hours' => 10, 'saving' => 50); $pack50->setDetails($details); $pack50->setIsActivated(true); $priceSolution = new PriceSolution(); $priceSolution->setPrice(575); $priceSolution->setProduct($pack50); $this->om->persist($priceSolution); $pack50->addPriceSolution($priceSolution); $this->om->persist($pack50); } $pack100 = $this->productRepo->findOneByCode('SUPPORT_CREDITS_PACK_100'); if (is_null($pack100)) { $pack100 = new Product(); $pack100->setCode('SUPPORT_CREDITS_PACK_100'); $pack100->setType('SUPPORT_CREDITS'); $details = array('name' => 'Pack 100', 'nb_credits' => 100, 'nb_hours' => 20, 'saving' => 250); $pack100->setDetails($details); $pack100->setIsActivated(true); $priceSolution = new PriceSolution(); $priceSolution->setPrice(1000); $priceSolution->setProduct($pack100); $this->om->persist($priceSolution); $pack50->addPriceSolution($priceSolution); $this->om->persist($pack100); } }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $data = array(array('code' => 'SUPPORT_CREDITS_PACK_20', 'type' => 'SUPPORT_CREDITS', 'details' => array('name' => 'Pack 20', 'nb_credits' => 20, 'nb_hours' => 4, 'saving' => 0), 'pricing' => 250), array('code' => 'SUPPORT_CREDITS_PACK_50', 'type' => 'SUPPORT_CREDITS', 'details' => array('name' => 'Pack 50', 'nb_credits' => 50, 'nb_hours' => 10, 'saving' => 50), 'pricing' => 575), array('code' => 'SUPPORT_CREDITS_PACK_100', 'type' => 'SUPPORT_CREDITS', 'details' => array('name' => 'Pack 100', 'nb_credits' => 100, 'nb_hours' => 20, 'saving' => 250), 'pricing' => 1000)); foreach ($data as $info) { $product = new Product(); $product->setCode($info['code']); $product->setType($info['type']); $product->setDetails($info['details']); $product->setIsActivated(true); $priceSolution = new PriceSolution(); $priceSolution->setPrice($info['pricing']); $priceSolution->setProduct($product); $manager->persist($priceSolution); $product->addPriceSolution($priceSolution); $manager->persist($product); } $manager->flush(); }
public function createFromFormByType($form, $type) { $code = $form->get('code')->getData(); $product = new Product(); $product->setCode($code); $product->setType($type); $data = $form->getData(); unset($data['code']); $product->setDetails($data); $this->om->persist($product); $this->om->flush(); return $product; }
public function isProductAvailableFor(SharedWorkspace $sws, Product $product) { $workspace = $this->getWorkspaceData($sws); $ut = $this->container->get('claroline.utilities.misc'); $productData = $product->getDetails(); if ($workspace->user_amount > $productData['max_users']) { return false; } if ($ut->getRealFileSize($workspace->storage_used) > $ut->getRealFileSize($productData['max_storage'])) { return false; } if ($workspace->count_resources > $productData['max_resources']) { return false; } return true; }
/** * @EXT\Route( * "/free_test/{product}", * name="formalibre_free_test_workspace" * ) * @return Response */ public function createFreeTestWorkspace(Product $product) { if (!$this->authorization->isGranted('ROLE_USER')) { $redirectRoute = $this->router->generate('formalibre_free_test_workspace', array('product' => $product->getId())); $this->session->set('redirect_route', $redirectRoute); $route = $this->router->generate('claro_security_login', array()); return new RedirectResponse($route); } $user = $this->tokenStorage->getToken()->getUser(); if (!$this->sharedWorkspaceManager->hasFreeTestMonth($user)) { $content = $this->renderView('FormaLibreInvoiceBundle:errors:freeTestMonthUsedException.html.twig'); return new Response($content); } $chart = new Chart(); $ps = $this->productManager->getPriceSolution($product, 1); $order = new Order(); $chart->setOwner($user); $chart->setIpAdress($_SERVER['REMOTE_ADDR']); $order->setPriceSolution($ps); $order->setProduct($product); $chart->addOrder($order); $order->setChart($chart); $this->em->persist($order); $this->em->persist($chart); $this->sharedWorkspaceManager->useFreeTestMonth($user); $invoice = $this->invoiceManager->create($chart, 'free'); $this->invoiceManager->validate($invoice); $invoice->setPaymentSystemName('none'); $this->em->persist($invoice); $this->em->flush(); return new RedirectResponse($this->router->generate('claro_desktop_open', array())); }
/** * @EXT\Route( * "/product/{product}/edit", * name="formalibre_product_edit", * options = {"expose"=true} * ) * @Security("has_role('ROLE_ADMIN')") * @EXT\Template * * @return Response */ public function editProductAction(Product $product) { $type = $product->getType(); $form = $this->createForm($this->productManager->getEditFormByType($type)); $form->handleRequest($this->get('request')); if ($form->isValid()) { //do some stuff $details = $product->getDetails(); foreach ($form->getIterator() as $el) { //var_dump($el); $details[$el->getName()] = $form->get($el->getName())->getData(); } $product->setDetails($details); $this->productManager->persist($product); return new JsonResponse(array('id' => $product->getId(), 'code' => $product->getCode(), 'type' => $product->getType(), 'details' => $product->getDetails(), 'priceSolutions' => array())); } return $this->render('FormaLibreInvoiceBundle:Administration:editProductForm.html.twig', array('form' => $form->createView(), 'product' => $product)); }