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 processAction() { $ipn = $this->validateNotification(); if ($ipn != null) { $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:Order'); $order = $repository->findOneById($ipn->getCustom()); $order->setFirstName($ipn->getFirstName()); $order->setLastName($ipn->getLastName()); $order->setDeliveryName($ipn->getAddressName()); $order->setDeliveryAddress($ipn->getAddressStreet()); $order->setDeliveryTown($ipn->getAddressCity()); $order->setDeliveryPostcode($ipn->getAddressZip()); $order->setBillingName($ipn->getAddressName()); $order->setBillingAddress($ipn->getAddressStreet()); $order->setBillingTown($ipn->getAddressCity()); $order->setBillingPostcode($ipn->getAddressZip()); $order->setEmail($ipn->getPayerEmail()); if ($ipn->getPaymentStatus() == 'Completed') { $order->setOrderStatus("Paid"); } elseif ($ipn->getPaymentStatus() == 'Refunded') { $order->setOrderStatus("Cancelled"); } elseif ($ipn->getPaymentStatus() == 'Reversed') { $order->setOrderStatus("Disputed"); } elseif ($ipn->getPaymentStatus() == 'Canceled_Reversal') { if ($this->hasOrderBeenDispatched($ipn->getCustom())) { $order->setOrderStatus("Dispatched"); } else { $order->setOrderStatus("Paid"); } } elseif ($ipn->getPaymentStatus() == 'Pending') { $order->setOrderStatus("Clearing"); $this->sendInterimCustomerEmail($order); } else { $order->setOrderStatus("Error"); } $em = $this->getDoctrine()->getEntityManager(); $order = $em->merge($order); $em->persist($ipn); $em->flush(); $this->sendBackOfficeEmail($order); if ($ipn->getPaymentStatus() == 'Completed') { $orderTracking = new OrderTracking(); $orderTracking->setOrder($order); $orderTracking->setTrackingStatus('Received'); $orderTracking->setEstimatedDispatchDate($this->calculateDispatchDate()); $em->persist($orderTracking); $em->flush(); $this->sendCustomerEmail($orderTracking); $curtainColours = $this->updateStock($order); if (!empty($curtainColours['low'])) { $this->sendLowStockNotification($curtainColours['low']); } if (!empty($curtainColours['out'])) { $this->sendOutOfStockNotification($curtainColours['out']); } } $status = "Success"; } else { $status = "Failure"; } return new Response($status); }