Question

I'm getting the below error when I browse the following URL:

http://127.0.0.1/mywebsite/customer/account/create

1 exception(s): Exception #0 (Exception): Notice: Undefined variable: customergroupid in /var/www/html/mywebsite/app/design/frontend/Module/vendor/Magento_CustomerCustomAttributes/templates/form/userattributes.phtml on line 27

I have checked the path and see I have below code:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Create account form template
 *
 * @see \Magento\CustomerCustomAttributes\Block\Form
 */
/* @var $block \Magento\CustomerCustomAttributes\Block\Form */
?>
<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
if ($customerSession->isLoggedIn()) {
     $customergroupid = $customerSession->getCustomer()->getGroupId();
    //echo $customergroupid;

}
?>
<?php if(($customergroupid == 4) || ($customergroupid == 5) || ($customergroupid == 6)): ?>
<?php if ($block->hasUserDefinedAttributes()): ?>
    <?php if ($block->isShowContainer()): ?>
    <fieldset class="fieldset">
    <?php endif;?>
    <?php foreach ($block->getUserDefinedAttributes() as $attribute):?>
        <?php $attributeContent = $block->getAttributeHtml($attribute);?>
        <?php if ($attributeContent): ?>
            <?= /* @escapeNotVerified */ $attributeContent ?>
        <?php endif;?>
    <?php endforeach;?>
    <?php if ($block->isShowContainer()): ?>
    </fieldset>
    <?php endif;?>
<?php endif; ?>
<?php endif; ?>

How can I resolve this issue?

Your help will be greatly appreciated!

Was it helpful?

Solution

Define $customergroupid this variable before if condition with NULL value, or update your file with below content

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Create account form template
 *
 * @see \Magento\CustomerCustomAttributes\Block\Form
 */
/* @var $block \Magento\CustomerCustomAttributes\Block\Form */
?>
<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
$customergroupid = '';
if ($customerSession->isLoggedIn()) {
     $customergroupid = $customerSession->getCustomer()->getGroupId();
    //echo $customergroupid;

}
?>
<?php if(($customergroupid == 4) || ($customergroupid == 5) || ($customergroupid == 6)): ?>
<?php if ($block->hasUserDefinedAttributes()): ?>
    <?php if ($block->isShowContainer()): ?>
    <fieldset class="fieldset">
    <?php endif;?>
    <?php foreach ($block->getUserDefinedAttributes() as $attribute):?>
        <?php $attributeContent = $block->getAttributeHtml($attribute);?>
        <?php if ($attributeContent): ?>
            <?= /* @escapeNotVerified */ $attributeContent ?>
        <?php endif;?>
    <?php endforeach;?>
    <?php if ($block->isShowContainer()): ?>
    </fieldset>
    <?php endif;?>
<?php endif; ?>
<?php endif; ?>

Hope this will fix your issue!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top