0

I'm new to php and opencart. but was planning to set my online store. I was creating an option of selecting a delivery time slot in check out page in opencart. As shown in the picture below :

enter image description here

So, I started to write a vqmod t achive this but stuck on how to store the value in database : My xml looks like this :

<modification>
<id>Salutation Field Modification</id>
<version>1</version>
<vqmver>1.0.8</vqmver>
<author>maca</author>
<file name="catalog/view/theme/bigshop/template/checkout/shipping_method.tpl">
    <operation>
        <search position="before"><![CDATA[
            <p><?php echo $text_shipping_method; ?></p>
        ]]></search>
        <add><![CDATA[
            <p><?php echo $text_shipping_timeslot; ?></p>
            <table class="radio">

      <tr>
        <td colspan="3"><b><?php echo "Delivery time slot"; ?></b></td>
      </tr>
      <tr class="highlight">
        <td>
          <input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_one; ?></" id="morning?>" checked="checked"/><?php echo $ship_slot_one; ?></br>
          <input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_two; ?></" id="afternoon?>"/><?php echo $ship_slot_two; ?></br>
          <input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_three; ?></" id="evening?>"/><?php echo $ship_slot_three; ?></br>
          <input type="radio" name="shipping_timeslot" value="><?php echo $ship_slot_four; ?></" id="night?>"/><?php echo $ship_slot_four; ?></br>
        </td>
      </tr>
      <tr>
        <td colspan="3"></td>
      </tr>
      </table>
        ]]></add>
    </operation>
</file>
<file name="catalog/language/english/checkout/checkout.php">
    <operation>
        <search position="before"><![CDATA[
            $_['text_shipping_method']           = 'Please select the preferred shipping method to use on this order.';
        ]]></search>
        <add><![CDATA[
            $_['text_shipping_timeslot']           = 'Please select the preferred shipping time slot.';
            $_['ship_slot_one']           = 'Morning';
            $_['ship_slot_two']           = 'Afternoon';
            $_['ship_slot_three']           = 'Evening';
            $_['ship_slot_four']           = 'Night';
        ]]></add>
    </operation>
</file>

   <file name="catalog/controller/checkout/shipping_method.php">
       <operation>
           <search position="before"><![CDATA[
               $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
           ]]></search>
           <add><![CDATA[
               $this->data['text_shipping_timeslot'] = $this->language->get('text_shipping_timeslot');
               $this->data['ship_slot_one'] = $this->language->get('ship_slot_one');
               $this->data['ship_slot_two'] = $this->language->get('ship_slot_two');
               $this->data['ship_slot_three'] = $this->language->get('ship_slot_three');
               $this->data['ship_slot_four'] = $this->language->get('ship_slot_four');
           ]]></add>
       </operation>

   </file>

</modification>

Please guide me.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Arun Kumar K S
  • 139
  • 1
  • 3
  • 13
  • 1
    For starters, look at the code (HTML) that this produces - does it even compile/parse? It doesn't look like you close your `` tags very well... (You have a `>` right after you start `value="` - how is that supposed to work? ) How did you set the variables `$ship_slot_one` etc? – Floris Jan 05 '14 at 20:37
  • hi Floris, I was just trying to do something like shown in the image. This looks fine in checkout page. Now I m stuck in getting the value of selected input and store the same in db – Arun Kumar K S Jan 05 '14 at 20:46

2 Answers2

1

As Floris mentioned - there is > sign in the value part of the inputs which is incorrect I guess. Also it is better to put the label of the input into a real HTML label so that checkbox/radio is checked when clicking on that label (it is not very comfortable to have to click on small checkbox/radio directly).

Now to Your saving problem: I'd suggest creating a new DB column in table order called shipping_time_slot and of type enum('opt1', 'opt2', 'etc.'). Here You will store Your selected shipping time slot.

Now for the controller, You'd have to modify (by vQmod) the catalog/controller/checkout/shipping_method.php (additionally You should do the very same modifications for Guest checkout - different files apply) and receive the shipping_timeslot value from the POST and save it into the session along with all other shipping information.

Finally (but not really) You will have to modify the model catalog/model/checkout/order.php and method addOrder() to save the shipping_timeslot value into the database.

That should be just for storing into database.

But You should keep in mind that You should also extend the backend (administration) to be able to load the shipping_timeslot value from database and to display them within the order details - this means modifications of at least these files:

  • admin/controller/sale/order.php
  • admin/model/sale/order.php (maybe not needed)
  • admin/language/<YOUR_LANG>/sale/order.php - add new translation for shipping_timeslot
  • admin/view/template/sale/order_info.tpl and admin/view/template/sale/order_form.tpl
