Skip to content

Commit

Permalink
2.0.x (#41)
Browse files Browse the repository at this point in the history
- Refactor - same search design everywhere
- Dont show store delivery shipping method if no markers found
  • Loading branch information
livca-smile authored May 3, 2024
1 parent 148ee06 commit 6f0e065
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 75 deletions.
86 changes: 52 additions & 34 deletions Block/Checkout/LayoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,56 @@ public function __construct(
public function process($jsLayout)
{
if ($this->carrierFactory->getIfActive($this->methodCode)) {
// @codingStandardsIgnoreStart
$storeDelivery = $jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery'];
// @codingStandardsIgnoreEnd

$storeDelivery['provider'] = $this->map->getIdentifier();
$storeDelivery['markers'] = $this->getStores();
$storeDelivery = array_merge($storeDelivery, $this->map->getConfig());

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery'] = $storeDelivery;
// @codingStandardsIgnoreEnd

// @codingStandardsIgnoreStart
$geocoder = $jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery']['children']['geocoder'];
// @codingStandardsIgnoreEnd

$geocoder['provider'] = $this->map->getIdentifier();
$geocoder = array_merge($geocoder, $this->map->getConfig());

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery']['children']['geocoder'] = $geocoder;
// @codingStandardsIgnoreEnd
$markers = $this->getStores();

if ($markers) {
// @codingStandardsIgnoreStart
$storeDelivery = $jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery'];
// @codingStandardsIgnoreEnd

$storeDelivery['provider'] = $this->map->getIdentifier();
$storeDelivery['markers'] = $markers;
$storeDelivery['searchPlaceholderText'] = $this->storeLocatorHelper->getSearchPlaceholder();
$storeDelivery = array_merge($storeDelivery, $this->map->getConfig());

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery'] = $storeDelivery;
// @codingStandardsIgnoreEnd

// @codingStandardsIgnoreStart
$geocoder = $jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery']['children']['geocoder'];
// @codingStandardsIgnoreEnd

$geocoder['provider'] = $this->map->getIdentifier();
$geocoder = array_merge($geocoder, $this->map->getConfig());

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']['children']['smile-store-delivery']
['children']['store-delivery']['children']['geocoder'] = $geocoder;
// @codingStandardsIgnoreEnd
}

// unset store-delivery if $markers found
if (!$markers) {
unset($jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['shippingAddress']['children']['address-list']
['rendererTemplates']['store-delivery']);
unset($jsLayout['components']['checkout']['children']['steps']['children']
['shipping-step']['children']['smile-store-delivery-address-provider']);
unset($jsLayout['components']['checkout']['children']['sidebar']['children']
['shipping-information']['children']['ship-to']['rendererTemplates']['store-delivery']);
}
}

return $jsLayout;
Expand Down Expand Up @@ -118,6 +134,8 @@ private function getStores(): array
'directionUrl' => $this->map->getDirectionUrl($address->getCoordinates()),
'setStoreData' => $this->getSetStorePostData($retailer),
'addressData' => $address->getData(),
'postCode' => $address->getPostcode(),
'city' => $address->getCity(),
];

// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [2.0.1] - 2024-05-03
[2.0.1]: https://github.com/Smile-SA/magento2-module-store-delivery/compare/2.0.0...2.0.1

- Refactor - same search design everywhere
- Dont show store delivery shipping method if no markers found

## [2.0.0] - 2023-09-20
[2.0.0]: https://github.com/Smile-SA/magento2-module-store-delivery/compare/1.1.10...2.0.0

Expand Down
30 changes: 30 additions & 0 deletions Plugin/CustomerData/CurrentStorePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Smile\StoreDelivery\Plugin\CustomerData;

use Magento\Framework\DataObject;
use Smile\Retailer\Api\Data\RetailerInterface;
use Smile\StoreLocator\CustomerData\CurrentStore;

class CurrentStorePlugin
{
/**
* Add current store allow_store_delivery value to customerData
*/
public function afterGetSectionData(
CurrentStore $subject,
array $result
): array {
$result['allow_store_delivery'] = 0;
/** @var DataObject|RetailerInterface|null $retailer */
$retailer = $subject->getRetailer();

if ($retailer) {
$result['allow_store_delivery'] = (int) $retailer->getData('allow_store_delivery');
}

return $result;
}
}
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
<plugin name="gift_registry_quote_address_to_order_address" type="Smile\StoreDelivery\Plugin\Quote\Model\ConvertQuoteAddressToOrderAddress"/>
</type>

<type name="Smile\StoreLocator\CustomerData\CurrentStore">
<plugin name="store-delivery_customerdata_currentstore_allow_store_delivery" type="Smile\StoreDelivery\Plugin\CustomerData\CurrentStorePlugin"/>
</type>

<!-- Fix issue with Temando module : https://github.com/magento/magento2/issues/12921 - no more needed -->
</config>
1 change: 0 additions & 1 deletion view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<item name="geocoder" xsi:type="array">
<item name="component" xsi:type="string">smile-geocoder</item>
<item name="searchTitleText" xsi:type="string" translate="true">Find a store :</item>
<item name="searchPlaceholderText" xsi:type="string" translate="true">City, Zipcode, Department, ...</item>
<item name="searchButtonText" xsi:type="string" translate="true">Search</item>
</item>
<item name="store-list" xsi:type="array">
Expand Down
76 changes: 40 additions & 36 deletions view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
Expand Up @@ -87,52 +87,56 @@ body.checkout-index-index {
.shop-search {
width: 250px;
height: 100%;

// TODO cleaning
.fulltext-search-wrapper {
border-bottom: 1px solid #c2c2c2;
height: @fulltext-search-wrapper-height;
padding: @fulltext-search-wrapper-padding;
padding: 10px;
position: relative;
display: flex;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;

div.geolocalize-container {
flex: 0 0 100%;
a {
width: 100%;
text-align: center;
}
}

.form {
.store-search-form {
display: flex;
padding: 10px 0 5px;
margin-left: auto;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;

flex: 0 0 100%;
margin-top: 5px;
.field {
flex: 1;
flex: 5;
}
.actions {
flex:1;
button {
width: 100%;

.actions-toolbar {

.primary .action {
margin: 0;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
padding: 6px 15px;
font-size: 1.4rem;
span {
line-height: 1.3em;
&:before {
content: '\e615';
font-family: 'luma-icons';
font-size: 16px;
color: #FFFFFF;
margin: 0;
vertical-align: top;
display: inline-block;
font-weight: normal;
overflow: hidden;
speak: none;
text-align: center;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: antialiased;
}
}
}

.geolocalize-container {
flex: 0 0 100%;
a {
width:100%;
text-align:center;
}
}

.store-search-form {
display: flex;
margin-left: auto;
align-items: center;
flex: 0 0 100%;
margin-top: 5px;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions view/frontend/web/js/view/checkout/shipping/store-delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define([
var type = quote.shippingAddress().getType();
if (type === 'store-delivery') {
selectShippingMethodAction({
carrier_code: this.getCarrierCode(),
carrier_code: this.getCarrierCode(),
carrier_title: this.getCarrierTitle(),
method_code: this.getMethodCode(),
method_title: this.getMethodTitle(),
Expand Down Expand Up @@ -67,15 +67,15 @@ define([
return this.methodCode;
},

getMethodTitle: function() {
getMethodTitle: function() {
return this.methodTitle;
},

getCarrierCode: function() {
return this.carrierCode;
},

getCarrierTitle: function() {
getCarrierTitle: function() {
return this.carrierTitle;
},

Expand Down
7 changes: 6 additions & 1 deletion view/frontend/web/js/view/shipping-address/store-delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ define(

var address = new storeDeliveryAddress(null, {});
var currentStore = customerData.get('current-store');
if (currentStore() && currentStore().entity_id && currentStore().address_data) {
if (currentStore()
&& currentStore().entity_id
&& currentStore().address_data
// write address only if allow_store_delivery === 1 for currentStore in customerData
&& currentStore().allow_store_delivery
) {
var addressData = currentStore().address_data;
if ((addressData.company === undefined) && currentStore().name) {
addressData.company = currentStore().name;
Expand Down

0 comments on commit 6f0e065

Please sign in to comment.