1

Hey everyone I know the title is vague so I will clarify here.

I have code that updates Customer attributes and Product attributes. Unfortunately you guys are all going to frown upon me because I run all these updates programmatically on the front-end pages... that's right! the phtml... My reasoning behind it was that users have to select certain drop downs to update their own attributes and product attributes so I kept everything together.

If I wanted to write code that effects ALL Products or Customers such as adding an attribute where would you suggest writing it? I know HOW to do it I just want to know WHERE you would place it, not necessarily the best place just where you do and why?

Sorry if you don't like how my question is formatted! I'll make sure to up-vote helpful tips and tricks ^^

I'm pretty sure I shouldn't write in any of the
app/code/core files
Possibly create a file in local and make custom modules?

4
  • Look into setup resources. Alan Storm has a good article about them.
    – scrowler
    Jun 3, 2016 at 21:47
  • I already read his article but if possible I want to avoid MYSQL queries Jun 3, 2016 at 21:54
  • I don't blame you, it's bad practice to use SQL queries anywhere in magento code
    – scrowler
    Jun 3, 2016 at 22:14
  • Direct raw SQL queries are definitely not the way to go. Sql queries using install scripts are not an issue. If you need them linked to an entity then always put them in the resource model and never somewhere else. And use the Magento native methods and never direct raw sql Jun 3, 2016 at 22:20

1 Answer 1

2

Two options:

If you want to run it only one time

  • sql script if it is database changing code
  • data script if it is a content changing script

If it runs more often than once

cronjob

4
  • Do most people create new modules from scratch or touch on already existing ones? I'm only going to run it one time to give customers this new attribute Jun 6, 2016 at 18:22
  • ALWAYS create your own module NEVER touch other modules. If you do you are not able to update them ever again (as in: take the pain now, not later) Jun 6, 2016 at 18:51
  • Alright I upvoted your answer thank you! If possible do you know of any good examples of code I can look over? By sql/data scripts am I running actual SQL code somewhere in my custom module? Jun 6, 2016 at 18:55
  • Inchoo is a great resource for such things: inchoo.net/magento/… Jun 7, 2016 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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