Skip to content

Commit 6f0e065

Browse files
authored
2.0.x (#41)
- Refactor - same search design everywhere - Dont show store delivery shipping method if no markers found
1 parent 148ee06 commit 6f0e065

File tree

8 files changed

+141
-75
lines changed

8 files changed

+141
-75
lines changed

Block/Checkout/LayoutProcessor.php

+52-34
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,56 @@ public function __construct(
5151
public function process($jsLayout)
5252
{
5353
if ($this->carrierFactory->getIfActive($this->methodCode)) {
54-
// @codingStandardsIgnoreStart
55-
$storeDelivery = $jsLayout['components']['checkout']['children']['steps']['children']
56-
['shipping-step']['children']['shippingAddress']['children']['address-list']
57-
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
58-
['children']['store-delivery'];
59-
// @codingStandardsIgnoreEnd
60-
61-
$storeDelivery['provider'] = $this->map->getIdentifier();
62-
$storeDelivery['markers'] = $this->getStores();
63-
$storeDelivery = array_merge($storeDelivery, $this->map->getConfig());
64-
65-
// @codingStandardsIgnoreStart
66-
$jsLayout['components']['checkout']['children']['steps']['children']
67-
['shipping-step']['children']['shippingAddress']['children']['address-list']
68-
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
69-
['children']['store-delivery'] = $storeDelivery;
70-
// @codingStandardsIgnoreEnd
71-
72-
// @codingStandardsIgnoreStart
73-
$geocoder = $jsLayout['components']['checkout']['children']['steps']['children']
74-
['shipping-step']['children']['shippingAddress']['children']['address-list']
75-
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
76-
['children']['store-delivery']['children']['geocoder'];
77-
// @codingStandardsIgnoreEnd
78-
79-
$geocoder['provider'] = $this->map->getIdentifier();
80-
$geocoder = array_merge($geocoder, $this->map->getConfig());
81-
82-
// @codingStandardsIgnoreStart
83-
$jsLayout['components']['checkout']['children']['steps']['children']
84-
['shipping-step']['children']['shippingAddress']['children']['address-list']
85-
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
86-
['children']['store-delivery']['children']['geocoder'] = $geocoder;
87-
// @codingStandardsIgnoreEnd
54+
$markers = $this->getStores();
55+
56+
if ($markers) {
57+
// @codingStandardsIgnoreStart
58+
$storeDelivery = $jsLayout['components']['checkout']['children']['steps']['children']
59+
['shipping-step']['children']['shippingAddress']['children']['address-list']
60+
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
61+
['children']['store-delivery'];
62+
// @codingStandardsIgnoreEnd
63+
64+
$storeDelivery['provider'] = $this->map->getIdentifier();
65+
$storeDelivery['markers'] = $markers;
66+
$storeDelivery['searchPlaceholderText'] = $this->storeLocatorHelper->getSearchPlaceholder();
67+
$storeDelivery = array_merge($storeDelivery, $this->map->getConfig());
68+
69+
// @codingStandardsIgnoreStart
70+
$jsLayout['components']['checkout']['children']['steps']['children']
71+
['shipping-step']['children']['shippingAddress']['children']['address-list']
72+
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
73+
['children']['store-delivery'] = $storeDelivery;
74+
// @codingStandardsIgnoreEnd
75+
76+
// @codingStandardsIgnoreStart
77+
$geocoder = $jsLayout['components']['checkout']['children']['steps']['children']
78+
['shipping-step']['children']['shippingAddress']['children']['address-list']
79+
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
80+
['children']['store-delivery']['children']['geocoder'];
81+
// @codingStandardsIgnoreEnd
82+
83+
$geocoder['provider'] = $this->map->getIdentifier();
84+
$geocoder = array_merge($geocoder, $this->map->getConfig());
85+
86+
// @codingStandardsIgnoreStart
87+
$jsLayout['components']['checkout']['children']['steps']['children']
88+
['shipping-step']['children']['shippingAddress']['children']['address-list']
89+
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
90+
['children']['store-delivery']['children']['geocoder'] = $geocoder;
91+
// @codingStandardsIgnoreEnd
92+
}
93+
94+
// unset store-delivery if $markers found
95+
if (!$markers) {
96+
unset($jsLayout['components']['checkout']['children']['steps']['children']
97+
['shipping-step']['children']['shippingAddress']['children']['address-list']
98+
['rendererTemplates']['store-delivery']);
99+
unset($jsLayout['components']['checkout']['children']['steps']['children']
100+
['shipping-step']['children']['smile-store-delivery-address-provider']);
101+
unset($jsLayout['components']['checkout']['children']['sidebar']['children']
102+
['shipping-information']['children']['ship-to']['rendererTemplates']['store-delivery']);
103+
}
88104
}
89105

90106
return $jsLayout;
@@ -118,6 +134,8 @@ private function getStores(): array
118134
'directionUrl' => $this->map->getDirectionUrl($address->getCoordinates()),
119135
'setStoreData' => $this->getSetStorePostData($retailer),
120136
'addressData' => $address->getData(),
137+
'postCode' => $address->getPostcode(),
138+
'city' => $address->getCity(),
121139
];
122140

123141
// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge

CHANGELOG.md

+6
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.0.1] - 2024-05-03
6+
[2.0.1]: https://github.com/Smile-SA/magento2-module-store-delivery/compare/2.0.0...2.0.1
7+
8+
- Refactor - same search design everywhere
9+
- Dont show store delivery shipping method if no markers found
10+
511
## [2.0.0] - 2023-09-20
612
[2.0.0]: https://github.com/Smile-SA/magento2-module-store-delivery/compare/1.1.10...2.0.0
713

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Smile\StoreDelivery\Plugin\CustomerData;
6+
7+
use Magento\Framework\DataObject;
8+
use Smile\Retailer\Api\Data\RetailerInterface;
9+
use Smile\StoreLocator\CustomerData\CurrentStore;
10+
11+
class CurrentStorePlugin
12+
{
13+
/**
14+
* Add current store allow_store_delivery value to customerData
15+
*/
16+
public function afterGetSectionData(
17+
CurrentStore $subject,
18+
array $result
19+
): array {
20+
$result['allow_store_delivery'] = 0;
21+
/** @var DataObject|RetailerInterface|null $retailer */
22+
$retailer = $subject->getRetailer();
23+
24+
if ($retailer) {
25+
$result['allow_store_delivery'] = (int) $retailer->getData('allow_store_delivery');
26+
}
27+
28+
return $result;
29+
}
30+
}

etc/di.xml

+4
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
<plugin name="gift_registry_quote_address_to_order_address" type="Smile\StoreDelivery\Plugin\Quote\Model\ConvertQuoteAddressToOrderAddress"/>
1818
</type>
1919

20+
<type name="Smile\StoreLocator\CustomerData\CurrentStore">
21+
<plugin name="store-delivery_customerdata_currentstore_allow_store_delivery" type="Smile\StoreDelivery\Plugin\CustomerData\CurrentStorePlugin"/>
22+
</type>
23+
2024
<!-- Fix issue with Temando module : https://github.com/magento/magento2/issues/12921 - no more needed -->
2125
</config>

view/frontend/layout/checkout_index_index.xml

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
<item name="geocoder" xsi:type="array">
7171
<item name="component" xsi:type="string">smile-geocoder</item>
7272
<item name="searchTitleText" xsi:type="string" translate="true">Find a store :</item>
73-
<item name="searchPlaceholderText" xsi:type="string" translate="true">City, Zipcode, Department, ...</item>
7473
<item name="searchButtonText" xsi:type="string" translate="true">Search</item>
7574
</item>
7675
<item name="store-list" xsi:type="array">

view/frontend/web/css/source/_module.less

+40-36
Original file line numberDiff line numberDiff line change
@@ -87,52 +87,56 @@ body.checkout-index-index {
8787
.shop-search {
8888
width: 250px;
8989
height: 100%;
90+
91+
// TODO cleaning
9092
.fulltext-search-wrapper {
91-
border-bottom: 1px solid #c2c2c2;
92-
height: @fulltext-search-wrapper-height;
93-
padding: @fulltext-search-wrapper-padding;
93+
padding: 10px;
94+
position: relative;
95+
display: flex;
96+
align-items: center;
97+
flex-direction: row;
98+
flex-wrap: wrap;
99+
justify-content: center;
100+
101+
div.geolocalize-container {
102+
flex: 0 0 100%;
103+
a {
104+
width: 100%;
105+
text-align: center;
106+
}
107+
}
94108

95-
.form {
109+
.store-search-form {
96110
display: flex;
97-
padding: 10px 0 5px;
111+
margin-left: auto;
98112
align-items: center;
99-
flex-direction: row;
100-
flex-wrap: wrap;
101-
justify-content: center;
102-
113+
flex: 0 0 100%;
114+
margin-top: 5px;
103115
.field {
104-
flex: 1;
116+
flex: 5;
105117
}
118+
.actions {
119+
flex:1;
120+
button {
121+
width: 100%;
106122

107-
.actions-toolbar {
108-
109-
.primary .action {
110-
margin: 0;
111-
border-top-left-radius: 0px;
112-
border-bottom-left-radius: 0px;
113-
padding: 6px 15px;
114-
font-size: 1.4rem;
115-
span {
116-
line-height: 1.3em;
123+
&:before {
124+
content: '\e615';
125+
font-family: 'luma-icons';
126+
font-size: 16px;
127+
color: #FFFFFF;
128+
margin: 0;
129+
vertical-align: top;
130+
display: inline-block;
131+
font-weight: normal;
132+
overflow: hidden;
133+
speak: none;
134+
text-align: center;
135+
-webkit-font-smoothing: antialiased;
136+
-moz-osx-font-smoothing: antialiased;
117137
}
118138
}
119139
}
120-
121-
.geolocalize-container {
122-
flex: 0 0 100%;
123-
a {
124-
width:100%;
125-
text-align:center;
126-
}
127-
}
128-
129-
.store-search-form {
130-
display: flex;
131-
margin-left: auto;
132-
align-items: center;
133-
flex: 0 0 100%;
134-
margin-top: 5px;
135-
}
136140
}
137141
}
138142
}

view/frontend/web/js/view/checkout/shipping/store-delivery.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ define([
2828
var type = quote.shippingAddress().getType();
2929
if (type === 'store-delivery') {
3030
selectShippingMethodAction({
31-
carrier_code: this.getCarrierCode(),
31+
carrier_code: this.getCarrierCode(),
3232
carrier_title: this.getCarrierTitle(),
3333
method_code: this.getMethodCode(),
3434
method_title: this.getMethodTitle(),
@@ -67,15 +67,15 @@ define([
6767
return this.methodCode;
6868
},
6969

70-
getMethodTitle: function() {
70+
getMethodTitle: function() {
7171
return this.methodTitle;
7272
},
7373

7474
getCarrierCode: function() {
7575
return this.carrierCode;
7676
},
7777

78-
getCarrierTitle: function() {
78+
getCarrierTitle: function() {
7979
return this.carrierTitle;
8080
},
8181

view/frontend/web/js/view/shipping-address/store-delivery.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ define(
3333

3434
var address = new storeDeliveryAddress(null, {});
3535
var currentStore = customerData.get('current-store');
36-
if (currentStore() && currentStore().entity_id && currentStore().address_data) {
36+
if (currentStore()
37+
&& currentStore().entity_id
38+
&& currentStore().address_data
39+
// write address only if allow_store_delivery === 1 for currentStore in customerData
40+
&& currentStore().allow_store_delivery
41+
) {
3742
var addressData = currentStore().address_data;
3843
if ((addressData.company === undefined) && currentStore().name) {
3944
addressData.company = currentStore().name;

0 commit comments

Comments
 (0)