shadyyx
  • 15,825
  • 6
  • 60
  • 95
  • Thanks for the reply..... let me try to do what u have explained.... seems complicated... this should be a learning curve : – Arun Kumar K S Jan 09 '14 at 21:28
  • This definitely is a learning curve, but the best I can give You (just kick You, not give You the end solution - so that You have to do it all by Yourself - so that You will learn the most that is possible). – shadyyx Jan 10 '14 at 09:28
  • `addOrder()` method is the model's method. It should receive the `POST`ed data directly from controller. Does MVC pattern mean anything to you? – shadyyx Feb 10 '15 at 09:59
  • yup thanx buddy got it :) now the task is how to fetch that value from Admin :( – Amol Navsupe Feb 10 '15 at 11:13
1
  Here is full solution....
  Open file..
        /*** TIME SLOT OPENCART CODING ***/

        C:\wamp\www\OC\catalog\controller\checkout\shipping_method.php

        1)
        Find :- 
        $this->session->data['comment'] = strip_tags($this->request->post['comment']);

        After that copy and paste :-
        $this->session->data['shipping_timeslot'] = $this->request->post['shipping_timeslot'];
        -------------------------------------------------------------------------------------------------------------
        2)
        Find :- 
        $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');

        After that copy and paste :-
        $this->data['text_shipping_timeslot'] = $this->language->get('text_shipping_timeslot');
        $this->data['ship_slot_one'] = $this->language->get('ship_slot_one');
        $this->data['ship_slot_two'] = $this->language->get('ship_slot_two');
        $this->data['ship_slot_three'] = $this->language->get('ship_slot_three');
        $this->data['ship_slot_four'] = $this->language->get('ship_slot_four');
        -------------------------------------------------------------------------------------------------------------
        3)
        Find :- 
        if (isset($this->session->data['comment'])) {
        $this->data['comment'] = $this->session->data['comment'];
        } else {
        $this->data['comment'] = '';
        }

        After that copy and paste :-
        if (isset($this->session->data['shipping_timeslot'])) {
        $this->data['shipping_timeslot'] = $this->session->data['shipping_timeslot'];
        } else {
        $this->data['shipping_timeslot'] = '';
        }
        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\catalog\model\checkout\order.php

        1)
        Find :-
        commission = '" . (float)$data['commission'] . "'

        After that copy and paste :-
        shipping_time_slot = '" . $this->db->escape($data['shipping_timeslot']) . "',

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\catalog\language\english\checkout\checkout.php

        1)
        Find :-
        $_['text_length']

        After that copy and paste :-
        $_['text_shipping_timeslot']           = 'Please select the preferred shipping time slot.';
        $_['ship_slot_one']           = 'Morning';
        $_['ship_slot_two']           = 'Afternoon';
        $_['ship_slot_three']           = 'Evening';
        $_['ship_slot_four']           = 'Night';

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\catalog\view\theme\vitalia\template\checkout\shipping_method.tpl

        1)
        Find :-
        <p><?php echo $text_shipping_method; ?></p>

        Above that copy and paste :-
        <p><?php echo $text_shipping_timeslot; ?></p>
        <table class="radio">

            <tr>
                <td colspan="3"><b><?php echo "Delivery time slot"; ?></b></td>
            </tr>
            <tr class="highlight">
                <td>
                    <input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_one; ?>" id="morning" checked="checked"/><?php echo $ship_slot_one; ?></br>
                    <input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_two; ?>" id="afternoon"/><?php echo $ship_slot_two; ?></br>
                    <input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_three; ?>" id="evening"/><?php echo $ship_slot_three; ?></br>
                    <input type="radio" name="shipping_timeslot" value="<?php echo $ship_slot_four; ?>" id="night"/><?php echo $ship_slot_four; ?></br>
                </td>
            </tr>
            <tr>
                <td colspan="3"></td>
            </tr>
        </table>

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\admin\controller\sale\order.php

        1)
        Find :-
        $this->data['store_url'] = $order_info['store_url'];

        Above that copy and paste :-
        $this->data['shipping_time_slot'] = $order_info['shipping_time_slot'];
        -------------------------------------------------------------------------------------------------------------

        2)
        Find :- May be line no. 1580
        $this->data['comment'] = nl2br($order_info['comment']);

        Below that copy and paste :-
        $this->data['shipping_time_slot'] = $order_info['shipping_time_slot'];

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\catalog\controller\checkout\confirm.php

        1)
        Find :-
        $data['comment'] = $this->session->data['comment'];

        Below that copy and paste :-
        $data['shipping_timeslot'] = $this->session->data['shipping_timeslot'];

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\admin\language\english\sale\order.php

        1)
        Find :-
        $_['text_store_name']                         = 'Store Name:';

        Below that copy and paste :-
        $_['text_time_slot']                           = 'Time Slot:';

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\admin\view\template\sale\order_info.tpl

        1)
        Find :-
        <tr>
            <td><?php echo $text_store_name; ?></td>
            <td><?php echo $store_name; ?></td>
        </tr>

        Below that copy and paste :-

        <tr>
            <td><?php echo $text_time_slot; ?></td>
            <td><?php echo $shipping_time_slot ?></td>
        </tr>

        -------------------------------------------------------------------------------------------------------------
        -------------------------------------------------------------------------------------------------------------

        C:\wamp\www\OC\admin\model\sale\order.php

        1)
        Find :-
        'date_modified'           => $order_query->row['date_modified']

        Below that copy and paste :-
        ,
                                        'shipping_time_slot'           => $order_query->row['shipping_time_slot']

        -------------------------------------------------------------------------------------------------------------
                                                                THATS IT
        -------------------------------------------------------------------------------------------------------------
Amol Navsupe
  • 172
  • 1
  • 11