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:
@@ -435,6 +435,91 @@ class OrderRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- Order product CRUD (admin) ---
|
||||
|
||||
public function getOrderProduct(int $orderProductId): ?array
|
||||
{
|
||||
if ($orderProductId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $this->db->get('pp_shop_order_products', '*', ['id' => $orderProductId]);
|
||||
|
||||
return is_array($row) ? $row : null;
|
||||
}
|
||||
|
||||
public function addOrderProduct(int $orderId, array $data): ?int
|
||||
{
|
||||
if ($orderId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->db->insert('pp_shop_order_products', [
|
||||
'order_id' => $orderId,
|
||||
'product_id' => (int)($data['product_id'] ?? 0),
|
||||
'parent_product_id' => (int)($data['parent_product_id'] ?? 0),
|
||||
'name' => (string)($data['name'] ?? ''),
|
||||
'attributes' => (string)($data['attributes'] ?? ''),
|
||||
'vat' => (float)($data['vat'] ?? 0),
|
||||
'price_brutto' => (float)($data['price_brutto'] ?? 0),
|
||||
'price_brutto_promo' => (float)($data['price_brutto_promo'] ?? 0),
|
||||
'quantity' => max(1, (int)($data['quantity'] ?? 1)),
|
||||
'message' => (string)($data['message'] ?? ''),
|
||||
'custom_fields' => (string)($data['custom_fields'] ?? ''),
|
||||
]);
|
||||
|
||||
$id = $this->db->id();
|
||||
|
||||
return $id ? (int)$id : null;
|
||||
}
|
||||
|
||||
public function updateOrderProduct(int $orderProductId, array $data): bool
|
||||
{
|
||||
if ($orderProductId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = [];
|
||||
|
||||
if (array_key_exists('quantity', $data)) {
|
||||
$update['quantity'] = max(1, (int)$data['quantity']);
|
||||
}
|
||||
if (array_key_exists('price_brutto', $data)) {
|
||||
$update['price_brutto'] = (float)$data['price_brutto'];
|
||||
}
|
||||
if (array_key_exists('price_brutto_promo', $data)) {
|
||||
$update['price_brutto_promo'] = (float)$data['price_brutto_promo'];
|
||||
}
|
||||
|
||||
if (empty($update)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_order_products', $update, ['id' => $orderProductId]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteOrderProduct(int $orderProductId): bool
|
||||
{
|
||||
if ($orderProductId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->delete('pp_shop_order_products', ['id' => $orderProductId]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateTransportCost(int $orderId, float $cost): void
|
||||
{
|
||||
if ($orderId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_orders', ['transport_cost' => $cost], ['id' => $orderId]);
|
||||
}
|
||||
|
||||
// --- Frontend methods ---
|
||||
|
||||
public function findIdByHash(string $hash)
|
||||
@@ -652,6 +737,11 @@ class OrderRepository
|
||||
|
||||
$product_price_tmp = \Domain\Basket\BasketCalculator::calculateBasketProductPrice((float)$product['price_brutto_promo'], (float)$product['price_brutto'], $coupon, $basket_position, $productRepo);
|
||||
|
||||
// Cena promo = 0 gdy taka sama jak cena bazowa (brak realnej promocji/kuponu)
|
||||
$effectivePromoPrice = (float)$product_price_tmp['price_new'];
|
||||
$effectiveBasePrice = (float)$product_price_tmp['price'];
|
||||
$promoPrice = ($effectivePromoPrice != $effectiveBasePrice) ? $effectivePromoPrice : 0;
|
||||
|
||||
$this->db->insert('pp_shop_order_products', [
|
||||
'order_id' => $order_id,
|
||||
'product_id' => $basket_position['product-id'],
|
||||
@@ -659,8 +749,8 @@ class OrderRepository
|
||||
'name' => $product['language']['name'],
|
||||
'attributes' => $attributes,
|
||||
'vat' => $product['vat'],
|
||||
'price_brutto' => $product_price_tmp['price'],
|
||||
'price_brutto_promo' => $product_price_tmp['price_new'],
|
||||
'price_brutto' => $effectiveBasePrice,
|
||||
'price_brutto_promo' => $promoPrice,
|
||||
'quantity' => $basket_position['quantity'],
|
||||
'message' => $basket_position['message'],
|
||||
'custom_fields' => $product_custom_fields,
|
||||
|
||||
Reference in New Issue
Block a user