0

I am unable to place order from admin. I enter all the data in required field. When I place order, error showing in the City field - this is a required field. I am using magento 1.9.3.7 version

can anyone help me to resolve this issue?

enter image description here

  • Please can you give us more details about installed modules and admin edits? That is not the default position for City in that form. It is supposed to be between Street Address and Country, so I suppose you are using a customization. – Fra H May 22 '18 at 14:05
  • Please provide more details. – kunj May 23 '18 at 11:56
  • Thank you for your response. I am using this module magebuzz.com/region-city-manager.html . I think this module cause city field error – Aks May 23 '18 at 15:13
  • @Aks Some questions: #1: Are there any specific Validation Rules introduced by this module in terms of this Field? (Have you tried to update those?) #2: If #1 is YES: Are you sure that the City you were entering does not contain characters that are not allowed? – Piotr Siejczuk May 24 '18 at 13:55
  • @Aks let me know if you have any issue related to this. – kunj May 26 '18 at 16:23
2

Try this:

You need to change in some file for this:

In this app/code/local/Magebuzz/Improvedaddress/Block/Adminhtml/Customer/Edit/Renderer/City.php file, you need to update some code, you can either override or update in this file because this is a bug:

Current public function render function :

public function render(Varien_Data_Form_Element_Abstract $element)
    {
        $country = $element->getForm()->getElement('country_id');
                $region = $element->getForm()->getElement('region_id');
        if (!is_null($region)) {
            $regionId = $region->getValue();
        } else {
            return $element->getDefaultHtml();
        }

        $cityId = $element->getForm()->getElement('city_id')->getValue();
        $quoteStoreId = $element->getEntityAttribute()->getStoreId();

        $html = '<tr>';
        $element->setClass('input-text');
        $element->setRequired(true);
        $html .= '<td class="label">' . $element->getLabelHtml() . '</td><td class="value">';
        $html .= $element->getElementHtml();

        $selectName = str_replace('city', 'city_id', $element->getName());
        $selectId = $element->getHtmlId() . '_id';
        $html .= '<select id="' . $selectId . '" name="' . $selectName
            . '" class="select required-entry" style="display:none">';
        $html .= '<option value="">' . $this->_factory->getHelper('customer')->__('Please select') . '</option>';
        $html .= '</select>';

        $html .= '<script type="text/javascript">' . "\n";
        $html .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $cityId.'");' . "\n";
        $html .= 'new CityUpdater("' . $country->getHtmlId() . '", "' . $region->getHtmlId() . '", "' . $element->getHtmlId() . '", "' .
            $selectId . '", ' . Mage::helper('improvedaddress')->getCityJson().');' . "\n";
        $html .= '</script>' . "\n";

        $html .= '</td></tr>' . "\n";

        return $html;
    }

Update public function render function :

public function render(Varien_Data_Form_Element_Abstract $element)
    {
        $country = $element->getForm()->getElement('country_id');
                $region = $element->getForm()->getElement('region_id');
        if (!is_null($region)) {
            $regionId = $region->getValue();
        } else {
            return $element->getDefaultHtml();
        }

        $cityId = $element->getForm()->getElement('city_id')->getValue();
        $quoteStoreId = $element->getEntityAttribute()->getStoreId();

        $html = '<tr>';
        $element->setClass('input-text');
        $element->setRequired(true);
        $html .= '<td class="label">' . $element->getLabelHtml() . '</td><td class="value">';
        $html .= $element->getElementHtml();

        $selectName = str_replace('city', 'city_id', $element->getName());
        $selectId = $element->getHtmlId() . '_id';
        $html .= '<select id="' . $selectId . '" name="' . $selectName
            . '" class="select required-entry" style="display:none" disabled="disabled">';
        $html .= '<option value="">' . $this->_factory->getHelper('customer')->__('Please select') . '</option>';
        $html .= '</select>';

        $html .= '<script type="text/javascript">' . "\n";
        $html .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $cityId.'");' . "\n";
        $html .= 'new CityUpdater("' . $country->getHtmlId() . '", "' . $region->getHtmlId() . '", "' . $element->getHtmlId() . '", "' .
            $selectId . '", ' . Mage::helper('improvedaddress')->getCityJson().');' . "\n";
        $html .= '</script>' . "\n";

        $html .= '</td></tr>' . "\n";

        return $html;
    }

