From 37be0e44d0e39da755ad89782d17570b8f78ba29 Mon Sep 17 00:00:00 2001 From: eastern-parth Date: Fri, 14 Aug 2020 10:42:20 +0530 Subject: [PATCH] Adding the changes for segregation of PHP & html code from controller to template --- Controller/Parcelshops/Index.php | 70 +++++++------------ .../checkout/shipping/parcelshop-marker.phtml | 36 ++++++++++ .../shipping/parcelshop-opening-hours.phtml | 12 ++++ 3 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 view/frontend/templates/checkout/shipping/parcelshop-marker.phtml create mode 100644 view/frontend/templates/checkout/shipping/parcelshop-opening-hours.phtml diff --git a/Controller/Parcelshops/Index.php b/Controller/Parcelshops/Index.php index 778da80..e988750 100644 --- a/Controller/Parcelshops/Index.php +++ b/Controller/Parcelshops/Index.php @@ -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 { @@ -205,15 +206,18 @@ protected function _getOpeningHoursHtml($openMorning, $closeMorning, $openAftern $openingHoursAfternoon = __('Closed'); } - $html = ' - - - ' . __(strtolower($weekday)) . ' - ' . $openingHoursMorning . ' - ' . $openingHoursAfternoon . ' - '; + $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(); } /** @@ -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 = ' -
- - - - - - - - - '; - + $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'], @@ -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'], @@ -270,17 +255,16 @@ protected function _getMarkerHtml($shop, $special) } } - $html .= ' - - - - - -
- - - ' . ($special ? $shop['getParcelshopPudoName']() : $shop['company']) . '
- ' . ($special ? $shop['getData']('parcelshop_address_1') : $shop['street'] . " " . $shop['houseNo']) . '
- ' . ($special ? $shop['getParcelshopPostCode']() . ' ' . $shop['getParcelshopTown']() : $shop['zipCode'] . ' ' . $shop['city']) . ' -
- Openingstijden -
- ' . __('Select Parcelshop') . ' -
-
'; - - 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(); } } diff --git a/view/frontend/templates/checkout/shipping/parcelshop-marker.phtml b/view/frontend/templates/checkout/shipping/parcelshop-marker.phtml new file mode 100644 index 0000000..d5cfe83 --- /dev/null +++ b/view/frontend/templates/checkout/shipping/parcelshop-marker.phtml @@ -0,0 +1,36 @@ +getData('markerParams'); +$shop = $markerParams['shop']; +$special = $markerParams['special']; +$image = $markerParams['image']; +$openingHoursHtml = $markerParams['openingHoursHtml']; +?> +
+ + + + + + + + + + + + + + + +
+ + +
+ + ' . ($special ? $shop['getParcelshopPostCode']() . ' ' . $shop['getParcelshopTown']() : $shop['zipCode'] . ' ' . $shop['city']) ?> +
+ Openingstijden +
+ +
+
+ diff --git a/view/frontend/templates/checkout/shipping/parcelshop-opening-hours.phtml b/view/frontend/templates/checkout/shipping/parcelshop-opening-hours.phtml new file mode 100644 index 0000000..2ce9d5a --- /dev/null +++ b/view/frontend/templates/checkout/shipping/parcelshop-opening-hours.phtml @@ -0,0 +1,12 @@ +getData('openingHours'); +$openingHoursMorning = $openingHours['openingHoursMorning']; +$openingHoursAfternoon= $openingHours['openingHoursAfternoon']; +$weekday = $openingHours['weekday']; +?> + + + + + +