fix(webservice): Polished code

This commit is contained in:
2026-03-05 09:37:45 +01:00
parent 29859178bd
commit 5511ebfe42
10 changed files with 55 additions and 41 deletions

View File

@@ -9,7 +9,7 @@
],
"autoload": {
"psr-4": {
"Websmid\\WsOrderReference\\": "src/"
"Websmid\\OrderReference\\": "src/"
},
"classmap": [
"ws_orderreference.php",

View File

@@ -4,15 +4,8 @@ services:
autoconfigure: true
# Repository - this makes it available via dependency injection
Websmid\WsOrderReference\Repository\OrderReferenceRepository:
Websmid\OrderReference\Repository\OrderReferenceRepository:
public: true
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
- Websmid\WsOrderReference\Entity\OrderReference
# Database installer
Websmid\WsOrderReference\Database\ReferenceInstaller:
public: true
arguments:
- "@doctrine.dbal.default_connection"
- "%database_prefix%"
- Websmid\OrderReference\Entity\OrderReference

View File

@@ -1,7 +1,7 @@
<?php
use Websmid\WsOrderReference\Entity\OrderReference;
use Websmid\WsOrderReference\Repository\OrderReferenceRepository;
use Websmid\OrderReference\Entity\OrderReference;
use Websmid\OrderReference\Repository\OrderReferenceRepository;
if (file_exists(__DIR__ . '../../vendor/autoload.php')) {
require_once __DIR__ . '../../vendor/autoload.php';
@@ -29,6 +29,7 @@ class ws_orderreferenceAjaxModuleFrontController extends ModuleFrontController
]));
return;
}
try {
/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
@@ -37,11 +38,11 @@ class ws_orderreferenceAjaxModuleFrontController extends ModuleFrontController
/** @var OrderReferenceRepository $repository */
$repository = $entityManager->getRepository(OrderReference::class);
$orderRef = $repository->findByCartId($idCart);
$orderRef = $repository->findByCartId((int)$idCart);
if (!$orderRef) {
$orderRef = new OrderReference();
$orderRef->setIdCart($idCart);
$orderRef->setIdCart((int)$idCart);
}
$orderRef->setOrderReference(pSQL($orderReference));

18
src/Config/Config.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace Websmid\OrderReference\Config;
class Config
{
const DISPLAYABLE_HOOKS = [
'displayShoppingCart' => 'displayShoppingCart',
'displayPDFDeliverySlip' => 'displayPDFDeliverySlip',
];
const HOOKS = [
'displayShoppingCart',
'displayPDFDeliverySlip',
'addWebserviceResources',
'actionFrontControllerSetMedia',
];
}

View File

@@ -10,13 +10,13 @@
declare(strict_types=1);
namespace Websmid\WsOrderReference\Entity;
namespace Websmid\OrderReference\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="Websmid\WsOrderReference\Repository\OrderReferenceRepository")
* @ORM\Entity(repositoryClass="Websmid\OrderReference\Repository\OrderReferenceRepository")
*/
class OrderReference
{

View File

@@ -1,8 +1,9 @@
<?php
namespace Websmid\WsOrderReference\Module;
namespace Websmid\OrderReference\Module;
use Websmid\WsOrderReference\Database\ReferenceInstaller;
use Db;
use Websmid\OrderReference\Config\Config;
trait Install
{
@@ -29,16 +30,20 @@ trait Install
`order_reference` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_cart` (`id_cart`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
);';
return \Db::getInstance()->execute($sql);
return Db::getInstance()->execute($sql);
}
public function registerHooks(){
return $this->registerHook('displayShoppingCart')
&& $this->registerHook('displayPDFDeliverySlip')
&& $this->registerHook('addWebserviceResources')
&& $this->registerHook('actionFrontControllerSetMedia');
public function registerHooks(): bool
{
foreach (Config::HOOKS as $hook) {
if (!$this->registerHook($hook)) {
return false;
}
}
return true;
}
}

View File

@@ -1,12 +1,14 @@
<?php
namespace Websmid\WsOrderReference\Module;
namespace Websmid\OrderReference\Module;
use Media;
trait ActionHooks
{
public function hookActionFrontControllerSetMedia($params)
{
\Media::addJsDef([
Media::addJsDef([
'ajax_url' => $this->context->link->getModuleLink($this->name, 'ajax'),
]);

View File

@@ -1,6 +1,6 @@
<?php
namespace Websmid\WsOrderReference\Module;
namespace Websmid\OrderReference\Module;
trait DisplayHooks
{
@@ -13,7 +13,7 @@ trait DisplayHooks
{
$orderId = $params['object']->id_order;
$orderReferenceRepo = \PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance()->get('Websmid\WsOrderReference\Repository\OrderReferenceRepository');
$orderReferenceRepo = \PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance()->get('Websmid\OrderReference\Repository\OrderReferenceRepository');
$orderReference = $orderReferenceRepo->customRefByOrderId($orderId);
$this->context->smarty->assign('orderReference', $orderReference);

View File

@@ -9,10 +9,10 @@
declare(strict_types=1);
namespace Websmid\WsOrderReference\Repository;
namespace Websmid\OrderReference\Repository;
use Doctrine\ORM\EntityRepository;
use Websmid\WsOrderReference\Entity\OrderReference;
use Websmid\OrderReference\Entity\OrderReference;
class OrderReferenceRepository extends EntityRepository
{

View File

@@ -4,9 +4,9 @@ if (!defined('_PS_VERSION_')) {
exit;
}
use Websmid\WsOrderReference\Module\Install;
use Websmid\WsOrderReference\Module\DisplayHooks;
use Websmid\WsOrderReference\Module\ActionHooks;
use Websmid\OrderReference\Module\Install;
use Websmid\OrderReference\Module\DisplayHooks;
use Websmid\OrderReference\Module\ActionHooks;
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
@@ -27,18 +27,13 @@ class Ws_OrderReference extends Module
$this->name = 'ws_orderreference';
$this->tab = 'other';
$this->version = '1.0.0';
$this->author = 'Isabelle Oving-Anno | De Websmid b.v.';
$this->author = 'Isabelle Oving-Anno | De Websmid B.V.';
$this->need_instance = 0;
$this->ps_versions_compliancy = [
'min' => '9.0.0',
'max' => '9.99.99',
];
$this -> bootstrap = true;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Order Reference');
$this->description = $this->l('Adds an optional order reference field to the shopping cart summary.');
}
}