-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(checkout): fix delivery options not loading in ps 1.7 (#270)
INT-596
- Loading branch information
1 parent
05afd1c
commit 11c6a46
Showing
9 changed files
with
204 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Router\Service; | ||
|
||
use Context; | ||
|
||
final class Ps17RouterService extends PsRouterService | ||
{ | ||
/** | ||
* @param string $route | ||
* | ||
* @return string | ||
*/ | ||
protected function generateRoute(string $route): string | ||
{ | ||
/** @var \LinkCore $link */ | ||
$link = Context::getContext()->link; | ||
|
||
if (! defined('_PS_ADMIN_DIR_')) { | ||
// Do not generate admin links in the frontend. There are currently no frontend endpoints anyway. | ||
return ''; | ||
} | ||
|
||
return $link->getAdminLink('MyParcelNLAdminSettings', true, ['route' => $route]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Router\Service; | ||
|
||
use Context; | ||
use MyParcelNL\Pdk\Facade\Pdk; | ||
use MyParcelNL\Pdk\Storage\Contract\StorageInterface; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Routing\Loader\YamlFileLoader; | ||
use Symfony\Component\Routing\Router; | ||
|
||
final class Ps8RouterService extends PsRouterService | ||
{ | ||
/** | ||
* @var \Symfony\Component\Routing\Router | ||
*/ | ||
private Router $router; | ||
|
||
/** | ||
* @param \MyParcelNL\Pdk\Storage\Contract\StorageInterface $storage | ||
* | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
public function __construct(StorageInterface $storage) | ||
{ | ||
parent::__construct($storage); | ||
$this->router = $this->getRouter(); | ||
} | ||
|
||
/** | ||
* @param string $route | ||
* | ||
* @return string | ||
*/ | ||
protected function generateRoute(string $route): string | ||
{ | ||
return $this->router->generate($route); | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\Routing\Router | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
private function getRouter(): Router | ||
{ | ||
/** @var \Psr\Container\ContainerInterface $container */ | ||
$container = Pdk::get('ps.container'); | ||
|
||
$controller = Context::getContext()->controller; | ||
|
||
if ('order' === $controller->php_self) { | ||
$routesDirectory = _PS_ROOT_DIR_ . '/modules/myparcelnl/config'; | ||
$locator = new FileLocator([$routesDirectory]); | ||
$loader = new YamlFileLoader($locator); | ||
|
||
return new Router($loader, 'routes.yml'); | ||
} | ||
|
||
return $container->get('prestashop.router'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** @noinspection StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
use MyParcelNL\Pdk\Facade\Pdk; | ||
use MyParcelNL\PrestaShop\Pdk\Account\Repository\PsPdkAccountRepository; | ||
use MyParcelNL\PrestaShop\Pdk\Cart\Repository\PsPdkCartRepository; | ||
use MyParcelNL\PrestaShop\Pdk\Order\Repository\PsPdkOrderNoteRepository; | ||
use MyParcelNL\PrestaShop\Pdk\Settings\Repository\PsPdkSettingsRepository; | ||
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance; | ||
use function DI\value; | ||
use function MyParcelNL\Pdk\Tests\mockPdkProperties; | ||
use function MyParcelNL\Pdk\Tests\usesShared; | ||
use function MyParcelNL\PrestaShop\psVersionFactory; | ||
|
||
usesShared(new UsesMockPsPdkInstance([ | ||
// Must have an initial value to use mockPdkProperties | ||
'someProperty' => value(null), | ||
])); | ||
|
||
it('gets class based on prestashop version number', function (string $version, string $expectedClass) { | ||
mockPdkProperties([ | ||
'ps.version' => value($version), | ||
|
||
'someProperty' => psVersionFactory([ | ||
['class' => PsPdkAccountRepository::class, 'version' => 8], | ||
['class' => PsPdkCartRepository::class, 'version' => '1.7', 'operator' => '>=',], | ||
['class' => PsPdkSettingsRepository::class, 'version' => '1.6', 'operator' => '<'], | ||
['class' => PsPdkOrderNoteRepository::class], | ||
]), | ||
]); | ||
|
||
$result = Pdk::get('someProperty'); | ||
|
||
expect($result)->toBeInstanceOf($expectedClass); | ||
})->with([ | ||
'version 9.999.999' => ['9.999.999', PsPdkAccountRepository::class], | ||
'version 8.2.0' => ['8.2.0', PsPdkAccountRepository::class], | ||
'version 1.7.0' => ['1.7.0', PsPdkCartRepository::class], | ||
'version 1.6.0' => ['1.6.0', PsPdkOrderNoteRepository::class], | ||
'version 1.5.999' => ['1.5.999', PsPdkSettingsRepository::class], | ||
'version 1.0.0' => ['1.0.0', PsPdkSettingsRepository::class], | ||
]); |