Skip to content

In Magento 2.4.7, retrieving customer session data using the getCustomerData method is not Working

In Magento 2.4.7, the following code attempts to retrieve customer session data using the getCustomerData method, but it does not return any data

<?php
...
use MagentoCustomerModelSession;
use BlissPricePerCustomerModelCustomerPriceProdcut;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoStoreModelScopeInterface;
use MagentoCatalogModelProduct as MainProduct;

class Product
{
    protected $customerSession;
    protected $customerPriceProdcut;
    public $scopeConfig;
    const ENABLE_PRICEPER_CUSTOMER = 'bliss/settings/enable';

    public function __construct(
        Session $customerSession,
        CustomerPriceProdcut $customerPriceProdcut,
        ScopeConfigInterface $scopeConfig
    ) {
        $this->customerSession = $customerSession;
        $this->customerPriceProdcut = $customerPriceProdcut;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Modify product price based on the customer's global price adjustment attribute or product-specific prices.
     *
     * @param MagentoCatalogModelProduct $subject
     * @param float $result
     * @return float
     */
    public function afterGetPrice($subject, $result)
    {
        $moduleEnableValue = $this->getModuleEnable();
        $customer = $this->customerSession->getCustomer();