canChangeOrderAddress = $canChangeOrderAddress; $this->fetchesOrder = $fetchesOrder; $this->createsAddress = $createsAddress; $this->fetchesAddress = $fetchesAddress; $this->deletesAddress = $deletesAddress; $this->createContactProcessor = $createContactProcessor; $this->createRemarkProcessor = $createRemarkProcessor; } /** * @param Request $request * @return mixed * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function execute(Request $request) { $this->canChangeOrderAddress->passes(); $order = $this->fetchesOrder->execute(['id' => $request->get('order_id')]); foreach ($order->addressesPendingVerification as $address) { $this->deletesAddress->execute($address); } $address = $this->fetchesAddress->execute(['id' => $request->get('address_id')]); $addressObject = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode, AddressType::DELIVERY, ApprovalStatus::PENDING_VERIFICATION, $address->reference); $order_address = $this->createsAddress->execute($order, $addressObject); $contact = $address->contacts()->first(); if($contact){ $contactObject = new ContactObject( $contact->reference, $contact->phone, '', '' ); $this->createContactProcessor->execute($contactObject, $order_address); } $remark = $address->remarks()->first(); if($remark){ $remarkObject = new RemarkObject( $remark->content, Auth()->user()->id ); $this->createRemarkProcessor->execute($order_address, $remarkObject); } return $order; } }