Skip to content

Commit a4fa9c3

Browse files
authored
2.2.x (#156) Refactor - same search design everywhere
- Refactor - same search design everywhere - Update contact form
1 parent 32017e7 commit a4fa9c3

File tree

27 files changed

+578
-344
lines changed

27 files changed

+578
-344
lines changed

Block/AbstractView.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
namespace Smile\StoreLocator\Block;
66

7+
use Magento\Framework\Exception\NoSuchEntityException;
78
use Magento\Framework\Registry;
9+
use Magento\Framework\UrlInterface;
810
use Magento\Framework\View\Element\Template;
911
use Magento\Framework\View\Element\Template\Context;
12+
use Magento\Store\Model\Store;
1013
use Smile\Retailer\Api\Data\RetailerInterface;
1114

1215
/**
@@ -29,4 +32,36 @@ public function getRetailer(): ?RetailerInterface
2932
{
3033
return $this->coreRegistry->registry('current_retailer');
3134
}
35+
36+
/**
37+
* Get image name.
38+
*/
39+
protected function getMediaPath(): string|bool
40+
{
41+
return $this->getRetailer()->getMediaPath() ?: false;
42+
}
43+
44+
/**
45+
* Get full image url.
46+
*/
47+
public function getImage(): string|bool
48+
{
49+
$mediaPath = $this->getMediaPath();
50+
$imageUrlRetailer = $this->getImageUrl() . 'seller/';
51+
52+
return $mediaPath ? $imageUrlRetailer . $mediaPath : false;
53+
}
54+
55+
/**
56+
* * Get base media url.
57+
*
58+
* @throws NoSuchEntityException
59+
*/
60+
public function getImageUrl(): string
61+
{
62+
/** @var Store $currentStore */
63+
$currentStore = $this->_storeManager->getStore();
64+
65+
return $currentStore->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
66+
}
3267
}

Block/ContactForm.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
namespace Smile\StoreLocator\Block;
66

7+
use Magento\Customer\Helper\View as CustomerHelperView;
8+
use Magento\Customer\Model\Session;
79
use Magento\Framework\App\Request\DataPersistorInterface;
810
use Magento\Framework\Registry;
911
use Magento\Framework\View\Element\AbstractBlock;
1012
use Magento\Framework\View\Element\Template\Context;
1113
use Magento\Store\Model\Store;
1214
use Magento\Theme\Block\Html\Breadcrumbs;
15+
use Smile\Map\Model\AddressFormatter;
16+
use Smile\StoreLocator\Api\Data\RetailerAddressInterface;
1317
use Smile\StoreLocator\Helper\Data as StoreLocatorHelper;
1418

1519
/**
@@ -25,7 +29,10 @@ public function __construct(
2529
Context $context,
2630
Registry $coreRegistry,
2731
private StoreLocatorHelper $storeLocatorHelper,
32+
protected Session $customerSession,
33+
protected CustomerHelperView $customerViewHelper,
2834
DataPersistorInterface $dataPersistorInterface,
35+
private AddressFormatter $addressFormatter,
2936
array $data
3037
) {
3138
$this->dataPersistor = $dataPersistorInterface;
@@ -129,4 +136,48 @@ private function setBreadcrumbs(): self
129136

130137
return $this;
131138
}
139+
140+
/**
141+
* Get customer user name if logged in
142+
*/
143+
public function getUserName(): string
144+
{
145+
if (!$this->customerSession->isLoggedIn()) {
146+
return '';
147+
}
148+
$customer = $this->customerSession->getCustomerDataObject();
149+
150+
return trim($this->customerViewHelper->getCustomerName($customer));
151+
}
152+
153+
/**
154+
* Get customer user email if logged in
155+
*/
156+
public function getUserEmail(): string
157+
{
158+
if (!$this->customerSession->isLoggedIn()) {
159+
return '';
160+
}
161+
$customer = $this->customerSession->getCustomerDataObject();
162+
163+
return $customer->getEmail();
164+
}
165+
166+
/**
167+
* Returns current store address.
168+
*/
169+
public function getAddress(): ?RetailerAddressInterface
170+
{
171+
return $this->getRetailer()->getData('address');
172+
}
173+
174+
/**
175+
* Get address formatted in HTML.
176+
*/
177+
public function getAddressHtml(): string
178+
{
179+
return $this->getAddress()
180+
? $this->addressFormatter->formatAddress($this->getAddress(), AddressFormatter::FORMAT_HTML)
181+
: '';
182+
}
132183
}

Block/Search.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function getJsLayout()
9393
$this->map->getConfig()
9494
);
9595

