예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function create($orderId)
 {
     $order = $this->orderRepository->get($orderId);
     if ($order->getCustomerId()) {
         throw new AlreadyExistsException(__("This order already has associated customer account"));
     }
     $customerData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer', $order->getBillingAddress(), []);
     $addresses = $order->getAddresses();
     foreach ($addresses as $address) {
         $addressData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer_address', $address, []);
         /** @var \Magento\Customer\Api\Data\AddressInterface $customerAddress */
         $customerAddress = $this->addressFactory->create(['data' => $addressData]);
         if (is_string($address->getRegion())) {
             /** @var \Magento\Customer\Api\Data\RegionInterface $region */
             $region = $this->regionFactory->create();
             $region->setRegion($address->getRegion());
             $region->setRegionCode($address->getRegionCode());
             $region->setRegionId($address->getRegionId());
             $customerAddress->setRegion($region);
         }
         $customerData['addresses'][] = $customerAddress;
     }
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $this->customerFactory->create(['data' => $customerData]);
     $account = $this->accountManagement->createAccount($customer);
     $order->setCustomerId($account->getId());
     $this->orderRepository->save($order);
     return $account;
 }
예제 #2
0
 /**
  * Process relations for CreditMemo
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @throws \Exception
  * @return void
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Creditmemo $object */
     if ($object->getState() == \Magento\Sales\Model\Order\Creditmemo::STATE_REFUNDED) {
         $this->prepareOrder($object);
         if ($object->getInvoice()) {
             $this->prepareInvoice($object);
             $this->invoiceRepository->save($object->getInvoice());
         }
         $this->preparePayment($object);
         $this->orderRepository->save($object->getOrder());
     }
 }
예제 #3
0
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  * @throws \Exception
  */
 public function place(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     // transaction will be here
     //begin transaction
     try {
         $order->place();
         return $this->orderRepository->save($order);
         //commit
     } catch (\Exception $e) {
         throw $e;
         //rollback;
     }
 }