Files
2026-06-22 14:32:50 +02:00

54 lines
1.4 KiB
PHP

<?php
use Websmid\GiftDropdown\Config\Config;
use Configuration;
use Db;
use Tools;
if (!defined('_PS_VERSION_')) {
exit;
}
class Ws_GiftDropdownSavepaperModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
if (!$this->ajax) {
http_response_code(400);
exit;
}
$choice = Tools::getValue('gift_paper', '');
$saved = Configuration::get(Config::CONFIG_KEY);
$options = $saved ? json_decode($saved, true) : Config::DEFAULT_OPTIONS;
if (!in_array($choice, $options, true)) {
$this->ajaxRender(json_encode(['success' => false, 'error' => 'Invalid option']));
exit;
}
$idCart = (int) $this->context->cart->id;
if (!$idCart) {
$this->ajaxRender(json_encode(['success' => false, 'error' => 'No cart']));
exit;
}
Db::getInstance()->execute(
'INSERT INTO `' . _DB_PREFIX_ . 'ws_gift_dropdown`
(`id_cart`, `id_order`, `paper_choice`, `date_add`)
VALUES
(' . (int) $idCart . ', 0, \'' . pSQL($choice) . '\', NOW())
ON DUPLICATE KEY UPDATE
`paper_choice` = \'' . pSQL($choice) . '\',
`date_add` = NOW()'
);
$this->ajaxRender(json_encode(['success' => true]));
exit;
}
}