Additional field from module in user_billing template not inserting in database

Hello everyone!

I have a module that creates some additional text fields under user_billing.tpl form and also an additional field for user overview under admin panel

The problem is when I go to my account and change billing address form, and add some value in that field it doesn’t get saved in the database.

But when I go to:

vendor/oxid-esale/oxidshop-ce/source/Application/Model/User/UserUpdatabaleFields.php

and add the column name in the array under function public function getUpdatableFields() and then goes to save the form with some value, then it updates.

So… is there something missing in a module or any leads?

Oxide shop version: 6.1.5

Can you post some example code?

i just added the template block in the **user_billing.tpl**

<li [{if $aErrors.oxuser__asigneori}]class="oxInValid"[{/if}]>
  <label [{if $oView->isFieldRequired(oxuser__asigneori) }]class="req"[{else}]class="form_userbill" 
[{/if}]>[{ oxmultilang ident="EORI_FIELD" suffix="COLON" }]
  </label>

  <input class="textbox" [{if $oView->isFieldRequired(oxuser__asigneori) }]class="textbox js-oxValidate js-oxValidate_notEmpty" [{/if}]type="text"  maxlength="255" name="invadr[oxuser__asigneori]" value="[{if isset( $invadr.oxuser__asigneori ) }][{ $invadr.oxuser__asigneori }][{else }][{ $oxcmp_user->oxuser__asigneori->value }][{/if}]">

  [{if $oView->isFieldRequired(oxuser__asigneori)}]

  <p class="oxValidateError message_invalid [{if $oView->getClassName() == 'oxwservicemenu'}]od_popupreg[{/if}]">
<span class="js-oxError_notEmpty validate_error_bill">[{ oxmultilang ident="ERROR_MESSAGE_INPUT_NOTALLFIELDS" }]
</span>
   [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxuser__asigneori}]
  </p>

  [{/if}]
      <a class="eori_info" title="[{oxifcontent ident='eori_info' object='oCont'}]
                          [{$oCont->oxcontents__oxcontent->value}]
                          [{/oxifcontent}]">
        <img src="[{$oViewConf->getImageUrl('info_icon.png')}]">
      </a>
</li>
[{oxscript add="
       $('.eori_info').tooltip();
     "}]
[{$smarty.block.parent}]

And this is my metadata.php file

 'blocks' => [
    [
        'template' => 'form/fieldset/user_billing.tpl',
        'block' => 'form_user_billing_country',
        'file' => '/views/blocks/addfields_user_billing.tpl'
    ]
]

Any leads? The additional field creatd in user_billing.tpl doesn’t get updated, but when i go to the user from admin panel and updates that field from input field, it gets update.

I am not also getting any errors in log, so that’s why i am bit confused.

Alright! fixed it on my own, created a model and overrided the default save() method from core user model.

Wrote parent::save() as a first line under my custom model save() method after that wrote my own logic.

Example:

class foo extends foo_parent
{
    protected $_sClassName = 'oxuser';

    public function __construct()
    {
        parent::__construct();

        $this->init('oxuser');
    }

    public function save()
    {
        parent::save();
        $oUser = $this->getUser();
        $id = $oUser->oxuser__oxid->value;

        $_oUserData = Registry::getConfig()->getRequestParameter('invadr');
        if ($_oUserData == NULL || $_oUserData == '') {
            $_oUserData = Registry::getConfig()->getRequestParameter('editval');
        }

        $sql = "UPDATE oxuser SET some_awesome_column = '" . $_oUserData["oxuser__some_awesome_column"] . "' WHERE oxid = '$id'";

        $db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
        $db->execute($sql);
    }
}

Just a little heads up if someone falls on to this topic.

I had a problem where some extra fields via module weren’t inserting in the database, So i extended the save() function from User’s model and implemented that under my module.

So far, it worked pretty fine when i was playing with billing address form in my accounts section after logging in. But i never checked if the regisration of new user worked fine too.

Few months later now, i checked and user registration weren’t working and the problem was the save() function i extended in my module.

Turns out, i also had to this little tweak which was missing logically before. Here it goes:

    public function save()
    {
        $blRet = parent::save(); // this should be taken in variable and then returned
        $oUser = $this->getUser();
        $id = $oUser->oxuser__oxid->value;

        $_oUserData = Registry::getRequest()->getRequestParameter('invadr');
        if ($_oUserData == NULL || $_oUserData == '') {
            $_oUserData = Registry::getRequest()->getRequestParameter('editval');
        }

        $sql = "UPDATE oxuser SET some_awesome_column = '" . $_oUserData["oxuser__some_awesome_column"] . "' WHERE oxid = '$id'";

        $db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
        $db->execute($sql);

        return $blRet;    // returned right here
    }

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.