No image available

A module that bring to you an extended ObjectModel class on steroids

A module that bring to you an extended ObjectModel class on steroids

Developed by friends-of-presta

Get This Module Free on GitHub
License: MIT Status: Unknown Health: Very Outdated

Info updated 1 month ago

Sources
Stars: 4 Last commit: Apr 19, 2020
Type
Module

Info checked: Mar 2, 2026

PrestaShop Super Model

Requirements

You need a Shop with PrestaShop 1.6.1+, Composer and PHP 7.1 at least.

Installation

Get the module here and move it into the <code>modules</code> folder of your Shop.

Then, you need to install the vendors of the module:

`<code> cd modules/products &amp;&amp; composer install </code><code>

Then install it using the command line (if you&#039;re using PrestaShop 1.7.5+):

</code><code> php bin/console prestashop:module install products </code><code>

Or using the Back Office.

Features demonstrated in the module

Object Model self validation

If your Object Model extends the </code>SuperModel<code> abstract class, you don&#039;t need to override </code>Validate` class in order to implement a new validation rule.

This is an exemple of what you can do:

<?php

/**

Implements the Validation Rules into your models !

*/ class Person extends SuperModel { public $id; public $name; public $age; public $gender;

public static $definition = [ &#039;table&#039; =&gt; &#039;person&#039;, &#039;primary&#039; =&gt; &#039;id_person&#039;, &#039;fields&#039; =&gt; [ &#039;name&#039; =&gt; [ &#039;type&#039; =&gt; self::TYPE_STRING, &#039;validate&#039; =&gt; &#039;isString&#039; ], &#039;age&#039; =&gt; [ &#039;type&#039; =&gt; self::TYPE_INT, &#039;validate&#039; =&gt; &#039;Person::isAdult&#039; ], &#039;gender&#039; =&gt; [ &#039;type&#039; =&gt; self::TYPE_STRING, &#039;validate&#039; =&gt; &#039;PersonValidator::isValidGender&#039;, ] ] ];

public static function isAdult($value) { return $value &gt;= 18; } }

/**

Or create your own Validator classes !

*/ class PersonValidator { public static function isValidGender($value) { return in_array($value, [ &#039;MALE&#039;, &#039;FEMALE&#039;, &#039;NOT_BINARY&#039;, ]); } }

Feel free to contribute and let me know if you need more improvements !

  • Riferimento
    super-model

  • License
    MIT
  • Status
    Unknown

Commenti (0)

Ancora nessuna recensione da parte degli utenti.
Caricamento in corso ...