Advertisement:

Author Topic: I would like to add new fields and also remove some.  (Read 1665 times)

Zacdaniel

  • Full Member
  • ***
  • Posts: 115
  • Why, Yes I'm a white african haha...
I would like to add new fields and also remove some.
« on: February 11, 2016, 03:10:02 pm »
Hi

I have absolutely no idea how to do this.
I have no experience on changing all of this different coding.

Where would I start in customising this plugin, I would like to add different fields in and also remove some like transmission, gears, amount of doors etc.

If anyone can help me on how to do this as I looked at the other posts on here but can't really find something posted on here on how to edit these fields.

Thanks

envmar

  • Newbie
  • *
  • Posts: 8
Re: I would like to add new fields and also remove some.
« Reply #1 on: February 24, 2016, 05:01:25 am »
I'm new to OSClass and how things are done but you'll need to touch on several files and update your MySQL database.

If you're just removing and adding some of the basic fields like transmission, gears, doors then some of the files, from what I can see, that you would be working with are:

oc-content/plugins/cars_attributes/index.php
oc-content/plugins/cars_attributes/item_detail.php
oc-content/plugins/cars_attributes/item_edit.php
oc-content/plugins/cars_attributes/ModelCars.php
oc-content/plugins/cars_attributes/search_form.php

and the MySQL table you would be dealing with: oc_t_item_car_attr

So, for example to permanently remove the transmission field you could:

1) Remove transmission code from item_detail.php:
- Around line 41 remove the following code:
Code: [Select]
                case 'transmission':
                    if( $value == 'AUTO' || $value == 'MANUAL' ) {
                        Search::newInstance()->addConditions(sprintf("%st_item_car_attr.e_transmission = '%s'", DB_TABLE_PREFIX, $value));
                        $has_conditions = true;
                    }
                break;

- Around line 241 remove the line:
Code: [Select]
        Session::newInstance()->_setForm('pc_transmission', Params::getParam("transmission"));
- Around line 261 remove the line:
Code: [Select]
        Session::newInstance()->_keepForm('pc_transmission');
- Around line 296 remove the line:
Code: [Select]
            'transmission'  => Params::getParam("transmission"),
2) Remove transmission references from item_detail.php:
- Around line 70 you'll remove the code:
Code: [Select]
    <?php if( !empty($detail['e_transmission']) ) { ?>
    <tr>
        <?php $transmission = array('MANUAL' => __('Manual''cars_attributes'), 'AUTO' => __('Auto''cars_attributes')); ?>
        <td width="150px"><label><?php _e('Transmission''cars_attributes'); ?></label></td>
        <td width="150px"><label><?php echo $transmission[$detail['e_transmission']]; ?></td>
    </tr>
    <?php ?>

3) Remove from item_edit.php:
- Around line 186 remove the code:
Code: [Select]
    <div class="row _200">
        <?php
            
if( Session::newInstance()->_getForm('pc_transmission') != '' ) {
                
$detail['e_transmission'] = Session::newInstance()->_getForm('pc_transmission');
            }
        
?>

        <label><?php _e('Transmission''cars_attributes'); ?></label>
        <select name="transmission" id="transmission">
            <option value="MANUAL" <?php if(@$detail['e_transmission'] == 'MANUAL') { echo 'selected'; } ?>><?php _e('Manual''cars_attributes'); ?></option>
            <option value="AUTO" <?php if(@$detail['e_transmission'] == 'AUTO') { echo 'selected'; } ?>><?php _e('Auto''cars_attributes'); ?></option>
        </select>
    </div>

4) Remove from ModelCars.php:
- Around line 465 remove the line:
Code: [Select]
                'e_transmission'    => $arrayInsert['transmission'],
5) Remove from search_form.php:
- Around line 74 remove the code:
Code: [Select]
    <div class="row one_input">
        <?php $transmission Params::getParam('transmission') ; ?>
        <h6 for="transmission"><?php _e('Transmission''cars_attributes'); ?></h6>
        <input style="width:20px;" type="radio" name="transmission" value="MANUAL" id="manual" <?php if($transmission == 'MANUAL') { echo 'checked="yes"'; } ?>/> <label for="manual"><?php _e('Manual''cars_attributes'); ?></label><br />
        <input style="width:20px;" type="radio" name="transmission" value="AUTO" id="auto" <?php if($transmission == 'AUTO') { echo 'checked="yes"'; } ?>/> <label for="auto"><?php _e('Automatic''cars_attributes'); ?></label>
    </div>

6) Remove occurrences of "transmission" from language files (use a language editor and remove the entries, probably work fine if you don't though).

7) After everything is edited you can test. If everything is working good then you can drop the field from the database (or not, shouldn't hurt to keep it, just not as clean):
     - In phpMyAdmin you would select the table: oc_t_item_car_attr then select the checkbox next to the field "e_transmission" then click "Drop".
     - In MySQL console it would be: 'ALTER TABLE oc_t_item_car_attr DROP e_transmission;'


To remove other fields it would be the same idea. Adding would touch on all those same files.

NOTE / DISCLAIMER:

I haven't tested these steps. If you try then make sure you back up those files and the database before you do it. Also there's bender theme specific files in the plugin that have these fields. You may need to modify those if you're using bender. Maybe someone else can chime in.

This is just a guide to help you get a feel for things. If you plan to tackle it then make a list of all the fields you want to remove and a list of what you want to add (plus the field types). Then, do things one small step at a time. IMO it's easier to remove one field then test, then move on to the next. Then add one field and test then move on to the next, ect. Best not to do this on your live site either.

Hope it helps and good luck.