1

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!

4

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!

|improve this answer|||||
  • 1
    Thanks. Its working now. – Siva Dec 10 '19 at 10:38
  • Approve my answer if it helps. Thanks :) – Kishan Savaliya Dec 10 '19 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.