From a0366668ac536a809daae5af6c628a95e6e69c32 Mon Sep 17 00:00:00 2001 From: mbe Date: Mon, 26 Aug 2024 12:43:02 +0200 Subject: [PATCH] #36623 bugfix custom label cod --- .../ParcelShippingCustomRequestBuilder.php | 22 +++++++-------- .../Adapter/ParcelShippingRequestBuilder.php | 28 +++++++++++++------ .../Controller/Admin/OrderDHLController.php | 4 +-- .../admin/tpl/order_dhl_custom_label.tpl | 6 ++-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php index 51fa2bc..3feea23 100644 --- a/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php +++ b/src/modules/mo/mo_dhl/Adapter/ParcelShippingCustomRequestBuilder.php @@ -34,11 +34,12 @@ class ParcelShippingCustomRequestBuilder * @param Shipment $shipment * @return array */ - public function toCustomizableParametersArray($query, Shipment $shipment): array + public function toCustomizableParametersArray($query, Shipment $shipment, $order): array { $shipper = $shipment->getShipper(); $services = $shipment->getServices(); $returnReceiver = $services->isInitialized('dhlRetoure') ? $services->getDhlRetoure()->getReturnAddress() : oxNew(ParcelShippingRequestBuilder::class)->buildReturnReceiver(); + $codAmount = $services->isInitialized('cashOnDelivery') ? $services->getCashOnDelivery()->getAmount() : oxNew(ParcelShippingRequestBuilder::class)->createCashOnDelivery($order)->getAmount(); return [ 'weight' => array_merge([ 'total' => ['weight' => $shipment->getDetails()->getWeight()->getValue(), 'title' => Registry::getLang()->translateString('GENERAL_ATALL')], @@ -73,7 +74,10 @@ public function toCustomizableParametersArray($query, Shipment $shipment): array '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, + 'cashOnDelivery' => [ + 'active' => $services->isInitialized('cashOnDelivery'), + 'codAmount' => $codAmount->getValue(), + ], 'visualAgeCheck' => $services->isInitialized('visualCheckOfAge') ? $services->getVisualCheckOfAge() : null, 'pddp' => $services->isInitialized('postalDeliveryDutyPaid') && $services->getPostalDeliveryDutyPaid(), 'cdp' => $services->isInitialized('closestDropPoint') && $services->getClosestDropPoint(), @@ -179,16 +183,10 @@ protected function useCustomServices(Shipment $shipment, $servicesData, Order $o $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); + $cashOnDelivery = oxNew(ParcelShippingRequestBuilder::class)->createCashOnDelivery($order); + if ($details = $servicesData['cashOnDelivery']['codAmount'] ?? null) { + $cashOnDelivery->setAmount($this->createValue($details)); + } $services->setCashOnDelivery($cashOnDelivery); } if ($process->supportsIdentCheck() && filter_var($servicesData['identCheck']['active'], FILTER_VALIDATE_BOOLEAN)) { diff --git a/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php b/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php index 8924e45..1a476d1 100644 --- a/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php +++ b/src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php @@ -250,15 +250,7 @@ private function buildService(Order $order): ?VAS $initialized = true; } if ($process->supportsCashOnDelivery() && $order->moDHLUsesService(MoDHLService::MO_DHL__CASH_ON_DELIVERY)) { - $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($this->getEURPrice($order, $order->oxorder__oxtotalordersum->value))); - $cashOnDelivery->setBankAccount($bankAccount); - $cashOnDelivery->setTransferNote1($customerReference); + $cashOnDelivery = $this->createCashOnDelivery($order); $services->setCashOnDelivery($cashOnDelivery); $initialized = true; } @@ -561,4 +553,22 @@ public function buildQueryParameters(): array 'mustEncode' => (bool) Registry::getConfig()->getShopConfVar('mo_dhl__only_with_leitcode'), ]; } + + /** + * @param Order $order + * @return VASCashOnDelivery + */ + public function createCashOnDelivery(Order $order): VASCashOnDelivery + { + $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($this->getEURPrice($order, $order->oxorder__oxtotalordersum->value))); + $cashOnDelivery->setBankAccount($bankAccount); + $cashOnDelivery->setTransferNote1($customerReference); + return $cashOnDelivery; + } } diff --git a/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php b/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php index d28b493..dd969b7 100755 --- a/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php +++ b/src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php @@ -146,7 +146,7 @@ public function createCustomLabel() $customShipmentBuilder->applyCustomDataToShipmentOrder($shipmentOrder, $data, $this->getOrder()); $customShipmentBuilder->applyCustomDataToQuery($query, $data); - $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipmentOrder)); + $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipmentOrder, $this->getOrder())); $this->setTemplateName('mo_dhl__order_dhl_custom_label.tpl'); $this->createShipmentOrderWithParcelShipping([$query, $request]); } catch (\Exception $e) { @@ -167,7 +167,7 @@ public function prepareCustomLabel() [$query, $request] = $this->buildShipmentOrderRequest(); $shipment = $request->getShipments()[0]; $customShipmentBuilder = new ParcelShippingCustomRequestBuilder(); - $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipment)); + $this->addTplParam('shipmentOrder', $customShipmentBuilder->toCustomizableParametersArray($query, $shipment, $this->getOrder())); $this->setTemplateName('mo_dhl__order_dhl_custom_label.tpl'); } 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 6f21977..00bd860 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 @@ -187,7 +187,7 @@ + value="1" [{if $service.active}]checked[{/if}]> @@ -195,8 +195,8 @@ [{oxmultilang ident='MO_DHL__CASH_ON_DELIVERY'}] - + [{/if}]