canCreateOrder = $canCreateOrder; $this->createsOrder = $createsOrder; $this->createAddress = $createAddress; $this->createOrderRolesProcessor = $createOrderRolesProcessor; } /** * @param Company $company * @param CompanyModule $originWarehouse * @param Address $address * @param int|null $orderNumber * @return Addressable * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function execute(Company $company, CompanyModule $originWarehouse, Address $address, int $orderNumber){ /** @var CompanyModule $importer */ $importer = $company->companyModules()->importers()->first(); $orderObject = new OrderObject($orderNumber, OrderType::SHARED_CONTAINER, $company->status === ApprovalStatus::APPROVED ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION); $this->canCreateOrder->passes($orderObject); /** @var Order $order */ $order = $this->createsOrder->execute($importer, $orderObject); $addressObject = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode,$address->reference); $this->createAddress->execute($order, $addressObject); $this->createOrderRolesProcessor->execute($originWarehouse, $order); return $order; } }