简体   繁体   中英

Can't add new model to opencart

I a, trying to implement a modification to the registration process in opencart. I have modified the form in the view and the values are posted to the account/customer.php model in which I have added some code to process my new fields as shown below:

/* add children and links to product categories */
    $this->load->model('account/children');
    //loop childrens names to use key for remaining info
    foreach($data['children-name'] as $key=>$name){
        //re-assign data and purify
        $child['name'] = mysql_real_escape_string($name);
        $child['surname'] = mysql_real_escape_string($data['children-surname'][$key]);
        $child['gender'] = mysql_real_escape_string($data['children-gender'][$key]);
        $child['dob'] = mysql_real_escape_string($data['children-dob'][$key]);
        $child['school'] = mysql_real_escape_string($data['children-school'][$key]);
        $child['unit'] = mysql_real_escape_string($data['children-unit'][$key]);
        $child['height'] = mysql_real_escape_string($data['children-height'][$key]);
        $child['chest'] = mysql_real_escape_string($data['children-chest'][$key]);
        $child['waist'] = mysql_real_escape_string($data['children-waist'][$key]);
        $child['waistToKnee'] = mysql_real_escape_string($data['children-waist-to-knee'][$key]);
        $child['insideLeg'] = mysql_real_escape_string($data['children-inside-leg'][$key]);
        $child['shoeSize'] = mysql_real_escape_string($data['children-shoe-size'][$key]);
        $child['customerId'] = $customer_id;

        //update/create child record
        $this->model_account_children->addChild($child);
    }
    /* end add children and links to product categories */

I then created the relative model file in account/children.php in which has the following code:

class ModelAccountChildren extends Model {
    public function addChild($data) {
        //create other fields not in $data
        $lastUpdated = date('Y-m-d h:i:s');
        $childCat = getChildCategory($data['school']);
        $dob = date('Y-m-d h:i:s', $date['dob']);
        if($data['gender'] == 'm'){
            $data['gender'] = 'Male';
        }else{
            $data['gender'] = 'Female';
        }
        echo "INSERT INTO " . DB_PREFIX . "customer_children (customer_id, child_name, child_surname, child_gender, child_dob, category_id, child_school, child_unit, child_height, child_chest, child_waist, child_waist_to_knee, child_inside_leg, child_shoe_size, child_last_updated) VALUES (".$data['customerId'].", '".$data['name']."', '".$data['surname']."', '".$data['gender']."', '".$dob."', ".$childCat['category_id'].", '".$data['school']."', '".$data['unit']."', '".$data['unit']."', '".$data['height']."', '".$data['chest']."', '".$data['waist']."', '".$data['waistToKnee']."', '".$data['insideLeg']."', '".$data['shoeSize']."', '".$lastUpdated."')";
        //perform insert
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer_children (customer_id, child_name, child_surname, child_gender, child_dob, category_id, child_school, child_unit, child_height, child_chest, child_waist, child_waist_to_knee, child_inside_leg, child_shoe_size, child_last_updated) VALUES (".$data['customerId'].", '".$data['name']."', '".$data['surname']."', '".$data['gender']."', '".$dob."', ".$childCat['category_id'].", '".$data['school']."', '".$data['unit']."', '".$data['unit']."', '".$data['height']."', '".$data['chest']."', '".$data['waist']."', '".$data['waistToKnee']."', '".$data['insideLeg']."', '".$data['shoeSize']."', '".$lastUpdated."')");
    }

    public function updateChild($data) {

    }

    public function getChildCategory($childSchoolStr){
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_description WHERE name LIKE '" . $childSchoolStr . "'");

        return $query->row;
    }
}

For some reason the script is not getting access to the new model at the point I call it in model/account/customer.php on the line:

$this->load->model('account/children');

Am I doing something wrong?

Worked it out chaps.

$childCat = getChildCategory($data['school']);

Bit of a brain lapse, line above should be:

$childCat = $this->getChildCategory($data['school']);

It seems correct to me. You can use it within model. Do you use vqmod? Try deleting cache files. Maybe add a test function to your model and see you can call it. What is the error you get?

Have you definitely put the file in catalog/model/account/children.php ? If so, do you get any error messages at all that would help debug this? Also, when you run the code, are you certain that $data['children-name'] contains data?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM