private function createOrder($status, $stockLevel) { $repository = $this->em->getRepository('ElmetSiteBundle:CurtainColour'); $curtainColour = $repository->findOneById('1'); $curtainColour->setAvailableStock($stockLevel); $curtainColour->setInStock(1); $order = new Order(); $order->setOrderStatus($status); $orderItems = $order->getOrderItems(); $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Geneva Ready-made (Jacquard) Curtains"); $orderItem->setItemFilepath($curtainColour->getThumbnailFilepath()); $orderItem->setName("Ready-made Curtains (pair)"); $orderItem->setPrice(100.25); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Curtain"); $orderItem->setQuantity(1); $orderItem->setSize("52\" x 90\""); $orderItem->setSubtotal(100.25); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItem->setOrder($order); $orderItems->add($orderItem); $order->updateOrderTotal(); $this->em->merge($curtainColour); $this->em->persist($order); $this->em->flush(); return $order; }
private function createOrderTracking($em, $email, $billingName, $postCode, $status) { $repository = $this->em->getRepository('ElmetSiteBundle:CurtainColour'); $curtainColour = $repository->findOneById('2'); $order = new Order(); $order->setBillingAddress("20 Sussex Gardens"); $order->setBillingAddress2("Ancells Park"); $order->setBillingName($billingName); $order->setBillingPostcode($postCode); $order->setBillingTown("Fleet"); $order->setDeliveryAddress("8 Southwood Close"); $order->setDeliveryAddress2("Great Lever"); $order->setDeliveryName("Ranjiva Prasad"); $order->setDeliveryPostcode($postCode); $order->setDeliveryTown("Bolton"); $order->setEmail($email); $order->setFirstName("Ranjiva"); $order->setLastName("Prasad"); $order->setMobile("07769901335"); $order->setNotes("Ring the Doorbell"); $order->setOrderStatus($status); $order->setTelephone("01252 643872"); $orderItems = $order->getOrderItems(); $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Geneva Ready-made (Jacquard) Curtains"); $orderItem->setItemFilepath($curtainColour->getThumbnailFilepath()); $orderItem->setName("Ready-made Curtains (pair)"); $orderItem->setPrice(100.25); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Curtain"); $orderItem->setQuantity(1); $orderItem->setSize("52 X 90"); $orderItem->setSubtotal(100.25); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItem->setOrder($order); $orderItems->add($orderItem); $order->updateOrderTotal(); $orderTracking = new OrderTracking(); $orderTracking->setOrder($order); $orderTracking->setTrackingStatus('Received'); $em->persist($order); $em->persist($orderTracking); $em->flush(); return $orderTracking; }
public function addAction($urlName, $colour) { $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainColour'); $curtainColour = $repository->findOneByNameJoinedToDesignByUrlName($colour, $urlName); $curtainDesign = $curtainColour->getCurtainDesign(); $curtainPriceBand = $curtainDesign->getCurtainPriceBand(); $curtainFabrics = $curtainPriceBand->getCurtainFabrics(); $cushionCovers = $curtainPriceBand->getCushionCovers(); $curtainPelmets = $curtainPriceBand->getCurtainPelmets(); $curtainTieBacks = $curtainPriceBand->getCurtainTieBacks(); $em = $this->getDoctrine()->getEntityManager(); $query = $em->createQuery('SELECT cp FROM ElmetSiteBundle:CurtainPrice cp JOIN cp.curtain_price_band cpd WHERE cpd.id = :id ORDER BY cp.width ASC, cp.height asc'); $query->setParameter('id', $curtainPriceBand->getId()); $curtainPrices = $query->getResult(); $order = $this->getOrder(); $orderItems = $order->getOrderItems(); $discount = 1 - $curtainColour->getDiscountPercentage() / 100; //add curtains first $homeWindowIndex = 0; $caravanWindowIndex = 0; $caravanDoorIndex = 0; foreach ($curtainPrices as $curtainPrice) { $eyeletQuantity = 0; $quantity = 0; if ($curtainPrice->getType() == 'HomeWindow') { $quantity = $this->getRequest()->get('home_tape_curtain_' . $homeWindowIndex); $eyeletQuantity = $this->getRequest()->get('home_eyelet_curtain_' . $homeWindowIndex); } else { if ($curtainPrice->getType() == 'CaravanWindow') { $quantity = $this->getRequest()->get('caravan_window_curtain_' . $caravanWindowIndex); } else { if ($curtainPrice->getType() == 'CaravanDoor') { $quantity = $this->getRequest()->get('caravan_door_curtain_' . $caravanDoorIndex); } } } if ($quantity != 0) { $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); if ($curtainPrice->getType() == 'CaravanDoor') { $orderItem->setDescription("Ready-made Curtains"); } else { $orderItem->setDescription("Ready-made Curtains (pair)"); } $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName()); if ($curtainColour->getOnOffer() == 0) { $price = $curtainPrice->getPrice(); } else { $price = number_format(round($curtainPrice->getPrice() * $discount, 2), 2); } $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Curtain"); $orderItem->setQuantity($quantity); $orderItem->setSize($curtainPrice->getSize()); $orderItem->setSubtotal($quantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } if ($eyeletQuantity != 0) { $price = $curtainPrice->getPrice() + $curtainPrice->getCurtainEyeletPriceBand()->getPrice(); if ($curtainColour->getOnOffer() == 1) { $price = number_format(round($price * $discount, 2), 2); } $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Ready-made Curtains (pair)"); $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName() . " with Eyelets"); $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Curtain"); $orderItem->setQuantity($eyeletQuantity); $orderItem->setSize($curtainPrice->getSize()); $orderItem->setSubtotal($eyeletQuantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } if ($curtainPrice->getType() == 'HomeWindow') { $homeWindowIndex = $homeWindowIndex + 1; } else { if ($curtainPrice->getType() == 'CaravanWindow') { $caravanWindowIndex = $caravanWindowIndex + 1; } else { if ($curtainPrice->getType() == 'CaravanDoor') { $caravanDoorIndex = $caravanDoorIndex + 1; } } } } $i = 0; foreach ($curtainPelmets as $curtainPelmet) { $quantity = $this->getRequest()->get('pelmet_' . $i); if ($quantity != 0) { $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Pelmet"); $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName()); if ($curtainColour->getOnOffer() == 0) { $price = $curtainPelmet->getPrice(); } else { $price = number_format(round($curtainPelmet->getPrice() * $discount, 2), 2); } $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Pelmet"); $orderItem->setQuantity($quantity); $orderItem->setSize($curtainPelmet->getSize()); $orderItem->setSubtotal($quantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } $i = $i + 1; } $i = 0; foreach ($cushionCovers as $cushionCover) { $quantity = $this->getRequest()->get('cushion_' . $i); if ($quantity != 0) { $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Cushion Cover"); $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName()); if ($curtainColour->getOnOffer() == 0) { $price = $cushionCover->getPrice(); } else { $price = number_format(round($cushionCover->getPrice() * $discount, 2), 2); } $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Cushion Cover"); $orderItem->setQuantity($quantity); $orderItem->setSize($cushionCover->getSize()); $orderItem->setSubtotal($quantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } $i = $i + 1; } $curtainFabric = $curtainFabrics->first(); $quantity = $this->getRequest()->get('fabric'); if ($quantity != 0) { $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Fabric Only"); $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName()); if ($curtainColour->getOnOffer() == 0) { $price = $curtainFabric->getPricePerMetre(); } else { $price = number_format(round($curtainFabric->getPricePerMetre() * $discount, 2), 2); } $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Fabric"); $orderItem->setFabricQuantity($quantity); $orderItem->setSize($curtainDesign->getFabricWidth()); $orderItem->setSubtotal($quantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } $homeTieBackIndex = 0; $caravanTieBackIndex = 0; foreach ($curtainTieBacks as $curtainTieBack) { if ($curtainTieBack->getType() == 'HomeWindow') { $quantity = $this->getRequest()->get('home_tieback_' . $homeTieBackIndex); } else { if ($curtainTieBack->getType() == 'CaravanWindow') { $quantity = $this->getRequest()->get('caravan_tieback_' . $caravanTieBackIndex); } } if ($quantity != 0) { $orderItem = new OrderItem(); $orderItem->setColour($curtainColour->getName()); $orderItem->setDescription("Tieback (pair)"); $orderItem->setItemFilepath("/img/products/" . $curtainColour->getThumbnailFilepath()); $orderItem->setName($curtainDesign->getName()); if ($curtainColour->getOnOffer() == 0) { $price = $curtainTieBack->getPrice(); } else { $price = number_format(round($curtainTieBack->getPrice() * $discount, 2), 2); } $orderItem->setPrice($price); $orderItem->setCurtainColour($curtainColour); $orderItem->setProductType("Tieback"); $orderItem->setQuantity($quantity); $orderItem->setSize($curtainTieBack->getSize()); $orderItem->setSubtotal($quantity * $price); $orderItem->setOrder($order); $orderItem->setProductCategoryId($curtainColour->getId()); $orderItems->add($orderItem); } if ($curtainTieBack->getType() == 'HomeWindow') { $homeTieBackIndex = $homeTieBackIndex + 1; } else { if ($curtainTieBack->getType() == 'CaravanWindow') { $caravanTieBackIndex = $caravanTieBackIndex + 1; } } } $order->updateOrderTotal(); return $this->viewAction(); }