Skip to content

Commit

Permalink
fix: implement feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen committed Apr 22, 2024
1 parent 56436f8 commit 16ff9e2
Showing 1 changed file with 57 additions and 30 deletions.
87 changes: 57 additions & 30 deletions Block/Sales/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\App\ObjectManager;
use Magento\Sales\Block\Adminhtml\Order\AbstractOrder;
use MyParcelNL\Magento\Helper\Checkout as CheckoutHelper;
use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractDeliveryOptionsAdapter;
use MyParcelNL\Sdk\src\Factory\DeliveryOptionsAdapterFactory;

class View extends AbstractOrder
Expand All @@ -44,49 +45,75 @@ public function getCheckoutOptionsHtml(): string
return '';
}

$date = new DateTime($data['date'] ?? '');
$dateTime = $date->format('d-m-Y H:i');
$deliveryOptions = DeliveryOptionsAdapterFactory::create((array) $data);
$returnString = '';

try {
if ($deliveryOptions->isPickup()) {
$returnString = htmlentities($this->getCheckoutOptionsPickupHtml($deliveryOptions));
}

if ($deliveryOptions->getDate()) {
$returnString = htmlentities($this->getCheckoutOptionsDeliveryHtml($deliveryOptions));
}
} catch (\Throwable $e) {
ObjectManager::getInstance()->get(CheckoutHelper::class)->log($e->getMessage());
$returnString = __('MyParcel options data not found');
}

return $returnString;
}

/**
* @param AbstractDeliveryOptionsAdapter $deliveryOptions
* @return string
*/
private function getCheckoutOptionsPickupHtml(AbstractDeliveryOptionsAdapter $deliveryOptions): string {
ob_start();

if ($deliveryOptions->isPickup()) {
try {
echo __("{$data['carrier']} location:"), ' ', $dateTime;
echo __("{$deliveryOptions->getCarrier()} location:"), ' ';

if ($data['deliveryType'] !== 'pickup') {
echo ', ', __($data['deliveryType']);
}
if ('pickup' !== $deliveryOptions->getDeliveryType()) {
echo __($deliveryOptions->getDeliveryType()), ', ';
}

$pickupLocation = $deliveryOptions->getPickupLocation();
$pickupLocation = $deliveryOptions->getPickupLocation();

if (null !== $pickupLocation) {
echo ', ', $pickupLocation->getLocationName(), ', ', $pickupLocation->getCity(), ' (', $pickupLocation->getPostalCode(), ')';
}
if (null !== $pickupLocation) {
echo $pickupLocation->getLocationName(), ', ';
echo $pickupLocation->getCity(), ' (', $pickupLocation->getPostalCode(), ')';
}

} catch (\Throwable $e) {
ObjectManager::getInstance()->get(CheckoutHelper::class)->log($e->getMessage());
echo __('MyParcel options data not found');
}
} elseif (array_key_exists('date', $data)) {
if (array_key_exists('packageType', $data)) {
echo __($data['packageType']), ' ';
}
return ob_get_clean();
}

/**
* @param AbstractDeliveryOptionsAdapter $deliveryOptions
* @return string
* @throws \Exception
*/
private function getCheckoutOptionsDeliveryHtml(AbstractDeliveryOptionsAdapter $deliveryOptions): string {
ob_start();

if ($deliveryOptions->getPackageType()) {
echo __($deliveryOptions->getPackageType()), ' ';
}

$date = new DateTime($deliveryOptions->getDate() ?? '');

echo __('Deliver:'), ' ', $dateTime;
echo __('Deliver:'), ' ', $date->format('d-m-Y H:i');

$shipmentOptions = $deliveryOptions->getShipmentOptions();
$shipmentOptions = $deliveryOptions->getShipmentOptions();

if (null !== $shipmentOptions) {
if ($shipmentOptions->hasSignature()) {
echo ', ', __('Signature on receipt');
}
if ($shipmentOptions->hasOnlyRecipient()) {
echo ', ', __('Home address only');
}
if (null !== $shipmentOptions) {
if ($shipmentOptions->hasSignature()) {
echo ', ', __('Signature on receipt');
}
if ($shipmentOptions->hasOnlyRecipient()) {
echo ', ', __('Home address only');
}
}

return htmlentities(ob_get_clean());
return ob_get_clean();
}
}

0 comments on commit 16ff9e2

Please sign in to comment.