0

Here is my test code trying to save data what I am getting in request, but it is not saving in table.

$json = '{  
   "isMobileConfirm":false,
   "cid":"85036",
   "managerid":"12345",
   "location":"12.961125000000001,77.64933166666667",
   "studentprofilepic":"studentprofilepic_1496989696628",
   "studentfrontpic":"studentfrontpic_1496989698785",
   "studentbackpic":"studentbackpic_1496989703275",
   "govtfrontpic":"govtfrontpic_1496989713175",
   "govtbackpic":"govtbackpic_1496989707848",
   "selfiepic":"selfiepic_1496989713394",
   "extrapic":[  
      {  
         "extra_imagepath":"extrapic_1496989714945",
         "extra_doctype":"Hostel Bill\/Receipt",
         "extra_docremark":"gvvg"
      }
   ],
   "loanpic":[  
      "LFA\/loanpic_1496989716375"
   ]
}';


  $student = Mage::getModel("customer/customer")->load(85036);
        // load cmupload
        $cmuploads = Mage::getModel("manager/cmuploads");
        // decode the json data into arrya
        $obj = json_decode($json,true);
        echo "<pre>";
        var_dump($obj);
        // check is array or not
        if(is_array($obj)){
            foreach ($obj as $key => $value) {
                echo $key;
                echo $value;
                                // if not array save data student pics
                if(!is_array($value)){
                    $cmuploads->setCustomerId(85036);
                    $cmuploads->setFileName('studentprofilepic_1496989696628');
                    $cmuploads->setFileFilekey('studentprofilepic');
                    $cmuploads->setManagerId($value->managerid);
                    $cmuploads->setStatus(1);
                    $cmuploads->setLocation($value->location);
                    $cmuploads->setCreatedDate(NOW());                               
                } else if(is_array($value)) {
                    // If it's array check its loan pic or extra pics

                }
            }
            try {
            $cmuploads->save();
         }
         catch(exception $ex2){
            echo "sa";
         }
        }else {
  • Can you please share the error while saving? – rajat kara Jun 13 '17 at 12:39
  • No error is coming it is saving , but only hardcoded one not others – supriya mishra Jun 13 '17 at 12:47
  • what to pass $cmuploads->setManagerId($value->managerid); instead of this. – supriya mishra Jun 13 '17 at 12:48
0

Please find the code below

$json = '{  
   "isMobileConfirm":false,
   "cid":"85036",
   "managerid":"12345",
   "location":"12.961125000000001,77.64933166666667",
   "studentprofilepic":"studentprofilepic_1496989696628",
   "studentfrontpic":"studentfrontpic_1496989698785",
   "studentbackpic":"studentbackpic_1496989703275",
   "govtfrontpic":"govtfrontpic_1496989713175",
   "govtbackpic":"govtbackpic_1496989707848",
   "selfiepic":"selfiepic_1496989713394",
   "extrapic":[  
      {  
         "extra_imagepath":"extrapic_1496989714945",
         "extra_doctype":"Hostel Bill\/Receipt",
         "extra_docremark":"gvvg"
      }
   ],
   "loanpic":[  
      "LFA\/loanpic_1496989716375"
   ]
}';

 $obj = json_decode($json,true);
  $student = Mage::getModel("customer/customer")->load($obj['cid']);
        // load cmupload
        $cmuploads = Mage::getModel("manager/cmuploads");
        // decode the json data into arrya


        // check is array or not
        if(is_array($obj)){

                    $cmuploads->setCustomerId($obj['cid']);


                    $cmuploads->setManagerId($obj['managerid']);

                    $cmuploads->setCreatedDate(NOW());                               

            }
            try {
            $cmuploads->save();
         }
         catch(exception $ex2){
            echo "sa";
         }
        }else {
  • but i need to save all parameters – supriya mishra Jun 13 '17 at 13:33
  • I have given 2-3 field as an example.Please do the same for other fields. – rajat kara Jun 13 '17 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.