7

This a question regarding Magento development, it can apply for both M1 and M2.

For the last weeks, I've been working on several modules that are directly related to native Magento entities/database table.

Here's an example but this is valid for several module development cases:

A module that lets you restrict a shopping cart rule for one customer only (described by the email).

I came to the conclusion that there's two possible ways of doing it and I'm wondering which one would be the recommended one:

First way: use Magento core tables

Never edit the core, is that applicable to core tables ?

  • Add an email column to the salesrule_rule table
  • Applying the restriction can be done when the model is loaded.

Second way: use a custom table

  • Create a custom table with salesrule_id and email linked to a custom model
  • Applying the restriction can be done by doing an extra join or load (of the custom model)

Back in the days I used to always modify the core tables directly but now I don't feel like this is the right way. However, I'm concerned about performance regarding the second way.

What is the best/recommended way of dealing with this ?

5

This is purely opinion based so others might differ in opinion but for me mutating a core table isn't an issue as long as you only add columns or an index etc.

Changing existing columns, deleting them etc will have unexpected behavior so should be avoided.

If you add the column via your modules installer script that should be perfectly fine. Next to that, adding yet another table you have to join or query on its own has a performance penalty that comes along with it so in my opinion a bad decision.

But as I said, that's just my opinion ;)

| improve this answer | |
  • Thanks for your contribution, wouldn't it be a problem regarding Magento upgrades though ? – Raphael at Digital Pianism Jun 1 '16 at 9:14
  • 1
    only if they introduce the same column. I personally prefix all columns in core tables with the module name – Sander Mangel Jun 1 '16 at 9:27
  • 2
    also make sure added columns have a proper name prefix, so other modules dont come into conflict with them. – Flyingmana Jun 1 '16 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.