Jump to content

ewsoares

Member
  • Posts

    3
  • Joined

  • Last visited

Everything posted by ewsoares

  1. And remember my posted code only replaces the following portion of what IZGHITU posted. You still need the whole code he posted replacing only below with what I posted if($_REQUEST['getAll'] == '1') { if($_REQUEST['userid'] != '') { $all = Capsule::table('tblcustomfieldsvalues') ->join('tblhosting', 'tblcustomfieldsvalues.relid', '=', 'tblhosting.id') ->where('fieldid', $customfieldId ) ->where('userid', $_REQUEST['userid'] ) ->get(); }else { $all = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $customfieldId)->get(); } $all = json_decode( json_encode( $all ) , true ); $newAll = []; foreach($all as $a) { $newAll[$a['relid']] = $a['value']; } ob_clean(); echo json_encode(array( "all" => $newAll )); die; }
  2. Off the top of my head I think you may not have created your custom fields or added the custom field name into the code. See below and let us know if this was it to help someone else who stumbles upon this thread please. ->where('tblcustomfields.type','product') ->where('tblcustomfields.fieldname','Location Name') <--- The name you named your custom field that you added to a PRODUCT. See line above as it is PRODUCT type as opposed to I think CUSTOMER custom fields. ->where('tblcustomfields.fieldtype','text') <--- The type of custom field you added, currently set to text field, can use drop down, etc. Check DataBase to be sure what these field types are called.
  3. I wanted to give back for this brilliant piece of code IZGHITU provided that helped me tremendously. The problem I faced is that I needed this coded to work for multiple products utilizing the same custom field name and his code snippet was hard coded for one product. I am not that great but a couple hours later it is dynamic for multiple products. Just change the 'fieldname' in the first query to match your needs. You can also change 'fieldtype' and 'type' to further suit your needs. If anyone can provide constructive criticism I'd appreciate it but for now this works for me and for many products instead of just one even if you delete a product and add it again since it will find the id for us now. For me I wanted to see the Location Name in the admin area. if($_REQUEST['getAll'] == '1') { $newAll = []; $gotCustomFieldID = []; // Get fieldid for 'Location Name' for every product // Change 'Location Name' to suit your custom field needed $getCustomFieldID = Capsule::table('tblcustomfields') ->select('id') ->where('tblcustomfields.type','product') ->where('tblcustomfields.fieldname','Location Name') ->where('tblcustomfields.fieldtype','text') ->get(); foreach ($getCustomFieldID as $data) { $gotCustomFieldID[] = $data->id; } foreach ($gotCustomFieldID as $customFieldID) { $all = Capsule::table('tblcustomfieldsvalues') ->join('tblhosting', 'tblcustomfieldsvalues.relid', '=', 'tblhosting.id') ->where('fieldid', $customFieldID ) ->where('userid', $_REQUEST['userid'] ) ->get(); $all = json_decode( json_encode( $all ) , true ); foreach($all as $a) { $newAll[$a['relid']] = $a['value']; } } ob_clean(); echo json_encode(array( "all" => $newAll )); die; }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated