0

Here is my code:

if ($user->isLoggedIn()) {

            $userinfo = $user->getCustomer();
            $userid = $userinfo->getId();
            $username = $userinfo->getEmail();
            $userfullname = $userinfo->getName();
            Mage::log(
                    "{$userid},{$username},{$userfullname}\n",
                    null,
                    'product-updates.log'
                );
            $up_id = intval($userinfo->getId().$product->getId()."");
            $data = array(
                        'click_time' => date("Y-m-d H:i:s"),
                        'product_id' => $product->getId(),
                        'product_name' => $product->getName(),
                        'product_category' => $category,
                        'product_value' => $product->getPrice(),
                        'user_id' => $userid,
                        'username' => $username,
                        'fullname' => $userfullname,
                        'firstname' => $userinfo->getFirstname(),
                        'middlename' => $userinfo->getMiddlename(),
                        'lastname' => $userinfo->getLastname(),
                        'register_time' => $userinfo->getCreatedAt(),
                        'up_id' => $up_id
                    );
            $model = Mage::getModel('modulename/modelName')->load($up_id,'up_id')->addData($data);
            try {
                $insertId = $model->save()->getId();
            } catch (Exception $e){
            }
}

Points:

-> product-updates.log file logs everything correctly with username (email) and full name of the customer.

-> on saving to database, product_id , and all fields successfully save except for customer name, customer middle, first and last name and register_time.

-> No errors in system.log, no exceptions in exception.log

-> Logs are enabled and cache is disabled.

Problem:

So problem is that I am not able to save customer name, even though it is being displayed in the product-log file correctly. Also there are no syntax errors or any other error because other fields are getting saved to the database.

Edit: My database structure:

username    varchar(200)
fullname    varchar(200)
firstname   varchar(200)
middlename  varchar(200)
lastname    varchar(200)
3
  • Did you clear the cache? Even if your cache is disabled, the table schema is cached by ZF and maybe a cached older version is used in order to determine what fields need to be inserted/updated. Commented Oct 23, 2015 at 7:53
  • Is Mage::getModel('modulename/modelName')->load($up_id,'up_id') actually loading a record? Also I see a lot more fields in the data array vs your table structure Commented Oct 23, 2015 at 7:59
  • @Marius cache was the problem, yup. Flushed cache from the script itself, then it worked. Thankyou for hint. Commented Oct 23, 2015 at 8:55

2 Answers 2

0

Based on the comments....
the cache should be cleared.
Even if the cache is disabled, ZF still caches the table schemas and these schemas are used when saving entities in the tables.

0

This fixed the problem:

Mage::app('admin');
Mage::app()->getCacheInstance()->flush();

Posting an answer, incase someone googles through this.

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.