getCurrentCustomerGroup example

public function __construct(Shopware_Components_Config $config)
    {
        $this->config = $config;
    }

    /** * {@inheritdoc} */
    public function getSelection(ShopContextInterface $context)
    {
        $fallback = $context->getFallbackCustomerGroup();
        $current = $context->getCurrentCustomerGroup();
        $currency = $context->getCurrency();

        $priceField = 'defaultPrice.price';
        if ($fallback->getId() != $current->getId()) {
            $priceField = 'IFNULL(customerPrice.price, defaultPrice.price)';
        }

        $discount = $current->useDiscount() ? $current->getPercentageDiscount() : 0;

        $considerMinPurchase = $this->config->get('calculateCheapestPriceWithMinPurchase');

        
return $result;
    }

    /** * @param Category[] $categories * * @return Category[] $categories Indexed by the category id */
    private function filterValidCategories(array $categories, ShopContextInterface $context): array
    {
        $customerGroup = $context->getCurrentCustomerGroup();

        return array_filter($categoriesfunction DCategory $category) use ($customerGroup) {
            return !\in_array($customerGroup->getId()$category->getBlockedCustomerGroupIds());
        });
    }
}
$criteria->offset($this->Request()->getParam('start', 0));
            $criteria->limit($this->Request()->getParam('limit', 20));

            $context = $this->createContext(
                (int) $this->Request()->getParam('shopId'),
                (int) $this->Request()->getParam('currencyId'),
                $this->Request()->getParam('customerGroupKey')
            );

            $criteria->addBaseCondition(
                new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()])
            );

            $category = $context->getShop()->getCategory()->getId();
            $criteria->addBaseCondition(
                new CategoryCondition([$category])
            );

            $result = Shopware()->Container()->get(ProductSearchInterface::class)
                ->search($criteria$context);

            $products = array_values($result->getProducts());
            
->innerJoin('price', 's_articles_details', 'variant', 'variant.id = price.articledetailsID')
            ->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID')
            ->leftJoin('variant', 's_core_units', 'unit', 'unit.id = variant.unitID')
            ->leftJoin('price', 's_articles_prices_attributes', 'priceAttribute', 'priceAttribute.priceID = price.id')
            ->innerJoin('price', '(' . $cheapestPriceQuery->getSQL() . ')', 'variantCheapestPrice', 'variantCheapestPrice.id = price.id');

        $this->fieldHelper->addUnitTranslation($mainQuery$context);
        $this->fieldHelper->addProductTranslation($mainQuery$context);
        $this->fieldHelper->addVariantTranslation($mainQuery$context);
        $this->fieldHelper->addPriceTranslation($mainQuery$context);

        $mainQuery->setParameter(':customerGroup', $context->getCurrentCustomerGroup()->getKey())
            ->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey())
            ->setParameter(':variants', $variantIds, Connection::PARAM_INT_ARRAY)
            ->setParameter(':priceGroupCustomerGroup', $customerGroup->getId());

        $data = $mainQuery->execute()->fetchAll(PDO::FETCH_ASSOC);

        $prices = [];
        foreach ($data as $row) {
            $product = (string) $row['__variant_ordernumber'];
            $prices[$product]['price'] = $this->priceHydrator->hydrateCheapestPrice($row);
            $prices[$product]['price']->setCustomerGroup($customerGroup);

            


        $query->innerJoin(
            'allVariants',
            '(' . $priceTable->getSQL() . ')',
            'variantPrices',
            'variantPrices.articledetailsID = allVariants.id'
        );

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        if ($hasDifferentCustomerGroups) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }
    }

    private function hasDifferentCustomerGroups(ShopContextInterface $context): bool
    {
        return $context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId();
    }
}
$term = $request->getParam('sSearch');
        if (empty($term)) {
            return;
        }
        $term = $this->searchTermPreProcessor->process($term);
        $criteria->addBaseCondition(new SearchTermCondition($term));
    }

    private function addCustomerGroupCondition(Criteria $criteria, ShopContextInterface $context): void
    {
        $condition = new CustomerGroupCondition(
            [$context->getCurrentCustomerGroup()->getId()]
        );
        $criteria->addBaseCondition($condition);
    }

    private function addOffset(Request $request, Criteria $criteria): void
    {
        $page = (int) $request->getParam('sPage', 1);
        $page = ($page > 0) ? $page : 1;
        $request->setParam('sPage', $page);

        $criteria->offset(
            (

        $cheapestPrices = $this->getList([$product]$context);

        return array_shift($cheapestPrices);
    }

    /** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context)
    {
        $group = $context->getCurrentCustomerGroup();

        $rules = $this->cheapestPriceGateway->getList($products$context$group);

        $prices = $this->buildPrices($products$rules$group);

        // check if one of the products have no assigned price within the prices variable.         $fallbackProducts = array_filter(
            $products,
            function DBaseProduct $product) use ($prices) {
                return !\array_key_exists($product->getNumber()$prices);
            }
        );
$query->andWhere('prices.articledetailsID = availableVariant.id');

        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            $query->andWhere("IF(priceGroup.id IS NOT NULL, prices.from = 1, prices.to = 'beliebig')");
        } else {
            $query->andWhere('prices.from = 1');
        }

        $query->groupBy('product.id');

        $query->setParameter(':fallbackCustomerGroup', $context->getFallbackCustomerGroup()->getKey());
        $query->setParameter(':priceGroupCustomerGroup', $context->getCurrentCustomerGroup()->getId());

        if ($this->hasDifferentCustomerGroups($context)) {
            $query->setParameter(':currentCustomerGroup', $context->getCurrentCustomerGroup()->getKey());
        }

        return $query;
    }

    /** * @return bool */
    
use Shopware\Core\Checkout\Cart\Price\Struct\CartPrice;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\Country\CountryEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

#[Package('checkout')] class TaxDetector
{
    public function useGross(SalesChannelContext $context): bool
    {
        return $context->getCurrentCustomerGroup()->getDisplayGross();
    }

    public function isNetDelivery(SalesChannelContext $context): bool
    {
        $shippingLocationCountry = $context->getShippingLocation()->getCountry();
        $countryTaxFree = $shippingLocationCountry->getCustomerTax()->getEnabled();

        if ($countryTaxFree) {
            return true;
        }

        

        $prices = $this->getList([$product]$context);

        return array_shift($prices);
    }

    /** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context)
    {
        $group = $context->getCurrentCustomerGroup();
        $specify = $this->graduatedPricesGateway->getList(
            $products,
            $context,
            $group
        );

        // iterates the passed prices and products and assign the product unit to the prices and the passed customer group         $prices = $this->buildPrices(
            $products,
            $specify,
            $group
        );
public function __construct(Connection $connection, Shopware_Components_Config $config)
    {
        $this->connection = $connection;
        $this->config = $config;
    }

    /** * @return string */
    public function getSelection(ShopContextInterface $context)
    {
        $current = $context->getCurrentCustomerGroup();
        $currency = $context->getCurrency();

        $discount = $current->useDiscount() ? $current->getPercentageDiscount() : 0;

        $considerMinPurchase = $this->config->get('calculateCheapestPriceWithMinPurchase');

        $taxCase = $this->buildTaxCase($context);

        // Rounded to filter this value correctly         // => 2,99999999 displayed as 3,- € but won't be displayed with a filter on price >= 3,- €         $selection = 'ROUND(' .

            
namespace Shopware\Bundle\SearchBundleES;

use Shopware\Bundle\SearchBundle\Condition\VariantCondition;
use Shopware\Bundle\SearchBundle\Criteria;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface;

class PriceFieldMapper
{
    public function getPriceField(Criteria $criteria, ShopContextInterface $context)
    {
        $customerGroup = $context->getCurrentCustomerGroup()->getKey();
        $currency = $context->getCurrency()->getId();

        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $ids = array_map(function DVariantCondition $condition) {
            return $condition->getGroupId();
        }$conditions);

        if (empty($conditions)) {
            return 'calculatedPrices.' . $customerGroup . '_' . $currency . '.calculatedPrice';
        }

        
TextMappingInterface $textMapping
    ) {
        $this->shopAnalyzer = $shopAnalyzer;
        $this->textMapping = $textMapping;
    }

    /** * @return string */
    public function getPriceField(ShopContextInterface $context)
    {
        $key = $context->getCurrentCustomerGroup()->getKey();
        $currency = $context->getCurrency()->getId();

        return 'calculatedPrices.' . $key . '_' . $currency . '.calculatedPrice';
    }

    /** * @return array */
    public function getLanguageField(Shop $shop)
    {
        $analyzers = $this->shopAnalyzer->get($shop);

        

    public function getAdvancedMenu($category$activeCategoryId$depth)
    {
        $context = $this->get(ContextServiceInterface::class)->getShopContext();

        $cacheKey = sprintf(
            'Shopware_AdvancedMenu_Tree_%s_%s_%s',
            $context->getShop()->getId(),
            $category,
            $this->Config()->get('includeCustomergroup') ? $context->getCurrentCustomerGroup()->getId() : 'x'
        );

        $cacheKey = $this->get('events')->filter('Shopware_Plugins_AdvancedMenu_CacheKey', $cacheKey[
            'shopContext' => $context,
            'config' => $this->Config(),
        ]);

        $cache = $this->get(Zend_Cache_Core::class);

        if ($this->Config()->get('caching') && $cache->test($cacheKey)) {
            $menu = $cache->load($cacheKey, true);
        }
array $products,
        array $configurations,
        ?VariantFacet $variantFacet = null
    ) {
        $combinationPrices = [];

        $contexts = $this->getCustomerGroupContexts($shop);

        /** @var ShopContextInterface $context */
        foreach ($contexts as $context) {
            $prices = $this->fetchPrices($products$context);
            $key = $context->getCurrentCustomerGroup()->getKey();

            foreach ($products as $product) {
                if (!isset($configurations[$product->getNumber()]) || !isset($prices[$product->getId()])) {
                    continue;
                }

                $configuration = $configurations[$product->getNumber()];
                $groups = $this->getFilteredGroups($configuration$variantFacet);

                if (empty($groups)) {
                    continue;
                }
Home | Imprint | This part of the site doesn't use cookies.