96+
$placeholder = $this->storeLocatorHelper->getSearchPlaceholder();
97+
$jsLayout['components']['store-locator-search']['searchPlaceholderText'] = $placeholder;
98+
$jsLayout['components']['store-locator-search']['children']['geocoder']['searchPlaceholderText'] = $placeholder;
99+
96100
if ($this->getRequest()->getParam('query', false)) {
97101
$query = $this->getRequest()->getParam('query', false);
98102
$jsLayout['components']['store-locator-search']['children']['geocoder']['fulltextSearch'] =

Block/StoreChooser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public function __construct(
2727
$this->map = $mapProvider->getMap();
2828
}
2929

30+
/**
31+
* Get placeholder for search input of store_locator, default: City, Zipcode, Address, ...
32+
*/
33+
public function getSearchPlaceholder(): string
34+
{
35+
return $this->storeLocatorHelper->getSearchPlaceholder();
36+
}
37+
3038
/**
3139
* @inheritdoc
3240
*/

Block/View/Map.php

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Smile\StoreLocator\Block\View;
66

7-
use Magento\Framework\Exception\NoSuchEntityException;
87
use Magento\Framework\Registry;
98
use Magento\Framework\UrlInterface;
109
use Magento\Framework\View\Element\Template\Context;
11-
use Magento\Store\Model\Store;
1210
use Smile\Map\Api\Data\GeoPointInterface;
1311
use Smile\Map\Api\MapInterface;
1412
use Smile\Map\Api\MapProviderInterface;
@@ -19,6 +17,7 @@
1917
use Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory as RetailerCollectionFactory;
2018
use Smile\StoreLocator\Api\Data\RetailerAddressInterface;
2119
use Smile\StoreLocator\Block\AbstractView;
20+
use Smile\StoreLocator\Helper\Contact;
2221
use Smile\StoreLocator\Helper\Data;
2322
use Smile\StoreLocator\Helper\Schedule;
2423
use Smile\StoreLocator\Model\Retailer\ScheduleManagement;
@@ -39,6 +38,7 @@ public function __construct(
3938
Context $context,
4039
Registry $coreRegistry,
4140
MapProviderInterface $mapProvider,
41+
private Contact $contactHelper,
4242
private Data $storeLocatorHelper,
4343
private AddressFormatter $addressFormatter,
4444
private Schedule $scheduleHelper,
@@ -168,38 +168,6 @@ public function getDescription(): ?string
168168
return $this->getRetailer()->getData('description');
169169
}
170170

171-
/**
172-
* * Get base media url.
173-
*
174-
* @throws NoSuchEntityException
175-
*/
176-
public function getImageUrl(): string
177-
{
178-
/** @var Store $currentStore */
179-
$currentStore = $this->_storeManager->getStore();
180-
181-
return $currentStore->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
182-
}
183-
184-
/**
185-
* Get image name.
186-
*/
187-
protected function getMediaPath(): string|bool
188-
{
189-
return $this->getRetailer()->getMediaPath() ?: false;
190-
}
191-
192-
/**
193-
* Get full image url.
194-
*/
195-
public function getImage(): string|bool
196-
{
197-
$mediaPath = $this->getMediaPath();
198-
$imageUrlRetailer = $this->getImageUrl() . 'seller/';
199-
200-
return $mediaPath ? $imageUrlRetailer . $mediaPath : false;
201-
}
202-
203171
/**
204172
* Get store name.
205173
*/
@@ -294,4 +262,20 @@ private function getSetStorePostData(RetailerInterface $retailer): array
294262

295263
return ['action' => $setUrl, 'data' => $postData];
296264
}
265+
266+
/**
267+
* Check if we can display contact form for current retailer.
268+
*/
269+
public function showContactForm(): bool
270+
{
271+
return $this->contactHelper->canDisplayContactForm($this->getRetailer());
272+
}
273+
274+
/**
275+
* Retrieve Contact form Url for current retailer.
276+
*/
277+
public function getContactFormUrl(): string
278+
{
279+
return $this->contactHelper->getContactFormUrl($this->getRetailer());
280+
}
297281
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.2.1] - 2024-05-03
6+
[2.2.1]: https://github.com/Smile-SA/magento2-module-store-locator/compare/2.2.0...2.2.1
7+
8+
- Refactor - same search design everywhere
9+
- Update contact form
10+
511
## [2.2.0] - 2023-09-20
612
[2.2.0]: https://github.com/Smile-SA/magento2-module-store-locator/compare/2.1.0...2.2.0
713

