Files
kupshop/admin/printCenter/printCenter.Product.php
2025-08-02 16:30:27 +02:00

79 lines
3.1 KiB
PHP

<?php
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
class PrintCenterProducts extends Base
{
use DatabaseCommunication;
private $pageVars;
public function __construct($pageVars)
{
$this->pageVars = $pageVars;
}
public function get_vars()
{
$vars = parent::get_vars();
$vars = array_merge($this->pageVars, $vars);
$printLabels = ServiceContainer::getService(\KupShop\AdminBundle\AdminRegister\ProductsPrintLabelsLocator::class);
$generic = [];
foreach ($printLabels->getPrintClasses() as $class) {
$generic[$class->getLabel()] = $class->getDimensions();
}
if (!($printClass = $printLabels->getPrintClass($vars['template_type']))) {
$printClasses = $printLabels->getPrintClasses();
$printClass = reset($printClasses);
$vars['template_type'] = $printClass->getLabel();
}
$this->setTemplate($printClass->getTemplate());
$vars['count_rows'] = $generic[$vars['template_type']][1];
$vars['count_columns'] = $generic[$vars['template_type']][0];
$IDs = [];
if ($IDo = getVal('IDo')) {
$IDs = sqlFetchAll(sqlQuery('SELECT id_product AS idp, id_variation AS idv, pieces AS pcs FROM order_items WHERE id_order=:id', ['id' => $IDo]));
} elseif (getVal('ID')) {
$qb = sqlQueryBuilder()->select('p.id AS idp ,pv.id AS idv')
->from('products', 'p')
->leftJoin('p', 'products_variations', 'pv', 'pv.id_product=p.id')
->where(\Query\Operator::equals(['p.id' => getVal('ID')]));
if (getVal('IDv')) {
$qb->andWhere(\Query\Operator::equals(['pv.id' => getVal('IDv')]));
}
$IDs = $qb->execute()->fetchAll();
} elseif ($json = getVal('json', null, getVal('JSON_IDs'))) {
// Když to přijde z GET parametrů, hodí se to zrovna do pole.
$vars['json'] = is_string($json) ? json_decode($json, true) : $json;
foreach ($vars['json'] as $item) {
if ($item['idp'] ?? false || $item['idv'] ?? false) {
$qb = sqlQueryBuilder()->select('p.id AS idp')
->from('products', 'p');
if ($item['idv'] ?? false) {
$qb->addSelect('pv.id AS idv')
->leftJoin('p', 'products_variations', 'pv', 'pv.id_product=p.id')
->where(\Query\Operator::equals(['pv.id' => $item['idv']]));
} else {
$qb->where(\Query\Operator::equals(['p.id' => $item['idp']]));
}
foreach ($qb->execute()->fetchAll() as $product) {
$IDs[] = ['idp' => $product['idp'], 'idv' => $product['idv'] ?? null, 'pcs' => getVal('pcs', $item, 1)];
}
}
}
}
if (isset($IDs)) {
$vars['products'] = $printClass->getData($IDs, $vars);
} else {
echo 'Nebyl vybrán žádný produkt!';
}
return $vars;
}
}