Search code examples
mysqlmagentoormmodelupdatemodel

How to get data on magento model based on phone number?


I want to edit magento custom table based upon phone number and status search, i am not sure how to do it this in magento model architecture. Please help me. I found some update queries with load id but i want to load data using customer phone number, and then do an data update.

$phone="12345678";
    $collection = Mage::getModel('customer/customer')->getCollection()
                    ->addFieldToFilter('phone', $phone);
            //return $collection->getFirstItem();
            $id = $collection->getFirstItem();
            $u_id = $id["entity_id"];

Solution

  • $existingUser = Mage::getModel("supportticket/supportticketadminusersession")->getCollection()
                            ->addFieldToFilter('user_phnumber', $user["phone_number"]);
    $existingId = $existingUser->getFirstItem()->getId();
    $data = array(
                        'customer_phnumber' => "",
                        'user_status' => 0,
                        'created_time' => $date,
                        'updated_time' => ""
                        );
                    $updateCollection = Mage::getModel("supportticket/supportticketadminusersession")->load($existingId)->addData($data);
    $updateCollection->save();