130 lines
4.6 KiB
PHP
130 lines
4.6 KiB
PHP
<?php
|
|
|
|
use KupShop\AdminBundle\FulltextUpdatesTrait;
|
|
|
|
class ProductsParameters extends Frame
|
|
{
|
|
use DatabaseCommunication;
|
|
use FulltextUpdatesTrait;
|
|
|
|
protected $template = 'window/products.parameters.tpl';
|
|
|
|
public function get_vars()
|
|
{
|
|
$vars = parent::get_vars();
|
|
|
|
$pageVars = getVal('body', $vars, []);
|
|
|
|
$ID = getVal('ID');
|
|
|
|
/* params */
|
|
|
|
// Load all parameters
|
|
$parameters = Parameter::get();
|
|
|
|
// Load configurations
|
|
if (findModule(\Modules::PRODUCTS_PARAMETERS, \Modules::SUB_CONFIGURATIONS)) {
|
|
$param_configurations = ParameterConfiguration::createFromSpec(Query\Operator::equals(['id_product' => $ID]));
|
|
|
|
foreach ($param_configurations as $param_configuration) {
|
|
$parameters[$param_configuration->id]->parameter_configuration = true;
|
|
}
|
|
}
|
|
|
|
// Load parameter values from current product
|
|
if (!empty($ID)) {
|
|
Parameter::getValues($parameters, $ID);
|
|
|
|
$query = 'SELECT ps.id_parameter
|
|
FROM parameters_sections AS ps
|
|
LEFT JOIN products_in_sections AS pis ON ps.id_section=pis.id_section
|
|
WHERE pis.id_product=:id_product AND ps.required = :figureY';
|
|
|
|
if (findModule('producers')) {
|
|
$query .= ' UNION
|
|
SELECT pp.id_parameter
|
|
FROM products AS p
|
|
LEFT JOIN parameters_producers AS pp ON pp.id_producer=p.producer
|
|
WHERE p.id=:id_product';
|
|
}
|
|
|
|
foreach (sqlQuery($query, ['id_product' => $ID, 'figureY' => 'Y']) as $row) {
|
|
if (!empty($row['id_parameter'])) {
|
|
$parameters[$row['id_parameter']]['active'] = true;
|
|
}
|
|
}
|
|
}
|
|
$pageVars['parameters'] = $parameters;
|
|
if (findModule(Modules::PARAMETER_GROUPS)) {
|
|
$pageVars['data']['id_parameter_group'] = $this->selectSQL('products', ['id' => $ID], ['id_parameter_group'])->fetchColumn();
|
|
}
|
|
|
|
/* params */
|
|
$vars['body'] = $pageVars;
|
|
$vars['body']['ID'] = $ID;
|
|
|
|
return $vars;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
parent::handle();
|
|
|
|
$data = getVal('data');
|
|
$ID = getVal('ID');
|
|
|
|
// save parameter group
|
|
if (isset($data['id_parameter_group']) && findModule(Modules::PARAMETER_GROUPS)) {
|
|
$this->updateSQL('products', ['id_parameter_group' => $data['id_parameter_group'] ?: null], ['id' => $ID]);
|
|
}
|
|
|
|
if (!empty($data['param'])) {
|
|
foreach ($data['param'] as $id_parameter => $values) {
|
|
$parameter = new Parameter();
|
|
$parameter->createFromDB($id_parameter);
|
|
|
|
if (findModule('products_parameters', 'configurations')) {
|
|
if ($values['parameters_configurations'] == 'N' || empty($values)) {
|
|
(new ParameterConfiguration())->deleteValue($id_parameter, $ID);
|
|
} else {
|
|
ParameterConfiguration::insertValue($id_parameter, $ID);
|
|
}
|
|
|
|
unset($values['parameters_configurations']);
|
|
}
|
|
|
|
foreach ($values as $id => $param) {
|
|
if (!empty($param['delete'])) {
|
|
$this->deleteSQL('parameters_products', ['id' => $id]);
|
|
continue;
|
|
}
|
|
unset($param['delete']);
|
|
|
|
// jestli neni prazdny klic, hodnota a jestli ma parametr nastaveno - pouzit: Y
|
|
if (!empty($id_parameter) && isset($param['value']) && $param['value'] != '' && $id != 0) {
|
|
if (isset($param['configuration_price']) && $param['configuration_price'] == '') {
|
|
$param['configuration_price'] = null;
|
|
}
|
|
|
|
$param['id_product'] = $ID;
|
|
$param['id_parameter'] = $id_parameter;
|
|
|
|
if ($parameter->value_type == 'float') {
|
|
$param['value'] = $this->preparePrice($param['value']);
|
|
}
|
|
|
|
$parameter->setValue($param, ($id > 0 && !$this->isDuplicate()) ? $id : null);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (findModule(\Modules::PRODUCTS_SECTIONS, \Modules::SUB_ELASTICSEARCH) && !findModule(Modules::KAFKA)) {
|
|
$this->updateProductsFulltext([$ID]);
|
|
}
|
|
// save
|
|
}
|
|
}
|
|
}
|
|
|
|
$main_class = 'ProductsParameters';
|