From 7819db8dbd9a15ef74347d20d40f818fd4596fa1 Mon Sep 17 00:00:00 2001 From: mbe Date: Thu, 4 Jul 2024 07:18:52 +0200 Subject: [PATCH] #36623 replace GKVCustomShipmentBuilder --- .../GKVCreateShipmentOrderRequestBuilder.php | 52 -- .../Adapter/GKVCustomShipmentBuilder.php | 302 ---------- .../mo/mo_dhl/Adapter/GKVShipmentBuilder.php | 532 ------------------ ...rnetmarkeShoppingCartPDFRequestBuilder.php | 3 +- .../ParcelShippingCustomRequestBuilder.php | 292 ++++++++++ .../Adapter/ParcelShippingRequestBuilder.php | 2 +- .../views/admin/de/module_lang.php | 20 +- .../views/admin/en/module_lang.php | 2 +- .../Admin/DeliverySetDHLController.php | 4 +- .../Controller/Admin/ErrorDisplayTrait.php | 3 - .../Controller/Admin/OrderDHLController.php | 23 +- src/modules/mo/mo_dhl/Model/MoDHLLabel.php | 22 - src/modules/mo/mo_dhl/Model/MoDHLService.php | 4 +- .../admin/tpl/order_dhl_custom_label.tpl | 367 ++---------- tests/Api/GKV/CreateShipmentOrderTest.php | 1 - 15 files changed, 371 insertions(+), 1258 deletions(-) delete mode 100644 src/modules/mo/mo_dhl/Adapter/GKVCreateShipmentOrderRequestBuilder.php delete mode 100644 src/modules/mo/mo_dhl/Adapter/GKVCustomShipmentBuilder.php delete mode 100644 src/modules/mo/mo_dhl/Adapter/GKVShipmentBuilder.php create mode 100644 src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php diff --git a/src/modules/mo/mo_dhl/Adapter/GKVCreateShipmentOrderRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/GKVCreateShipmentOrderRequestBuilder.php deleted file mode 100644 index bc7a14b6..00000000 --- a/src/modules/mo/mo_dhl/Adapter/GKVCreateShipmentOrderRequestBuilder.php +++ /dev/null @@ -1,52 +0,0 @@ -setCombinedPrinting(0)->setGroupProfileName(self::STANDARD_GRUPPENPROFIL); - } - - /** - * @param string $orderId - * @return ShipmentOrderType - * @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function buildShipmentOrder(string $orderId): ShipmentOrderType - { - $order = \oxNew(Order::class); - $order->load($orderId); - $shipmentOrder = new ShipmentOrderType($orderId, Registry::get(GKVShipmentBuilder::class)->build($order)); - $shipmentOrder->setPrintOnlyIfCodeable(new Serviceconfiguration((bool)Registry::getConfig()->getShopConfVar('mo_dhl__only_with_leitcode'))); - return $shipmentOrder; - } -} diff --git a/src/modules/mo/mo_dhl/Adapter/GKVCustomShipmentBuilder.php b/src/modules/mo/mo_dhl/Adapter/GKVCustomShipmentBuilder.php deleted file mode 100644 index 1d14c9d0..00000000 --- a/src/modules/mo/mo_dhl/Adapter/GKVCustomShipmentBuilder.php +++ /dev/null @@ -1,302 +0,0 @@ -getShipment()->getShipper(); - $receiver = $shipmentOrder->getShipment()->getReceiver(); - $returnReceiver = $shipmentOrder->getShipment()->getReturnReceiver(); - return [ - 'weight' => array_merge([ - 'total' => ['weight' => $shipmentOrder->getShipment()->getShipmentDetails()->getShipmentItem()->getWeightInKG(), 'title' => Registry::getLang()->translateString('GENERAL_ATALL')], - ], $this->getExportDocPositionWeights($shipmentOrder)), - 'shipper' => [ - 'name' => $shipper->getName(), - 'address' => $shipper->getAddress(), - ], - 'receiver' => [ - 'name' => $receiver->getName1(), - 'type' => $receiver->getAddress() !== null ? 'address' : ($receiver->getPackstation() !== null ? 'packstation' : 'poftfiliale'), - 'address' => $receiver->getAddress() ?: $receiver->getPackstation() ?: $receiver->getPostfiliale(), - 'communication' => $receiver->getCommunication(), - ], - 'returnReceiver' => [ - 'name' => $returnReceiver->getName(), - 'address' => $returnReceiver->getAddress(), - ], - 'services' => [ - 'parcelOutletRouting' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getParcelOutletRouting(), - 'printOnlyIfCodeable' => $shipmentOrder->getPrintOnlyIfCodeable(), - 'beilegerretoure' => $shipmentOrder->getShipment()->getShipmentDetails()->getReturnShipmentAccountNumber(), - 'bulkyGoods' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getBulkyGoods(), - 'additionalInsurance' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getAdditionalInsurance(), - 'identCheck' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getIdentCheck(), - 'cashOnDelivery' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getCashOnDelivery(), - 'visualAgeCheck' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getVisualCheckOfAge(), - 'pddp' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getPDDP(), - 'cdp' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getCDP(), - 'economy' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getEconomy(), - 'premium' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getPremium(), - 'endorsement' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getEndorsement(), - 'noNeighbourDelivery' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getNoNeighbourDelivery(), - 'namedPersonOnly' => $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getNamedPersonOnly(), - 'signedForByRecipient'=> $shipmentOrder->getShipment()->getShipmentDetails()->getService()->getSignedForByRecipient(), - ], - ]; - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $data - * @param Order $order - */ - public function applyCustomDataToShipmentOrder(&$shipmentOrder, $data, Order $order) - { - $this->useCustomWeightData($shipmentOrder, $data['weight']); - $this->useCustomShipper($shipmentOrder, $data['shipper']); - $this->useCustomReturnReceiver($shipmentOrder, $data['returnReceiver']); - $this->useCustomReceiver($shipmentOrder, $data['receiver']); - $this->useCustomServices($shipmentOrder, $data['services'], $order); - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $weightData - */ - protected function useCustomWeightData(ShipmentOrderType $shipmentOrder, $weightData) - { - foreach ($weightData as $key => $value) { - if (strpos($value, ',') !== false) { - $value = \OxidEsales\EshopCommunity\Core\Registry::getUtils()->string2Float($value); - } - if ($key === 'total') { - $shipmentOrder->getShipment()->getShipmentDetails()->getShipmentItem()->setWeightInKG($value); - } else { - $shipmentOrder->getShipment()->getExportDocument()->getExportDocPosition()[$key]->setNetWeightInKG($value); - } - } - } - - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $shipperData - */ - protected function useCustomShipper(ShipmentOrderType $shipmentOrder, $shipperData) - { - $shipper = $shipmentOrder->getShipment()->getShipper(); - $shipper->getName()->setName1($shipperData['name1'])->setName2($shipperData['name2'])->setName3($shipperData['name3']); - $shipperData['Origin'] = new CountryType($shipperData['country']); - $shipper->getAddress()->assign($shipperData); - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $returnReceiverData - */ - protected function useCustomReturnReceiver(ShipmentOrderType $shipmentOrder, $returnReceiverData) - { - $returnReceiver = $shipmentOrder->getShipment()->getReturnReceiver(); - $returnReceiver->getName()->setName1($returnReceiverData['name1'])->setName2($returnReceiverData['name2'])->setName3($returnReceiverData['name3']); - $returnReceiverData['Origin'] = new CountryType($returnReceiverData['country']); - $returnReceiver->getAddress()->assign($returnReceiverData); - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $receiverData - */ - protected function useCustomReceiver(ShipmentOrderType $shipmentOrder, $receiverData) - { - $receiver = $shipmentOrder->getShipment()->getReceiver(); - $receiver->setName1($receiverData['name']); - if ($receiverData['country']) { - $receiverData['Origin'] = new CountryType($receiverData['country']); - } - if ($communication = $receiver->getCommunication()) { - $communication - ->setEmail($receiverData['email']) - ->setPhone($receiverData['phone']); - } - $receiverAddress = $receiver->getAddress() ?: $receiver->getPackstation() ?: $receiver->getPostfiliale(); - if ($receiverData['province']) { - $receiverAddress->setProvince($receiverData['province']); - } - $receiverAddress->assign($receiverData); - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @param array $servicesData - * @param Order $order - */ - protected function useCustomServices(ShipmentOrderType $shipmentOrder, $servicesData, Order $order) - { - $process = $this->getProcess($order); - $services = $shipmentOrder->getShipment()->getShipmentDetails()->getService(); - if ($process->supportsParcelOutletRouting()) { - $isActive = filter_var($servicesData['parcelOutletRouting']['active'], FILTER_VALIDATE_BOOLEAN); - $details = $servicesData['parcelOutletRouting']['details'] ?? null; - $services->setParcelOutletRouting(new ServiceconfigurationDetailsOptional($isActive, $details)); - } - - if ($process->supportsDHLRetoure() && filter_var($servicesData['beilegerretoure']['active'], FILTER_VALIDATE_BOOLEAN)) { - $accountNumber = Registry::get(GKVShipmentBuilder::class)->buildReturnAccountNumber($order); - $shipmentOrder->getShipment()->getShipmentDetails()->setReturnShipmentAccountNumber($accountNumber); - } else { - $shipmentOrder->getShipment()->getShipmentDetails()->setReturnShipmentAccountNumber(null); - } - if ($process->supportsBulkyGood()) { - $isActive = filter_var($servicesData['bulkyGoods']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setBulkyGoods(new Serviceconfiguration($isActive)); - } - if ($process->supportsAdditionalInsurance()) { - $isActive = filter_var($servicesData['additionalInsurance']['active'], FILTER_VALIDATE_BOOLEAN); - $details = $servicesData['additionalInsurance']['insuranceAmount'] ?? null; - $services->setAdditionalInsurance(new ServiceconfigurationAdditionalInsurance($isActive, $details)); - } - if ($process->supportsCashOnDelivery()) { - $isActive = filter_var($servicesData['cashOnDelivery']['active'], FILTER_VALIDATE_BOOLEAN); - $details = $servicesData['cashOnDelivery']['codAmount'] ?? null; - $services->setCashOnDelivery(new ServiceconfigurationCashOnDelivery($isActive, $details)); - } - if ($process->supportsIdentCheck()) { - $isActive = filter_var($servicesData['identCheck']['active'], FILTER_VALIDATE_BOOLEAN); - if ($isActive) { - $ident = $this->extractIdent($servicesData['identCheck']); - $services->setIdentCheck(new ServiceconfigurationIC($ident, true)); - } else { - $services->setIdentCheck(null); - } - } - if ($process->supportsVisualAgeCheck()) { - $identCheckUsed = $process->supportsIdentCheck() && filter_var($servicesData['identCheck']['active'], FILTER_VALIDATE_BOOLEAN); - if (!$identCheckUsed && $ageCheck = $servicesData['visualAgeCheck'] ?? null) { - $services->setVisualCheckOfAge(new ServiceconfigurationVisualAgeCheck(true, 'A' . $ageCheck)); - } else { - $services->setVisualCheckOfAge(null); - } - - } - if ($process->supportsPDDP()) { - $isActive = filter_var($servicesData['pddp']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setPDDP(new PDDP($isActive)); - } - if ($process->supportsCDP()) { - $isActive = filter_var($servicesData['cdp']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setCDP(new CDP($isActive)); - } - if ($process->supportsEconomy()) { - $isActive = filter_var($servicesData['economy']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setEconomy(new Economy($isActive)); - } - if ($process->supportsPremium()) { - $isActive = filter_var($servicesData['premium']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setPremium(new Serviceconfiguration($isActive)); - } - if ($process->supportsEndorsement()) { - $endorsement = $servicesData['endorsement'] ?? MoDHLService::MO_DHL__ENDORSEMENT_IMMEDIATE; - $services->setEndorsement(new ServiceconfigurationEndorsement(true, $endorsement)); - } - if ($process->supportsNoNeighbourDelivery()) { - $isActive = filter_var($servicesData['noNeighbourDelivery']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setNoNeighbourDelivery(new Serviceconfiguration($isActive)); - } - if ($process->supportsNamedPersonOnly()) { - $isActive = filter_var($servicesData['namedPersonOnly']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setNamedPersonOnly(new Serviceconfiguration($isActive)); - } - if ($process->supportsSignedForByRecipient()) { - $isActive = filter_var($servicesData['signedForByRecipient']['active'], FILTER_VALIDATE_BOOLEAN); - $services->setSignedForByRecipient(new Serviceconfiguration($isActive)); - } - - $isActive = filter_var($servicesData['printOnlyIfCodeable']['active'], FILTER_VALIDATE_BOOLEAN); - $shipmentOrder->setPrintOnlyIfCodeable(new Serviceconfiguration($isActive)); - } - - /** - * @param array $identCheck - * @return Ident - * @throws \Exception - */ - protected function extractIdent($identCheck) : Ident - { - return new Ident( - $identCheck['surname'], - $identCheck['givenName'], - $identCheck['dateOfBirth'] ? (new \DateTime($identCheck['dateOfBirth']))->format('Y-m-d') : null, - $identCheck['minimumAge'] ? 'A' . $identCheck['minimumAge'] : null - ); - } - - /** - * @param Order - * @return Process|null - */ - protected function getProcess(Order $order) - { - if ($processNr = $order->oxorder__mo_dhl_process->rawValue) { - return Process::build($processNr); - } - return null; - } - - /** - * @param ShipmentOrderType $shipmentOrder - * @return array[] - */ - protected function getExportDocPositionWeights(ShipmentOrderType $shipmentOrder): array - { - if (!$exportDocument = $shipmentOrder->getShipment()->getExportDocument()) - { - return []; - } - return array_map( - [$this, 'parseExportDocPostition'], - $exportDocument->getExportDocPosition() - ); - - } - - protected function parseExportDocPostition(ExportDocPosition $exportDocPosition): array - { - return ['weight' => $exportDocPosition->getNetWeightInKG(), 'title' => $exportDocPosition->getDescription()]; - } -} diff --git a/src/modules/mo/mo_dhl/Adapter/GKVShipmentBuilder.php b/src/modules/mo/mo_dhl/Adapter/GKVShipmentBuilder.php deleted file mode 100644 index 04b78a26..00000000 --- a/src/modules/mo/mo_dhl/Adapter/GKVShipmentBuilder.php +++ /dev/null @@ -1,532 +0,0 @@ -buildShipmentDetails($order), $this->buildShipper(), $this->buildReceiver($order)); - $shipment->setExportDocument($this->buildExportDocument($order)); - $shipment->setReturnReceiver($this->buildReturnReceiver()); - return $shipment; - } - - /** - * @param Order $order - * @return ShipmentDetailsTypeType - */ - protected function buildShipmentDetails(Order $order): ShipmentDetailsTypeType - { - $details = new ShipmentDetailsTypeType($this->getProcess($order)->getServiceIdentifier(), $this->buildAccountNumber($order), $this->buildShipmentDate(), $this->buildShipmentItem($order)); - if (Registry::getConfig()->getShopConfVar('mo_dhl__beilegerretoure_active') && $this->getProcess($order)->supportsDHLRetoure() && $returnBookingNumber = $this->buildReturnAccountNumber($order)) { - $details->setReturnShipmentAccountNumber($returnBookingNumber); - } - if ($this->sendNotificationAllowed($order)) { - $details->setNotification(new ShipmentNotificationType($order->getFieldData('oxbillemail'))); - } - $customerReference = Registry::getLang()->translateString('GENERAL_ORDERNUM') . ' ' . $order->getFieldData('oxordernr'); - if ($order->moDHLUsesService(MoDHLService::MO_DHL__CASH_ON_DELIVERY) && $this->getProcess($order)->supportsCashOnDelivery()) { - $accountOwner = Registry::getConfig()->getShopConfVar('mo_dhl__cod_accountOwner') ?: null; - $bankName = Registry::getConfig()->getShopConfVar('mo_dhl__cod_bankName') ?: null; - $iban = Registry::getConfig()->getShopConfVar('mo_dhl__cod_iban') ?: null; - $details->setBankData((new BankType($accountOwner, $bankName, $iban))->setNote1($customerReference)); - } - $details->setCustomerReference($customerReference); - $details->setService($this->buildService($order)); - return $details; - } - - /** - * @param Order $order - * @return ReceiverType - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function buildReceiver($order): ReceiverType - { - $receiver = new ReceiverType( - $this->convertSpecialChars($order->moDHLGetAddressData('fname')) - . ' ' . $this->convertSpecialChars($order->moDHLGetAddressData('lname')) - ); - if (Branch::isPackstation($order->moDHLGetAddressData('street'))) { - $receiver->setPackstation($this->buildPackstation($order)); - } else if (Branch::isFiliale($order->moDHLGetAddressData('street'))) { - $receiver->setPostfiliale($this->buildPostfiliale($order)); - } else { - $receiver->setAddress($this->buildAddress($order)); - $receiver->setCommunication($this->buildCommunication($order)); - } - return $receiver; - } - - /** - * @param Order $order - * @return CommunicationType - */ - protected function buildCommunication($order) - { - return (new CommunicationType()) - ->setContactPerson($order->moDHLGetAddressData('fname') . ' ' . $order->moDHLGetAddressData('lname')) - ->setEmail($this->sendNotificationAllowed($order) ? $order->getFieldData('oxbillemail') : null) - ->setPhone($order->moDHLGetAddressData('fon')); - } - - /** - * @param string|null $stateId - * @return string|null - */ - protected function getStateName(?string $stateId) - { - if (is_null($stateId)) { - return null; - } - - $state = \oxNew(State::class); - $state->load($stateId); - return $state->getFieldData('oxisoalpha2'); - } - - /** - * @param string $countryId - * @return CountryType - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function buildCountry($countryId) - { - $country = \oxNew(\OxidEsales\Eshop\Application\Model\Country::class); - $country->load($countryId); - return new CountryType($country->getFieldData('oxisoalpha2')); - } - - /** - * @param Order $order - * @return BillingNumber - */ - protected function buildAccountNumber(Order $order): BillingNumber - { - return new BillingNumber($this->getEkp($order), $this->getProcess($order), $this->getParticipation($order)); - } - - /** - * @param Order $order - * @return BillingNumber|null - */ - public function buildReturnAccountNumber(Order $order) - { - if (!$this->getReturnProcess($order)) { - return null; - } - return new BillingNumber($this->getEkp($order), $this->getReturnProcess($order), $this->getParticipation($order)); - } - - /** - * @return string - * @throws \Exception - */ - protected function buildShipmentDate(): string - { - $wunschpaket = Registry::get(\Mediaopt\DHL\Wunschpaket::class); - return $wunschpaket->getWunschpaket()->getTransferDay()->format('Y-m-d'); - } - - /** - * @param Order $order - * @return ShipmentItemType - */ - protected function buildShipmentItem(Order $order): ShipmentItemType - { - return new ShipmentItemType($this->calculateWeight($order)); - } - - /** - * @param Order $order - * @return ShipmentService - */ - private function buildService(Order $order): ShipmentService - { - $service = new ShipmentService(); - $process = $this->getProcess($order); - $remark = $order->oxorder__oxremark->value; - $wunschpaket = Registry::get(\Mediaopt\DHL\Wunschpaket::class); - if ($wunschpaket->hasWunschtag($remark) && $process->supportsPreferredDay()) { - $wunschtag = $wunschpaket->extractWunschtag($remark); - $wunschtag = date('Y-m-d', strtotime($wunschtag)); - $service->setPreferredDay(new ServiceconfigurationDetailsPreferredDay(1, $wunschtag)); - } - [$type, $locationPart1, $locationPart2] = $wunschpaket->extractLocation($remark); - if ($wunschpaket->hasWunschnachbar($remark) && $process->supportsPreferredNeighbour()) { - $service->setPreferredNeighbour(new ServiceconfigurationDetailsPreferredNeighbour(1, "$locationPart2, $locationPart1")); - } - if ($wunschpaket->hasWunschort($remark) && $process->supportsPreferredLocation()) { - $service->setPreferredLocation(new ServiceconfigurationDetailsPreferredLocation(1, $locationPart1)); - } - if ($process->supportsParcelOutletRouting()) { - $isActive = (int) Registry::getConfig()->getShopConfVar('mo_dhl__filialrouting_active'); - $altEmail = Registry::getConfig()->getShopConfVar('mo_dhl__filialrouting_alternative_email') ?: null; - $service->setParcelOutletRouting(new ServiceconfigurationDetailsOptional($isActive, $altEmail)); - } - if ($order->moDHLUsesService(MoDHLService::MO_DHL__IDENT_CHECK) && $process->supportsIdentCheck()) { - $service->setIdentCheck(new ServiceconfigurationIC($this->createIdent($order), true)); - } elseif ($order->moDHLUsesService(MoDHLService::MO_DHL__VISUAL_AGE_CHECK18) && $process->supportsVisualAgeCheck()) { - $service->setVisualCheckOfAge(new ServiceconfigurationVisualAgeCheck(true, 'A18')); - } elseif ($order->moDHLUsesService(MoDHLService::MO_DHL__VISUAL_AGE_CHECK16) && $process->supportsVisualAgeCheck()) { - $service->setVisualCheckOfAge(new ServiceconfigurationVisualAgeCheck(true, 'A16')); - } - if ($process->supportsBulkyGood()) { - $service->setBulkyGoods(new Serviceconfiguration((int) $order->moDHLUsesService(MoDHLService::MO_DHL__BULKY_GOOD))); - } - if ($process->supportsCashOnDelivery()) { - $active = (int) $order->moDHLUsesService(MoDHLService::MO_DHL__CASH_ON_DELIVERY); - $service->setCashOnDelivery(new ServiceconfigurationCashOnDelivery($active, $this->getEURPrice($order, $order->oxorder__oxtotalordersum->value))); - } - $orderBrutSum = $this->getEURPrice($order, $order->oxorder__oxtotalbrutsum->value); - if ($process->supportsAdditionalInsurance()) { - $active = (int) ($order->moDHLUsesService(MoDHLService::MO_DHL__ADDITIONAL_INSURANCE) && $orderBrutSum > 500); - $service->setAdditionalInsurance(new ServiceconfigurationAdditionalInsurance($active, $orderBrutSum)); - } - if ($process->supportsPremium()) { - $active = (bool) ($order->moDHLUsesService(MoDHLService::MO_DHL__PREMIUM)); - $service->setPremium(new Serviceconfiguration($active)); - } - if ($process->supportsCDP()) { - $active = (bool) ($order->moDHLUsesService(MoDHLService::MO_DHL__CDP)); - $service->setCDP(new CDP($active)); - } - if ($process->supportsEconomy()) { - $active = (bool) ($order->moDHLUsesService(MoDHLService::MO_DHL__ECONOMY)); - $service->setEconomy(new Economy($active)); - } - if ($process->supportsEndorsement()) { - $abandonment = (bool) ($order->moDHLUsesService(MoDHLService::MO_DHL__ENDORSEMENT)); - $service->setEndorsement(new ServiceconfigurationEndorsement(true, $abandonment ? MoDHLService::MO_DHL__ENDORSEMENT_ABANDONMENT : MoDHLService::MO_DHL__ENDORSEMENT_IMMEDIATE)); - } - if ($process->supportsPDDP()) { - $active = (bool) ($order->moDHLUsesService(MoDHLService::MO_DHL__PDDP)); - $service->setPDDP(new PDDP($active)); - } - if ($process->supportsNoNeighbourDelivery()) { - $isActive = (int) Registry::getConfig()->getShopConfVar('mo_dhl__no_neighbour_delivery_active'); - $service->setNoNeighbourDelivery(new Serviceconfiguration($isActive)); - } - if ($process->supportsNamedPersonOnly()) { - $isActive = $order->moDHLUsesService(MoDHLService::MO_DHL__NAMED_PERSON_ONLY); - $service->setNamedPersonOnly(new Serviceconfiguration($isActive)); - } - if ($process->supportsSignedForByRecipient()) { - $isActive = $order->moDHLUsesService(MoDHLService::MO_DHL__SIGNED_FOR_BY_RECIPIENT); - $service->setSignedForByRecipient(new Serviceconfiguration($isActive)); - } - return $service; - } - - /** - * @param Order $order - * @return Ident - */ - protected function createIdent(Order $order) : Ident - { - $ident = new Ident( - $order->moDHLGetAddressData('lname'), - $order->moDHLGetAddressData('fname'), - $order->getFieldData('mo_dhl_ident_check_birthday'), - Registry::getConfig()->getShopConfVar('mo_dhl__ident_check_min_age') - ? 'A' . Registry::getConfig()->getShopConfVar('mo_dhl__ident_check_min_age') - : null); - if ($order->moDHLUsesService(MoDHLService::MO_DHL__VISUAL_AGE_CHECK18)) { - $ident->setMinimumAge('A18'); - } elseif ($order->moDHLUsesService(MoDHLService::MO_DHL__VISUAL_AGE_CHECK16) && !$ident->getMinimumAge()) { - $ident->setMinimumAge('A16'); - } - return $ident; - } - - /** - * @return ShipperType - * @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException - */ - protected function buildReturnReceiver(): ShipperType - { - $config = Registry::getConfig(); - if ($config->getShopConfVar('mo_dhl__retoure_receiver_use_sender')) { - return $this->buildShipper(); - } - $name = new NameType($config->getShopConfVar('mo_dhl__retoure_receiver_line1'), $config->getShopConfVar('mo_dhl__retoure_receiver_line2'), $config->getShopConfVar('mo_dhl__retoure_receiver_line3')); - $iso2 = $this->getIsoalpha2FromIsoalpha3($config->getShopConfVar('mo_dhl__retoure_receiver_country')); - $country = new CountryType($iso2); - $address = new NativeAddressTypeNew($config->getShopConfVar('mo_dhl__retoure_receiver_street'), $config->getShopConfVar('mo_dhl__retoure_receiver_street_number'), $config->getShopConfVar('mo_dhl__retoure_receiver_zip'), $config->getShopConfVar('mo_dhl__retoure_receiver_city'), $country); - return new ShipperType($name, $address); - } - - /** - * @return ShipperType - * @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException - */ - protected function buildShipper(): ShipperType - { - $config = Registry::getConfig(); - - $name = new NameType( - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_line1')), - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_line2')), - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_line3')) - ); - $iso2 = $this->getIsoalpha2FromIsoalpha3($config->getShopConfVar('mo_dhl__sender_country')); - $country = new CountryType($iso2); - $address = new NativeAddressTypeNew( - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_street')), - $config->getShopConfVar('mo_dhl__sender_street_number'), - $config->getShopConfVar('mo_dhl__sender_zip'), - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_city')), - $country - ); - return new ShipperType($name, $address); - } - - /** - * @param Order $order - * @return PostfilialeTypeNoCountry - */ - private function buildPostfiliale(Order $order): PostfilialeTypeNoCountry - { - return new PostfilialeTypeNoCountry($order->moDHLGetAddressData('streetnr'), $order->moDHLGetAddressData('addinfo'), $order->moDHLGetAddressData('zip'), $order->moDHLGetAddressData('city')); - } - - /** - * @param Order $order - * @return PackStationType - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function buildPackstation(Order $order): PackStationType - { - return new PackStationType($order->moDHLGetAddressData('addinfo'), $order->moDHLGetAddressData('streetnr'), $order->moDHLGetAddressData('zip'), $order->moDHLGetAddressData('city'), null, $this->buildCountry($order->moDHLGetAddressData('countryid'))); - } - - /** - * @param Order $order - * @return ReceiverNativeAddressType - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function buildAddress(Order $order): ReceiverNativeAddressType - { - $address = new ReceiverNativeAddressType( - $order->moDHLGetAddressData('company') - ? $this->convertSpecialChars($order->moDHLGetAddressData('company')) - : null, - $order->moDHLGetAddressData('addinfo') - ? $this->convertSpecialChars($order->moDHLGetAddressData('addinfo')) - : null, - $this->convertSpecialChars($order->moDHLGetAddressData('street')), - $order->moDHLGetAddressData('streetnr'), - $order->moDHLGetAddressData('zip'), - $this->convertSpecialChars($order->moDHLGetAddressData('city')), - $this->getStateName($order->moDHLGetAddressData('stateid')) ?: null, - $this->buildCountry($order->moDHLGetAddressData('countryid')) - ); - return $address; - } - - /** - * @param Order $order - * @return bool - */ - protected function sendNotificationAllowed(Order $order): bool - { - if (!$this->getProcess($order)->supportsNotification()) { - return false; - } - switch (Registry::getConfig()->getShopConfVar('mo_dhl__notification_mode')) { - case MoDHLNotificationMode::NEVER: - return false; - case MoDHLNotificationMode::ALWAYS: - return true; - default: - return (bool)$order->getFieldData('MO_DHL_ALLOW_NOTIFICATION'); - } - } - - /** - * @param Order $order - */ - protected function buildExportDocument(Order $order) - { - if (!$this->isInternational($order)) { - return null; - } - $config = Registry::getConfig(); - $exportDocumentType = (new ExportDocumentType( - 'COMMERCIAL_GOODS', - $this->convertSpecialChars($config->getShopConfVar('mo_dhl__sender_city')) - ))->setAdditionalFee($this->getEURPrice($order, $order->oxorder__oxdelcost->value)); - - $iso2 = $this->getIsoalpha2FromIsoalpha3($config->getShopConfVar('mo_dhl__sender_country')); - - $receiverLanguages = $this->getReceiverLanguages($order); - - $exportDocuments = []; - - /** @var OrderArticle $orderArticle */ - foreach ($order->getOrderArticles() as $orderArticle) { - $count = $orderArticle->getFieldData('oxamount'); - $exportDocuments[] = new ExportDocPosition( - $this->getArticleTitle($orderArticle, $receiverLanguages), - $iso2, - $orderArticle->getArticle()->getFieldData(MoDHLService::MO_DHL__ZOLLTARIF), - $count, - $this->getArticleWeight($orderArticle, $config), - $this->getEURPrice($order, $orderArticle->getPrice()->getPrice()) - ); - } - - return $exportDocumentType->setExportDocPosition($exportDocuments); - } - - /** - * @param string $isoalpha3 - * @return false|string - * @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException - */ - protected function getIsoalpha2FromIsoalpha3($isoalpha3) { - return \OxidEsales\Eshop\Core\DatabaseProvider::getDb() - ->getOne('SELECT OXISOALPHA2 from oxcountry where OXISOALPHA3 = ? ', [$isoalpha3]); - } - - /** - * @param Order $order - * @param float $price - * @return float - */ - protected function getEURPrice(Order $order, float $price): float - { - if ($order->oxorder__oxcurrency->value === Currency::MO_DHL__EUR) { - return $price; - } - - return round($price / $order->oxorder__oxcurrate->value, 2); - } - - /** - * @param Order $order - * @return array - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - */ - protected function getReceiverLanguages(Order $order): array - { - $receiverCountryISO2 = strtolower( - $this->buildCountry($order->moDHLGetAddressData('countryid'))->getCountryISOCode() - ); - - $storeLanguages = []; - foreach (Registry::getLang()->getLanguageArray() as $language) { - $storeLanguages[$language->oxid] = $language->id; - } - - if (!array_key_exists($receiverCountryISO2, CountriesLanguages::$LIST)) { - // If we have no list of languages for receiver country we will use default language - return []; - } - - $receiverLanguages = []; - foreach (CountriesLanguages::$LIST[$receiverCountryISO2] as $language) { - if (array_key_exists($language, $storeLanguages)) { - $receiverLanguages[$language] = $storeLanguages[$language]; - } - } - - // If we have a list we will use receiver languages in order from CountriesLanguages - return $receiverLanguages; - } - - /** - * @param OrderArticle $orderArticle - * @param array $receiverLanguages - * @return false|string - */ - protected function getArticleTitle(OrderArticle $orderArticle, array $receiverLanguages) - { - $articleId = $orderArticle->getArticle()->getId(); - $articleModel = oxNew(\OxidEsales\EshopCommunity\Application\Model\Article::class); - - $title = ''; - foreach ($receiverLanguages as $languageId) { - $articleModel->loadInLang($languageId, $articleId); - $title = $articleModel->getFieldData('oxtitle'); - if (!empty($title)) { - break; - } - } - $title = $title - ?? $orderArticle->getArticle()->getFieldData('oxtitle') - ?? $orderArticle->getFieldData('oxtitle'); - - return mb_substr($this->convertSpecialChars($title), 0, 50); - } - - /** - * @param string $string - * @return string - */ - public static function convertSpecialChars($string = ''): string - { - return html_entity_decode($string); - } -} diff --git a/src/modules/mo/mo_dhl/Adapter/InternetmarkeShoppingCartPDFRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/InternetmarkeShoppingCartPDFRequestBuilder.php index ce260794..2c492fa5 100644 --- a/src/modules/mo/mo_dhl/Adapter/InternetmarkeShoppingCartPDFRequestBuilder.php +++ b/src/modules/mo/mo_dhl/Adapter/InternetmarkeShoppingCartPDFRequestBuilder.php @@ -2,7 +2,6 @@ namespace Mediaopt\DHL\Adapter; -use Mediaopt\DHL\Api\GKV\ShipmentOrderType; use Mediaopt\DHL\Api\Internetmarke\CreateShopOrderIdRequest; use Mediaopt\DHL\Api\Internetmarke\ShoppingCartPDFPosition; use Mediaopt\DHL\Api\Internetmarke\ShoppingCartPDFRequestType; @@ -42,7 +41,7 @@ public function build(array $orderIds): ShoppingCartPDFRequestType /** * @param string $orderId - * @return ShipmentOrderType + * @return ShoppingCartPDFPosition * @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException */ diff --git a/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php new file mode 100644 index 00000000..7f8337f3 --- /dev/null +++ b/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php @@ -0,0 +1,292 @@ +getShipper(); + $services = $shipment->getServices(); + $returnReceiver = $services->isInitialized('dhlRetoure') ? $services->getDhlRetoure()->getReturnAddress() : null; + return [ + 'weight' => array_merge([ + 'total' => ['weight' => $shipment->getDetails()->getWeight()->getValue(), 'title' => Registry::getLang()->translateString('GENERAL_ATALL')], + ], $this->getExportItemWeights($shipment)), + 'shipper' => [ + 'name1' => $shipper->getName1(), + 'name2' => $shipper->isInitialized('name2') ? $shipper->getName2() : '', + 'name3' => $shipper->isInitialized('name3') ? $shipper->getName3() : '', + 'addressStreet' => $shipper->getAddressStreet(), + 'addressHouse' => $shipper->getAddressHouse(), + 'postalCode' => $shipper->getPostalCode(), + 'city' => $shipper->getCity(), + 'country' => $shipper->getCountry(), + ], + 'receiver' => $shipment->getConsignee(), + 'services' => [ + 'parcelOutletRouting' => $services->isInitialized('parcelOutletRouting') ? $services->getParcelOutletRouting() : null, + 'printOnlyIfCodeable' => $query['mustEncode'], + 'dhlRetoure' => $services->isInitialized('dhlRetoure') ? [ + 'active' => (bool)$services->getDhlRetoure()->getBillingNumber(), + 'address' => [ + 'name1' => $returnReceiver->getName1(), + 'name2' => $returnReceiver->isInitialized('name2') ? $returnReceiver->getName2() : '', + 'name3' => $returnReceiver->isInitialized('name3') ? $returnReceiver->getName3() : '', + 'addressStreet' => $returnReceiver->getAddressStreet(), + 'addressHouse' => $returnReceiver->getAddressHouse(), + 'postalCode' => $returnReceiver->getPostalCode(), + 'city' => $returnReceiver->getCity(), + 'country' => $returnReceiver->getCountry(), + ] + ] : null, + 'bulkyGoods' => $services->isInitialized('bulkyGoods') && $services->getBulkyGoods(), + 'additionalInsurance' => $services->isInitialized('additionalInsurance') ? $services->getAdditionalInsurance()->getValue() : null, + 'identCheck' => $services->isInitialized('identCheck') ? $services->getIdentCheck() : null, + 'cashOnDelivery' => $services->isInitialized('cashOnDelivery') ? $services->getCashOnDelivery()->getAmount()->getValue() : null, + 'visualAgeCheck' => $services->isInitialized('visualCheckOfAge') ? $services->getVisualCheckOfAge() : null, + 'pddp' => $services->isInitialized('postalDeliveryDutyPaid') && $services->getPostalDeliveryDutyPaid(), + 'cdp' => $services->isInitialized('closestDropPoint') && $services->getClosestDropPoint(), + 'premium' => $services->isInitialized('premium') && $services->getPremium(), + 'endorsement' => $services->isInitialized('endorsement') ? $services->getEndorsement() : null, + 'noNeighbourDelivery' => $services->isInitialized('noNeighbourDelivery') && $services->getNoNeighbourDelivery(), + 'namedPersonOnly' => $services->isInitialized('namedPersonOnly') && $services->getNamedPersonOnly(), + 'signedForByRecipient' => $services->isInitialized('signedForByRecipient') && $services->getSignedForByRecipient(), + ], + ]; + } + + /** + * @param Shipment $shipmentOrder + * @param array $data + * @param Order $order + */ + public function applyCustomDataToShipmentOrder(&$shipment, $data, Order $order) + { + $this->useCustomWeightData($shipment, $data['weight']); + $this->useCustomShipper($shipment, $data['shipper']); + $this->useCustomReceiver($shipment, $data['receiver']); + $this->useCustomServices($shipment, $data['services'], $order); + } + + public function applyCustomDataToQuery(&$query, $data) + { + $query['mustEncode'] = filter_var($data['services']['printOnlyIfCodeable']['active'], FILTER_VALIDATE_BOOLEAN); + } + + /** + * @param Shipment $shipment + * @param array $weightData + */ + protected function useCustomWeightData(Shipment $shipment, $weightData) + { + foreach ($weightData as $key => $value) { + if (strpos($value, ',') !== false) { + $value = \OxidEsales\EshopCommunity\Core\Registry::getUtils()->string2Float($value); + } + if ($key === 'total') { + $shipment->getDetails()->getWeight()->setValue($value); + } else { + $shipment->getCustoms()->getItems()[$key]->getItemWeight()->setValue($value); + } + } + } + + + /** + * @param Shipment $shipment + * @param array $shipperData + */ + protected function useCustomShipper(Shipment $shipment, array $shipperData) + { + $shipper = new Shipper(); + foreach (array_filter($shipperData) as $key => $value) { + $shipper->{"set" . ucfirst($key)}($value); + } + $shipment->setShipper($shipper); + } + + + /** + * @param Shipment $shipment + * @param array $receiverData + */ + protected function useCustomReceiver(Shipment $shipment, $receiverData) + { + $shipment->setConsignee($receiverData); + } + + /** + * @param Shipment $shipment + * @param array $servicesData + * @param Order $order + */ + protected function useCustomServices(Shipment $shipment, $servicesData, Order $order) + { + $process = $this->getProcess($order); + $services = new VAS(); + if ($process->supportsParcelOutletRouting() && filter_var($servicesData['parcelOutletRouting']['active'], FILTER_VALIDATE_BOOLEAN)) { + $details = $servicesData['parcelOutletRouting']['details'] ?: ''; + $services->setParcelOutletRouting($details); + } + + if ($process->supportsDHLRetoure() && filter_var($servicesData['dhlRetoure']['active'], FILTER_VALIDATE_BOOLEAN)) { + $accountNumber = Registry::get(ParcelShippingRequestBuilder::class)->buildReturnAccountNumber($order); + $retoure = new VASDhlRetoure(); + $retoure->setBillingNumber($accountNumber); + $address = new ContactAddress(); + foreach (array_filter($servicesData['dhlRetoure']['address']) as $key => $value) { + $address->{"set" . ucfirst($key)}($value); + } + $retoure->setReturnAddress($address); + } + if ($process->supportsBulkyGood() && filter_var($servicesData['bulkyGoods']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setBulkyGoods(true); + } + if ($process->supportsAdditionalInsurance() && filter_var($servicesData['additionalInsurance']['active'], FILTER_VALIDATE_BOOLEAN)) { + $details = $servicesData['additionalInsurance']['insuranceAmount'] ?? null; + $services->setAdditionalInsurance($this->createValue($details)); + } + if ($process->supportsCashOnDelivery() && filter_var($servicesData['cashOnDelivery']['active'], FILTER_VALIDATE_BOOLEAN)) { + $details = $servicesData['cashOnDelivery']['codAmount'] ?? null; + $customerReference = Registry::getLang()->translateString('GENERAL_ORDERNUM') . ' ' . $order->getFieldData('oxordernr'); + $bankAccount = new BankAccount(); + $bankAccount->setAccountHolder(Registry::getConfig()->getShopConfVar('mo_dhl__cod_accountOwner')); + $bankAccount->setBankName(Registry::getConfig()->getShopConfVar('mo_dhl__cod_bankName')); + $bankAccount->setIban(Registry::getConfig()->getShopConfVar('mo_dhl__cod_iban')); + $cashOnDelivery = new VASCashOnDelivery(); + $cashOnDelivery->setAmount($this->createValue($details)); + $cashOnDelivery->setBankAccount($bankAccount); + $cashOnDelivery->setTransferNote1($customerReference); + $services->setCashOnDelivery($cashOnDelivery); + } + if ($process->supportsIdentCheck() && filter_var($servicesData['identCheck']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setIdentCheck($this->extractIdent($servicesData['identCheck'])); + } + elseif ($process->supportsVisualAgeCheck() && $ageCheck = $servicesData['visualAgeCheck'] ?? null) { + $services->setVisualCheckOfAge('A' . $ageCheck); + } + if ($process->supportsPDDP() && filter_var($servicesData['pddp']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setPostalDeliveryDutyPaid(true); + } + if ($process->supportsCDP() && filter_var($servicesData['cdp']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setClosestDropPoint(true); + } + if ($process->supportsPremium() && filter_var($servicesData['premium']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setPremium(true); + } + if ($process->supportsEndorsement()) { + $endorsement = $servicesData['endorsement'] ?? MoDHLService::MO_DHL__ENDORSEMENT_RETURN; + $services->setEndorsement($endorsement); + } + if ($process->supportsNoNeighbourDelivery() && filter_var($servicesData['noNeighbourDelivery']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setNoNeighbourDelivery(true); + } + if ($process->supportsNamedPersonOnly() && filter_var($servicesData['namedPersonOnly']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setNamedPersonOnly(true); + } + if ($process->supportsSignedForByRecipient() && filter_var($servicesData['signedForByRecipient']['active'], FILTER_VALIDATE_BOOLEAN)) { + $services->setSignedForByRecipient(true); + } + $shipment->setServices($services); + } + + /** + * @param array $identCheckData + * @return VASIdentCheck + * @throws \Exception + */ + protected function extractIdent($identCheckData): VASIdentCheck + { + var_dump($identCheckData); + $identCheck = (new VASIdentCheck()) + ->setFirstName($identCheckData['firstName']) + ->setLastName($identCheckData['lastName']); + if ($identCheckData['dateOfBirth']) { + $identCheck->setDateOfBirth((new \DateTime($identCheckData['dateOfBirth']))); + } + if ($identCheckData['minimumAge']) { + $identCheck->setMinimumAge('A' . $identCheckData['minimumAge']); + } + return $identCheck; + } + + /** + * @param Order + * @return Process|null + */ + protected function getProcess(Order $order) + { + if ($processNr = $order->oxorder__mo_dhl_process->rawValue) { + return Process::build($processNr); + } + return null; + } + + /** + * @param Shipment $shipment + * @return array[] + */ + protected function getExportItemWeights(Shipment $shipment): array + { + if (!$shipment->isInitialized('customs')) { + return []; + } + $exportDocument = $shipment->getCustoms(); + return array_map( + [$this, 'parseCommodity'], + $exportDocument->getItems() + ); + + } + + protected function parseCommodity(Commodity $commodity): array + { + return ['weight' => $commodity->getItemWeight()->getValue(), 'title' => $commodity->getItemDescription()]; + } + + /** + * This method will return a value with EUR as currency since the currency this class receives is EUR at the moment. + * + * @param float $amount + * @param string|null $currency + * @return Value + */ + protected function createValue(float $amount, ?string $currency = null): Value + { + $value = new Value(); + $value->setValue($amount); + $value->setCurrency($currency ?: 'EUR'); + return $value; + } +} diff --git a/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php index 80ee1b86..1364812a 100644 --- a/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php +++ b/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php @@ -277,7 +277,7 @@ private function buildService(Order $order): ?VAS } if ($process->supportsEndorsement()) { $abandonment = (bool)($order->moDHLUsesService(MoDHLService::MO_DHL__ENDORSEMENT)); - $services->setEndorsement($abandonment ? 'ABANDON' : 'RETURN'); + $services->setEndorsement($abandonment ? MoDHLService::MO_DHL__ENDORSEMENT_ABANDONMENT : MoDHLService::MO_DHL__ENDORSEMENT_RETURN); $initialized = true; } if ($process->supportsPDDP() && $order->moDHLUsesService(MoDHLService::MO_DHL__PDDP)) { diff --git a/src/modules/mo/mo_dhl/Application/views/admin/de/module_lang.php b/src/modules/mo/mo_dhl/Application/views/admin/de/module_lang.php index 7105a469..fce2ea46 100644 --- a/src/modules/mo/mo_dhl/Application/views/admin/de/module_lang.php +++ b/src/modules/mo/mo_dhl/Application/views/admin/de/module_lang.php @@ -64,14 +64,16 @@ 'MO_DHL__CUSTOM_LABEL_PROCESS' => 'Verfahrensnummer', 'MO_DHL__CUSTOM_LABEL_RECEIVER' => 'Empfänger', 'MO_DHL__CUSTOM_LABEL_RETURN_RECEIVER' => 'Retoure - Empfängerdaten', + 'MO_DHL__CUSTOM_LABEL_NAME1' => 'Name', 'MO_DHL__CUSTOM_LABEL_NAME' => 'Name', - 'MO_DHL__CUSTOM_LABEL_MAIL' => 'E-Mail', + 'MO_DHL__CUSTOM_LABEL_CONTACTNAME' => 'Name', + 'MO_DHL__CUSTOM_LABEL_EMAIL' => 'E-Mail', 'MO_DHL__CUSTOM_LABEL_PHONE' => 'Telefonnummer', - 'MO_DHL__CUSTOM_LABEL_COMPANY' => 'Firma', - 'MO_DHL__CUSTOM_LABEL_ADRESS_ADDITION' => 'Adresszusatz', - 'MO_DHL__CUSTOM_LABEL_STREETNAME' => 'Straßenname', - 'MO_DHL__CUSTOM_LABEL_STREETNUMBER' => 'Hausnummer', - 'MO_DHL__CUSTOM_LABEL_ZIP' => 'Postleitzahl', + 'MO_DHL__CUSTOM_LABEL_NAME2' => 'Firma', + 'MO_DHL__CUSTOM_LABEL_NAME3' => 'Adresszusatz', + 'MO_DHL__CUSTOM_LABEL_ADDRESSSTREET' => 'Straßenname', + 'MO_DHL__CUSTOM_LABEL_ADDRESSHOUSE' => 'Hausnummer', + 'MO_DHL__CUSTOM_LABEL_POSTALCODE' => 'Postleitzahl', 'MO_DHL__CUSTOM_LABEL_CITY' => 'Stadt', 'MO_DHL__CUSTOM_LABEL_STATE' => 'Bundesstaat', 'MO_DHL__CUSTOM_LABEL_COUNTRY' => 'Land', @@ -106,14 +108,14 @@ 'HELP_MO_DHL__PREMIUM' => 'Ein Paket mit Service Premium wird bevorzugt und immer auf dem schnellsten Weg transportiert. Ihr Paket nimmt immer den nächstmöglichen Flug oder LKW in Richtung Zieldestination und wird auch im Zielland prioritär behandelt. So erreicht es deutlich schneller seinen Bestimmungsort.', 'MO_DHL__NAMED_PERSON_ONLY' => 'Persönliche Übergabe', 'MO_DHL__SIGNED_FOR_BY_RECIPIENT' => 'Empfängerunterschrift', - 'MO_DHL__PDDP' => 'PDDP (Postal Delivery Duty Paid)', - 'HELP_MO_DHL__PDDP' => 'DHL führt mit Postal Delivered Duty Paid (Postal DDP) einen Service ein, der es ermöglicht, dass der Versender alle Einfuhrabgaben für den Empfänger bezahlt.', + 'MO_DHL__PDDP' => 'PDDP (Postal Delivery Duty Paid)', + 'HELP_MO_DHL__PDDP' => 'DHL führt mit Postal Delivered Duty Paid (Postal DDP) einen Service ein, der es ermöglicht, dass der Versender alle Einfuhrabgaben für den Empfänger bezahlt.', 'MO_DHL__ZOLLTARIF' => 'Zolltarifnummer', 'HELP_MO_DHL__ZOLLTARIF' => 'Optionaler Parameter bei der Erzeugung von Exportdokumenten für DHL Paket International. International standardisiertes System von Namen und Nummern zur Klassifizierung gehandelter Produkte.', 'MO_DHL__ENDORSEMENT' => 'Vorausverfügung bei Unzustellbarkeit', 'HELP_MO_DHL__ENDORSEMENT' => 'Dieser Service gibt an, was mit einem Paket passieren soll, wenn es nicht zugestellt werden kann. Dieser Service ist nur für Paket International relevant.', - 'MO_DHL__ENDORSEMENT_IMMEDIATE' => 'Rücksendung an den Absender', + 'MO_DHL__ENDORSEMENT_RETURN' => 'Rücksendung an den Absender', 'MO_DHL__ENDORSEMENT_ABANDONMENT' => 'Preisgabe des Pakets (Verzicht auf die Rücksendung)', 'MO_DHL__LABEL_CREATED_WITH_WEAK_VALIDATION_ERROR' => 'Bei der Anfrage ist ein schwacher Fehler aufgetreten. Die Anfrage konnte trotzdem erfolgreich umgesetzt werden.', diff --git a/src/modules/mo/mo_dhl/Application/views/admin/en/module_lang.php b/src/modules/mo/mo_dhl/Application/views/admin/en/module_lang.php index 8640dd8e..1d1e5343 100644 --- a/src/modules/mo/mo_dhl/Application/views/admin/en/module_lang.php +++ b/src/modules/mo/mo_dhl/Application/views/admin/en/module_lang.php @@ -113,7 +113,7 @@ 'MO_DHL__ENDORSEMENT' => 'Endorsement', 'HELP_MO_DHL__ENDORSEMENT' => 'This service defines the handling of parcels that cannot be delivered. This service is only relevant for DHL Paket International.', - 'MO_DHL__ENDORSEMENT_IMMEDIATE' => 'Sending back to sender', + 'MO_DHL__ENDORSEMENT_RETURN' => 'Sending back to sender', 'MO_DHL__ENDORSEMENT_ABANDONMENT' => 'Abandonment of parcel at the hands of sender (free of charge)', 'MO_DHL__LABEL_CREATED_WITH_WEAK_VALIDATION_ERROR' => 'While processing the request a weak error occured. The request was still processed successfully.', diff --git a/src/modules/mo/mo_dhl/Controller/Admin/DeliverySetDHLController.php b/src/modules/mo/mo_dhl/Controller/Admin/DeliverySetDHLController.php index d4d31c2d..742365e6 100644 --- a/src/modules/mo/mo_dhl/Controller/Admin/DeliverySetDHLController.php +++ b/src/modules/mo/mo_dhl/Controller/Admin/DeliverySetDHLController.php @@ -95,7 +95,6 @@ private function validateProcess($identifier) try { Process::build($identifier); } catch (\InvalidArgumentException $exception) { - /** @noinspection PhpParamsInspection */ Registry::get(\OxidEsales\Eshop\Core\UtilsView::class)->addErrorToDisplay('MO_DHL__PROCESS_IDENTIFIER_ERROR'); throw $exception; } @@ -113,7 +112,6 @@ private function validateParticipation($participation) try { Participation::build($participation); } catch (\InvalidArgumentException $exception) { - /** @noinspection PhpParamsInspection */ Registry::get(\OxidEsales\Eshop\Core\UtilsView::class)->addErrorToDisplay('MO_DHL__PARTICIPATION_NUMBER_ERROR'); throw $exception; } @@ -161,7 +159,7 @@ public function getInternetmarkeProductsBySearchString() protected function getEndorsements() { return [ - Registry::getLang()->translateString('MO_DHL__ENDORSEMENT_IMMEDIATE'), + Registry::getLang()->translateString('MO_DHL__ENDORSEMENT_RETURN'), Registry::getLang()->translateString('MO_DHL__ENDORSEMENT_ABANDONMENT'), ]; } diff --git a/src/modules/mo/mo_dhl/Controller/Admin/ErrorDisplayTrait.php b/src/modules/mo/mo_dhl/Controller/Admin/ErrorDisplayTrait.php index 2d6979df..06e9075f 100644 --- a/src/modules/mo/mo_dhl/Controller/Admin/ErrorDisplayTrait.php +++ b/src/modules/mo/mo_dhl/Controller/Admin/ErrorDisplayTrait.php @@ -3,7 +3,6 @@ namespace Mediaopt\DHL\Controller\Admin; -use Mediaopt\DHL\Api\GKV\StatusElement; use OxidEsales\Eshop\Core\Registry; trait ErrorDisplayTrait @@ -25,8 +24,6 @@ protected function displayErrors($errors) if ($error instanceof \Exception) { $lang = Registry::getLang(); $error = sprintf($lang->translateString('MO_DHL__ERROR_PRINT_FORMAT'), $lang->translateString($error->getMessage()), $error->getLine(), $error->getFile()); - } elseif ($error instanceof StatusElement) { - $error = $error->getStatusElement() . ': ' . $error->getStatusMessage(); } $utilsView->addErrorToDisplay($error); $error = $nextError; diff --git a/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php b/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php index 8fbccc61..d28b4938 100755 --- a/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php +++ b/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php @@ -4,12 +4,13 @@ use GuzzleHttp\Exception\ClientException; use Mediaopt\DHL\Adapter\DHLAdapter; -use Mediaopt\DHL\Adapter\GKVCustomShipmentBuilder; use Mediaopt\DHL\Adapter\InternetmarkeRefundRetoureVouchersRequestBuilder; use Mediaopt\DHL\Adapter\InternetmarkeShoppingCartPDFRequestBuilder; +use Mediaopt\DHL\Adapter\ParcelShippingCustomRequestBuilder; use Mediaopt\DHL\Adapter\ParcelShippingRequestBuilder; use Mediaopt\DHL\Api\Internetmarke\ShoppingCartResponseType; use Mediaopt\DHL\Api\ParcelShipping\Client; +use Mediaopt\DHL\Api\ParcelShipping\Model\ShipmentOrderRequest; use Mediaopt\DHL\Api\Wunschpaket; use Mediaopt\DHL\Merchant\Ekp; use Mediaopt\DHL\Model\MoDHLInternetmarkeRefund; @@ -136,16 +137,18 @@ public function createRetoure($order = null) public function createCustomLabel() { try { - $request = $this->buildShipmentOrderRequest(); - $shipmentOrder = $request->getShipmentOrder()[0]; + /** @var $request ShipmentOrderRequest */ + [$query, $request] = $this->buildShipmentOrderRequest(); + $shipmentOrder = $request->getShipments()[0]; $data = Registry::getConfig()->getRequestParameter('data'); - $customShipmentBuilder = new GKVCustomShipmentBuilder(); + $customShipmentBuilder = new ParcelShippingCustomRequestBuilder(); $customShipmentBuilder->applyCustomDataToShipmentOrder($shipmentOrder, $data, $this->getOrder()); + $customShipmentBuilder->applyCustomDataToQuery($query, $data); - $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($shipmentOrder)); + $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipmentOrder)); $this->setTemplateName('mo_dhl__order_dhl_custom_label.tpl'); - $this->createShipmentOrderWithParcelShipping($request); + $this->createShipmentOrderWithParcelShipping([$query, $request]); } catch (\Exception $e) { $this->displayErrors($e); } @@ -160,9 +163,11 @@ public function createCustomLabel() */ public function prepareCustomLabel() { - $shipmentOrder = $this->buildShipmentOrderRequest()->getShipmentOrder()[0]; - $customShipmentBuilder = new GKVCustomShipmentBuilder(); - $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($shipmentOrder)); + /** @var $request ShipmentOrderRequest */ + [$query, $request] = $this->buildShipmentOrderRequest(); + $shipment = $request->getShipments()[0]; + $customShipmentBuilder = new ParcelShippingCustomRequestBuilder(); + $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipment)); $this->setTemplateName('mo_dhl__order_dhl_custom_label.tpl'); } diff --git a/src/modules/mo/mo_dhl/Model/MoDHLLabel.php b/src/modules/mo/mo_dhl/Model/MoDHLLabel.php index 8f684567..b93e395c 100644 --- a/src/modules/mo/mo_dhl/Model/MoDHLLabel.php +++ b/src/modules/mo/mo_dhl/Model/MoDHLLabel.php @@ -8,7 +8,6 @@ namespace Mediaopt\DHL\Model; -use Mediaopt\DHL\Api\GKV\CreationState; use Mediaopt\DHL\Api\Internetmarke\ShoppingCartResponseType; use Mediaopt\DHL\Api\Retoure\RetoureResponse; use OxidEsales\Eshop\Application\Model\Order; @@ -55,27 +54,6 @@ public function __construct() $this->init(); } - /** - * @param Order $order - * @param CreationState $creationState - * @return MoDHLLabel - */ - public static function fromOrderAndCreationState(Order $order, CreationState $creationState) - { - $label = new self(); - $label->assign([ - 'oxshopid' => $order->getShopId(), - 'orderId' => $order->getId(), - 'type' => self::TYPE_DELIVERY, - 'shipmentNumber' => $creationState->getShipmentNumber(), - 'returnShipmentNumber' => $creationState->getReturnShipmentNumber(), - 'labelUrl' => $creationState->getLabelData()->getLabelUrl(), - 'returnLabelUrl' => $creationState->getLabelData()->getReturnLabelUrl(), - 'exportLabelUrl' => $creationState->getLabelData()->getExportLabelUrl(), - ]); - return $label; - } - /** * @param Order $order * @param array $item diff --git a/src/modules/mo/mo_dhl/Model/MoDHLService.php b/src/modules/mo/mo_dhl/Model/MoDHLService.php index 0dd1cc6c..c400faa3 100644 --- a/src/modules/mo/mo_dhl/Model/MoDHLService.php +++ b/src/modules/mo/mo_dhl/Model/MoDHLService.php @@ -65,12 +65,12 @@ class MoDHLService /** * @var string */ - const MO_DHL__ENDORSEMENT_IMMEDIATE = 'IMMEDIATE'; + const MO_DHL__ENDORSEMENT_RETURN = 'RETURN'; /** * @var string */ - const MO_DHL__ENDORSEMENT_ABANDONMENT = 'ABANDONMENT'; + const MO_DHL__ENDORSEMENT_ABANDONMENT = 'ABANDON'; /** * @var string */ diff --git a/src/modules/mo/mo_dhl/views/admin/tpl/order_dhl_custom_label.tpl b/src/modules/mo/mo_dhl/views/admin/tpl/order_dhl_custom_label.tpl index bbeaf1fe..31f04686 100644 --- a/src/modules/mo/mo_dhl/views/admin/tpl/order_dhl_custom_label.tpl +++ b/src/modules/mo/mo_dhl/views/admin/tpl/order_dhl_custom_label.tpl @@ -53,148 +53,17 @@ [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_RECEIVER'}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_NAME'}] - - - - - - [{assign var="address" value=$shipmentOrder.receiver.address}] - [{if $shipmentOrder.receiver.type == 'address'}] - [{assign var="communication" value=$shipmentOrder.receiver.communication}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_MAIL'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_PHONE'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_COMPANY'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNAME'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNUMBER'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_ADRESS_ADDITION'}] - - - - - - [{elseif $shipmentOrder.receiver.type == 'packstation'}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_PACKSTATION_NUMBER'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_POST_NUMBER'}] - - - - - - [{else}] + [{foreach from=$shipmentOrder.receiver key="key" item="item"}] - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_POSTFILIAL_NUMBER'}] + [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_'|cat:$key|upper}] - + - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_POST_NUMBER'}] - - - - - - [{/if}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_ZIP'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_CITY'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STATE'}] - - - - - - [{if $shipmentOrder.receiver.type == 'address'}] - [{assign var="origin" value=$address->getOrigin()}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_COUNTRY'}] - - - - - - [{/if}] + [{/foreach}] @@ -207,79 +76,17 @@ [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_SHIPPER'}] - [{assign var="name" value=$shipmentOrder.shipper.name}] - - - [{oxmultilang ident='SHOP_MODULE_mo_dhl__sender_line1'}] - - - - - - - - [{oxmultilang ident='SHOP_MODULE_mo_dhl__sender_line2'}] - - - - - + [{foreach from=$shipmentOrder.shipper key="key" item="item"}] - [{oxmultilang ident='SHOP_MODULE_mo_dhl__sender_line3'}] + [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_'|cat:$key|upper}] - - - - [{assign var="address" value=$shipmentOrder.shipper.address}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNAME'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNUMBER'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_ZIP'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_CITY'}] - - - - - - [{assign var="origin" value=$address->getOrigin()}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_COUNTRY'}] - - - + + [{/foreach}] @@ -292,81 +99,17 @@ [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_RETURN_RECEIVER'}] - [{assign var="name" value=$shipmentOrder.returnReceiver.name}] - - - [{oxmultilang ident='SHOP_MODULE_mo_dhl__retoure_receiver_line1'}] - - - - - - - - [{oxmultilang ident='SHOP_MODULE_mo_dhl__retoure_receiver_line2'}] - - - - - + [{foreach from=$shipmentOrder.services.dhlRetoure.address key="key" item="item"}] - [{oxmultilang ident='SHOP_MODULE_mo_dhl__retoure_receiver_line3'}] + [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_'|cat:$key|upper}] - - - - [{assign var="address" value=$shipmentOrder.returnReceiver.address}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNAME'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_STREETNUMBER'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_ZIP'}] - - - - - - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_CITY'}] - - - - - - [{assign var="origin" value=$address->getOrigin()}] - - - [{oxmultilang ident='MO_DHL__CUSTOM_LABEL_COUNTRY'}] - - - + + [{/foreach}] @@ -380,15 +123,14 @@ [{if $process->supportsParcelOutletRouting()}] - [{assign var="service" value=$shipmentOrder.services.parcelOutletRouting}] [{oxmultilang ident='SHOP_MODULE_mo_dhl__filialrouting_active'}] - + getActive()}]checked[{/if}]> + value="1" [{if $shipmentOrder.services.parcelOutletRouting}]checked[{/if}]> @@ -397,7 +139,7 @@ + value="[{$shipmentOrder.services.parcelOutletRouting}]"> [{/if}] @@ -410,7 +152,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> [{/if}] @@ -423,7 +165,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> @@ -432,7 +174,7 @@ + value="[{$service}]"> [{/if}] @@ -445,7 +187,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> @@ -453,15 +195,15 @@ [{oxmultilang ident='MO_DHL__CASH_ON_DELIVERY'}] - + [{/if}] [{if $process->supportsIdentCheck()}] [{assign var="service" value=$shipmentOrder.services.identCheck}] - [{if $service && $service->getActive()}] - [{assign var="identDetails" value=$service->getIdent()}] + [{if $service}] + [{assign var="identDetails" value=$service}] [{/if}] @@ -470,7 +212,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> @@ -478,8 +220,8 @@ [{oxmultilang ident='LAST_NAME'}] [{oxmultilang ident='MO_DHL__FOR_IDENT_CHECK'}] - + @@ -487,8 +229,8 @@ [{oxmultilang ident='FIRST_NAME'}] [{oxmultilang ident='MO_DHL__FOR_IDENT_CHECK'}] - + @@ -497,7 +239,7 @@ + value="[{if $identDetails && $identDetails->isInitialized('dateOfBirth')}][{$identDetails->getDateOfBirth()}][{/if}]"> @@ -507,8 +249,8 @@ @@ -522,8 +264,8 @@ @@ -537,7 +279,7 @@ getActive()}]checked[{/if}]> + [{if $service}]checked[{/if}]> [{if $process->supportsDHLRetoure()}] @@ -546,10 +288,10 @@ [{oxmultilang ident='SHOP_MODULE_mo_dhl__beilegerretoure_active'}] - - + [{/if}] @@ -563,7 +305,7 @@ getActive()}]checked[{/if}]> + [{if $shipmentOrder.services.noNeighbourDelivery}]checked[{/if}]> [{/if}] @@ -576,7 +318,7 @@ getActive()}]checked[{/if}]> + [{if $shipmentOrder.services.namedPersonOnly}]checked[{/if}]> [{/if}] @@ -589,7 +331,7 @@ getActive()}]checked[{/if}]> + [{if $shipmentOrder.services.signedForByRecipient}]checked[{/if}]> [{/if}] @@ -602,7 +344,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> [{/if}] @@ -615,20 +357,7 @@ getActive()}]checked[{/if}]> - - - [{/if}] - [{if $process->supportsEconomy()}] - [{assign var="service" value=$shipmentOrder.services.economy}] - - - [{oxmultilang ident='MO_DHL__ECONOMY'}] - - - - getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> [{/if}] @@ -641,7 +370,7 @@ getActive()}]checked[{/if}]> + value="1" [{if $service}]checked[{/if}]> [{/if}] @@ -653,8 +382,8 @@ diff --git a/tests/Api/GKV/CreateShipmentOrderTest.php b/tests/Api/GKV/CreateShipmentOrderTest.php index 56b6d0a6..e8deab42 100644 --- a/tests/Api/GKV/CreateShipmentOrderTest.php +++ b/tests/Api/GKV/CreateShipmentOrderTest.php @@ -12,7 +12,6 @@ use Mediaopt\DHL\Adapter\ParcelShippingConverter; use Mediaopt\DHL\Api\GKV\CreateShipmentOrderRequest; use Mediaopt\DHL\Api\GKV\ShipmentOrderType; -use Mediaopt\DHL\Api\GKV\Version; use Mediaopt\DHL\Api\MyAccount\Runtime\Client\Client; use Psr\Http\Message\ResponseInterface;