Skip to content

Commit

Permalink
#36623 bugfix custom label cod
Browse files Browse the repository at this point in the history
  • Loading branch information
mbe1987 committed Aug 26, 2024
1 parent 18f71bd commit a036666
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)) {
Expand Down
28 changes: 19 additions & 9 deletions src/modules/mo/mo_dhl/Adapter/ParcelShippingRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/modules/mo/mo_dhl/Controller/Admin/OrderDHLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@
<td>
<input type="hidden" name="data[services][cashOnDelivery][active]" value="false">
<input type="checkbox" name="data[services][cashOnDelivery][active]"
value="1" [{if $service}]checked[{/if}]>
value="1" [{if $service.active}]checked[{/if}]>
</td>
</tr>
<tr>
<td>
[{oxmultilang ident='MO_DHL__CASH_ON_DELIVERY'}]
</td>
<td>
<input type="text" name="data[services][cashOnDelivery][amount]"
value="[{$service}]">
<input type="text" name="data[services][cashOnDelivery][codAmount]"
value="[{$service.codAmount}]">
</td>
</tr>
[{/if}]
Expand Down

0 comments on commit a036666

Please sign in to comment.