feat(webservice): Started on api endpoint
Using specific management and the WebserviceSpecificManagementInterface contract to tap into the webservice api.
This commit is contained in:
80
classes/WebserviceSpecificManagementOrderreference.php
Normal file
80
classes/WebserviceSpecificManagementOrderreference.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// You can do api/order_reference?id_order=12 or api/order_reference?id_cart=12
|
||||
|
||||
class WebserviceSpecificManagementOrderreference implements WebserviceSpecificManagementInterface
|
||||
{
|
||||
private $objectOutput;
|
||||
private $wsObject;
|
||||
private ?array $result = null;
|
||||
|
||||
public function setObjectOutput(WebserviceOutputBuilder $objectOutput)
|
||||
{
|
||||
$this->objectOutput = $objectOutput;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectOutput()
|
||||
{
|
||||
return $this->objectOutput;
|
||||
}
|
||||
|
||||
public function setWsObject(WebserviceRequest $wsObject)
|
||||
{
|
||||
$this->wsObject = $wsObject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWsObject()
|
||||
{
|
||||
return $this->wsObject;
|
||||
}
|
||||
|
||||
public function manage()
|
||||
{
|
||||
$fragments = $this->wsObject ? $this->wsObject->urlFragments : [];
|
||||
|
||||
if (isset($fragments['id_order'])) {
|
||||
$this->result = $this->fetchByOrderId((int) $fragments['id_order']);
|
||||
} elseif (isset($fragments['id_cart'])) {
|
||||
$this->result = $this->fetchByCartId((int) $fragments['id_cart']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function fetchByCartId(int $cartId): ?array
|
||||
{
|
||||
$row = Db::getInstance()->getRow(
|
||||
'SELECT id, id_cart, order_reference FROM ' . _DB_PREFIX_ . 'order_reference WHERE id_cart = ' . (int) $cartId
|
||||
);
|
||||
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
private function fetchByOrderId(int $orderId): ?array
|
||||
{
|
||||
$idCart = Db::getInstance()->getValue(
|
||||
'SELECT id_cart FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . (int) $orderId
|
||||
);
|
||||
|
||||
if ($idCart) {
|
||||
return $this->fetchByCartId((int) $idCart);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$xml = new SimpleXMLElement('<order_references/>');
|
||||
|
||||
if ($this->result !== null) {
|
||||
$node = $xml->addChild('order_reference');
|
||||
$node->addChild('id', (string) $this->result['id']);
|
||||
$node->addChild('id_cart', (string) $this->result['id_cart']);
|
||||
$node->addChild('reference', htmlspecialchars($this->result['order_reference']));
|
||||
}
|
||||
|
||||
return $xml->asXML();
|
||||
}
|
||||
}
|
||||
18
classes/config/services.yml
Normal file
18
classes/config/services.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
# Repository - this makes it available via dependency injection
|
||||
Module\WsOrderreference\Repository\OrderReferenceRepository:
|
||||
public: true
|
||||
factory: ["@doctrine.orm.default_entity_manager", getRepository]
|
||||
arguments:
|
||||
- Module\WsOrderreference\Entity\OrderReference
|
||||
|
||||
# Database installer
|
||||
Module\WsOrderreference\Database\ReferenceInstaller:
|
||||
public: true
|
||||
arguments:
|
||||
- "@doctrine.dbal.default_connection"
|
||||
- "%database_prefix%"
|
||||
Reference in New Issue
Block a user