Files
kupshop/web/block.cartInfo.php
2025-08-02 16:30:27 +02:00

51 lines
1.8 KiB
PHP

<?php
// #####################################################
// # BLOK MENU - VYPISE AKTIVNI VLASTNI ODKAZY V MENU
use KupShop\KupShopBundle\Context\UserContext;
use KupShop\KupShopBundle\Util\Contexts;
function block_cartInfo()
{
$totalPieces = 0;
$totalProducts = 0;
$totalPriceWithVat = DecimalConstants::zero();
$totalPriceNoVat = DecimalConstants::zero();
$freeShipping = false;
if (Contexts::get(UserContext::class)->isActive()) {
$items = CartItem::createFromSpec(\Query\Operator::equals(['c.id_user' => Contexts::get(UserContext::class)->getActiveId()]));
} else {
$items = CartItem::createFromSpec(\Query\Operator::equals(['c.user_key' => Cart::getCartID()]));
}
foreach ($items as $item) {
/*if (findModule(Modules::PRICELISTS)) {
$item['price'] = $item['product']->price_array;
}*/
$price = $item['price'];
// celkova cena s dani
$totalPriceWithVat = $totalPriceWithVat->add($price['value_with_vat']);
// celkova cena bez dane
$totalPriceNoVat = $totalPriceNoVat->add($price['value_without_vat']);
// celkovy pocet druhu produktu
$totalProducts++;
// celkovy pocet objednavanych kusu
$totalPieces += $item->pieces;
// Doprava zdarma
$freeShipping |= $item['freeShipping'];
}
return [
'items' => $items,
'totalPrice' => printPrice($totalPriceWithVat, ['ceil' => false, 'decimal' => 'dynamic', 'dealerdiscount' => false]),
'totalPriceWithVat_array' => formatPrice($totalPriceWithVat, 0, false),
'totalPriceNoVat_array' => formatPrice($totalPriceNoVat, 0, false),
'totalPieces' => $totalPieces,
'totalProducts' => $totalProducts,
'freeShipping' => $freeShipping,
];
}