Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the changes for segregation of PHP & html code from controller to template #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 27 additions & 43 deletions Controller/Parcelshops/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use DpdConnect\Shipping\Helper\Data;
use DpdConnect\Shipping\Helper\Services\DPDPickupService;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\Element\Template;

class Index extends \Magento\Framework\App\Action\Action
{
Expand Down Expand Up @@ -205,15 +206,18 @@ protected function _getOpeningHoursHtml($openMorning, $closeMorning, $openAftern
$openingHoursAfternoon = __('Closed');
}

$html = '
<tr>
<td style="padding: 3px; border: none;"></td>
<td style="padding: 3px; width: 33%;"><strong>' . __(strtolower($weekday)) . '</strong></td>
<td style="padding: 3px; width: 33%; text-align: center;">' . $openingHoursMorning . '</td>
<td style="padding: 3px; width: 33%; text-align: center;">' . $openingHoursAfternoon . '</td>
</tr>';
$layout = $this->_view->getLayout();
$openingHoursData = [
'openingHoursMorning' => $openingHoursMorning,
'openingHoursAfternoon'=> $openingHoursAfternoon,
'weekday' => $weekday
];

$block = $layout->createBlock(Template::class)
->setTemplate('DpdConnect_Shipping::checkout/shipping/parcelshop-opening-hours.phtml')
->setData('openingHours', $openingHoursData);

return $html;
return $block->toHtml();
}

/**
Expand All @@ -227,30 +231,11 @@ protected function _getMarkerHtml($shop, $special)
{
$image = $this->assetRepo->getUrlWithParams('DpdConnect_Shipping::images/dpd_parcelshop_logo.png', array('_secure' => $this->getRequest()->isSecure()));
$routeIcon = $this->assetRepo->getUrlWithParams('DpdConnect_Shipping::images/icon_route.png', array('_secure' => $this->getRequest()->isSecure()));

$html = '
<div class="content">
<table style="min-width: 380px" cellpadding="3" cellspacing="3">
<tbody>
<tr>
<td style="padding: 3px; padding-right: 15px;" rowspan="2">
<img class="parcelshoplogo bubble" style="width: 80px; height: 80px;" src="' . $image . '" alt="DPD Parcelshop logo"/>
</td>
<td style="padding: 3px; padding-top: 6px; width: 100%;" colspan="3">
<strong>' . ($special ? $shop['getParcelshopPudoName']() : $shop['company']) . '</strong><br />
' . ($special ? $shop['getData']('parcelshop_address_1') : $shop['street'] . " " . $shop['houseNo']) . '<br />
' . ($special ? $shop['getParcelshopPostCode']() . ' ' . $shop['getParcelshopTown']() : $shop['zipCode'] . ' ' . $shop['city']) . '
</td>
</tr>
<tr>
<td style="padding: 3px; padding-top: 6px; width: 100%;" colspan="3">
<strong>Openingstijden</strong>
</td>
</tr>';

$layout = $this->_view->getLayout();
$openingHoursHtml = '';
if (!$special && isset($shop['openingHours']) && $shop['openingHours'] != "") {
foreach ($shop['openingHours'] as $openinghours) {
$html .= $this->_getOpeningHoursHtml(
$openingHoursHtml .= $this->_getOpeningHoursHtml(
$openinghours['openMorning'],
$openinghours['closeMorning'],
$openinghours['openAfternoon'],
Expand All @@ -260,7 +245,7 @@ protected function _getMarkerHtml($shop, $special)
}
} else {
foreach (json_decode($shop['getParcelshopOpeninghours']()) as $openinghours) {
$html .= $this->_getOpeningHoursHtml(
$openingHoursHtml .= $this->_getOpeningHoursHtml(
$openinghours['openMorning'],
$openinghours['closeMorning'],
$openinghours['openAfternoon'],
Expand All @@ -270,17 +255,16 @@ protected function _getMarkerHtml($shop, $special)
}
}

$html .= '
<tr>
<td style="padding: 3px; border: none;"></td>
<td style="padding: 3px; width: 100%;" colspan="3">
<a class="parcelshoplink" id="' . ($special ? $shop['getParcelshopDelicomId']() : $shop['parcelShopId']) . '" href="#">' . __('Select Parcelshop') . '</a>
</td>
</tr>
</tbody>
</table>
</div>';

return $html;
$parcelShopData = [
'shop' => $shop,
'special' => $special,
'image' => $image,
'openingHoursHtml' => $openingHoursHtml
];
$block = $layout->createBlock(Template::class)
->setTemplate('DpdConnect_Shipping::checkout/shipping/parcelshop-marker.phtml')
->setData('markerParams', $parcelShopData);

return $block->toHtml();
}
}
36 changes: 36 additions & 0 deletions view/frontend/templates/checkout/shipping/parcelshop-marker.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
$markerParams = $block->getData('markerParams');
$shop = $markerParams['shop'];
$special = $markerParams['special'];
$image = $markerParams['image'];
$openingHoursHtml = $markerParams['openingHoursHtml'];
?>
<div class="content">
<table style="min-width: 380px" cellpadding="3" cellspacing="3">
<tbody>
<tr>
<td style="padding: 3px; padding-right: 15px;" rowspan="2">
<img class="parcelshoplogo bubble" style="width: 80px; height: 80px;" src="<?= $image ?>" alt="DPD Parcelshop logo" />
</td>
<td style="padding: 3px; padding-top: 6px; width: 100%;" colspan="3">
<strong><?= ($special ? $shop['getParcelshopPudoName']() : $shop['company']) ?></strong><br />
<?= ($special ? $shop['getData']('parcelshop_address_1') : $shop['street'] . " " . $shop['houseNo']) . '<br />
' . ($special ? $shop['getParcelshopPostCode']() . ' ' . $shop['getParcelshopTown']() : $shop['zipCode'] . ' ' . $shop['city']) ?>
</td>
</tr>
<tr>
<td style="padding: 3px; padding-top: 6px; width: 100%;" colspan="3">
<strong>Openingstijden</strong>
</td>
</tr>
<?= $openingHoursHtml; ?>
<tr>
<td style="padding: 3px; border: none;"></td>
<td style="padding: 3px; width: 100%;" colspan="3">
<a class="parcelshoplink" id="<?= ($special ? $shop['getParcelshopDelicomId']() : $shop['parcelShopId']) ?>" href="#"> <?= __('Select Parcelshop') ?></a>
</td>
</tr>
</tbody>
</table>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$openingHours = $block->getData('openingHours');
$openingHoursMorning = $openingHours['openingHoursMorning'];
$openingHoursAfternoon= $openingHours['openingHoursAfternoon'];
$weekday = $openingHours['weekday'];
?>
<tr>
<td style="padding: 3px; border: none;"></td>
<td style="padding: 3px; width: 33%;"><strong><?= __(strtolower($weekday)) ?></strong></td>
<td style="padding: 3px; width: 33%; text-align: center;"><?= $openingHoursMorning ?></td>
<td style="padding: 3px; width: 33%; text-align: center;"><?= $openingHoursAfternoon ?></td>
</tr>