fix(webservice): Namespaces and redundancies
redundant require statements, clean up install trait, standardize trait names, remove hard-coded php version require for composer.json
This commit is contained in:
@@ -7,12 +7,9 @@
|
||||
"email": "isabelle@dewebsmid.nl"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Module\\WsOrderreference\\": "src/"
|
||||
"Websmid\\WsOrderReference\\": "src/"
|
||||
},
|
||||
"classmap": [
|
||||
"ws_orderreference.php",
|
||||
|
||||
@@ -3,17 +3,15 @@ services:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Module\WsOrderreference\Controller\:
|
||||
resource: "../src/Controller/*"
|
||||
# Repository - this makes it available via dependency injection
|
||||
Module\WsOrderreference\Repository\OrderReferenceRepository:
|
||||
Websmid\WsOrderReference\Repository\OrderReferenceRepository:
|
||||
public: true
|
||||
factory: ["@doctrine.orm.default_entity_manager", getRepository]
|
||||
arguments:
|
||||
- Module\WsOrderreference\Entity\OrderReference
|
||||
- Websmid\WsOrderReference\Entity\OrderReference
|
||||
|
||||
# Database installer
|
||||
Module\WsOrderreference\Database\ReferenceInstaller:
|
||||
Websmid\WsOrderReference\Database\ReferenceInstaller:
|
||||
public: true
|
||||
arguments:
|
||||
- "@doctrine.dbal.default_connection"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Module\WsOrderreference\Entity\OrderReference;
|
||||
use Module\WsOrderreference\Repository\OrderReferenceRepository;
|
||||
use Websmid\WsOrderReference\Entity\OrderReference;
|
||||
use Websmid\WsOrderReference\Repository\OrderReferenceRepository;
|
||||
|
||||
if (file_exists(__DIR__ . '../../vendor/autoload.php')) {
|
||||
require_once __DIR__ . '../../vendor/autoload.php';
|
||||
@@ -44,7 +44,7 @@ class ws_orderreferenceAjaxModuleFrontController extends ModuleFrontController
|
||||
$orderRef->setIdCart($idCart);
|
||||
}
|
||||
|
||||
$orderRef->setOrderReference($orderReference);
|
||||
$orderRef->setOrderReference(pSQL($orderReference));
|
||||
|
||||
$entityManager->persist($orderRef);
|
||||
$entityManager->flush();
|
||||
|
||||
19
src/Controller/OrderReferenceController.php
Normal file
19
src/Controller/OrderReferenceController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Websmid\WsOrderReference\Controller;
|
||||
|
||||
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class OrderReferenceController extends PrestaShopAdminController
|
||||
{
|
||||
public function getReferenceAction(int $id_order)
|
||||
{
|
||||
// Dummy data for testing. See https://simonspeelgoed.websmid.dev/api/order_reference
|
||||
|
||||
return new JsonResponse([
|
||||
'orderId' => $id_order,
|
||||
'customReference' => 'DUMMY-REF-12345',
|
||||
'status' => 'This is a test response'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Module\WsOrderreference\Database;
|
||||
namespace Websmid\WsOrderReference\Database;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Module\WsOrderreference\Entity;
|
||||
namespace Websmid\WsOrderReference\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table()
|
||||
* @ORM\Entity(repositoryClass="Module\WsOrderreference\Repository\OrderReferenceRepository")
|
||||
* @ORM\Entity(repositoryClass="Websmid\WsOrderReference\Repository\OrderReferenceRepository")
|
||||
*/
|
||||
class OrderReference
|
||||
{
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Module\WsOrderreference\Module;
|
||||
namespace Websmid\WsOrderReference\Module;
|
||||
|
||||
use Module\WsOrderreference\Database\ReferenceInstaller;
|
||||
use Websmid\WsOrderReference\Database\ReferenceInstaller;
|
||||
|
||||
trait Install
|
||||
{
|
||||
public function install()
|
||||
{
|
||||
return $this->installTables()
|
||||
&& parent::install()
|
||||
&& $this->registerHook('displayShoppingCart')
|
||||
if (!parent::install()) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->installTables()){
|
||||
return false;
|
||||
}
|
||||
if (!$this->registerHooks()){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function registerHooks(){
|
||||
return $this->registerHook('displayShoppingCart')
|
||||
&& $this->registerHook('displayPDFDeliverySlip')
|
||||
&& $this->registerHook('addWebserviceResources')
|
||||
&& $this->registerHook('actionFrontControllerSetMedia');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Module\WsOrderreference\Module;
|
||||
namespace Websmid\WsOrderReference\Module;
|
||||
|
||||
trait actionHooks
|
||||
trait ActionHooks
|
||||
{
|
||||
public function hookActionFrontControllerSetMedia($params)
|
||||
{
|
||||
@@ -22,6 +22,7 @@ trait actionHooks
|
||||
['media' => 'all', 'priority' => 150]
|
||||
);
|
||||
}
|
||||
|
||||
// Register in web service using specific management to bypass objectmodel handling and return custom data.
|
||||
// I used specific_management because otherwise I'd have to make an objectmodel which conflicts with the doctrine entity I made.
|
||||
// Instead of having to manage two places where the order reference is handled, I can just use the specific management to return the data from the db directly.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Module\WsOrderreference\Module;
|
||||
namespace Websmid\WsOrderReference\Module;
|
||||
|
||||
trait displayHooks
|
||||
trait DisplayHooks
|
||||
{
|
||||
public function hookDisplayShoppingCart($params)
|
||||
{
|
||||
@@ -13,7 +13,7 @@ trait displayHooks
|
||||
{
|
||||
$orderId = $params['object']->id_order;
|
||||
|
||||
$orderReferenceRepo = \PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance()->get('Module\WsOrderreference\Repository\OrderReferenceRepository');
|
||||
$orderReferenceRepo = \PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance()->get('Websmid\WsOrderReference\Repository\OrderReferenceRepository');
|
||||
$orderReference = $orderReferenceRepo->customRefByOrderId($orderId);
|
||||
|
||||
$this->context->smarty->assign('orderReference', $orderReference);
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Module\WsOrderreference\Repository;
|
||||
namespace Websmid\WsOrderReference\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Module\WsOrderreference\Entity\OrderReference;
|
||||
use Websmid\WsOrderReference\Entity\OrderReference;
|
||||
|
||||
class OrderReferenceRepository extends EntityRepository
|
||||
{
|
||||
|
||||
@@ -4,25 +4,23 @@ if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use Module\WsOrderreference\Module\Install;
|
||||
use Module\WsOrderreference\Module\displayHooks;
|
||||
use Module\WsOrderreference\Module\actionHooks;
|
||||
|
||||
use Websmid\WsOrderReference\Module\Install;
|
||||
use Websmid\WsOrderReference\Module\DisplayHooks;
|
||||
use Websmid\WsOrderReference\Module\ActionHooks;
|
||||
|
||||
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/classes/WebserviceSpecificManagementOrderreference.php';
|
||||
|
||||
class Ws_OrderReference extends Module
|
||||
{
|
||||
/** @var OrderReferenceRepository */
|
||||
protected $orderReferenceRepository;
|
||||
|
||||
use Install;
|
||||
use displayHooks;
|
||||
use actionHooks;
|
||||
use DisplayHooks;
|
||||
use ActionHooks;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user