I have updated this code from $html .= '<select id="' . $selectId . '" name="' . $selectName . '" class="select required-entry" style="display:none">'; To $html .= '<select id="' . $selectId . '" name="' . $selectName . '" class="select required-entry" style="display:none" disabled="disabled">'; in that function.

Now you need to update this js/magebuzz/improvedaddress.js file in update: function() { function :

Current code in that JS:

update: function() {
        if (this.cities[this.regionEl.value]) {
            var i, option, city, def;
            def = this.citySelectEl.getAttribute('defaultValue');
            if (this.cityTextEl) {
                if (!def) {
                    def = this.cityTextEl.value.toLowerCase();
                }
                ////need to comment this to avoid issue when saving address without touching city field
                //this.cityTextEl.value = '';
            }

            this.citySelectEl.options.length = 1;
            for (cityId in this.cities[this.regionEl.value]) {
                city = this.cities[this.regionEl.value][cityId];

                option = document.createElement('OPTION');
                option.value = city.code;
                option.text = city.name.stripTags();
                option.title = city.name;

                if (this.citySelectEl.options.add) {
                    this.citySelectEl.options.add(option);
                } else {
                    this.citySelectEl.appendChild(option);
                }               

                if (cityId==def || (city.name && city.name==def) ||
                        (city.name && city.code.toLowerCase()==def)
                ) {
                    this.citySelectEl.value = city.code;
                }
            }

            if (this.cityTextEl) {
                this.cityTextEl.style.display = 'none';
            }
            this.citySelectEl.style.display = '';
        }
        else {
            this.citySelectEl.options.length = 1;
            if (this.cityTextEl) {
                this.cityTextEl.style.display = '';
            }
            this.citySelectEl.style.display = 'none';
            Validation.reset(this.citySelectEl);
        }
    }

Updated that update function:

update: function() {
        if (this.cities[this.regionEl.value]) {
            var i, option, city, def;
            def = this.citySelectEl.getAttribute('defaultValue');
            if (this.cityTextEl) {
                if (!def) {
                    def = this.cityTextEl.value.toLowerCase();
                }
                ////need to comment this to avoid issue when saving address without touching city field
                //this.cityTextEl.value = '';
            }

            this.citySelectEl.options.length = 1;
            for (cityId in this.cities[this.regionEl.value]) {
                city = this.cities[this.regionEl.value][cityId];

                option = document.createElement('OPTION');
                option.value = city.code;
                option.text = city.name.stripTags();
                option.title = city.name;

                if (this.citySelectEl.options.add) {
                    this.citySelectEl.options.add(option);
                } else {
                    this.citySelectEl.appendChild(option);
                }               

                if (cityId==def || (city.name && city.name==def) ||
                        (city.name && city.code.toLowerCase()==def)
                ) {
                    this.citySelectEl.value = city.code;
                }
            }

            if (this.cityTextEl) {
                this.cityTextEl.style.display = 'none';
            }
            this.citySelectEl.style.display = '';
            this.citySelectEl.disabled = '';
        }
        else {
            this.citySelectEl.options.length = 1;
            if (this.cityTextEl) {
                this.cityTextEl.style.display = '';
            }
            this.citySelectEl.disabled = true;
            this.citySelectEl.style.display = 'none';
            Validation.reset(this.citySelectEl);
        }
    }

After the changes, it will disable that select so you can submit form without hidden fields validation. Let me know you face any issue related to this.

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.