0

I have magento 1.9.3.8. I use amasty customer attributes and one step checkout. In out theme's folder I have added layout files for these attributes and a new customer attributes phtml file with this code:

<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2008-2012 Amasty (http://www.amasty.com)
* @package Amasty_Customerattr
*/ 

/* @var $this Amasty_Customerattr_Block_Customer_Fields */
$relations = $this->getElementsRelation();

/*
 * Get form elements to be rendered
 */
$formElements = $this->getFormElements();

$jsCode = Mage::getModel('amcustomerattr/validation')->getJS();
?>

<?php if ($this->isShowHeader()): ?>
    <div class="fieldset">
        <h2 class=""><?php echo $this->__('Additional Information') ?></h2>
<?php endif; ?>
        <div style="float: left;">
            <ul class="form-list">
            <?php foreach ($formElements as $element): ?>
                <li class="fields">
                    <div class="field">
                        <?php echo $element->toHtml(); ?>
                    </div>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>
<!-- CUSTOM IMAGE AT THE RIGHT: <div style="float: right;"><img src="PATH HERE" /></div>-->
        <div style="clear: both;"></div>
<?php if ($this->isShowHeader()): ?>
    </div>
<?php endif;?>

<?php if (!Mage::registry('amcustomerattr_client_side')):?>
    <style>
        #amcustomerattr .required {
            color: #EB340A;
        }

        .amcustomerattr .required {
            color: #EB340A;
        }

        #amcustomerattr .hidden {
            display: none;
        }

        .amcustomerattr .hidden {
            display: none;
        }
    </style>
<script type="text/javascript">

<?php echo $jsCode; ?>

Validation.addAllThese([
    ['validate-tendigits', 'Please use 10 digit numbers only in this field. Please avoid spaces or other characters such as dots or commas.', function(v) {
        return Validation.get('IsEmpty').test(v) ||  /^(\d){10}$/.test(v);
    }],

    ['validate-aaa-0000', 'Please use the value in the following format: AAA-0000', function(v) {
        return Validation.get('IsEmpty').test(v) ||  /^([A-Za-z]){3}-(\d){4}$/.test(v);
    }],

    ['validate-checkboxgroup-required', 'Please select an option.', function(v, elm) {
        id = elm.id.substr(0, elm.id.search('___'));
        checkboxGroupChecked = false;
        $$('input[id^=' + id + ']').each(function(checkbox){
            if (checkbox.checked)
            {
                checkboxGroupChecked = true;
            }
        });
        return checkboxGroupChecked;
    }],

    ['validate-radiogroup-required', 'Please select an option.', function(v, elm) {
        id = elm.id.substr(0, elm.id.search('___'));
        radioGroupChecked = false;
        $$('input[id^=' + id + ']').each(function(radio) {
            if (radio.checked) {
                radioGroupChecked = true;
            }
        });
        return radioGroupChecked
    }],
]);

/* Relations table */
var amcustomerattr_relations = '<?php echo Mage::helper('core')->jsonEncode($relations->toArray());?>'.evalJSON();
var indexed_elements = [];

/*
 * Hide element and its label
 */
function amcustomerattr_hide_element(id) 
{
    if ($(id)) {
        if(navigator.appVersion.indexOf("MSIE 7.") == -1) {
            if ($(id).readAttribute('class') == 'field-row') {
                $(id).hide();
            } else {
                $(id).parentNode.hide();
            }
        }
        else{
            $(id).hide();
            classAttr = 'label[for='+id+']';
            $$(classAttr).each(function(el) {
                el.hide();
            });
        }
    }
    hide_all_childs(id);
}

/*
 * Show element and its label
 */
function amcustomerattr_show_element(id) 
{
    if ($(id)) {
        if(navigator.appVersion.indexOf("MSIE 7.") == -1) {
            if ($(id).readAttribute('class') == 'field-row') {
                $(id).show();
            } else {
                $(id).parentNode.show();
            }
        } else {
            $(id).show();
            classAttr = 'label[for='+id+']';
            $$(classAttr).each(function(el) {
                el.show();
            });
        }

        var options = amcustomerattr_find_elements(id);
        if (options) {
            if ($(id).readAttribute('class') == ' select') {
                element = $(id);
                amcustomerattr_manage_dep(element);
            } else {
                options.each(function(item) {
                    element = $(id+'___'+item.value);
                    amcustomerattr_manage_dep(element);
                });
            }
        }
    }
}

/*
 * Hide childs elements and them labels
 */
function hide_all_childs(id)
{
    // Find dependents elements
    var dep = amcustomerattr_find_elements(id);

    // Iterate throw elements and show required elements
    dep.each(function(el) {
        amcustomerattr_hide_element(el.code);
    });

}