Controller/Store/Set.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function execute()
3939
$retailer = $this->retailerRepository->get((int) $retailerId);
4040
$this->customerData->setRetailer($retailer);
4141
} catch (Exception $exception) {
42+
$retailer = null;
4243
$this->messageManager->addExceptionMessage(
4344
$exception,
4445
__('We are sorry, an error occured when switching retailer.')
@@ -48,6 +49,9 @@ public function execute()
4849
/** @var Redirect $resultRedirect */
4950
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
5051
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
52+
if ($retailer) {
53+
$this->messageManager->addSuccess(__('Retailer shop %1 has been chosen.', $retailer->getName()));
54+
}
5155

5256
return $resultRedirect;
5357
}

Helper/Data.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Magento\Framework\App\Helper\AbstractHelper;
88
use Magento\Framework\App\Helper\Context;
9+
use Magento\Store\Model\ScopeInterface;
910
use Smile\Retailer\Api\Data\RetailerInterface;
1011
use Smile\StoreLocator\Model\Url;
1112

@@ -14,13 +15,31 @@
1415
*/
1516
class Data extends AbstractHelper
1617
{
18+
public const SEARCH_PLACEHOLDER_XML_PATH = 'store_locator/search/placeholder';
19+
1720
public function __construct(
1821
Context $context,
1922
private Url $urlModel
2023
) {
2124
parent::__construct($context);
2225
}
2326

27+
/**
28+
* Get config by config path.
29+
*/
30+
public function getConfigByPath(string $path, string $scope = ScopeInterface::SCOPE_STORE): mixed
31+
{
32+
return $this->scopeConfig->getValue($path, $scope);
33+
}
34+
35+
/**
36+
* Get placeholder for search input of store_locator, default: City, Zipcode, Address, ...
37+
*/
38+
public function getSearchPlaceholder(): string
39+
{
40+
return (string) $this->getConfigByPath(self::SEARCH_PLACEHOLDER_XML_PATH) ?: 'City, Zipcode, Address ...';
41+
}
42+
2443
/**
2544
* Store locator home URL.
2645
*/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Smile\StoreLocator\Plugin\Model\Layout;
6+
7+
use Magento\Customer\Model\Layout\DepersonalizePlugin;
8+
use Magento\Customer\Model\Session as CustomerSession;
9+
use Magento\Framework\View\LayoutInterface;
10+
use Magento\PageCache\Model\DepersonalizeChecker;
11+
use Smile\StoreLocator\CustomerData\CurrentStore;
12+
13+
/**
14+
* Depersonalize customer data.
15+
*
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
17+
*/
18+
class RetailerDepersonalizePlugin
19+
{
20+
//@SmileAnalyserSkip magento2/badpractices
21+
public function __construct(
22+
protected DepersonalizeChecker $depersonalizeChecker,
23+
protected CustomerSession $customerSession,
24+
protected CurrentStore $currentStore
25+
) {
26+
}
27+
28+
/**
29+
* Prevent losing retailer_id chosen - show product offer price if shop has been selected, even in Retail mode
30+
*/
31+
public function afterAfterGenerateElements(
32+
DepersonalizePlugin $subject,
33+
mixed $result,
34+
LayoutInterface $layout
35+
): void {
36+
if ($this->depersonalizeChecker->checkIfDepersonalize($layout)) {
37+
$retailer = $this->currentStore->getRetailer();
38+
if ($retailer && $retailer->getId()) {
39+
$data = $this->customerSession->getData();
40+
$data['retailer_id'] = $retailer->getId();
41+
$this->customerSession->setData($data);
42+
}
43+
}
44+
}
45+
}

etc/adminhtml/system.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
33
<system>
4+
<section id="store_locator" translate="label" type="text" sortOrder="2020" showInDefault="1" showInWebsite="1" showInStore="1">
5+
<class>separator-top</class>
6+
<label>Store Locator Settings</label>
7+
<tab>smile_elasticsuite</tab>
8+
<resource>Magento_Backend::smile_map</resource>
9+
10+
<group id="search" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
11+
<label>General Settings</label>
12+
<field id="placeholder" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
13+
<label>Shown placeholder to help user</label>
14+
<comment>default: City, Zipcode, Address ...</comment>
15+
</field>
16+
</group>
17+
<group id="seo" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
18+
<label>Seo</label>
19+
<field id="base_url" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
20+
<label>Store Locator URL</label>
21+
<comment>default: stores</comment>
22+
</field>
23+
</group>
24+
25+
</section>
426

527
<section id="smile_map" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
628

0 commit comments

Comments
 (0)