Skip to content

Commit 14655c0

Browse files
author
Maxime
authored
Merge pull request #123 from delyriand/fix_choose_store_button_120
Fix choose store button 120
2 parents 76b8ab3 + b0486cb commit 14655c0

File tree

5 files changed

+64
-95
lines changed

5 files changed

+64
-95
lines changed

Block/View/Map.php

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Smile\StoreLocator\Api\Data\RetailerAddressInterface;
2020
use Smile\StoreLocator\Block\AbstractView;
2121

22-
2322
/**
2423
* Map rendering block.
2524
*
@@ -54,24 +53,23 @@ class Map extends AbstractView
5453
*/
5554
private $scheduleManager;
5655

57-
5856
/**
5957
* @var RetailerCollectionFactory
6058
*/
6159
private $retailerCollectionFactory;
6260

63-
6461
/**
6562
* Constructor.
6663
*
67-
* @param \Magento\Framework\View\Element\Template\Context $context Application context.
68-
* @param \Magento\Framework\Registry $coreRegistry Application registry.
69-
* @param \Smile\Map\Api\MapProviderInterface $mapProvider Map configuration provider.
70-
* @param \Smile\StoreLocator\Helper\Data $storeLocatorHelper Store locacator helper.
71-
* @param AddressFormatter $addressFormatter Address formatter.
72-
* @param \Smile\StoreLocator\Helper\Schedule $scheduleHelper Schedule Helper
73-
* @param \Smile\StoreLocator\Model\Retailer\ScheduleManagement $scheduleManagement Schedule Management
74-
* @param array $data Additional data.
64+
* @param \Magento\Framework\View\Element\Template\Context $context Application context.
65+
* @param \Magento\Framework\Registry $coreRegistry Application registry.
66+
* @param \Smile\Map\Api\MapProviderInterface $mapProvider Map configuration provider.
67+
* @param \Smile\StoreLocator\Helper\Data $storeLocatorHelper Store locacator helper.
68+
* @param AddressFormatter $addressFormatter Address formatter.
69+
* @param \Smile\StoreLocator\Helper\Schedule $scheduleHelper Schedule Helper
70+
* @param \Smile\StoreLocator\Model\Retailer\ScheduleManagement $scheduleManagement Schedule Management
71+
* @param \Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory $retailerCollectionFactory The retailer collection factory.
72+
* @param array $data Additional data.
7573
*/
7674

7775
public function __construct(
@@ -105,8 +103,13 @@ public function getAddress()
105103
return $this->getRetailer()->getAddress();
106104
}
107105

108-
109-
public function getId() {
106+
/**
107+
* Return the retailer ID.
108+
*
109+
* @return int|null
110+
*/
111+
public function getId()
112+
{
110113
return $this->getRetailer()->getId();
111114
}
112115

@@ -142,35 +145,33 @@ public function getJsLayout()
142145
return json_encode($jsLayout);
143146
}
144147