/*
 * Manage dependencies.
 * Hide or show dependent attribute
 */
function amcustomerattr_manage_dep(element)
{
    if (element) {
        var elementId = element.id;

        if (element.id.indexOf('___') > 0) {
            elementId = element.id.substr(0, element.id.search('___')); 
        }

        if (element.readAttribute('rel')) {
            elementId = element.readAttribute('rel');
        }

        // Find dependents elements
        var dep = amcustomerattr_find_elements(elementId);

        if (element.type == 'radio') {
            hide_all_childs(elementId);
        }

        // Iterate throw elements and show required elements
        dep.each(function(el) {
            if ($(el.code)) {
                // Checkboxes and radio
                if (element.checked == false) {
                    if (must_hide(elementId, dep)) {
                        amcustomerattr_hide_element(el.code);
                    }
                } else if (element.checked) {
                    if (element.getValue().indexOf(el.value) >= 0) {
                        amcustomerattr_show_element(el.code);
                        indexed_elements.push(el.code);
                    } else if (indexed_elements.indexOf(el.code) < 0) {
                        if (must_hide(elementId, dep)) {
                            amcustomerattr_hide_element(el.code);
                        }
                    }
                } else {
                    // Multiselect and select
                    if (element.getValue().indexOf(el.value) >= 0) {
                        amcustomerattr_show_element(el.code);
                        indexed_elements.push(el.code);
                    } else if (indexed_elements.indexOf(el.code) < 0) {
                        amcustomerattr_hide_element(el.code);
                    }
                }

            } 
        });
        indexed_elements = [];
    }
}

function must_hide(elementId, dep)
{
    var hide = true;
    dep.each(function(el) {
        element = $(elementId+'___'+el.value);
        if (element.checked == true) {
            hide = false;
        }
    });
    return hide;
}

/*
 * Listen elements
 */
function amcustomerattr_listen_element(id) {
    if ($(id)) {
        $(id).observe('change', function(event) {
            var element = Event.element(event);
            amcustomerattr_manage_dep(element);
        });
    }
}

/*
 * Get dependents element for elementId
 */
function amcustomerattr_find_elements(elementId)
{
    var elements = [];
    amcustomerattr_relations.items.each(function(item) {
        if (item.parent_code == elementId) {
            var el = {
                'code' : item.dependent_code,
                'value' : item.option_id
            };
            elements.push(el);
        }
    });
    return elements;
}

var shownElements = [];

<?php 
/*
 * Hide dependent elements
 * Listen for changes
 */
foreach($relations as $relation) { ?>
    var parent = $('<?php echo $relation->getParentCode() ?>');     
    if (parent) {
        if (parent.value == '<?php echo $relation->getOptionId()?>') {
            amcustomerattr_show_element('<?php echo $relation->getDependentCode() ?>');
            shownElements.push('<?php echo $relation->getDependentCode() ?>');
        }
    } 

    var parent = $('<?php echo $relation->getParentCode() ?>___<?php echo $relation->getOptionId()?>');     
    if (parent) {
        if (parent.value == '<?php echo $relation->getOptionId()?>' && parent.readAttribute('checked') == 'checked') {
            amcustomerattr_show_element('<?php echo $relation->getDependentCode() ?>');
            shownElements.push('<?php echo $relation->getDependentCode() ?>');
        }
    }

    if (shownElements.indexOf('<?php echo $relation->getDependentCode() ?>') < 0) {
        amcustomerattr_hide_element('<?php echo $relation->getDependentCode() ?>');
    }

    amcustomerattr_listen_element('<?php echo $relation->getParentCode() ?>___<?php echo $relation->getOptionId()?>');
    amcustomerattr_listen_element('<?php echo $relation->getParentCode() ?>');
<?php
} 
?> 
</script>

<!--[if IE 7]>
<script type="text/javascript">
    $$('.amcustomerattr').each(function(el) {
        el.style.position='relative';
        el.style.left='-150px';
    });  
</script>
<![endif]-->

<?php         
Mage::register('amcustomerattr_client_side', 'displayed'); 
endif; // End Script output?>

This give a in checkout page but it is always hidden as I inspect the page:

<fieldset id="amcustomerattr26" class="amcustomerattr" style="
display: none;">

What am I doing wrong? I am stucked

1 Answer 1

0

We found the solution.The problem wasn't on attributes.phtml file. There was another file called relations.phtml

It had in its code a lot of these:

$(id).parentNode.parentNode

This changed in every place with:

$(id).parentNode

This changed dom and we are fine now in checkout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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