Skip to content

Commit

Permalink
Fix compatibility 2 4 6 (#40)
Browse files Browse the repository at this point in the history
Fix compatibility Magento 2.4.6

---------

Co-authored-by: guvra <guvra@smile.fr>
  • Loading branch information
livca-smile and guvra authored Sep 21, 2023
1 parent 8564d5e commit 148ee06
Show file tree
Hide file tree
Showing 50 changed files with 506 additions and 1,033 deletions.
25 changes: 0 additions & 25 deletions .codeclimate.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CHANGELOG.md export-ignore
/phpcs.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/README.md export-ignore
66 changes: 66 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Static Analysis'

on:
pull_request: ~
push:
branches:
- 'master'

jobs:
static-analysis:
runs-on: 'ubuntu-latest'

strategy:
matrix:
php-version:
- '8.1'

steps:
- name: 'Checkout'
uses: 'actions/checkout@v3'

- name: 'Install PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '${{ matrix.php-version }}'
coverage: 'none'
tools: 'composer:v2'
env:
COMPOSER_AUTH_JSON: |
{
"http-basic": {
"repo.magento.com": {
"username": "${{ secrets.MAGENTO_USERNAME }}",
"password": "${{ secrets.MAGENTO_PASSWORD }}"
}
}
}
- name: 'Get composer cache directory'
id: 'composer-cache'
run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

- name: 'Cache dependencies'
uses: 'actions/cache@v3'
with:
path: '${{ steps.composer-cache.outputs.dir }}'
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: '${{ runner.os }}-composer-'

- name: 'Install dependencies'
run: 'composer install --prefer-dist'

- name: 'Run composer audit'
run: 'composer audit --format=plain'

- name: 'Run Parallel Lint'
run: 'vendor/bin/parallel-lint --exclude vendor .'

- name: 'Run PHP CodeSniffer'
run: 'vendor/bin/phpcs --extensions=php,phtml'

- name: 'Run PHPMD'
run: 'vendor/bin/phpmd . xml phpmd.xml.dist'

# - name: 'Run PHPStan'
# run: 'vendor/bin/phpstan analyse'
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.fleet
/.idea
/vendor
/composer.lock
/phpcs.xml
/phpstan.neon
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

171 changes: 49 additions & 122 deletions Block/Checkout/LayoutProcessor.php
Original file line number Diff line number Diff line change
@@ -1,121 +1,52 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\StoreDelivery
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @copyright 2017 Smile
* @license Open Software License ("OSL") v. 3.0
*/

declare(strict_types=1);

namespace Smile\StoreDelivery\Block\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\DataObject;
use Magento\Framework\UrlInterface;
use Magento\Shipping\Model\CarrierFactoryInterface;
use Smile\Map\Api\MapInterface;
use Smile\Map\Api\MapProviderInterface;
use Smile\Map\Model\AddressFormatter;
use Smile\Retailer\Api\Data\RetailerExtensionInterface;
use Smile\Retailer\Api\Data\RetailerInterface;
use Smile\Retailer\Model\ResourceModel\Retailer\Collection;
use Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory;
use Smile\StoreDelivery\Model\Carrier;
use Smile\StoreLocator\Api\Data\RetailerAddressInterface;
use Smile\StoreLocator\Helper\Data;
use Smile\StoreLocator\Helper\Schedule;
use Smile\StoreLocator\Model\Retailer\ScheduleManagement;

/**
* Specific JS Layout processor for StoreDelivery.
* Inject Map, Geolocation and Stores into checkout UI Components.
*
* @category Smile
* @package Smile\StoreDelivery
* @author Romain Ruaud <romain.ruaud@smile.fr>
*/
class LayoutProcessor implements LayoutProcessorInterface
{
/**
* @var string
*/
private $methodCode = \Smile\StoreDelivery\Model\Carrier::METHOD_CODE;

/**
* @var MapInterface
*/
private $map;

/**
* @var CollectionFactory
*/
private $retailerCollectionFactory;

/**
* @var \Smile\StoreLocator\Helper\Data
*/
private $storeLocatorHelper;

/**
* @var \Smile\Map\Model\AddressFormatter
*/
private $addressFormatter;
private string $methodCode = Carrier::METHOD_CODE;
private MapInterface $map;

/**
* @var \Smile\StoreLocator\Helper\Schedule
*/
private $scheduleHelper;

/**
* @var \Smile\StoreLocator\Model\Retailer\ScheduleManagement
*/
private $scheduleManager;

/**
* @var \Magento\Shipping\Model\CarrierFactoryInterface
*/
private $carrierFactory;

/**
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;

/**
* @var \Magento\Framework\App\CacheInterface
*/
private $cache;

/**
* Constructor.
*
* @param \Smile\Map\Api\MapProviderInterface $mapProvider Map provider.
* @param \Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory $retailerCollectionFactory Retailer collection factory.
* @param \Smile\StoreLocator\Helper\Data $storeLocatorHelper Store locator helper.
* @param \Smile\Map\Model\AddressFormatter $addressFormatter Address formatter tool.
* @param \Smile\StoreLocator\Helper\Schedule $scheduleHelper Schedule Helper
* @param \Smile\StoreLocator\Model\Retailer\ScheduleManagement $scheduleManagement Schedule Management
* @param CarrierFactoryInterface $carrierFactory Carrier Factory
* @param \Magento\Framework\UrlInterface $urlBuilder URL Builder
* @param \Magento\Framework\App\CacheInterface $cacheInterface Cache Interface
*/
public function __construct(
\Smile\Map\Api\MapProviderInterface $mapProvider,
\Smile\Retailer\Model\ResourceModel\Retailer\CollectionFactory $retailerCollectionFactory,
\Smile\StoreLocator\Helper\Data $storeLocatorHelper,
\Smile\Map\Model\AddressFormatter $addressFormatter,
\Smile\StoreLocator\Helper\Schedule $scheduleHelper,
\Smile\StoreLocator\Model\Retailer\ScheduleManagement $scheduleManagement,
CarrierFactoryInterface $carrierFactory,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\App\CacheInterface $cacheInterface
MapProviderInterface $mapProvider,
private CollectionFactory $retailerCollectionFactory,
private Data $storeLocatorHelper,
private AddressFormatter $addressFormatter,
private Schedule $scheduleHelper,
private ScheduleManagement $scheduleManagement,
private CarrierFactoryInterface $carrierFactory,
private UrlInterface $urlBuilder,
private CacheInterface $cache
) {
$this->map = $mapProvider->getMap();
$this->retailerCollectionFactory = $retailerCollectionFactory;
$this->storeLocatorHelper = $storeLocatorHelper;
$this->addressFormatter = $addressFormatter;
$this->scheduleHelper = $scheduleHelper;
$this->scheduleManager = $scheduleManagement;
$this->carrierFactory = $carrierFactory;
$this->urlBuilder = $urlBuilder;
$this->cache = $cacheInterface;
$this->map = $mapProvider->getMap();
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function process($jsLayout)
{
Expand All @@ -128,8 +59,8 @@ public function process($jsLayout)
// @codingStandardsIgnoreEnd

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

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
Expand All @@ -146,7 +77,7 @@ public function process($jsLayout)
// @codingStandardsIgnoreEnd

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

// @codingStandardsIgnoreStart
$jsLayout['components']['checkout']['children']['steps']['children']
Expand All @@ -161,10 +92,8 @@ public function process($jsLayout)

/**
* List of markers displayed on the map.
*
* @return array
*/
private function getStores()
private function getStores(): array
{
$collection = $this->getRetailerCollection();
$cacheKey = sprintf("%s_%s", 'checkout_storedelivery', $collection->getStoreId());
Expand All @@ -174,26 +103,30 @@ private function getStores()
$markers = [];
/** @var RetailerInterface $retailer */
foreach ($collection as $retailer) {
$address = $retailer->getExtensionAttributes()->getAddress();
$coords = $address->getCoordinates();
/** @var RetailerExtensionInterface $retailerExtensionAttr */
$retailerExtensionAttr = $retailer->getExtensionAttributes();
/** @var DataObject|RetailerAddressInterface $address */
$address = $retailerExtensionAttr->getAddress();
$coords = $address->getCoordinates();
$markerData = [
'id' => $retailer->getId(),
'latitude' => $coords->getLatitude(),
'longitude' => $coords->getLongitude(),
'name' => $retailer->getName(),
'address' => $this->addressFormatter->formatAddress($address, AddressFormatter::FORMAT_ONELINE),
'url' => $this->storeLocatorHelper->getRetailerUrl($retailer),
'id' => $retailer->getId(),
'latitude' => $coords->getLatitude(),
'longitude' => $coords->getLongitude(),
'name' => $retailer->getName(),
'address' => $this->addressFormatter->formatAddress($address, AddressFormatter::FORMAT_ONELINE),
'url' => $this->storeLocatorHelper->getRetailerUrl($retailer),
'directionUrl' => $this->map->getDirectionUrl($address->getCoordinates()),
'setStoreData' => $this->getSetStorePostData($retailer),
'addressData' => $address->getData(),
'addressData' => $address->getData(),
];

// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
$markerData['schedule'] = array_merge(
$this->scheduleHelper->getConfig(),
[
'calendar' => $this->scheduleManager->getCalendar($retailer),
'openingHours' => $this->scheduleManager->getWeekOpeningHours($retailer),
'specialOpeningHours' => $retailer->getExtensionAttributes()->getSpecialOpeningHours(),
'calendar' => $this->scheduleManagement->getCalendar($retailer),
'openingHours' => $this->scheduleManagement->getWeekOpeningHours($retailer),
'specialOpeningHours' => $retailerExtensionAttr->getSpecialOpeningHours(),
]
);

Expand All @@ -213,10 +146,8 @@ private function getStores()

/**
* Collection of displayed retailers.
*
* @return \Smile\Retailer\Model\ResourceModel\Retailer\Collection
*/
private function getRetailerCollection()
private function getRetailerCollection(): Collection
{
$retailerCollection = $this->retailerCollectionFactory->create();
$retailerCollection->addAttributeToSelect(
Expand All @@ -231,12 +162,8 @@ private function getRetailerCollection()

/**
* Get the JSON post data used to build the set store link.
*
* @param \Smile\Retailer\Api\Data\RetailerInterface $retailer The store
*
* @return string
*/
private function getSetStorePostData($retailer)
private function getSetStorePostData(RetailerInterface $retailer): array
{
$setUrl = $this->urlBuilder->getUrl('storelocator/store/set');
$postData = ['id' => $retailer->getId()];
Expand Down
Loading

0 comments on commit 148ee06

Please sign in to comment.