I am working on a custom app where customers will be able to virtually try on and potentially even buy my products via an iphone/android app.

I am currently working on mastering using the Magento2 API to pull in product information needed in the app.

However I am wondering what is the cons of just having my app connect to the Magento database directly to pull needed product information vs using the app?

are there benefits of using the magento app over directly querying the database assuming I know what tables and how to write the needed quires to pull all product data out of the magento database?

| improve this question | | | | |

There are many reasons to avoid direct connection to the database. The first, is SQL injection, and our good friend Bobby Tables (look it up :-)

Beyond that, there are SO many reasons. It might seem like the easier or clearer path for you right now, but I promise it will lead to an app that will end up failing in the end and probably not deal with Magento platform upgrades well either.

You'd be creating an absolute ton of unnecessary work for yourself. You'd need to conduct many table joins at the store scope level to pull in product and category attributes. For attributes that are of the type dropdown, multiselect, etc, the value is an integer or sometimes a comma separated list of integers. You'd need to know which attribute is which, how to parse the raw value, and how to extract the proper public facing label for the current store view.

The things I mentioned above are just the tip of the iceberg. Magento is an event-based system. What I mean is when you load a product, category, or any entity, or call a collection, those functions trigger other necessary events to happen in order to return the information you seek. But beyond that, Magento has spent years perfecting all of these queries and events which means you don't need to spend countless hours making it all work.

From first hand experience, the very first thing I built for Magento, many years ago at this point, exclusively used direct database queries. I got stuck in my version of Magento, the app STILL breaks, is difficult to work on, and is an absolute nightmare.

Anyways, I hope I did a half-decent job on talking you out of it. If you have any questions please let me know.

| improve this answer | | | | |

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.