/**
  * @param EntityManager $manager
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BOrderBundle/Migrations/Data/Demo/ORM/data/orders.csv');
     if (is_array($filePath)) {
         $filePath = current($filePath);
     }
     $handler = fopen($filePath, 'r');
     $headers = fgetcsv($handler, 1000, ',');
     /** @var EntityRepository $userRepository */
     $userRepository = $manager->getRepository('OroUserBundle:User');
     /** @var User $user */
     $user = $userRepository->findOneBy([]);
     $accountUser = $this->getAccountUser($manager);
     while (($data = fgetcsv($handler, 1000, ',')) !== false) {
         $row = array_combine($headers, array_values($data));
         $order = new Order();
         $billingAddress = ['label' => $row['billingAddressLabel'], 'country' => $row['billingAddressCountry'], 'city' => $row['billingAddressCity'], 'region' => $row['billingAddressRegion'], 'street' => $row['billingAddressStreet'], 'postalCode' => $row['billingAddressPostalCode']];
         $shippingAddress = ['label' => $row['shippingAddressLabel'], 'country' => $row['shippingAddressCountry'], 'city' => $row['shippingAddressCity'], 'region' => $row['shippingAddressRegion'], 'street' => $row['shippingAddressStreet'], 'postalCode' => $row['shippingAddressPostalCode']];
         $order->setOwner($user)->setAccount($accountUser->getAccount())->setIdentifier($row['identifier'])->setAccountUser($accountUser)->setOrganization($user->getOrganization())->setBillingAddress($this->createOrderAddress($manager, $billingAddress))->setShippingAddress($this->createOrderAddress($manager, $shippingAddress))->setPaymentTerm($this->getPaymentTerm($manager, $row['paymentTerm']))->setPriceList($this->getPriceList($manager, $row['priceListName']))->setShipUntil(new \DateTime())->setCurrency($row['currency'])->setPoNumber($row['poNumber'])->setSubtotal($row['subtotal']);
         if (!empty($row['customerNotes'])) {
             $order->setCustomerNotes($row['customerNotes']);
         }
         $manager->persist($order);
     }
     fclose($handler);
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * @param ObjectManager $manager
  * @param string        $name
  *
  * @return Order
  */
 protected function createOrder(ObjectManager $manager, $name)
 {
     $user = $this->getReference('order.simple_user');
     $order = new Order();
     $order->setOwner($user);
     $order->setOrganization($user->getOrganization());
     $manager->persist($order);
     $this->addReference($name, $order);
     return $order;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var User[] $users */
     $users = $manager->getRepository('OroUserBundle:User')->findAll();
     // create orders
     foreach ($users as $user) {
         $order = new Order();
         $order->setOwner($user)->setOrganization($user->getOrganization())->setIdentifier($user->getId());
         $manager->persist($order);
     }
     $manager->flush();
 }
Exemplo n.º 4
0
 /**
  * @param Order $order
  * @param Request $request
  *
  * @return array|RedirectResponse
  */
 protected function update(Order $order, Request $request)
 {
     if (!$order->getAccountUser()) {
         $accountUser = $this->get('oro_security.security_facade')->getLoggedUser();
         if (!$accountUser instanceof AccountUser) {
             throw new \InvalidArgumentException('Only AccountUser can create an Order.');
         }
         $order->setAccountUser($accountUser);
     }
     if ($order->getAccount()) {
         $paymentTerm = $this->get('orob2b_payment.provider.payment_term')->getPaymentTerm($order->getAccount());
         if ($paymentTerm) {
             $order->setPaymentTerm($paymentTerm);
         }
     }
     //TODO: set correct owner in task BB-929
     if (!$order->getOwner()) {
         $user = $this->getDoctrine()->getManagerForClass('OroUserBundle:User')->getRepository('OroUserBundle:User')->findOneBy([]);
         $order->setOwner($user);
     }
     $form = $this->createForm(FrontendOrderType::NAME, $order);
     $handler = new OrderHandler($form, $request, $this->getDoctrine()->getManagerForClass(ClassUtils::getClass($order)), $this->get('orob2b_order.provider.subtotals'));
     return $this->get('oro_form.model.update_handler')->handleUpdate($order, $form, function (Order $order) {
         return ['route' => 'orob2b_order_frontend_update', 'parameters' => ['id' => $order->getId()]];
     }, function (Order $order) {
         return ['route' => 'orob2b_order_frontend_view', 'parameters' => ['id' => $order->getId()]];
     }, $this->get('translator')->trans('orob2b.order.controller.order.saved.message'), $handler, function (Order $order, FormInterface $form, Request $request) {
         return ['form' => $form->createView(), 'entity' => $order, 'isWidgetContext' => (bool) $request->get('_wid', false), 'isShippingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_SHIPPING), 'isBillingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_BILLING), 'tierPrices' => $this->getTierPrices($order), 'matchedPrices' => $this->getMatchedPrices($order)];
     });
 }