Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:14:15+00:00 2026-06-06T07:14:15+00:00

I am working on a module for Magento which involves taking the total price

  • 0

I am working on a module for Magento which involves taking the total price for every order submitted and storing it in an SQL table. My first instinct would be to use raw SQL commands to do so, but according to most of the Magento articles I have read so far on the topic, it seems I am supposed to ues Magento/Zend classes to do this instead.

How would I access the SQL database with Magento classes and what are the advantages of doing so instead of just using raw SQL commands?

All help is greatly appreciated and I always accept an answer!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:14:16+00:00Added an answer on June 6, 2026 at 7:14 am

    The answer on question “why is usage of ORM/ActiveRecord better than raw SQL” is the same as for “Why do i need to use MVC or programming patterns?”. It’s a bit philosophical questions, so a lot of answers on them you can find using Google.

    You must create business and resource models. Also you need to assign resource model to business one using config.xml file in you module etc folder and also in _construct methods of each model’s classes.

    For example, you have a business class with My_Module_Model_Bussines and resource class My_Module_Model_Resource_Bussines. The smallest realization (and must be) of these classes are

    First One:

    class My_Module_Model_Business extends Mage_Core_Model_Abstract
    {
    
        protected function _construct()
        {
            $this->_init('my_module/business');
        }
    }
    

    Second:

    class My_Module_Model_Resource_Business extends Mage_Core_Model_Mysql4_Abstract
    {
        protected function _construct()
        {
            $this->_init('my_module/table', 'id');
        }
    }
    

    where the first parameter of method _init in each classes is an xpath in XML configuration, second one (in the resource class) is primary key name.

    Also in config.xml you must have something like this:

    <?xml version="1.0"?>
    <config>
        <modules>
            <My_Module>
                <version>YOUR_VERSION_OF_MODULE(e.g. 0.0.1)</version>
            </My_Module>
        </modules>
        <global>
            <models>
                <my_module>
                    <class>My_Module_Model</class>
                    <!-- name of the resource model node -->
                    <resourceModel>my_module_resource</resourceModel>
                </my_module>
                <my_module_resource>
                    <class>My_Module_Model_Resource</class>
                    <entities>
                        <table>
                            <table>your_table_name</table>
                        </table>
                    </entities>
                </my_module_resource>
            </models>
        <!-- another config nodes -->
        </global>
    </config>
    

    After that you may use something like this:

    Mage::getModel('my_module/business')->setFirstField('some data')
       ->setTotal('100.1')
       ->setOrderId(10)
       ->save();
    

    If you use newer version of Magento than 1.5.1 you will need to change Mysql4 in class names to Resource

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im working on a custom admin module for magento, and trying to learn the
Had received a module from CCAVENUE and it was working fine with Magento 1.6.2...
I'm currently working on a custom module in which I have a controller extending
I am working on a new payment module for Magento and have come across
I am working in a new Filter by Product module in Magento, i have
I am new to Magento. I need two table in my custom module and
I am working on a module which is common for a number of forms.
I see there are some people that got Amazon’s payment module working w/ Magento
I am working on a Magento module that has a Form where a user
I am working on a magento admin module and currently I am running a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.