fix(webservice): Polished code
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Websmid\\WsOrderReference\\": "src/"
|
"Websmid\\OrderReference\\": "src/"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"ws_orderreference.php",
|
"ws_orderreference.php",
|
||||||
|
|||||||
@@ -4,15 +4,8 @@ services:
|
|||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
# Repository - this makes it available via dependency injection
|
# Repository - this makes it available via dependency injection
|
||||||
Websmid\WsOrderReference\Repository\OrderReferenceRepository:
|
Websmid\OrderReference\Repository\OrderReferenceRepository:
|
||||||
public: true
|
public: true
|
||||||
factory: ["@doctrine.orm.default_entity_manager", getRepository]
|
factory: ["@doctrine.orm.default_entity_manager", getRepository]
|
||||||
arguments:
|
arguments:
|
||||||
- Websmid\WsOrderReference\Entity\OrderReference
|
- Websmid\OrderReference\Entity\OrderReference
|
||||||
|
|
||||||
# Database installer
|
|
||||||
Websmid\WsOrderReference\Database\ReferenceInstaller:
|
|
||||||
public: true
|
|
||||||
arguments:
|
|
||||||
- "@doctrine.dbal.default_connection"
|
|
||||||
- "%database_prefix%"
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Websmid\WsOrderReference\Entity\OrderReference;
|
use Websmid\OrderReference\Entity\OrderReference;
|
||||||
use Websmid\WsOrderReference\Repository\OrderReferenceRepository;
|
use Websmid\OrderReference\Repository\OrderReferenceRepository;
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '../../vendor/autoload.php')) {
|
if (file_exists(__DIR__ . '../../vendor/autoload.php')) {
|
||||||
require_once __DIR__ . '../../vendor/autoload.php';
|
require_once __DIR__ . '../../vendor/autoload.php';
|
||||||
@@ -30,6 +30,7 @@ class ws_orderreferenceAjaxModuleFrontController extends ModuleFrontController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
|
/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
|
||||||
$entityManager = $this->get('doctrine.orm.default_entity_manager');
|
$entityManager = $this->get('doctrine.orm.default_entity_manager');
|
||||||
@@ -37,11 +38,11 @@ class ws_orderreferenceAjaxModuleFrontController extends ModuleFrontController
|
|||||||
/** @var OrderReferenceRepository $repository */
|
/** @var OrderReferenceRepository $repository */
|
||||||
$repository = $entityManager->getRepository(OrderReference::class);
|
$repository = $entityManager->getRepository(OrderReference::class);
|
||||||
|
|
||||||
$orderRef = $repository->findByCartId($idCart);
|
$orderRef = $repository->findByCartId((int)$idCart);
|
||||||
|
|
||||||
if (!$orderRef) {
|
if (!$orderRef) {
|
||||||
$orderRef = new OrderReference();
|
$orderRef = new OrderReference();
|
||||||
$orderRef->setIdCart($idCart);
|
$orderRef->setIdCart((int)$idCart);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orderRef->setOrderReference(pSQL($orderReference));
|
$orderRef->setOrderReference(pSQL($orderReference));
|
||||||
|
|||||||
18
src/Config/Config.php
Normal file
18
src/Config/Config.php
Normal 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',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Websmid\WsOrderReference\Entity;
|
namespace Websmid\OrderReference\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Table()
|
* @ORM\Table()
|
||||||
* @ORM\Entity(repositoryClass="Websmid\WsOrderReference\Repository\OrderReferenceRepository")
|
* @ORM\Entity(repositoryClass="Websmid\OrderReference\Repository\OrderReferenceRepository")
|
||||||
*/
|
*/
|
||||||
class OrderReference
|
class OrderReference
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Websmid\WsOrderReference\Module;
|
namespace Websmid\OrderReference\Module;
|
||||||
|
|
||||||
use Websmid\WsOrderReference\Database\ReferenceInstaller;
|
use Db;
|
||||||
|
use Websmid\OrderReference\Config\Config;
|
||||||
|
|
||||||
trait Install
|
trait Install
|
||||||
{
|
{
|
||||||
@@ -29,16 +30,20 @@ trait Install
|
|||||||
`order_reference` varchar(255) NOT NULL,
|
`order_reference` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `id_cart` (`id_cart`)
|
UNIQUE KEY `id_cart` (`id_cart`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
|
);';
|
||||||
|
|
||||||
return \Db::getInstance()->execute($sql);
|
return Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerHooks(){
|
public function registerHooks(): bool
|
||||||
return $this->registerHook('displayShoppingCart')
|
{
|
||||||
&& $this->registerHook('displayPDFDeliverySlip')
|
foreach (Config::HOOKS as $hook) {
|
||||||
&& $this->registerHook('addWebserviceResources')
|
if (!$this->registerHook($hook)) {
|
||||||
&& $this->registerHook('actionFrontControllerSetMedia');
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Websmid\WsOrderReference\Module;
|
namespace Websmid\OrderReference\Module;
|
||||||
|
|
||||||
|
use Media;
|
||||||
|
|
||||||
trait ActionHooks
|
trait ActionHooks
|
||||||
{
|
{
|
||||||
public function hookActionFrontControllerSetMedia($params)
|
public function hookActionFrontControllerSetMedia($params)
|
||||||
{
|
{
|
||||||
\Media::addJsDef([
|
Media::addJsDef([
|
||||||
'ajax_url' => $this->context->link->getModuleLink($this->name, 'ajax'),
|
'ajax_url' => $this->context->link->getModuleLink($this->name, 'ajax'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Websmid\WsOrderReference\Module;
|
namespace Websmid\OrderReference\Module;
|
||||||
|
|
||||||
trait DisplayHooks
|
trait DisplayHooks
|
||||||
{
|
{
|
||||||
@@ -13,7 +13,7 @@ trait DisplayHooks
|
|||||||
{
|
{
|
||||||
$orderId = $params['object']->id_order;
|
$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);
|
$orderReference = $orderReferenceRepo->customRefByOrderId($orderId);
|
||||||
|
|
||||||
$this->context->smarty->assign('orderReference', $orderReference);
|
$this->context->smarty->assign('orderReference', $orderReference);
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Websmid\WsOrderReference\Repository;
|
namespace Websmid\OrderReference\Repository;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Websmid\WsOrderReference\Entity\OrderReference;
|
use Websmid\OrderReference\Entity\OrderReference;
|
||||||
|
|
||||||
class OrderReferenceRepository extends EntityRepository
|
class OrderReferenceRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
use Websmid\WsOrderReference\Module\Install;
|
use Websmid\OrderReference\Module\Install;
|
||||||
use Websmid\WsOrderReference\Module\DisplayHooks;
|
use Websmid\OrderReference\Module\DisplayHooks;
|
||||||
use Websmid\WsOrderReference\Module\ActionHooks;
|
use Websmid\OrderReference\Module\ActionHooks;
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
require_once __DIR__ . '/vendor/autoload.php';
|
||||||
@@ -27,12 +27,8 @@ class Ws_OrderReference extends Module
|
|||||||
$this->name = 'ws_orderreference';
|
$this->name = 'ws_orderreference';
|
||||||
$this->tab = 'other';
|
$this->tab = 'other';
|
||||||
$this->version = '1.0.0';
|
$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->need_instance = 0;
|
||||||
$this->ps_versions_compliancy = [
|
|
||||||
'min' => '9.0.0',
|
|
||||||
'max' => '9.99.99',
|
|
||||||
];
|
|
||||||
$this->bootstrap = true;
|
$this->bootstrap = true;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -40,5 +36,4 @@ class Ws_OrderReference extends Module
|
|||||||
$this->displayName = $this->l('Order Reference');
|
$this->displayName = $this->l('Order Reference');
|
||||||
$this->description = $this->l('Adds an optional order reference field to the shopping cart summary.');
|
$this->description = $this->l('Adds an optional order reference field to the shopping cart summary.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user