<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name><![CDATA[<font color="#15c403"><b>Booking & Rental System</font>]]></name>
    <code>bookingSystem</code>
    <version>1.0</version>
    <author><![CDATA[<font color="#15c403"><b>Knowband</font>]]></author>

       <file path="catalog/controller/product/product.php" error="skip">
        <operation error="skip" info="">
            <search><![CDATA[if ($product_info['tag']) {]]></search>
            <add position="before"><![CDATA[
                $this->load->model('setting/setting');
                $kbbooking_data = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
                
		if(isset($kbbooking_data['kbbooking']['enable']) && $kbbooking_data['kbbooking']['enable']){
                    $data['kbbooking_data'] = $this->load->controller('kbbooking/kbbooking',$product_info);
                }
            ]]></add>
        </operation>
    </file>
    
    <file path="catalog/view/theme/*/template/product/product.twig" error="skip">
        <operation error="skip" info="">
            <search index="1"><![CDATA[ <div class="{{ class }}"> ]]></search>
            <add position="replace" offset="180"><![CDATA[
            <div class="{{ class }}">
                <div class="btn-group">
                    <button type="button" data-toggle="tooltip" class="btn btn-default" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product_id }}');"><i class="fa fa-heart"></i></button>
                    <button type="button" data-toggle="tooltip" class="btn btn-default" title="{{ button_compare }}" onclick="compare.add('{{ product_id }}');"><i class="fa fa-exchange"></i></button>
                </div>
                <h1>{{ heading_title }}</h1>
                {% if (kbbooking_data['booking_template'] is defined and kbbooking_data['booking_template'] != '') %} 
                    {{ kbbooking_data['booking_template'] }}
                {% else %} 
                    <ul class="list-unstyled">
                      {% if (manufacturer) %} 
                      <li>{{ text_manufacturer }} <a href="{{ manufacturers }}">{{ manufacturer }}</a></li>
                      {% endif %} 
                      <li>{{ text_model }} {{ model }}</li>
                      {% if (reward) %} 
                      <li>{{ text_reward }} {{ reward }}</li>
                      {% endif %} 
                      <li>{{ text_stock }} {{ stock }}</li>
                    </ul>
                    {% if (price) %} 
                    <ul class="list-unstyled">
                      {% if (not special) %} 
                      <li>
                        <h2>{{ price }}</h2>
                      </li>
                      {% else %} 
                      <li><span style="text-decoration: line-through;">{{ price }}</span></li>
                      <li>
                        <h2>{{ special }}</h2>
                      </li>
                      {% endif %} 
                      {% if (tax) %} 
                      <li>{{ text_tax }} {{ tax }}</li>
                      {% endif %} 
                      {% if (points) %} 
                      <li>{{ text_points }} {{ points }}</li>
                      {% endif %} 
                      {% if (discounts) %} 
                      <li>
                        <hr>
                      </li>
                      {% for discount in discounts %} 
                      <li>{{ discount['quantity'] }}{{ text_discount }}{{ discount['price'] }}</li>
                      {% endfor %} 
                      {% endif %} 
                    </ul>
                    {% endif %} 
                    <div id="product">
                      {% if (options) %} 
                      <hr>
                      <h3>{{ text_option }}</h3>
                      {% for option in options %} 
                      {% if (option['type'] == 'select') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <select name="option[{{ option['product_option_id'] }}]" id="input-option{{ option['product_option_id'] }}" class="form-control">
                          <option value="">{{ text_select }}</option>
                          {% for option_value in option['product_option_value'] %} 
                          <option value="{{ option_value['product_option_value_id'] }}">{{ option_value['name'] }} 
                          {% if (option_value['price']) %} 
                          ({{ option_value['price_prefix'] }}{{ option_value['price'] }})
                          {% endif %} 
                          </option>
                          {% endfor %} 
                        </select>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'radio') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label">{{ option['name'] }}</label>
                        <div id="input-option{{ option['product_option_id'] }}">
                          {% for option_value in option['product_option_value'] %} 
                          <div class="radio">
                            <label>
                              <input type="radio" name="option[{{ option['product_option_id'] }}]" value="{{ option_value['product_option_value_id'] }}" />
                              {% if (option_value['image']) %} 
                              <img src="{{ option_value['image'] }}" alt="{{ option_value['name'] ~ option_value['price'] ? ' ' ~ option_value['price_prefix'] ~ option_value['price'] : '' }}" class="img-thumbnail" /> 
                              {% endif %}                    
                              {{ option_value['name'] }} 
                              {% if (option_value['price']) %} 
                              ({{ option_value['price_prefix'] }}{{ option_value['price'] }})
                              {% endif %} 
                            </label>
                          </div>
                          {% endfor %} 
                        </div>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'checkbox') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label">{{ option['name'] }}</label>
                        <div id="input-option{{ option['product_option_id'] }}">
                          {% for option_value in option['product_option_value'] %} 
                          <div class="checkbox">
                            <label>
                              <input type="checkbox" name="option[{{ option['product_option_id'] }}][]" value="{{ option_value['product_option_value_id'] }}" />
                              {% if (option_value['image']) %} 
                              <img src="{{ option_value['image'] }}" alt="{{ option_value['name'] ~ option_value['price'] ? ' ' ~ option_value['price_prefix'] ~ option_value['price'] : '' }}" class="img-thumbnail" /> 
                              {% endif %} 
                              {{ option_value['name'] }} 
                              {% if (option_value['price']) %} 
                              ({{ option_value['price_prefix'] }}{{ option_value['price'] }})
                              {% endif %} 
                            </label>
                          </div>
                          {% endfor %} 
                        </div>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'text') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <input type="text" name="option[{{ option['product_option_id'] }}]" value="{{ option['value'] }}" placeholder="{{ option['name'] }}" id="input-option{{ option['product_option_id'] }}" class="form-control" />
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'textarea') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <textarea name="option[{{ option['product_option_id'] }}]" rows="5" placeholder="{{ option['name'] }}" id="input-option{{ option['product_option_id'] }}" class="form-control">{{ option['value'] }}</textarea>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'file') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label">{{ option['name'] }}</label>
                        <button type="button" id="button-upload{{ option['product_option_id'] }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
                        <input type="hidden" name="option[{{ option['product_option_id'] }}]" value="" id="input-option{{ option['product_option_id'] }}" />
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'date') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <div class="input-group date">
                          <input type="text" name="option[{{ option['product_option_id'] }}]" value="{{ option['value'] }}" data-date-format="YYYY-MM-DD" id="input-option{{ option['product_option_id'] }}" class="form-control" />
                          <span class="input-group-btn">
                          <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                          </span></div>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'datetime') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <div class="input-group datetime">
                          <input type="text" name="option[{{ option['product_option_id'] }}]" value="{{ option['value'] }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option['product_option_id'] }}" class="form-control" />
                          <span class="input-group-btn">
                          <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                          </span></div>
                      </div>
                      {% endif %} 
                      {% if (option['type'] == 'time') %} 
                      <div class="form-group{{ option['required'] ? ' required' : '' }}">
                        <label class="control-label" for="input-option{{ option['product_option_id'] }}">{{ option['name'] }}</label>
                        <div class="input-group time">
                          <input type="text" name="option[{{ option['product_option_id'] }}]" value="{{ option['value'] }}" data-date-format="HH:mm" id="input-option{{ option['product_option_id'] }}" class="form-control" />
                          <span class="input-group-btn">
                          <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                          </span></div>
                      </div>
                      {% endif %} 
                      {% endfor %} 
                      {% endif %} 
                      {% if (recurrings) %} 
                      <hr>
                      <h3>{{ text_payment_recurring }}</h3>
                      <div class="form-group required">
                        <select name="recurring_id" class="form-control">
                          <option value="">{{ text_select }}</option>
                          {% for recurring in recurrings %} 
                          <option value="{{ recurring['recurring_id'] }}">{{ recurring['name'] }}</option>
                          {% endfor %} 
                        </select>
                        <div class="help-block" id="recurring-description"></div>
                      </div>
                      {% endif %} 
                      <div class="form-group">
                        <label class="control-label" for="input-quantity">{{ entry_qty }}</label>
                        <input type="text" name="quantity" value="{{ minimum }}" size="2" id="input-quantity" class="form-control" />
                        <input type="hidden" name="product_id" value="{{ product_id }}" />
                        <br />
                        <button type="button" id="button-cart" data-loading-text="{{ text_loading }}" class="btn btn-primary btn-lg btn-block">{{ button_cart }}</button>
                      </div>
                      {% if (minimum > 1) %} 
                      <div class="alert alert-info"><i class="fa fa-info-circle"></i> {{ text_minimum }}</div>
                      {% endif %} 
                    </div>
                    {% if (review_status) %} 
                    <div class="rating">
                      <p>
                        {% set i = 1 %}{% for i in i..5 %} 
                        {% if (rating < i) %} 
                        <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-1x"></i></span>
                        {% else %} 
                        <span class="fa fa-stack"><i class="fa fa-star fa-stack-1x"></i><i class="fa fa-star-o fa-stack-1x"></i></span>
                        {% endif %} 
                        {% endfor %} 
                        <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ reviews }}</a> / <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ text_write }}</a></p>
                      <hr>
                      <!-- AddThis Button BEGIN -->
                      <div class="addthis_toolbox addthis_default_style" data-url="{{ share }}"><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_button_pinterest_pinit"></a> <a class="addthis_counter addthis_pill_style"></a></div>
                      <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-515eeaf54693130e"></script>
                      <!-- AddThis Button END -->
                    </div>
                    {% endif %} 
                {% endif %} 
            </div>
            </div>    
            ]]></add>
        </operation>
        <operation error="skip" info="">
            <search><![CDATA[{% if products %}]]></search>
            <add position="before"><![CDATA[
            <div id="kbbooking-room-details">
            {% if (kbbooking_data['room_template'] is defined and kbbooking_data['room_template'] != '') %} 
                {{ kbbooking_data['room_template'] }}
            {% endif %} 
            </div>
            {% if (kbbooking_data['facility_template'] is defined and kbbooking_data['facility_template'] != '') %} 
                {{ kbbooking_data['facility_template'] }}
            {% endif %}
            ]]></add>
        </operation>
    </file>

    <file path="system/library/cart/cart.php">
        <operation>
            <search><![CDATA[$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");]]></search>
            <add position="after"><![CDATA[
            $query2 = $this->db->query("SELECT cart_id FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "' AND kbbooking_id = '0'");
            if(!$query2->num_rows){
                $query->row['total'] = 0;
            }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");]]></search>
            <add position="replace"><![CDATA[
            $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "' AND kbbooking_id ='0'");
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);]]></search>
            <add position="replace"><![CDATA[
                if(isset($cart['kbbooking_id']) && $cart['kbbooking_id'] != '0'){
                    $this->db->query("INSERT " . DB_PREFIX . "cart SET kbbooking_id='".(int)$cart['kbbooking_id']."', api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$cart['product_id'] . "', recurring_id = '" . (int)$cart['recurring_id'] . "', `option` = '" . $this->db->escape($cart['option']) . "', quantity = '" . (int)$cart['quantity'] . "', date_added = NOW()");
                    $cart_id = $this->db->getLastId();
                    $this->db->query("UPDATE " . DB_PREFIX . "kbbooking_cart SET cart_id = " . (int)$cart_id . " WHERE kbbooking_id = '" . (int)$cart['kbbooking_id'] . "'");
                }else{
                    $this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$product_data[] = array(]]></search>
            <add position="before"><![CDATA[
                $booking_data = $this->db->query("SELECT price FROM " . DB_PREFIX . "kbbooking_output WHERE id = '". (int)$cart['kbbooking_id'] ."'");
                if(isset($booking_data->row['price'])){
                    $price = $booking_data->row['price'];
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[public function clear() {]]></search>
            <add position="after"><![CDATA[
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
                if($query->num_rows){
                    foreach($query->rows as $cart){
                        $query = $this->db->query("DELETE FROM " . DB_PREFIX . "kbbooking_cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'");
                    }
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[public function remove($cart_id) {]]></search>
            <add position="after"><![CDATA[
                $query = $this->db->query("DELETE FROM " . DB_PREFIX . "kbbooking_cart WHERE cart_id = '" . (int)$cart_id . "'");
            ]]></add>
        </operation>
    </file>
    <file path="catalog/controller/checkout/cart.php">
        <operation>
            <search><![CDATA[if (!$json) {]]></search>
            <add position="before"><![CDATA[
                    $this->load->model('setting/setting');
                    $kbbooking_data = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));

                    if(isset($kbbooking_data['kbbooking']['enable']) && $kbbooking_data['kbbooking']['enable']){
                        $this->load->model('kbbooking/kbbooking');
                        $data['kbbooking_data'] = $this->model_kbbooking_kbbooking->getProductById($product_id);
                        if (isset($data['kbbooking_data']['id'])){
                            if (!empty($data['kbbooking_data']['id'])){
                                if ($data['kbbooking_data']['id'] != ''){
                                  $json['redirect'] = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']));  
                                }
                                
                            }
                            
                        }
                    }
		  ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
            $this->load->model('setting/setting');
            $this->load->language('kbbooking/kbbooking');

            $kbbooking_settings = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
                if (isset($kbbooking_settings['kbbooking']['enable']) && $kbbooking_settings['kbbooking']['enable'] == 1) {
                    $this->load->model('kbbooking/kbbooking');
                    //condition
                    $productCheck = $this->model_kbbooking_kbbooking->getproductCheck($product['product_id']);
                    if ($productCheck > 0) {
                        $kbbooking_cart = $this->load->controller('kbbooking/kbbooking/displayCustomization', array('cart_id' => $product['cart_id'], 'quantity' => $product['quantity']));
                        if (!$kbbooking_cart['stock']) {
                            $data['error_warning'] = $this->language->get('error_stock');
                        }
                    } else {
                        $kbbooking_cart['stock'] = $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'));
                        $kbbooking_cart['template'] = '';
                    }
                } else {
                    $kbbooking_cart['template'] = '';
                    $kbbooking_cart['stock'] = $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'));
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['cart_id'   => $product['cart_id'],]]></search>
            <add position="before"><![CDATA[
            'kbbooking'   => $kbbooking_cart['template'],
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['stock'     => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),]]></search>
            <add position="replace"><![CDATA[
            'stock'   => $kbbooking_cart['stock'],
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/checkout/cart.twig">
        <operation>
            <search><![CDATA[{% if product.reward %}]]></search>
            <add position="before"><![CDATA[
                {% if (product['kbbooking'] is defined and product['kbbooking'] is not empty) %} 
                {{ product['kbbooking'] }}
                {% endif %}   
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[<input type="text" name="quantity[{{ product.cart_id }}]" value="{{ product.quantity }}" size="1" class="form-control" />]]></search>
            <add position="replace"><![CDATA[
            {% if (product['kbbooking'] is not defined or product['kbbooking'] is empty) %} 
               <input type="text" name="quantity[{{ product.cart_id }}]" value="{{ product.quantity }}" size="1" class="form-control" />
            {% else %} 
                <input type="text" name="quantity[{{ product.cart_id }}]" value="{{ product.quantity }}" size="1" class="form-control" readonly='true'/>
            {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[<button type="submit" data-toggle="tooltip" title="{{ button_update }}" class="btn btn-primary"><i class="fa fa-refresh"></i></button>]]></search>
            <add position="replace"><![CDATA[
            {% if (product['kbbooking'] is not defined or product['kbbooking'] is empty) %} 
                <button type="submit" data-toggle="tooltip" title="{{ button_update }}" class="btn btn-primary"><i class="fa fa-refresh"></i></button>
            {% endif %}
            ]]></add>
        </operation>
    </file>
    <!--
        Save kbbooking_id in order_product table
    -->
     <file path="catalog/model/extension/module/so_onepagecheckout.php">
     <operation info="">
            <search><![CDATA[foreach ($data['products'] as $product) {]]></search>
            <add position="after"><![CDATA[
            $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "cart` WHERE product_id = '" . (int)$product['product_id'] . "' AND customer_id = '" . (int)$this->session->data['customer_id'] . "'");
				$order_query = $order_query->row;
				
				$order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "kbbooking_cart` WHERE product_id = '" . (int)$product['product_id'] . "' AND  cart_id = '" . (int)$order_query['cart_id'] . "'");
				$order_query = $order_query->row;
            ]]></add>
        </operation>
    </file>
    <file path="catalog/model/extension/module/so_onepagecheckout.php">
     <operation  info="">
            <search><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', reward = '" . (int)$product['reward'] . "'");]]></search>
            <add position="replace"><![CDATA[
            $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', kbbooking_id = '" . (int)$order_query['kbbooking_id'] . "',reward = '" . (int)$product['reward'] . "'");
            ]]></add>
        </operation>
    </file>
    <file path="catalog/model/checkout/order.php">
        <operation>
            <search><![CDATA[foreach ($product['option'] as $option) {]]></search>
            <add position="before"><![CDATA[
            
            if(isset($product['kbbooking_id'])){
                $this->db->query("UPDATE " . DB_PREFIX . "order_product SET kbbooking_id = '" . (int)$product['kbbooking_id'] . "' WHERE order_product_id='".(int)$order_product_id."'");
            }
            ]]></add>
        </operation>
    </file>
    <!--
        To add kbbooking id in order_data table
    -->
    <file path="catalog/controller/checkout/confirm.php">
        <operation>
            <search><![CDATA[$order_data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
            $this->load->model('setting/setting');
            $kbbooking_data = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
            if(isset($kbbooking_data['kbbooking']['enable']) && $kbbooking_data['kbbooking']['enable'] ==1){
                $this->load->model('kbbooking/kbbooking');
                $kbbooking_id = $this->model_kbbooking_kbbooking->getKbbooking_id($product['cart_id'],$product['quantity']);
            }else{
                $kbbooking_id = 0;
            }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$order_data['products'][] = array(]]></search>
            <add position="after"><![CDATA[
            'kbbooking_id'   => $kbbooking_id,
            ]]></add>
        </operation>
    </file>
    <!--
        Admin Order info
    -->
    <file path="admin/controller/sale/order.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
            $this->load->model('setting/setting');
            $kbbooking_settings = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
            if(isset($kbbooking_settings['kbbooking']['enable']) && $kbbooking_settings['kbbooking']['enable'] ==1){
                $this->load->model('kbbooking/kbbooking');
                $kbbooking_order = $this->load->controller('extension/module/kbbooking/displayCustomization',array('kbbooking_id' => $product['kbbooking_id'],'quantity' => $product['quantity']));
            }else{
                $kbbooking_order = '';
            }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="after"><![CDATA[
            'kbbooking'   => $kbbooking_order,
            ]]></add>
        </operation>
    </file>
    <file path="admin/view/template/sale/order_info.twig">
        <operation>
            <search index="1"><![CDATA[<table class="table table-bordered">]]></search>
            <add position="before"><![CDATA[
                {% for product in products %}
                {% if (product['kbbooking'] is defined and product['kbbooking'] is not empty) %} 
                {{ product['kbbooking'] }}
                {% endif %}
                {% endfor %}
            ]]></add>
        </operation>
    </file>
    <!--
        For account page in front side
    -->
    <file path="catalog/controller/account/order.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
            $this->load->model('setting/setting');
            $this->load->language('kbbooking/kbbooking');

            $kbbooking_settings = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
            if(isset($kbbooking_settings['kbbooking']['enable']) && $kbbooking_settings['kbbooking']['enable'] ==1){
                $this->load->model('kbbooking/kbbooking');
                $kbbooking_cart = $this->load->controller('kbbooking/kbbooking/displayCustomization',array('kbbooking_id' => $product['kbbooking_id'],'quantity' => $product['quantity']));
                if($kbbooking_cart != ''){
                    $reorder = '';
                }
            }else{
                $kbbooking_cart['template'] = '';
            }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="after"><![CDATA[
            'kbbooking'   => $kbbooking_cart['template'],
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/account/order_info.twig">
        <operation>
            <search><![CDATA[{% for option in product.option %}]]></search>
            <add position="before"><![CDATA[
            {% if (product['kbbooking'] is defined and product['kbbooking'] is not empty) %} 
            {{ product['kbbooking'] }}
            {% endif %}
            ]]></add>
        </operation>
    </file>
    <!--
        Order creation mail
    -->
    <file path="catalog/model/checkout/order.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
            $this->load->model('setting/setting');
            $this->load->language('kbbooking/kbbooking');

            $this->load->language('kbbooking/kbbooking');
            $kbbooking_settings = $this->model_setting_setting->getSetting('kbbooking', $this->config->get('config_store_id'));
            if(isset($kbbooking_settings['kbbooking']['enable']) && $kbbooking_settings['kbbooking']['enable'] ==1){
                $this->load->model('kbbooking/kbbooking');
                $data['text_appointment_date'] = $this->language->get('text_appointment_date');
                $data['text_slot'] = $this->language->get('text_slot');
                $data['text_check_in'] = $this->language->get('text_check_in');
                $data['text_check_out'] = $this->language->get('text_check_out');
                $data['text_service_type'] = $this->language->get('text_service_type');
                $data['text_room_category'] = $this->language->get('text_room_category');
                $data['text_room'] = $this->language->get('text_room');
                $data['text_service_type'] = $this->language->get('text_service_type');
                $data['text_total_hours'] = $this->language->get('text_total_hours');
                $data['text_total_days'] = $this->language->get('text_total_days');
                $kbbooking_data = $this->model_kbbooking_kbbooking->getDataForMail($product['kbbooking_id'],$product['quantity']);
            }else{
                $kbbooking_data = array();
            }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="after"><![CDATA[
            'kbbooking'   => $kbbooking_data,
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/mail/order_add.twig" error="skip">
        <operation error="skip" info="">
            <search><![CDATA[ {% for option in product.option %} ]]></search>
            <add position="before"><![CDATA[
                {% if (product['kbbooking'] is defined and product['kbbooking'] is not empty) %}
                    {% if (product['kbbooking']['time_slot'] is defined) %} 
                        <br><strong>{{ text_appointment_date }}</strong> {{ product['kbbooking']['check_in'] }} <br>
                        <strong>{{ text_slot }}</strong> {{ product['kbbooking']['time_slot'] }} <br>
                    {% elseif (product['kbbooking']['check_out'] is defined) %} 
                        <br><strong>{{ text_check_in }}</strong> {{ product['kbbooking']['check_in'] }} <br>
                        <strong>{{ text_check_out }}</strong> {{ product['kbbooking']['check_out'] }} <br>
                    {% else %} 
                        <br><strong>{{ text_check_in }}</strong> {{ product['kbbooking']['check_in'] }} <br>
                    {% endif %} 
                    {% if (product['kbbooking']['service_type'] is defined) %} 
                        <strong>{{ text_service_type }}</strong> {{ product['kbbooking']['service_type'] }} <br>
                    {% endif %} 
                    {% if (product['kbbooking']['room_name'] is defined and product['kbbooking']['room_name'] != '') %} 
                        <strong>{{ text_room }}</strong> {{ product['kbbooking']['room_name'] }} <br>
                    {% endif %} 
                    {% if (product['kbbooking']['category_name'] is defined and product['kbbooking']['category_name'] != '') %} 
                        <strong>{{ text_room_category }}</strong> {{ product['kbbooking']['category_name'] }} <br>
                    {% endif %} 
                    {% if (product['kbbooking']['total_days'] is defined) %} 
                        <strong>{{ text_total_days }}</strong> {{ product['kbbooking']['total_days'] }} <br>
                    {% elseif (product['kbbooking']['total_hours'] is defined) %} 
                        <strong>{{ text_total_hours }}</strong> {{ product['kbbooking']['total_hours'] }} <br>
                    {% endif %} 
                {% endif %}
           ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/*/template/checkout/checkout.twig" error="skip">
        <operation error="skip" info="">
            <search><![CDATA[$(document).delegate('#button-payment-method', 'click', function() {]]></search>
            <add position="replace" offset="44"><![CDATA[
                $(document).delegate('#button-payment-method', 'click', function() {
                    $.ajax({
                        url: 'index.php?route=kbbooking/kbbooking/validateQuantity',
                        type: 'post',
                        dataType: 'json',
                        success: function(json) {
                            console.log(json);
                            if(json.status == 'success'){
                                $.ajax({
                                    url: 'index.php?route=checkout/payment_method/save',
                                    type: 'post',
                                    data: $('#collapse-payment-method input[type=\'radio\']:checked, #collapse-payment-method input[type=\'checkbox\']:checked, #collapse-payment-method textarea'),
                                    dataType: 'json',
                                    beforeSend: function() {
                                            $('#button-payment-method').button('loading');
                                            },
                                    success: function(json) {
                                        $('.alert, .text-danger').remove();

                                        if (json['redirect']) {
                                            location = json['redirect'];
                                        } else if (json['error']) {
                                            $('#button-payment-method').button('reset');

                                            if (json['error']['warning']) {
                                                $('#collapse-payment-method .panel-body').prepend('<div class="alert alert-danger">' + json['error']['warning'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                                            }
                                        } else {
                                            $.ajax({
                                                url: 'index.php?route=checkout/confirm',
                                                dataType: 'html',
                                                complete: function() {
                                                    $('#button-payment-method').button('reset');
                                                },
                                                success: function(html) {
                                                    $('#collapse-checkout-confirm .panel-body').html(html);

                                                                            $('#collapse-checkout-confirm').parent().find('.panel-heading .panel-title').html('<a href="#collapse-checkout-confirm" data-toggle="collapse" data-parent="#accordion" class="accordion-toggle"> {{ text_checkout_confirm }} <i class="fa fa-caret-down"></i></a>');

                                                                            $('a[href=\'#collapse-checkout-confirm\']').trigger('click');
                                                                    },
                                                error: function(xhr, ajaxOptions, thrownError) {
                                                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                                                }
                                            });
                                        }
                                    },
                                    error: function(xhr, ajaxOptions, thrownError) {
                                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                                    }
                                });
                            }else{
                                window.location = 'index.php?route=checkout/cart';
                            }
                        }
                    });

                });
           ]]></add>
        </operation>
    </file>
    <!--Start By dharmanshu for the module theme compatiblity 4-02-2021-->
    <file path="catalog/view/theme/so-matrix/template/product/product.twig" error="skip">
        <operation error="skip" info="">
            <search><![CDATA[<h1>{{heading_title}}</h1>]]></search>
            <add position="after"><![CDATA[   
                {% if (kbbooking_data['booking_template'] is defined and kbbooking_data['booking_template'] != '') %} 
                    {{ kbbooking_data['booking_template'] }}
                {%else %}  
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/so-matrix/template/product/product.twig" error="skip">
        <operation error="skip" info="">
            <search><![CDATA[<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-529be2200cc72db5"></script>]]></search>
            <add position="after"><![CDATA[   
                {%endif %} 
            ]]></add>
        </operation>
    </file>
    <file path="catalog/view/theme/so-matrix/template/product/product.twig" error="skip">
     <operation error="skip" info="">
            <search><![CDATA[{% if soconfig.get_settings('related_position')=='horizontal' and products and soconfig.get_settings('related_status') %}]]></search>
            <add position="before"><![CDATA[
            <div id="kbbooking-room-details">
            {% if (kbbooking_data['room_template'] is defined and kbbooking_data['room_template'] != '') %} 
                {{ kbbooking_data['room_template'] }}
            {% endif %} 
            </div>
            {% if (kbbooking_data['facility_template'] is defined and kbbooking_data['facility_template'] != '') %} 
                {{ kbbooking_data['facility_template'] }}
            {% endif %}
            ]]></add>
        </operation>
    </file>
    
    <!--End By dharmanshu for the module theme compatiblity 4-02-2021-->
</modification>