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
*/
if (!empty($_POST['wish_price'])) {
$wish_price = $_POST['wish_price'];
$wish_price = empty($_POST['wish_price']) || 'false' === $wish_is_purchasable
? 'NULL'
: $_POST['wish_price'];
$database
->query(
'UPDATE `products`
SET `price` = ' . $wish_price . '
WHERE `wish` = ' . $wish_id . ';'
);
}
$database
->query(
'REPLACE INTO `products`
(
`wish`,
`price`
) VALUES (
' . $wish_id . ',
' . $wish_price . '
);'
);
} elseif (isset($_POST['wishlist_id'])) {
/** Insert wish */
$wishlist_id = $_POST['wishlist_id'];

View file

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

View file

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

View file

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