Fix limited backoffice price save reset
This commit is contained in:
@@ -474,26 +474,26 @@ class limited_backoffice_service
|
||||
$mysqli->begin_transaction();
|
||||
|
||||
try {
|
||||
$priceUpdateAssignments = ['`price` = VALUES(`price`)'];
|
||||
if ($this->tableHasColumn('product_department_prices', 'updated_at')) {
|
||||
$priceUpdateAssignments[] = '`updated_at` = CURRENT_TIMESTAMP';
|
||||
}
|
||||
|
||||
$statement = $mysqli->prepare(
|
||||
'INSERT INTO `product_department_prices` (`department_id`, `product_id`, `price`)
|
||||
VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE ' . implode(', ', $priceUpdateAssignments)
|
||||
$deleteStatement = $mysqli->prepare(
|
||||
'DELETE FROM `product_department_prices` WHERE `department_id` = ? AND `product_id` = ?'
|
||||
);
|
||||
if ($statement === false) {
|
||||
$insertStatement = $mysqli->prepare(
|
||||
'INSERT INTO `product_department_prices` (`department_id`, `product_id`, `price`) VALUES (?, ?, ?)'
|
||||
);
|
||||
if ($deleteStatement === false || $insertStatement === false) {
|
||||
throw new \RuntimeException('Unable to prepare department price update.');
|
||||
}
|
||||
|
||||
foreach ($normalizedPrices as $productId => $price) {
|
||||
$statement->bind_param('iii', $departmentId, $productId, $price);
|
||||
$statement->execute();
|
||||
$deleteStatement->bind_param('ii', $departmentId, $productId);
|
||||
$deleteStatement->execute();
|
||||
|
||||
$insertStatement->bind_param('iii', $departmentId, $productId, $price);
|
||||
$insertStatement->execute();
|
||||
}
|
||||
|
||||
$statement->close();
|
||||
$deleteStatement->close();
|
||||
$insertStatement->close();
|
||||
$mysqli->commit();
|
||||
} catch (\Throwable $throwable) {
|
||||
$mysqli->rollback();
|
||||
@@ -868,8 +868,14 @@ class limited_backoffice_service
|
||||
INNER JOIN `categories` c ON c.`id` = dc.`category_id`
|
||||
INNER JOIN `products` p ON p.`category` = dc.`category_id`
|
||||
LEFT JOIN `product_department_prices` pdp
|
||||
ON pdp.`department_id` = dc.`department_id`
|
||||
AND pdp.`product_id` = p.`id`
|
||||
ON pdp.`id` = (
|
||||
SELECT pdp_latest.`id`
|
||||
FROM `product_department_prices` pdp_latest
|
||||
WHERE pdp_latest.`department_id` = dc.`department_id`
|
||||
AND pdp_latest.`product_id` = p.`id`
|
||||
ORDER BY pdp_latest.`id` DESC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE ' . implode(' AND ', $where) . '
|
||||
ORDER BY c.`name` ASC, c.`id` ASC, p.`order_priority` ASC, p.`name` ASC, p.`id` ASC'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user