Improve product price

This commit is contained in:
grandeljay 2022-06-13 11:00:56 +02:00
parent e1ec8bd69f
commit 7b6fef16c5
4 changed files with 28 additions and 23 deletions

View file

@ -108,16 +108,21 @@ switch ($_SERVER['REQUEST_METHOD']) {
/** /**
* Product * Product
*/ */
if (!empty($_POST['wish_price'])) { $wish_price = empty($_POST['wish_price']) || 'false' === $wish_is_purchasable
$wish_price = $_POST['wish_price']; ? 'NULL'
: $_POST['wish_price'];
$database $database
->query( ->query(
'UPDATE `products` 'REPLACE INTO `products`
SET `price` = ' . $wish_price . ' (
WHERE `wish` = ' . $wish_id . ';' `wish`,
); `price`
} ) VALUES (
' . $wish_id . ',
' . $wish_price . '
);'
);
} elseif (isset($_POST['wishlist_id'])) { } elseif (isset($_POST['wishlist_id'])) {
/** Insert wish */ /** Insert wish */
$wishlist_id = $_POST['wishlist_id']; $wishlist_id = $_POST['wishlist_id'];

View file

@ -335,14 +335,17 @@ $(function () {
formEdit.find('.item').tab('change tab', 'general'); formEdit.find('.item').tab('change tab', 'general');
/** Checkbox */ /** Checkbox */
formEdit.find('.checkbox').checkbox({ formEdit
.find('.checkbox')
.checkbox({
onChecked : function() { onChecked : function() {
formEdit.find('.item[data-tab="product"]').removeClass('disabled'); formEdit.find('.item[data-tab="product"]').removeClass('disabled');
}, },
onUnchecked : function() { onUnchecked : function() {
formEdit.find('.item[data-tab="product"]').addClass('disabled'); formEdit.find('.item[data-tab="product"]').addClass('disabled');
}, },
}); })
.checkbox('uncheck');
/** Get Wish */ /** Get Wish */
var wishID = $(this).attr('data-id'); var wishID = $(this).attr('data-id');
@ -478,7 +481,8 @@ $(function () {
onUnchecked : function() { onUnchecked : function() {
formAdd.find('.item[data-tab="product"]').addClass('disabled'); formAdd.find('.item[data-tab="product"]').addClass('disabled');
}, },
}); })
.checkbox('uncheck');
/** Modal */ /** Modal */
var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add'); var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add');

View file

@ -195,15 +195,13 @@ switch ($step) {
*/ */
$database->query( $database->query(
'CREATE TABLE `products` ( 'CREATE TABLE `products` (
`id` INT PRIMARY KEY AUTO_INCREMENT, `wish` INT NOT NULL PRIMARY KEY,
`wish` INT NOT NULL, `price` FLOAT NULL DEFAULT NULL,
`price` FLOAT NOT NULL DEFAULT 0,
FOREIGN KEY (`wish`) FOREIGN KEY (`wish`)
REFERENCES `wishes` (`id`) REFERENCES `wishes` (`id`)
ON DELETE CASCADE ON DELETE CASCADE
);' );'
); );
$database->query('CREATE INDEX `idx_wish` ON `products` (`wish`);');
/** /**
* Options * Options

View file

@ -2,11 +2,9 @@
* Products * Products
*/ */
CREATE TABLE `products` ( CREATE TABLE `products` (
`id` INT PRIMARY KEY AUTO_INCREMENT, `wish` INT NOT NULL PRIMARY KEY,
`wish` INT NOT NULL, `price` FLOAT NULL DEFAULT NULL,
`price` FLOAT NOT NULL DEFAULT 0, FOREIGN KEY (`wish`)
FOREIGN KEY (`wish`) REFERENCES `wishes` (`id`)
REFERENCES `wishes` (`id`) ON DELETE CASCADE
ON DELETE CASCADE
); );
CREATE INDEX `idx_wish` ON `products` (`wish`);