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

  • SEARCH
  • Home
  • 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 8696927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:23:19+00:00 2026-06-13T01:23:19+00:00

Hello my model save() function doesnt work. Magento cache turned off. My code below:

  • 0

Hello my model save() function doesnt work. Magento cache turned off. My code below:

$newInventory = Mage::getModel('reservation/newinventory');
Mage::log( get_class( $newInventory ) ); //print Apptha_Reservation_Model_Newinventory

$newInventory->setEntityId( $productId ); 
$newInventory->setRoomTypeId( $roomTypeId );
$newInventory->setRoomsCount( $roomsCount );
$newInventory->setDateFrom( $checkInStamp );
$newInventory->setDateTo( $checkOutStamp );
$newInventory->setOrderId( $orderId );

$query = $newInventory->save();

Mage::log( "save query below: " ); //I get this string
Mage::log( $query->toString() ); //return 2012-10-15T06:00:58+00:00 DEBUG (7): 17, 7, 8,
                                //1349913600, 1349913600, 300000040, 12

This is my code\local\Apptha\Reservation\etc\config.xml

 <models>
        <reservation>
            <class>Apptha_Reservation_Model</class>
            <resourceModel>reservation_mysql4</resourceModel>
        </reservation>
        <reservation_mysql4>
            <class>Apptha_Reservation_Model_Mysql4</class>
            <entities>
               <newinventory>
        <table>apptha_booking_hotel_newinventory</table>
       </newinventory>
            </entities>
        </reservation_mysql4> 
</models> 
    <resources>
        <reservation_setup>
            <setup>
                <module>Apptha_Reservation</module>
                <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </reservation_setup>
        <reservation_write>
            <connection>
                <use>core_write</use>
            </connection>
        </reservation_write>
        <reservation_read>
            <connection>
                <use>core_read</use>
            </connection>
        </reservation_read>
    </resources>

What I make wrong? Why new row doesnt appear in db?

UPDATE 1

In my index.php I have

error_reporting(E_ALL ^ E_NOTICE);

//if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
ini_set("display_errors", 1);
//}

UPDATE 2

My code\local\Apptha\Reservation\Model\newinventory.php below

class Apptha_Reservation_Model_Newinventory extends Mage_Core_Model_Abstract{

protected function _construct(){
    $this->_init('reservation/newinventory');
}
}

My code\local\Apptha\Reservation\Model\Mysql4\newinventory.php below

 class Apptha_Reservation_Model_Mysql4_Newinventory extends Mage_Core_Model_Mysql4_Abstract{

protected function _construct(){
    $this->_init('reservation/newinventory', 'id');
}

}

So I dont get any errors from Magento. It looks like Magento find all pathes (model, resource and etc.) But anyway can’t save() my data.

UPDATE 3
I inserted code to log queries in Mysql.php to public function query($sql, $bind = array())

    $code = 'SQL: ' . $sql . "\r\n";
if ($bind) {
    $code .= 'BIND: ' . print_r($bind, true) . "\r\n";
}
Mage::Log("[".date('Y-m-d H:i:s')."] ".$code);

Then I get in log file:

2012-10-15T09:54:31+00:00 DEBUG (7): [2012-10-15 09:54:31] SQL: INSERT INTO 
`apptha_booking_hotel_newinventory` (`entity_id`, `room_type_id`, `rooms_count`, `date_from`,
`date_to`, `order_id`) VALUES (?, ?, ?, ?, ?, ?)
BIND: Array
(
[0] => 17
[1] => 7
[2] => 8
[3] => 1349913600
[4] => 1349913600
[5] => 300000040
)

I try manually execute this query in phpmyadmin, It`s working fine. But Magento can’t make it.

UPDATE 4

okay. While I was debuging this issue, I have written additional testModel action in the controller where tried to test save() function. I saw, It worked there.

Then I returned to originally function and discovered when I make save() outside of if-block then save() works fine. if I make save() inside if-block,then it doesn’t work.

I log some string inside if-block and make sure, execution go inside if-block. So actually question why save() doesn’t work inside if-block below:

    if ( $state == "complete" ){
    Mage::log('here');
        $newInventory = Mage::getModel('reservation/newinventory');
        $newInventory->setEntityId(12);
        $newInventory->setRoomTypeId(7);
        $newInventory->setRoomsCount(8);
        $newInventory->setDateFrom(1349913600);
        $newInventory->setDateTo(1349913600);
        $newInventory->setOrderId(300000040);

        $query = $newInventory->save();
    die;
   } 

but if condition will be

if ( $state === "processing" )

then It works fine. This code are in observer function when order status is changed. When admin make “invoice” for product, producr state is changed from “processing” to “complete”. Thefore Magento go into the function two times. First time on “processing” save() working fine but on “complete” It doesn’t work.

  • 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-13T01:23:20+00:00Added an answer on June 13, 2026 at 1:23 am

    So problem is in some internal Magento processing. I have spent 1 day to understand it.

    But Stop now and solved it by using another observer event sales_order_save_commit_after where I check order state is completed and use save() function. And sure here It works fine.

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

Sidebar

Related Questions

Hello! It is happening a very weird thing when I save a model in
Hello I have a user model and a ratings model. Whenever a new user
Hello I`ve created simple WFC DataService and connected entit model with my database. This
Hello my problem is i try to save a new relation between a shop
hello for my app I need to save a record that the user type,
Hello i'm working on a blog app and I have a model: class Post(models.Model):
. Hello, I have the following code to set the re-ordering of the tableView.
I've the following model and I want to execute a method on save and
I have code that is inside my Activity class to load and save a
Hello i'm trying to understand how sessions work and how does session_set_handler() works, so

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.