Jump to content

"Property PrestaShopLogger->object_type is not valid" error while creating entry with object model


Recommended Posts

The error mentioned in the title is thrown while creating an entry using object model (placed in modules/Mod_Name/classes, which in turn is being called by an admincontroller inside the module). Fields array of the object model definition looks like this:

'fields' => array(
	'name_rank' => array('type' => self::TYPE_STRING,
	'validate' => 'isName', 'size' => 256),
	),

I tried changing isName to isAnything which also yields that error. Now interesting part is that when I changed isName() from

public static function isName($name)
    {
        return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u'), stripslashes($name));
    }

to

public static function isName($name)
    {
        return stripslashes($name);
    }

It works fine! I saw this trick here  https://www.prestashop.com/forums/topic/279096-solved-validation-error-causing-data-not-to-save/?p=1403753

 

AdminController Code:

class AdminSenaAffiliateController extends ModuleAdminController
{
	public function __construct()
	{
		// Set variables
		$this->module = 'senaaffiliate';
		$this->table = 'senaaff_rank';
		$this->className = 'SenaAff_Rank';
		$this->fields_list = array(
		'id_senaaff_rank' => array('title' => $this->l('Rank ID'),
		'align' => 'left', 'width' => 50),
		'name_rank' => array('title' => $this->l('Rank Title'),
		'width' => 256),
		);
			

		$this->bootstrap = true;
		
		// Call of the parent constructor method
		parent::__construct();		
	}

	public function initPageHeaderToolbar()
    {        
        $this->page_header_toolbar_btn['new_rank'] = array(
            'href' => self::$currentIndex.'&addsenaaff_rank&token='.$this->token,
            'desc' => $this->l('Add new rank', null, null, false),
            'icon' => 'process-icon-new'
        );
        parent::initPageHeaderToolbar();
    }


	public function renderForm()
    {
        /** @var Customer $obj */
        if (!($obj = $this->loadObject(true))) {
            return;
        }            
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Customer'),
                'icon' => 'icon-user'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Rank Title'),
                    'name' => 'name_rank',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
                ),
            )
        );

        $this->fields_form['submit'] = array(
            'title' => $this->l('Save'),
        );
        return parent::renderForm();
    }

}

However, I should mention that unlike the problem of the attached link the data is being saved perfectly. Problem is clients do not like seeing errors, petty or critical. Still, I would like to know about this more.

 

Please comment if I could not make this clear :)

Edited by safi_te (see edit history)
Link to comment
Share on other sites

  • 9 months later...

I just encountered this issue with my Image/Video Gallery module. The problem is the _ in the class name. Rename the class file and class name without the _, then change:

		$this->className = 'SenaAff_Rank';

to:

		$this->className = 'SenaAffRank';
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...