-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Setup class with possibility to create tables with translatable fields #31
Comments
Looks like this message is sending over and over ~ can you stop it? -----Original Message----- It's necessary to create Setup (or some behavior) class that would give api to easy implement modules with fields that must be available on different languages. This class can create some additinal tables automatically for example i have table "news" and i want that fields "title" and "description" will be available for a few languages (the api of business models and collection must be the same as for non-translatable table). Table "news" has few fields. There are id, title, description, is_active, created_at. In the install file of module i create a ddl table object and set some parameter (or behavior object) that responsible for the creation of the additional table with template name %base_tablename%_translation (e.g. news_translation). This table contains all translatable fields (e.g. title, description) id and store_id. Id field is the same that is in base table (e.g. news). Also you need to add primary index for (id, storeid). For example, $table = $installer->getConnection()
->newTable($installer->getTable('cms_block'))
->addColumn('block_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Block ID')
->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
'nullable' => false,
), 'Block Title')
->addColumn('identifier', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
'nullable' => false,
), 'Block String Identifier')
->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array(
), 'Block Content')
->addColumn('creation_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Block Creation Time')
->addColumn('update_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
), 'Block Modification Time')
->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
'nullable' => false,
'default' => '1',
), 'Is Block Active')
->setComment('CMS Block Table');
// Add Table Behavior
$table->addBehavior(new TranslatableBehavior(array('title', 'content'));
$installer->getConnection()->createTable($table); This code must generate the following SQL: CREATE TABLE `news` (
`id` smallint(6) NOT NULL AUTO_INCREMENT, `creation_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL, `is_active` tinyint(1) NOT NULL DEFAULT '1'
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='CMS Blocks'
CREATE TABLE `news_translation` (
`id` smallint(6) NOT NULL,
`store_id` smallint(5) unsigned NOT NULL, PRIMARY KEY (`id`,`store_id`), KEY `FK_CMS_BLOCK_STORE_STORE` (`store_id`), CONSTRAINT `FK_CMS_BLOCK_STORE_BLOCK` FOREIGN KEY (`id`) REFERENCES `news` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_CMS_BLOCK_STORE_STORE` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='CMS Blocks to Stores'; ```
To work with models withous changing api:
```php
// collection
$collection = new TranslatableCollection(); $collection->setStoreId(Mage::app()->getStore()->getId())->load();
// item
$item = new TranslatableModel();
$item->setStoreId(Mage::app()->getStore()->getId())->load($itemId);
echo $item->getTitle();
echo $item->getDescription(); It would look like a Doctrine I18n Behavior - http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/behaviors.html#i18n . Reply to this email directly or view it on GitHub: |
@stalniy, why not just write a (edit: community) Magento module that adds support for Doctrine? |
@colinmollenhour Edit: |
I fully agree it is a bad idea. I wouldn't personally do it and I definitely don't think the core team should do it. But this feature is very much ORM and Magento is not an ORM-heavy framework (thank god!). If you really want ORM-like features in Magento (as is evidenced by this issue you created) I thought you might like the idea of a community extension to support Doctrine in Magento rather than add these features into Magento core. |
I have described this thing at http://freaksidea.com/php_and_somethings/show-24-internatsionalizatsiia-v-magento . There is also realization for Magento 1.6 and it will work also for Magento2 (but the usage is different). Link to module is http://freaksidea.com/uploads/php/magento/i18n/FI_I18n.tar.bz2 |
@stalniy |
It's just terms. I did not suggest to create some kind of ORM or something like that. I suggested to use the similar design pattern for your DDL table class in addition to make it more flexible, easier extendable and more useful |
Closing as "won't fix". |
It's necessary to create Setup (or some behavior) class that would give api to easy implement modules with fields that must be available on different languages. This class can create some additinal tables automatically for example i have table "news" and i want that fields "title" and "description" will be available for a few languages (the api of business models and collection must be the same as for non-translatable table). Table "news" has few fields. There are id, title, description, is_active, created_at.
In the install file of module i create a ddl table object and set some parameter (or behavior object) that responsible for the creation of the additional table with template name %base_tablename%_translation (e.g. news_translation). This table contains all translatable fields (e.g. title, description) id and store_id. Id field is the same that is in base table (e.g. news). Also you need to add primary index for (id, storeid).
For example,
This code must generate the following SQL:
To work with models withous changing api:
It would look like a Doctrine I18n Behavior - http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/behaviors.html#i18n .
The text was updated successfully, but these errors were encountered: