refactor(shop-statuses): migrate to DI, restructure docs into docs/ folder (0.268)
- Migrate ShopStatuses module to Domain + DI architecture - Add ShopStatusRepository, ShopStatusesController with color picker - Convert front\factory\ShopStatuses to facade - Add FormFieldType::COLOR with HTML5 color picker - Move documentation files to docs/ folder (PROJECT_STRUCTURE, REFACTORING_PLAN, CHANGELOG, FORM_EDIT_SYSTEM, TESTING, DATABASE_STRUCTURE) - Tests: 254 tests, 736 assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
181
autoload/Domain/ShopStatus/ShopStatusRepository.php
Normal file
181
autoload/Domain/ShopStatus/ShopStatusRepository.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
namespace Domain\ShopStatus;
|
||||
|
||||
class ShopStatusRepository
|
||||
{
|
||||
private const MAX_PER_PAGE = 100;
|
||||
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function listForAdmin(
|
||||
array $filters,
|
||||
string $sortColumn = 'o',
|
||||
string $sortDir = 'ASC',
|
||||
int $page = 1,
|
||||
int $perPage = 15
|
||||
): array {
|
||||
$allowedSortColumns = [
|
||||
'id' => 'ss.id',
|
||||
'status' => 'ss.status',
|
||||
'color' => 'ss.color',
|
||||
'o' => 'ss.o',
|
||||
'apilo_status_id' => 'ss.apilo_status_id',
|
||||
];
|
||||
|
||||
$sortSql = $allowedSortColumns[$sortColumn] ?? 'ss.o';
|
||||
$sortDir = strtoupper(trim($sortDir)) === 'DESC' ? 'DESC' : 'ASC';
|
||||
$page = max(1, $page);
|
||||
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$where = ['1 = 1'];
|
||||
$params = [];
|
||||
|
||||
$status = trim((string)($filters['status'] ?? ''));
|
||||
if ($status !== '') {
|
||||
if (strlen($status) > 255) {
|
||||
$status = substr($status, 0, 255);
|
||||
}
|
||||
$where[] = 'ss.status LIKE :status';
|
||||
$params[':status'] = '%' . $status . '%';
|
||||
}
|
||||
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$sqlCount = "
|
||||
SELECT COUNT(0)
|
||||
FROM pp_shop_statuses AS ss
|
||||
WHERE {$whereSql}
|
||||
";
|
||||
|
||||
$stmtCount = $this->db->query($sqlCount, $params);
|
||||
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
|
||||
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
ss.id,
|
||||
ss.status,
|
||||
ss.color,
|
||||
ss.o,
|
||||
ss.apilo_status_id
|
||||
FROM pp_shop_statuses AS ss
|
||||
WHERE {$whereSql}
|
||||
ORDER BY {$sortSql} {$sortDir}, ss.id ASC
|
||||
LIMIT {$perPage} OFFSET {$offset}
|
||||
";
|
||||
|
||||
$stmt = $this->db->query($sql, $params);
|
||||
$items = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
if (!is_array($items)) {
|
||||
$items = [];
|
||||
}
|
||||
|
||||
foreach ($items as &$item) {
|
||||
$item['id'] = (int)($item['id'] ?? 0);
|
||||
$item['apilo_status_id'] = $item['apilo_status_id'] !== null
|
||||
? (int)$item['apilo_status_id']
|
||||
: null;
|
||||
$item['o'] = (int)($item['o'] ?? 0);
|
||||
}
|
||||
unset($item);
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
public function find(int $statusId): ?array
|
||||
{
|
||||
if ($statusId < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$status = $this->db->get('pp_shop_statuses', '*', ['id' => $statusId]);
|
||||
if (!is_array($status)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$status['id'] = (int)($status['id'] ?? 0);
|
||||
$status['apilo_status_id'] = $status['apilo_status_id'] !== null
|
||||
? (int)$status['apilo_status_id']
|
||||
: null;
|
||||
$status['o'] = (int)($status['o'] ?? 0);
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function save(int $statusId, array $data): int
|
||||
{
|
||||
if ($statusId < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$row = [
|
||||
'color' => trim((string)($data['color'] ?? '')),
|
||||
'apilo_status_id' => isset($data['apilo_status_id']) && $data['apilo_status_id'] !== ''
|
||||
? (int)$data['apilo_status_id']
|
||||
: null,
|
||||
];
|
||||
|
||||
$this->db->update('pp_shop_statuses', $row, ['id' => $statusId]);
|
||||
|
||||
return $statusId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera Apilo status ID dla danego statusu sklepowego.
|
||||
* Odpowiednik front\factory\ShopStatuses::get_apilo_status_id()
|
||||
*/
|
||||
public function getApiloStatusId(int $statusId): ?int
|
||||
{
|
||||
$value = $this->db->get('pp_shop_statuses', 'apilo_status_id', ['id' => $statusId]);
|
||||
return $value !== null && $value !== false ? (int)$value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera shop status ID na podstawie ID statusu integracji.
|
||||
* Odpowiednik front\factory\ShopStatuses::get_shop_status_by_integration_status_id()
|
||||
*/
|
||||
public function getByIntegrationStatusId(string $integration, int $integrationStatusId): ?int
|
||||
{
|
||||
if ($integration === 'apilo') {
|
||||
$value = $this->db->get('pp_shop_statuses', 'id', [
|
||||
'apilo_status_id' => $integrationStatusId,
|
||||
]);
|
||||
return $value !== null && $value !== false ? (int)$value : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liste wszystkich statusow (id => nazwa) posortowanych wg kolejnosci.
|
||||
* Odpowiednik shop\Order::order_statuses()
|
||||
*/
|
||||
public function allStatuses(): array
|
||||
{
|
||||
$results = $this->db->select('pp_shop_statuses', ['id', 'status'], [
|
||||
'ORDER' => ['o' => 'ASC'],
|
||||
]);
|
||||
|
||||
$statuses = [];
|
||||
if (is_array($results)) {
|
||||
foreach ($results as $row) {
|
||||
$statuses[(int)$row['id']] = $row['status'];
|
||||
}
|
||||
}
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
}
|
||||
260
autoload/admin/Controllers/ShopStatusesController.php
Normal file
260
autoload/admin/Controllers/ShopStatusesController.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\ShopStatus\ShopStatusRepository;
|
||||
use admin\ViewModels\Common\PaginatedTableViewModel;
|
||||
use admin\ViewModels\Forms\FormAction;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
use admin\ViewModels\Forms\FormTab;
|
||||
|
||||
class ShopStatusesController
|
||||
{
|
||||
private ShopStatusRepository $repository;
|
||||
|
||||
public function __construct(ShopStatusRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function list(): string
|
||||
{
|
||||
$sortableColumns = ['id', 'status', 'color', 'o', 'apilo_status_id'];
|
||||
$filterDefinitions = [
|
||||
[
|
||||
'key' => 'status',
|
||||
'label' => 'Status',
|
||||
'type' => 'text',
|
||||
],
|
||||
];
|
||||
|
||||
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
|
||||
$filterDefinitions,
|
||||
$sortableColumns,
|
||||
'o'
|
||||
);
|
||||
|
||||
$sortDir = $listRequest['sortDir'];
|
||||
if (trim((string)\S::get('sort')) === '') {
|
||||
$sortDir = 'ASC';
|
||||
}
|
||||
|
||||
$result = $this->repository->listForAdmin(
|
||||
$listRequest['filters'],
|
||||
$listRequest['sortColumn'],
|
||||
$sortDir,
|
||||
$listRequest['page'],
|
||||
$listRequest['perPage']
|
||||
);
|
||||
|
||||
$apiloStatusList = $this->getApiloStatusList();
|
||||
|
||||
$rows = [];
|
||||
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
|
||||
foreach ($result['items'] as $item) {
|
||||
$id = (int)($item['id'] ?? 0);
|
||||
$statusName = trim((string)($item['status'] ?? ''));
|
||||
$color = trim((string)($item['color'] ?? ''));
|
||||
$apiloStatusId = $item['apilo_status_id'] ?? null;
|
||||
|
||||
$apiloStatusLabel = '';
|
||||
if ($apiloStatusId !== null && isset($apiloStatusList[$apiloStatusId])) {
|
||||
$apiloStatusLabel = $apiloStatusList[$apiloStatusId];
|
||||
}
|
||||
|
||||
$colorHtml = $color !== ''
|
||||
? '<span style="display:inline-block;width:20px;height:20px;background:' . htmlspecialchars($color, ENT_QUOTES, 'UTF-8') . ';border:1px solid #ccc;vertical-align:middle;margin-right:5px;"></span> ' . htmlspecialchars($color, ENT_QUOTES, 'UTF-8')
|
||||
: '-';
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'status' => '<a href="/admin/shop_statuses/edit/id=' . $id . '">' . htmlspecialchars($statusName, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||
'color' => $colorHtml,
|
||||
'apilo_status' => htmlspecialchars($apiloStatusLabel, ENT_QUOTES, 'UTF-8'),
|
||||
'_actions' => [
|
||||
[
|
||||
'label' => 'Edytuj',
|
||||
'url' => '/admin/shop_statuses/edit/id=' . $id,
|
||||
'class' => 'btn btn-xs btn-primary',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$total = (int)$result['total'];
|
||||
$totalPages = max(1, (int)ceil($total / $listRequest['perPage']));
|
||||
|
||||
$viewModel = new PaginatedTableViewModel(
|
||||
[
|
||||
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
|
||||
['key' => 'status', 'sort_key' => 'status', 'label' => 'Status', 'sortable' => true, 'raw' => true],
|
||||
['key' => 'color', 'sort_key' => 'color', 'label' => 'Kolor', 'sortable' => true, 'raw' => true],
|
||||
['key' => 'apilo_status', 'sort_key' => 'apilo_status_id', 'label' => 'Status Apilo', 'sortable' => true],
|
||||
],
|
||||
$rows,
|
||||
$listRequest['viewFilters'],
|
||||
[
|
||||
'column' => $listRequest['sortColumn'],
|
||||
'dir' => $sortDir,
|
||||
],
|
||||
[
|
||||
'page' => $listRequest['page'],
|
||||
'per_page' => $listRequest['perPage'],
|
||||
'total' => $total,
|
||||
'total_pages' => $totalPages,
|
||||
],
|
||||
array_merge($listRequest['queryFilters'], [
|
||||
'sort' => $listRequest['sortColumn'],
|
||||
'dir' => $sortDir,
|
||||
'per_page' => $listRequest['perPage'],
|
||||
]),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/shop_statuses/list/',
|
||||
'Brak danych w tabeli.'
|
||||
);
|
||||
|
||||
return \Tpl::view('shop-statuses/view-list', [
|
||||
'viewModel' => $viewModel,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(): string
|
||||
{
|
||||
$status = $this->repository->find((int)\S::get('id'));
|
||||
if ($status === null) {
|
||||
\S::alert('Status nie zostal znaleziony.');
|
||||
header('Location: /admin/shop_statuses/list/');
|
||||
exit;
|
||||
}
|
||||
|
||||
$apiloStatusList = $this->getApiloStatusList();
|
||||
|
||||
return \Tpl::view('shop-statuses/status-edit', [
|
||||
'form' => $this->buildFormViewModel($status, $apiloStatusList),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$legacyValues = \S::get('values');
|
||||
|
||||
if ($legacyValues) {
|
||||
$values = json_decode((string)$legacyValues, true);
|
||||
$response = [
|
||||
'status' => 'error',
|
||||
'msg' => 'Podczas zapisywania statusu wystapil blad. Prosze sprobowac ponownie.',
|
||||
];
|
||||
|
||||
if (is_array($values)) {
|
||||
$statusId = (int)($values['id'] ?? 0);
|
||||
$id = $this->repository->save($statusId, $values);
|
||||
if ($id !== null && $id >= 0) {
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
'msg' => 'Status zostal zapisany.',
|
||||
'id' => (int)$id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $_POST;
|
||||
$statusId = isset($payload['id']) && $payload['id'] !== '' ? (int)$payload['id'] : null;
|
||||
if ($statusId === null) {
|
||||
$statusId = (int)\S::get('id');
|
||||
}
|
||||
|
||||
$id = $this->repository->save($statusId, $payload);
|
||||
if ($id !== null && $id >= 0) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => (int)$id,
|
||||
'message' => 'Status zostal zapisany.',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'errors' => ['general' => 'Podczas zapisywania statusu wystapil blad.'],
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function buildFormViewModel(array $status, array $apiloStatusList): FormEditViewModel
|
||||
{
|
||||
$id = (int)($status['id'] ?? 0);
|
||||
|
||||
$apiloOptions = ['' => '--- wybierz status apilo.com ---'];
|
||||
foreach ($apiloStatusList as $apiloId => $apiloName) {
|
||||
$apiloOptions[$apiloId] = $apiloName;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'status' => (string)($status['status'] ?? ''),
|
||||
'color' => (string)($status['color'] ?? ''),
|
||||
'apilo_status_id' => $status['apilo_status_id'] ?? '',
|
||||
];
|
||||
|
||||
$fields = [
|
||||
FormField::hidden('id', $id),
|
||||
FormField::text('status', [
|
||||
'label' => 'Status',
|
||||
'tab' => 'settings',
|
||||
'readonly' => true,
|
||||
]),
|
||||
FormField::color('color', [
|
||||
'label' => 'Kolor',
|
||||
'tab' => 'settings',
|
||||
]),
|
||||
FormField::select('apilo_status_id', [
|
||||
'label' => 'Status z Apilo',
|
||||
'tab' => 'settings',
|
||||
'options' => $apiloOptions,
|
||||
]),
|
||||
];
|
||||
|
||||
$tabs = [
|
||||
new FormTab('settings', 'Ustawienia', 'fa-wrench'),
|
||||
];
|
||||
|
||||
$actionUrl = '/admin/shop_statuses/save/id=' . $id;
|
||||
$actions = [
|
||||
FormAction::save($actionUrl, '/admin/shop_statuses/list/'),
|
||||
FormAction::cancel('/admin/shop_statuses/list/'),
|
||||
];
|
||||
|
||||
return new FormEditViewModel(
|
||||
'status-edit',
|
||||
'Edycja statusu zamowienia',
|
||||
$data,
|
||||
$fields,
|
||||
$tabs,
|
||||
$actions,
|
||||
'POST',
|
||||
$actionUrl,
|
||||
'/admin/shop_statuses/list/',
|
||||
true,
|
||||
['id' => $id]
|
||||
);
|
||||
}
|
||||
|
||||
private function getApiloStatusList(): array
|
||||
{
|
||||
$list = [];
|
||||
$raw = @unserialize(\admin\factory\Integrations::apilo_settings('status-types-list'));
|
||||
if (is_array($raw)) {
|
||||
foreach ($raw as $apiloStatus) {
|
||||
if (isset($apiloStatus['id'], $apiloStatus['name'])) {
|
||||
$list[(int)$apiloStatus['id']] = (string)$apiloStatus['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -308,6 +308,36 @@ class FormFieldRenderer
|
||||
'value="' . htmlspecialchars($value ?? '') . '">';
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje pole koloru (color picker + text input)
|
||||
*/
|
||||
public function renderColor(FormField $field): string
|
||||
{
|
||||
$value = $this->form->getFieldValue($field);
|
||||
$error = $this->form->getError($field->name);
|
||||
$colorValue = htmlspecialchars($value ?? '#000000', ENT_QUOTES, 'UTF-8');
|
||||
$fieldName = htmlspecialchars($field->name, ENT_QUOTES, 'UTF-8');
|
||||
$fieldId = htmlspecialchars($field->id, ENT_QUOTES, 'UTF-8');
|
||||
$label = htmlspecialchars($field->label, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$html = '<div class="form-group row">';
|
||||
$html .= '<label class="col-lg-4 control-label">' . $label . ':</label>';
|
||||
$html .= '<div class="col-lg-8">';
|
||||
$html .= '<div style="display:flex;align-items:center;gap:8px;">';
|
||||
$html .= '<input type="color" id="' . $fieldId . '_picker" value="' . $colorValue . '" style="width:40px;height:34px;padding:2px;border:1px solid #ccc;cursor:pointer;" />';
|
||||
$html .= '<input type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . $colorValue . '" class="form-control" style="max-width:150px;" />';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<script>$(function(){'
|
||||
. 'var $p=$("#' . $fieldId . '_picker"),$t=$("#' . $fieldId . '");'
|
||||
. '$p.on("input",function(){$t.val(this.value);});'
|
||||
. '$t.on("input",function(){var v=this.value;if(/^#[0-9a-fA-F]{6}$/.test(v))$p.val(v);});'
|
||||
. '});</script>';
|
||||
|
||||
return $this->wrapWithError($html, $error);
|
||||
}
|
||||
|
||||
public function renderCustom(FormField $field): string
|
||||
{
|
||||
return (string)($field->customHtml ?? '');
|
||||
|
||||
@@ -268,6 +268,21 @@ class FormField
|
||||
);
|
||||
}
|
||||
|
||||
public static function color(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::COLOR,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
$config['help'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public static function hidden(string $name, $value = null): self
|
||||
{
|
||||
return new self(
|
||||
|
||||
@@ -21,4 +21,5 @@ class FormFieldType
|
||||
public const HIDDEN = 'hidden';
|
||||
public const LANG_SECTION = 'lang_section';
|
||||
public const CUSTOM = 'custom';
|
||||
public const COLOR = 'color';
|
||||
}
|
||||
|
||||
@@ -332,6 +332,13 @@ class Site
|
||||
new \Domain\Integrations\IntegrationsRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ShopStatuses' => function() {
|
||||
global $mdb;
|
||||
|
||||
return new \admin\Controllers\ShopStatusesController(
|
||||
new \Domain\ShopStatus\ShopStatusRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
|
||||
return self::$newControllers;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class ShopStatuses {
|
||||
|
||||
// status_save
|
||||
public static function status_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// status_edit
|
||||
public static function status_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-statuses/status-edit', [
|
||||
'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
static public function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-statuses/view-list', [
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace admin\factory;
|
||||
/**
|
||||
* Fasada kompatybilnosci wstecznej.
|
||||
* Deleguje do Domain\Integrations\IntegrationsRepository.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\controls\ShopStatuses, admin\controls\ShopTransport, admin\controls\ShopPaymentMethod, admin\controls\ShopProduct.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\Controllers\ShopStatusesController, admin\controls\ShopTransport, admin\controls\ShopPaymentMethod, admin\controls\ShopProduct.
|
||||
*/
|
||||
class Integrations {
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopStatuses {
|
||||
// get_status
|
||||
public static function get_status( $id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', '*', [ 'id' => $id ] );
|
||||
}
|
||||
|
||||
// status_save
|
||||
public static function status_save( $status_id, $color, $apilo_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_statuses', [
|
||||
'color' => $color,
|
||||
'apilo_status_id' => $apilo_status_id ? $apilo_status_id : null,
|
||||
], [ 'id' => $status_id ] );
|
||||
|
||||
return $status_id;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class ShopStatuses {
|
||||
@@ -6,15 +6,15 @@ class ShopStatuses {
|
||||
// get_apilo_status_id
|
||||
static public function get_apilo_status_id( $status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'apilo_status_id', [ 'id' => $status_id ] );
|
||||
$repo = new \Domain\ShopStatus\ShopStatusRepository( $mdb );
|
||||
return $repo->getApiloStatusId( (int)$status_id );
|
||||
}
|
||||
|
||||
// get_shop_status_by_integration_status_id
|
||||
static public function get_shop_status_by_integration_status_id( $integration, $integration_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $integration == 'apilo' )
|
||||
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'apilo_status_id' => $integration_status_id ] );
|
||||
$repo = new \Domain\ShopStatus\ShopStatusRepository( $mdb );
|
||||
return $repo->getByIntegrationStatusId( (string)$integration, (int)$integration_status_id );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user