ver. 0.295: Admin order product editing — add/remove/modify products, AJAX search, stock adjustment
- Order product CRUD in admin panel (add, delete, edit quantity/prices) - AJAX product search endpoint for order edit form - Automatic stock adjustment when editing order products - Transport cost recalculation based on free delivery threshold - Fix: promo price = 0 when equal to base price (no real promotion) - Clean up stale temp/ build artifacts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\Order\OrderAdminService;
|
||||
use Domain\Product\ProductRepository;
|
||||
use admin\ViewModels\Common\PaginatedTableViewModel;
|
||||
|
||||
class ShopOrderController
|
||||
{
|
||||
private OrderAdminService $service;
|
||||
private $productRepo;
|
||||
|
||||
public function __construct(OrderAdminService $service)
|
||||
public function __construct(OrderAdminService $service, ProductRepository $productRepo = null)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->productRepo = $productRepo;
|
||||
}
|
||||
|
||||
public function list(): string
|
||||
@@ -187,12 +190,27 @@ class ShopOrderController
|
||||
public function order_edit(): string
|
||||
{
|
||||
$orderId = (int)\Shared\Helpers\Helpers::get('order_id');
|
||||
$transports = ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->allActive();
|
||||
|
||||
// Dane transportów do JS (id, cost, delivery_free)
|
||||
$transportsJson = [];
|
||||
if (is_array($transports)) {
|
||||
foreach ($transports as $t) {
|
||||
$transportsJson[] = [
|
||||
'id' => (int)$t['id'],
|
||||
'cost' => (float)$t['cost'],
|
||||
'delivery_free' => (int)($t['delivery_free'] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view('shop-order/order-edit', [
|
||||
'order' => $this->service->details($orderId),
|
||||
'order_statuses' => $this->service->statuses(),
|
||||
'transport' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->allActive(),
|
||||
'transport' => $transports,
|
||||
'payment_methods' => ( new \Domain\PaymentMethod\PaymentMethodRepository( $GLOBALS['mdb'] ) )->allActive(),
|
||||
'free_delivery' => $this->service->getFreeDeliveryThreshold(),
|
||||
'transports_json' => json_encode($transportsJson),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -203,8 +221,16 @@ class ShopOrderController
|
||||
|
||||
public function order_save(): void
|
||||
{
|
||||
$orderId = (int)\Shared\Helpers\Helpers::get('order_id');
|
||||
|
||||
// Zapisz produkty PRZED zapisem zamówienia (bo saveOrderByAdmin przelicza summary)
|
||||
$productsData = \Shared\Helpers\Helpers::get('products');
|
||||
if (is_array($productsData)) {
|
||||
$this->service->saveOrderProducts($orderId, $productsData);
|
||||
}
|
||||
|
||||
$saved = $this->service->saveOrderByAdmin([
|
||||
'order_id' => (int)\Shared\Helpers\Helpers::get('order_id'),
|
||||
'order_id' => $orderId,
|
||||
'client_name' => (string)\Shared\Helpers\Helpers::get('client_name'),
|
||||
'client_surname' => (string)\Shared\Helpers\Helpers::get('client_surname'),
|
||||
'client_street' => (string)\Shared\Helpers\Helpers::get('client_street'),
|
||||
@@ -225,7 +251,22 @@ class ShopOrderController
|
||||
\Shared\Helpers\Helpers::alert('Zamówienie zostało zapisane.');
|
||||
}
|
||||
|
||||
header('Location: /admin/shop_order/order_details/order_id=' . (int)\Shared\Helpers\Helpers::get('order_id'));
|
||||
header('Location: /admin/shop_order/order_details/order_id=' . $orderId);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function search_products_ajax(): void
|
||||
{
|
||||
$query = trim((string)\Shared\Helpers\Helpers::get('query'));
|
||||
$langId = trim((string)\Shared\Helpers\Helpers::get('lang_id'));
|
||||
if ($langId === '') {
|
||||
$langId = isset($_SESSION['lang_id']) ? (string)$_SESSION['lang_id'] : 'pl';
|
||||
}
|
||||
|
||||
$results = $this->service->searchProducts($query, $langId);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode(['status' => 'ok', 'products' => $results]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user