Files
kupshop/bundles/External/ZNZBundle/Context/UserContext.php
2025-08-02 16:30:27 +02:00

67 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace External\ZNZBundle\Context;
use External\ZNZBundle\Util\ZNZConfiguration;
use KupShop\KupShopBundle\Context\PriceLevelContext;
use KupShop\KupShopBundle\PriceType\PriceForDiscountPriceType;
use KupShop\KupShopBundle\PriceType\PriceIfOnlyDiscountPriceType;
use KupShop\KupShopBundle\PriceType\PriceTypeInterface;
use KupShop\KupShopBundle\PriceType\PriceWithoutDiscountPriceType;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\PricelistBundle\Context\PricelistContext;
use Symfony\Contracts\Service\Attribute\Required;
class UserContext extends \KupShop\KupShopBundle\Context\UserContext
{
private ZNZConfiguration $configuration;
#[Required]
final public function setZNZConfiguration(ZNZConfiguration $configuration): void
{
$this->configuration = $configuration;
}
public function isDealer()
{
if ($this->configuration->isB2BShop()) {
return $this->isType('b2b');
}
return false;
}
protected function loadOriginalPriceType(): PriceTypeInterface
{
if ($this->hasPriceLevelOrPriceList()) {
return new PriceWithoutDiscountPriceType();
}
// B2C
if (findModule(\Modules::PRICE_HISTORY)) {
return new PriceIfOnlyDiscountPriceType(new PriceForDiscountPriceType());
}
return parent::loadOriginalPriceType();
}
protected function hasPriceLevelOrPriceList(): bool
{
$priceLevelContext = Contexts::get(PriceLevelContext::class);
if ($priceLevelContext->getActiveId()) {
return true;
}
$priceListContext = Contexts::get(PricelistContext::class);
if ($priceList = $priceListContext->getActive()) {
if (str_contains($priceList->getName(), 'VIP')) {
return true;
}
}
return false;
}
}