示例#1
0
 protected function setOrderDetails($modxOrder, $order, $timezone, $em)
 {
     $order->setWcId($modxOrder['id']);
     $order->setNumber('UV' . $modxOrder['id']);
     $order->setCreatedAt(new \DateTime($modxOrder['createdon'], $timezone));
     $order->setState("backoffice");
     $order->setPeople($modxOrder['kolchel']);
     $order->setTotal($modxOrder['cost'] * 100);
     $order->setProductsTotal($modxOrder['cost'] * 100);
     $order->setAdjustmentTotal(0);
     $product = $em->getRepository('MeVisaERPBundle:Products')->findOneBy(array('name' => $modxOrder['namezakaz']));
     if (!$product) {
         $product = new Products();
         $product->setEnabled(true);
         $product->setName($modxOrder['namezakaz']);
         $product->setRequiredDocuments(array());
         $product->setUrgent(false);
         $productPrice = new ProductPrices();
         $productPrice->setCost(0);
         $productPrice->setPrice($modxOrder['cost'] * 100 / $modxOrder['kolchel']);
         $product->addPricing($productPrice);
         $em->persist($product);
     }
     $productPrice = $product->getPricing()->last();
     $orderProduct = new OrderProducts();
     $orderProduct->setProduct($product);
     $orderProduct->setQuantity($modxOrder['kolchel']);
     $orderProduct->setUnitPrice($modxOrder['cost'] * 100 / $modxOrder['kolchel']);
     $orderProduct->setUnitCost($productPrice->getCost());
     $orderProduct->setVendor($product->getVendor());
     $orderProduct->setTotal($modxOrder['cost'] * 100);
     $order->addOrderProduct($orderProduct);
     $order->setPeople($modxOrder['kolchel']);
     $arrival = \DateTime::createFromFormat('Y-m-d G:i:s', $modxOrder['datet'], $timezone);
     if ($arrival) {
         $order->setArrival($arrival);
     } else {
         //TODO: Report issue
         dump('Invalid arrival for Order: ' . $order->getNumber());
     }
     $departure = \DateTime::createFromFormat("Y-m-d G:i:s", $modxOrder['dateo'], $timezone);
     if ($departure) {
         $order->setDeparture($departure);
     } else {
         //TODO: Report issue
         dump('Invalid departure for Order: ' . $order->getNumber());
     }
     $accessBasePath = 'http://uaevisa.ru/assets/uploads/';
     $uploadBasePath = $this->getContainer()->getParameter('uaevc_path');
     $fs = new Filesystem();
     if ($fs->exists($uploadBasePath . $order->getWcId())) {
         $finder = new Finder();
         $finder->files()->in($uploadBasePath . $order->getWcId());
         foreach ($finder as $file) {
             $document = new \MeVisa\ERPBundle\Entity\OrderDocuments();
             $document->setName($file->getFileName());
             // http://uaevisa.ru/assets/uploads/74/0/contact_pasp_2016-09-06_12-54-15.png
             $document->setPath($accessBasePath . $order->getWcId() . '/' . $file->getRelativePathname());
             $order->addOrderDocument($document);
         }
     }
     $orderPayment = new OrderPayments();
     // method_id method_title
     $orderPayment->setMethod('payu');
     $orderPayment->setAmount($modxOrder['cost'] * 100);
     $orderPayment->setCreatedAt(new \DateTime($modxOrder['editedon'], $timezone));
     if (1 == $modxOrder['active']) {
         $orderPayment->setState("paid");
     } else {
         $orderPayment->setState("not_paid");
     }
     $order->addOrderPayment($orderPayment);
     if ("" != $modxOrder['description']) {
         $orderComment = new OrderComments();
         $orderComment->setComment($modxOrder['note'] . "-- Customer: " . $order->getCustomer()->getName());
         $orderComment->setCreatedAt(new \DateTime($modxOrder['created_at'], $timezone));
         $order->addOrderComment($orderComment);
     }
     if ("" != $modxOrder["name1"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name1"] . $modxOrder["famil1"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name2"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name2"] . $modxOrder["famil2"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name3"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name3"] . $modxOrder["famil3"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name4"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name4"] . $modxOrder["famil4"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name5"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name5"] . $modxOrder["famil5"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name6"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name6"] . $modxOrder["famil6"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name7"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name7"] . $modxOrder["famil7"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name8"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name8"] . $modxOrder["famil8"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name9"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name9"] . $modxOrder["famil9"]);
         $order->addOrderCompanion($orderCompanion);
     }
     //FIXME: Dynamic channel
     $order->setChannel("uaevisa.ru");
     $order->setTicketRequired(false);
 }
示例#2
0
 protected function setOrderDetails($wcOrder, $order, $timezone, $em)
 {
     foreach ($wcOrder['line_items'] as $lineItem) {
         $product = $em->getRepository('MeVisaERPBundle:Products')->findOneBy(array('wcId' => $lineItem['product_id']));
         if (!$product) {
             $product = new Products();
             $product->setEnabled(true);
             $product->setName($lineItem['name']);
             $product->setWcId($lineItem['product_id']);
             $product->setRequiredDocuments(array());
             $productPrice = new ProductPrices();
             $productPrice->setCost(0);
             $productPrice->setPrice($lineItem['price'] * 100);
             $product->addPricing($productPrice);
             $em->persist($product);
         }
         $orderProduct = new OrderProducts();
         $orderProduct->setProduct($product);
         $orderProduct->setQuantity($lineItem['quantity']);
         $orderProduct->setUnitPrice($lineItem['price'] * 100);
         $orderProduct->setTotal($lineItem['total'] * 100);
         $order->addOrderProduct($orderProduct);
         $order->setPeople($lineItem['meta'][0]['value']);
         $order->setDeparture(\DateTime::createFromFormat("d/m/Y", $lineItem['meta'][4]['value'], $timezone));
         $order->setArrival(\DateTime::createFromFormat("d/m/Y", $lineItem['meta'][5]['value']), $timezone);
         //FIXME: check available docs first
         $docs = explode(',', $lineItem['meta'][6]['value']);
         foreach ($docs as $doc) {
             $document = new \MeVisa\ERPBundle\Entity\OrderDocuments();
             $document->setName($doc);
             // http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/3975-915-img_9996.jpg
             $document->setPath('http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/' . $wcOrder['order_number'] . '-' . $lineItem['product_id'] . '-' . $doc);
             $order->addOrderDocument($document);
         }
     }
     $orderPayment = new OrderPayments();
     // method_id method_title
     $orderPayment->setMethod($wcOrder['payment_details']['method_id']);
     $orderPayment->setAmount($wcOrder['total'] * 100);
     $orderPayment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
     if ("true" == $wcOrder['payment_details']['paid']) {
         $orderPayment->setState("paid");
     } else {
         $orderPayment->setState("not_paid");
     }
     $order->addOrderPayment($orderPayment);
     if ("" != $wcOrder['note']) {
         $orderComment = new OrderComments();
         $orderComment->setComment($wcOrder['note'] . "-- Customer: " . $order->getCustomer()->getName());
         $orderComment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
         $order->addOrderComment($orderComment);
     }
     $order->setNumber($wcOrder['order_number']);
     $order->setWcId($wcOrder['order_number']);
     //FIXME: Dynamic channel
     $order->setChannel("MeVisa.ru");
     $order->setAdjustmentTotal($wcOrder['total_discount'] * 100);
     $order->setProductsTotal($wcOrder['subtotal'] * 100);
     $order->setTotal($wcOrder['total'] * 100);
     $order->setState($wcOrder['status']);
     $order->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
 }
示例#3
0
 protected function setOrderDetails($wcOrder, $order, $timezone, $em)
 {
     $order->setWcId($wcOrder['order_number']);
     $order->setNumber($wcOrder['order_number']);
     $order->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
     switch ($wcOrder['status']) {
         case "cancelled":
         case "failed":
             $state = "cancelled";
             break;
         case "refunded":
             $state = "refunded";
             break;
         case "pending":
         case "processing":
         case "on-hold":
         case "completed":
         default:
             $state = "backoffice";
             break;
     }
     $order->setState($state);
     $order->setTotal($wcOrder['total'] * 100);
     $order->setProductsTotal($wcOrder['subtotal'] * 100);
     $order->setPeople(0);
     foreach ($wcOrder['line_items'] as $lineItem) {
         $product = $em->getRepository('MeVisaERPBundle:Products')->findOneBy(array('wcId' => $lineItem['product_id']));
         if (!$product) {
             $product = new Products();
             $product->setEnabled(true);
             $product->setName($lineItem['name']);
             $product->setWcId($lineItem['product_id']);
             $product->setRequiredDocuments(array());
             $productPrice = new ProductPrices();
             $productPrice->setCost(0);
             $productPrice->setPrice($lineItem['price'] * 100);
             $product->addPricing($productPrice);
             $em->persist($product);
         }
         //TODO: 1) Check product cost structure
         //TODO: 2) Recalculate cost
         $productPrice = $product->getPricing()->last();
         $orderProduct = new OrderProducts();
         $orderProduct->setProduct($product);
         $orderProduct->setQuantity($lineItem['quantity']);
         $orderProduct->setUnitPrice($lineItem['price'] * 100);
         $orderProduct->setUnitCost($productPrice->getCost());
         $orderProduct->setVendor($product->getVendor());
         $orderProduct->setTotal($lineItem['total'] * 100);
         $order->addOrderProduct($orderProduct);
         foreach ($lineItem['meta'] as $key => $meta) {
             switch ($meta['key']) {
                 case 'Кол-во человек':
                     $order->setPeople($order->getPeople() + $meta['value']);
                     break;
                 case 'Дата вылета':
                     $arrival = \DateTime::createFromFormat("d/m/Y", $meta['value'], $timezone);
                     $order->setArrival($arrival);
                     break;
                 case 'Дата возврата':
                     $departure = \DateTime::createFromFormat("d/m/Y", $meta['value'], $timezone);
                     $order->setDeparture($departure);
                     break;
                 case 'Прикрепите копию паспорта и фото (для всех туристов)':
                     $docs = explode(',', $meta['value']);
                     foreach ($docs as $doc) {
                         $document = new \MeVisa\ERPBundle\Entity\OrderDocuments();
                         $document->setName($doc);
                         // http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/3975-915-img_9996.jpg
                         $document->setPath('http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/' . $wcOrder['order_number'] . '-' . $lineItem['product_id'] . '-' . $doc);
                         $order->addOrderDocument($document);
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     $order->setAdjustmentTotal($wcOrder['total_discount'] * 100);
     $orderPayment = new OrderPayments();
     // method_id method_title
     $orderPayment->setMethod($wcOrder['payment_details']['method_id']);
     $orderPayment->setAmount($wcOrder['total'] * 100);
     $orderPayment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
     if ("true" == $wcOrder['payment_details']['paid']) {
         $orderPayment->setState("paid");
     } else {
         $orderPayment->setState("not_paid");
     }
     $order->addOrderPayment($orderPayment);
     if ("" != $wcOrder['note']) {
         $orderComment = new OrderComments();
         $orderComment->setComment($wcOrder['note'] . "-- Customer: " . $order->getCustomer()->getName());
         $orderComment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
         $order->addOrderComment($orderComment);
     }
     //FIXME: Dynamic channel
     $order->setChannel("MeVisa.ru");
     $order->setTicketRequired(false);
 }