145-
146148
/**
147149
* Create full marker data for store view.
148150
*
149151
* @return array|null
150152
*/
151-
public function getMarkerData() {
152-
153+
public function getMarkerData()
154+
{
153155
$result = null;
154156
$mediaPath = $this->getMediaPath();
155157
$imageUrlRetailer = $this->getImageUrl() . 'seller/';
156158
$image = $mediaPath ? $imageUrlRetailer . $mediaPath : false;
157159
$retailer = $this->getRetailer();
158160

159-
160161
$storeMarkerData = [
161162
'latitude' => $this->getCoordinates()->getLatitude(),
162163
'longitude' => $this->getCoordinates()->getLongitude(),
163164
'image' => $image,
164165
'id' => $this->getId(),
165166
'phone' => $this->getPhone(),
166-
'mail' => $this->getContactMailMail(),
167+
'mail' => $this->getContactMail(),
167168
'closestShops' => $this->collectionFull(),
168169
];
169170
$storeMarkerData['schedule'] = array_merge(
170171
$this->scheduleHelper->getConfig(),
171172
[
172-
'calendar' => $this->scheduleManager->getCalendar($retailer),
173-
'openingHours' => $this->scheduleManager->getWeekOpeningHours($retailer),
173+
'calendar' => $this->scheduleManager->getCalendar($retailer),
174+
'openingHours' => $this->scheduleManager->getWeekOpeningHours($retailer),
174175
'specialOpeningHours' => $retailer->getExtensionAttributes()->getSpecialOpeningHours(),
175176
]
176177
);
@@ -200,7 +201,6 @@ public function getAddressHtml()
200201
return $this->addressFormatter->formatAddress($this->getAddress(), AddressFormatter::FORMAT_HTML);
201202
}
202203

203-
204204
/**
205205
* Get URL used to redirect user to the direction API.
206206
*
@@ -227,99 +227,73 @@ public function getDescription()
227227
* @return mixed
228228
* @throws \Magento\Framework\Exception\NoSuchEntityException
229229
*/
230-
public function getImageUrl(){
231-
230+
public function getImageUrl()
231+
{
232232
$currentStore = $this->_storeManager->getStore();
233-
$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
234233

235-
return $mediaUrl;
234+
return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
236235
}
237236

238237
/**
239238
* Get image name.
240239
*
241240
* @return bool|string
242241
*/
243-
protected function getMediaPath() {
244-
245-
$retailer = $this->getRetailer();
246-
247-
return $retailer ? $retailer->getMediaPath() : false;
248-
}
249-
250-
/**
251-
* Get current retailer.
252-
*
253-
* @return \Smile\Retailer\Api\Data\RetailerInterface
254-
*/
255-
protected function currentRetailer() {
256-
257-
$retailer = $this->getRetailer();
258-
259-
return $retailer;
242+
protected function getMediaPath()
243+
{
244+
return $this->getRetailer()->getMediaPath() ?: false;
260245
}
261246

262247
/**
263248
* Get full image url.
264249
*
265250
* @return bool|string
266251
*/
267-
public function getImage() {
268-
252+
public function getImage()
253+
{
269254
$mediaPath = $this->getMediaPath();
270255
$imageUrlRetailer = $this->getImageUrl() . 'seller/';
271-
$image = $mediaPath ? $imageUrlRetailer . $mediaPath : false;
272256

273-
return $image;
257+
return $mediaPath ? $imageUrlRetailer . $mediaPath : false;
274258
}
275259

276260
/**
277261
* Get store name.
278262
*
279263
* @return string
280264
*/
281-
public function getStoreName() {
282-
283-
$name = $this->getRetailer()->getName();
284-
285-
return $name;
265+
public function getStoreName()
266+
{
267+
return $this->getRetailer()->getName();
286268
}
287269

288270
/**
289271
* Get phone number.
290272
*
291-
* @return null|string
273+
* @return bool|string
292274
*/
293-
public function getPhone() {
294-
295-
$retailer = $this->getRetailer();
296-
$phone = $retailer->getContactPhone();
297-
$result = $phone ? $phone : false;
298-
299-
return $result;
275+
public function getPhone()
276+
{
277+
return $this->getRetailer()->getContactPhone() ?: false;
300278
}
301279

302280
/**
303281
* Get email address.
304282
*
305-
* @return null|string
283+
* @return bool|string
306284
*/
307-
public function getContactMailMail() {
308-
309-
$retailer = $this->getRetailer();
310-
$mail = $retailer->getMail();
311-
$result = $mail ? $mail : false;
312-
313-
return $result;
285+
public function getContactMail()
286+
{
287+
return $this->getRetailer()->getContactMail() ?: false;
314288
}
315289

316290
/**
317291
* Get all exist markers.
318292
*
319293
* @return mixed
320294
*/
321-
322-
public function getAllMarkers() {
295+
public function getAllMarkers()
296+
{
323297
$retailerCollection = $this->retailerCollectionFactory->create();
324298
$retailerCollection->addAttributeToSelect(['name', 'contact_mail', 'contact_phone', 'contact_mail', 'image']);
325299
$retailerCollection->addFieldToFilter('is_active', (int) true);
@@ -333,17 +307,18 @@ public function getAllMarkers() {
333307
*
334308
* @return array|null
335309
*/
336-
public function collectionFull() {
310+
public function collectionFull()
311+
{
337312
$collection = $this->getAllMarkers();
338313

339314
$markers = null;
340315

341316
if (!$markers) {
342317
/** @var RetailerInterface $retailer */
343-
$imageUrlRetailer = $this->getImageUrl().'seller/';
318+
$imageUrlRetailer = $this->getImageUrl() . 'seller/';
344319
foreach ($collection as $retailer) {
345320
$address = $retailer->getExtensionAttributes()->getAddress();
346-
$image = $retailer->getMediaPath() ? $imageUrlRetailer.$retailer->getMediaPath() : false;
321+
$image = $retailer->getMediaPath() ? $imageUrlRetailer . $retailer->getMediaPath() : false;
347322
$markerData = [
348323
'id' => $retailer->getId(),
349324
'latitude' => $address->getCoordinates()->getLatitude(),
@@ -357,7 +332,7 @@ public function collectionFull() {
357332
];
358333

359334
foreach (['contact_mail', 'contact_phone', 'contact_mail'] as $contactAttribute) {
360-
$markerData[$contactAttribute] = $retailer->getData($contactAttribute) ? $retailer->getData($contactAttribute) : '';
335+
$markerData[$contactAttribute] = $retailer->getData($contactAttribute) ?: '';
361336
}
362337

363338
$markerData['schedule'] = array_merge(

Block/View/SetStoreLink.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
*/
1313
namespace Smile\StoreLocator\Block\View;
1414

15+
use Smile\StoreLocator\Block\AbstractView;
16+
1517
/**
1618
* Set store link block.
1719
*
1820
* @category Smile
1921
* @package Smile\StoreLocator
2022
* @author Aurelien FOUCRET <[email protected]>
2123
*/
22-
class SetStoreLink extends \Smile\StoreLocator\Block\AbstractView
24+
class SetStoreLink extends AbstractView
2325
{
2426
/**
2527
* Get the JSON post data used to build the set store link.

view/frontend/layout/smile_store_locator_store_view.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
*/
1616
-->
1717
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
18-
1918
<update handle="smile_map_styles"/>
20-
19+
2120
<body>
2221
<attribute name="itemtype" value="http://schema.org/Store" />
2322
<attribute name="itemscope" value="itemscope"/>
2423
<referenceBlock name="page.main.title">
25-
<block class="Smile\StoreLocator\Block\View\SetStoreLink" name="smile_store_locator_retailer_view.setstorelink" template="view/setStoreLink.phtml"/>
2624
<arguments>
2725
<argument name="add_base_attribute" xsi:type="string">itemprop="name"</argument>
2826
</arguments>
@@ -33,8 +31,8 @@
3331
</arguments>
3432
</referenceBlock>
3533
<referenceContainer name="content">
36-
<block class="Smile\StoreLocator\Block\View" name="smile_store_locator_retailer_view" template="view.phtml">
37-
<block class="Smile\StoreLocator\Block\View\Map" name="smile_store_locator_retailer_view.map" template="view/map.phtml">
34+
<block class="Smile\StoreLocator\Block\View" name="smile_store_locator_retailer_view" template="Smile_StoreLocator::view.phtml">
35+
<block class="Smile\StoreLocator\Block\View\Map" name="smile_store_locator_retailer_view.map" template="Smile_StoreLocator::view/map.phtml">
3836
<arguments>
3937
<argument name="jsLayout" xsi:type="array">
4038
<item name="components" xsi:type="array">
@@ -58,6 +56,7 @@
5856
</item>
5957
</argument>
6058
</arguments>
59+
<block class="Smile\StoreLocator\Block\View\SetStoreLink" name="smile_store_locator_retailer_view.setstorelink" as="setstorelink" template="Smile_StoreLocator::view/setStoreLink.phtml"/>
6160
</block>
6261
</block>
6362
</referenceContainer>

view/frontend/templates/view/map.phtml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@ $storeName = $block->getStoreName();
7979
</a>
8080
</div>
8181

82-
<div class="set-store-button">
83-
<a href="#"
84-
title="<?php echo $block->escapeHtml(__('Choose this store')); ?>"
85-
class="action-set-store"
86-
data-post='<?php /* @escapeNotVerified */ echo $block->getSetStorePostJson(); ?>'>
87-
<span><?php echo $block->escapeHtml(__('Choose this store')); ?></span>
88-
</a>
89-
</div>
82+
<?= /** @noEscape */$block->getChildHtml('setstorelink') ?>
9083

9184
<a class= "back-to-result-btn" href="<?php echo $this->getStoreListUrl(); ?>"><?php echo __('Back to result'); ?></a>
9285
</div>

view/frontend/templates/view/setStoreLink.phtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
/** @var \Smile\StoreLocator\Block\View $block */
2020
?>
2121

22-
<!--<div class="primary set-store-button">-->
23-
<!-- <a href="#"-->
24-
<!-- title="--><?php //echo $block->escapeHtml(__('Choose this store')); ?><!--"-->
25-
<!-- class="action primary action-set-store"-->
26-
<!-- data-post='--><?php ///* @escapeNotVerified */ echo $block->getSetStorePostJson(); ?><!--'>-->
27-
<!-- <span>--><?php //echo $block->escapeHtml(__('Choose this store')); ?><!--</span>-->
28-
<!-- </a>-->
29-
<!--</div>-->
22+
<div class="set-store-button">
23+
<a href="#"
24+
title="<?php echo $block->escapeHtml(__('Choose this store')); ?>"
25+
class="action-set-store"
26+
data-post='<?php /* @escapeNotVerified */ echo $block->getSetStorePostJson(); ?>'>
27+
<span><?php echo $block->escapeHtml(__('Choose this store')); ?></span>
28+
</a>
29+
</div>

0 commit comments

Comments
 (0)