product_form.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App;
  3. /**
  4. * @var string $title
  5. * @var Product $product
  6. */
  7. $core = Core::getInstance();
  8. $user = $core->getUser();
  9. $suppliers = Supplier::getAll();
  10. $request = Request::fromRequest();
  11. if($product->isNew()) {
  12. $supplier_id = $request->int("supplier_id");
  13. }
  14. else {
  15. $supplier_id = $product->supplier_id;
  16. }
  17. ?>
  18. <h3><?=htmlspecialchars($title)?></h3>
  19. <form method="post">
  20. <?php
  21. $user->insertCsrfToken();
  22. ?>
  23. <div class="mb-3">
  24. <label for="supplier-id"><?=htmlspecialchars(__("Supplier"))?></label>
  25. <select class="form-select" name="supplier_id" id="supplier-id" required>
  26. <option value=""><?=htmlspecialchars(__("Select Supplier"))?></option>
  27. <?php
  28. foreach($suppliers as $supplier) {
  29. ?>
  30. <option value="<?=$supplier->id?>" <?=Html::selected($supplier->id, $supplier_id)?>>
  31. <?=htmlspecialchars($supplier->name)?>
  32. </option>
  33. <?php
  34. }
  35. ?>
  36. </select>
  37. </div>
  38. <div class="mb-3">
  39. <label for="name"><?=htmlspecialchars(__("Name"))?></label>
  40. <input class="form-control" type="text" id="name" name="name" placeholder="<?=htmlspecialchars(__("Type name"))?>" value="<?=htmlspecialchars($product->name)?>" maxlength="255" required />
  41. </div>
  42. <div class="mb-3">
  43. <label for="sku"><?=htmlspecialchars(__("SKU"))?></label>
  44. <input class="form-control" type="text" id="sku" name="sku" placeholder="<?=htmlspecialchars(__("Type SKU"))?>" value="<?=htmlspecialchars($product->sku)?>" maxlength="255" required />
  45. </div>
  46. <div class="row">
  47. <div class="col-6">
  48. <div class="mb-3">
  49. <label for="type"><?=htmlspecialchars(__("Type"))?></label>
  50. <select class="form-select" name="type" id="type" required>
  51. <?php
  52. foreach(Product::getTypeOptions() as $value => $display) {
  53. ?>
  54. <option value="<?=$value?>" <?=Html::selected($value, $product->type)?>>
  55. <?=htmlspecialchars($display)?>
  56. </option>
  57. <?php
  58. }
  59. ?>
  60. </select>
  61. </div>
  62. </div>
  63. <div class="col-6">
  64. <div class="mb-3">
  65. <label for="price"><?=htmlspecialchars(__("Price"))?></label>
  66. <input class="form-control" type="number" id="price" name="price" placeholder="<?=htmlspecialchars(__("Type price"))?>" value="<?=htmlspecialchars($product->price)?>" min="0" max="999999.99" step="any" required />
  67. </div>
  68. </div>
  69. </div>
  70. <div class="mb-3">
  71. <button class="btn btn-primary" type="submit" name="submit" value="1">
  72. <?=htmlspecialchars(__("Submit"))?>
  73. </button>
  74. </div>
  75. </form>