0

I need to save data to a custom table.

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Npm_Commission>
            <version>0.1.0</version>
        </Npm_Commission>
    </modules>
    <global>
        <events>
            <sales_order_place_after>
                <observers>
                    <npm_commission_model_observer>
                        <type>singleton</type>
                        <class>Npm_Commission_Model_Observer</class>
                        <method>calculateCommission</method>
                    </npm_commission_model_observer>
                </observers>
            </sales_order_place_after>
        </events>
        <models>
            <npm_commission>
                <class>Npm_Commission_Model</class>
                <resourceModel>commission_mysql4</resourceModel>
            </npm_commission>
            <commission_mysql4>
                <class>Npm_Commission_Model_Mysql4</class>
                <entities>
                    <commission>
                        <table>commission</table>
                    </commission>
                </entities>
            </commission_mysql4>
        </models>
        <resources>
            <commission_setup>
                <setup>
                    <module>Npm_Commission</module>
                      <!-- <class>Npm_Commission_Model_Mysql4_Commission</class> -->
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </commission_setup>
            <commission_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </commission_write>
            <commission_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </commission_read>
        </resources>
    </global>
</config>

DATA

$insertData = array(
            'order_id' => $orderId,
            'transaction_id' => $transaction_id,
            'foundation_id' => $foundation_id,
            'mano_admin_fees' => $manoAdminFees,
            'mano_promotion_fees' => $manoPromoFees,
            'paypal_fees' => $payPalFees,
            'foundation_fees' => $foundationFees,
            'created_at' => $created_at
            );

Insert code

$collectionSet = Mage::getModel('commission/commission');
            $collectionSet->setData($insertData)->save();

custom table install script

<?php
$installer = $this;
$installer->startSetup();
$installer->run("DROP TABLE IF EXISTS {$installer->getTable('commission')};
CREATE TABLE {$installer->getTable('commission')} (
  `id` int(11) unsigned NOT NULL auto_increment,
  `order_id` int(11) NOT NULL,
  `transaction_id` int(11) NOT NULL,
  `foundation_id` int(11) NOT NULL,
  `mano_admin_fees` decimal(10,2) NOT NULL,
  `mano_promotion_fees` decimal(10,2) NOT NULL,
  `paypal_fees` decimal(10,2) NOT NULL,
  `foundation_fees` decimal(10,2),
  `created_at` datetime,
  PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();

I am getting error

Fatal error: Call to a member function setData() on a non-object in 
1
  • Did you create model commission/commission in Magento? Post module config.xml, and all model files :) Commented Jun 23, 2014 at 8:38

1 Answer 1

2

It should be

$collectionSet = Mage::getModel('npm_commission/commission');

EDIT:

There should be npm too. The problem for me is that Magento don't have proper model config.

        <npm_commission_mysql4>
            <class>Npm_Commission_Model_Mysql4</class>
            <entities>
                <commission>
                    <table>commission</table>
                </commission>
            </entities>
        </npm_commission_mysql4>

Some links: http://www.pixafy.com/blog/2013/04/creating-a-magento-custom-model/ http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics

2
  • It gives new error Fatal error: Call to a member function beginTransaction() on a non-object in Commented Jun 23, 2014 at 9:02
  • I've edited my comment, problem is wrong module configuration for me ;) Commented Jun 23, 2014 at 9:17

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.