Jump to content

ObjectModel, multishop and multilanguage


manudas

Recommended Posts

Good morning everyone there

 

I have lots of doubs about how to develop a module with multishop and multilanguage characteristics.

 

When using the ObjectModel::add() method we have the next (line 489 in ObjectModel PS 1.7.1):

 

if (!$result = Db::getInstance()->insert($this->def['table'], $this->getFields(), $null_values)) {
    return false;
}

 

If we revise the getFields function we see the following (line 251):

 

        // For retro compatibility
        if (Shop::isTableAssociated($this->def['table'])) {
            $fields = array_merge($fields$this->getFieldsShop());
        }

 

 

Here the script is merging the shop specific fields with the non-shop dependants fields, returning all in the same array, So later in the insert method showed before, It is trying to insert a group of attributes that are not master table (the one without _shop sufix).

 

Please find attached the ObjectModel definition:

 

    public static $definition = array(
        'table' => 'codeextracts',
        'primary' => 'id',
        // 'multishop' => true,
        // 'multilang' => true,
        'multilang' => true,
        'multilang_shop' => true,
        'fields' => array(
            'id' =>                 array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt''required' => false),
            'subreference' =>       array('type' => self::TYPE_STRING, 'validate' => 'isString''required' => true'lang' => TRUE'shop' => true),
            'blockreference' =>     array('type' => self::TYPE_STRING, 'validate' => 'isString''required' => true'lang' => TRUE'shop' => true),
            'text' =>               array('type' => self::TYPE_HTML, 'validate' => 'isString''required' => true'lang' => TRUE'shop' => true)
        ),
    );

 

And the table creation method:

 

public static function createContentTable()
    {


        $sq1 = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.self::$definition['table'].'`(
            `id` int(10) unsigned NOT NULL auto_increment,
            PRIMARY KEY (`id`)
            ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';


        $sq2 = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.self::$definition['table'].'_shop`(
            `id` int(10) unsigned NOT NULL auto_increment,
            `id_shop` int(10) unsigned NOT NULL,
            PRIMARY KEY (`id`, `id_shop`)
            ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';



        $sq3 = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.self::$definition['table'].'_lang`(
            `id` int(10) unsigned NOT NULL auto_increment,
            `id_lang` int(10) NOT NULL,
            `subreference` varchar(32) NOT NULL,
            `blockreference` varchar(32) NOT NULL,
            `text` text NOT NULL,
            PRIMARY KEY (`id`, `id_lang`), UNIQUE (`blockreference`, `subreference`)
            ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

        $result = Db::getInstance()->execute($sq1
            && Db::getInstance()->execute($sq2
            && Db::getInstance()->execute($sq3);

        return $result;
    }

 

 

 

Can somebody help and tell me what I'm doing wrong?

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...