[Помогите] admin_order_edit_with_ajax есть проблема с добавление товара

Тема в разделе "OpenCart", создана пользователем maetus, 31 дек 2015.

  1. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    Подскажите может кто то уже сталкивался с проблемой данного характера.

    Так модуль работает отлично - но он немного не правильно работает при добавлении нового товара к заказу
    [​IMG]

    также при выборе опций нет самих названий опций.

    Скажите как быть и что делать с этим?

    эта часть кода выдаёт ошибку

    в частности строка

    'name' => $option_value['name'],

    Код:
    PHP:
    foreach ($options as $option) {
          if (
    $option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
            
    $option_value_data = array();

            foreach (
    $option['product_option_value'] as $option_value) {
              if (!
    $option_value['subtract'] || ($option_value['quantity'] > 0)) {
                
    $option_value_data[] = array(
                    
    'product_option_value_id' => $option_value['product_option_value_id'],
                    
    'option_value_id' => $option_value['option_value_id'],
                    
    'name' => $option_value['name'],
                    
    'image' => $this->model_tool_image->resize($option_value['image'], 5050),
                    
    'price' => (float) $option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
                    
    'price_prefix' => $option_value['price_prefix']
                );
              }
            }

            
    $this->data['options'][] = array(
                
    'product_option_id' => $option['product_option_id'],
                
    'option_id' => $option['option_id'],
                
    'name' => $option['name'],
                
    'type' => $option['type'],
                
    'option_value' => $option_value_data,
                
    'required' => $option['required']
            );
          } elseif (
    $option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
            
    $this->data['options'][] = array(
                
    'product_option_id' => $option['product_option_id'],
                
    'option_id' => $option['option_id'],
                
    'name' => $option['name'],
                
    'type' => $option['type'],
                
    'option_value' => $option['option_value'],
                
    'required' => $option['required']
            );
          }
        }

        
    $this->data['text_select'] = $this->language->get('text_select');
        
    $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
        
    $this->data['text_model'] = $this->language->get('text_model');
        
    $this->data['text_reward'] = $this->language->get('text_reward');
        
    $this->data['text_points'] = $this->language->get('text_points');
        
    $this->data['text_discount'] = $this->language->get('text_discount');
        
    $this->data['text_stock'] = $this->language->get('text_stock');
        
    $this->data['text_price'] = $this->language->get('text_price');
        
    $this->data['text_tax'] = $this->language->get('text_tax');
        
    $this->data['text_discount'] = $this->language->get('text_discount');
        
    $this->data['text_option'] = $this->language->get('text_option');
        
    $this->data['text_qty'] = $this->language->get('text_qty');
        
    $this->data['text_or'] = $this->language->get('text_or');
        
    $this->data['text_write'] = $this->language->get('text_write');
        
    $this->data['text_note'] = $this->language->get('text_note');
        
    $this->data['text_share'] = $this->language->get('text_share');
        
    $this->data['text_wait'] = $this->language->get('text_wait');
        
    $this->data['text_tags'] = $this->language->get('text_tags');
        
    $this->data['button_upload'] = $this->language->get('button_upload');

        
    $this->template 'sale/options.tpl';

        
    $this->response->setOutput($this->render());
      }
     
    Lasted edited by : 3 янв 2016
  2. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Если $option_value['name'] нет, значит оно не выгружается из базы в модели, смотрите код модели. А в коде выше, ошибок нет.

    P.S. Оформляйте посты правильно:
    - прямая ссылка на изображение должна быть вставлена через соответствующую кнопку в редакторе, а не весь код, который даёт фотохостинг с превью изображения и ссылкой на себя для просмотра полного
    - код нужно оборачивать в соответствующие теги, чтоб была подсветка, код сплошным текстом не читабелен.
     
  3. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40

    Да в admin/model/sale/order.php отсутствует запрос $option_value['name']
    Как его можно добавить что бы всё встало на свои места?
     
  4. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Выложите строку, в которой объявляется массив $options в контроллере и код модели.
     
  5. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    Опции заливались отдельным файлом admin/view/template/sale/options.tpl
    Код:
    <?php if ($options) { ?>
          <div class="options">
            <?php foreach ($options as $option) { ?>
            <?php if ($option['type'] == 'select') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <select name="option[<?php echo $option['product_option_id']; ?>]">
                <option value=""><?php echo $text_select; ?></option>
                <?php foreach ($option['option_value'] as $option_value) { ?>
                <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
                </option>
                <?php } ?>
              </select>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'radio') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
              <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
              </label>
              <br />
              <?php } ?>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'checkbox') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
              <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
              </label>
              <br />
              <?php } ?>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'image') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
                <table class="option-image">
                  <?php foreach ($option['option_value'] as $option_value) { ?>
                  <tr>
                    <td style="width: 1px;"><input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" /></td>
                    <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" /></label></td>
                    <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                        <?php if ($option_value['price']) { ?>
                        (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                        <?php } ?>
                      </label></td>
                  </tr>
                  <?php } ?>
                </table>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'text') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'textarea') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <textarea name="option[<?php echo $option['product_option_id']; ?>]" cols="40" rows="5"><?php echo $option['option_value']; ?></textarea>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'date') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="date" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'datetime') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="datetime" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'time') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="time" />
            </div>
            <br />
            <?php } ?>
            <?php } ?>
          </div>
          <?php } ?>
    вот модуль работающий на vqmod
    Код:
    <modification>
            <id>Admin Edit Order with Ajax</id>
            <version>1.5x</version>
            <vqmver>2</vqmver>        
            <file name="admin/view/template/sale/order_info.tpl">
                 
            <operation>
                <search position="after"><![CDATA[<?php echo $header; ?>]]></search>
                <add><![CDATA[<STYLE TYPE="text/css" MEDIA=screen>.note {
        padding-bottom: 5px;
        font-size: 9px;
        color: #BABABA;
    }</STYLE>]]></add>
            </operation>   
                 
                 <operation>
                            <search position="replace" ><![CDATA[<div class="vtabs">]]></search>
                            <add><![CDATA[<div class="vtabs"><a href="#tab-product"><?php echo $tab_product; ?></a>]]></add>
                  </operation>
                  <operation>
                            <search position="replace" index="2"><![CDATA[<a href="#tab-product"><?php echo $tab_product; ?></a>]]></search>
                            <add><![CDATA[ ]]></add>
                 </operation>
                  <operation>
                            <search position="replace" ><![CDATA[<?php echo $total; ?>]]></search>
                            <add><![CDATA[<td><div id="info_total"><?php echo $total; ?></div>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_firstname; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_firstname"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_firstname">&nbsp;<?php echo $payment_firstname; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_lastname; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_lastname"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_lastname">&nbsp;<?php echo $payment_lastname; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_company; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_company"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_company">&nbsp;<?php echo $payment_company; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_address_1; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_address_1"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_address_1">&nbsp;<?php echo $payment_address_1; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_address_2; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_address_2"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_address_2">&nbsp;<?php echo $payment_address_2; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_city; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_city"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_city">&nbsp;<?php echo $payment_city; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_postcode; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payment_postcode"><?php echo $edit_note; ?><br></div><div class="edit" id="payment_postcode">&nbsp;<?php echo $payment_postcode; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_zone; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_payzone"><?php echo $edit_note; ?><br></div><div id="payment_zone"><?php echo $payment_zone; ?></div><div id="payzonedrop" style="display: none;">&nbsp;<select name="payment_zone_id" id="payment_zone_id" onchange="setzonepay();">
                <option value=""></option>
                      </select></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $payment_country; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_paycountry"><?php echo $edit_note; ?><br></div><div id="payment_country"><?php echo $payment_country; ?></div><div id="paycountrydrop" style="display: none;"><select name="payment_country_id" id="payment_country_id" onchange="setshippingpay();">
                        <option value=""></option>
                        <?php foreach ($countries as $country) { ?>
                        <?php if ($country['country_id'] == $payment_country_id) { ?>
                        <option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
                        <?php } else { ?>
                        <option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
                        <?php } ?>
                        <?php } ?>
                      </select></div></td>]]></add>
                 </operation>
                 <operation>
                <search position="before" offset="2"><![CDATA[<div id="tab-shipping" class="vtabs-content">]]></search>
                <add><![CDATA[<script type="text/javascript">
                $('select[name=\'payment_zone_id\']').load('index.php?route=sale/order/zone&token=<?php echo $token; ?>&country_id=<?php echo $payment_country_id; ?>&zone_id=<?php echo $payment_zone_id; ?>');
                </script> ]]></add>
            </operation> 
            <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_firstname; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_firstname"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_firstname">&nbsp;<?php echo $shipping_firstname; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_lastname; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_lastname"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_lastname">&nbsp;<?php echo $shipping_lastname; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_company; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_company"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_company">&nbsp;<?php echo $shipping_company; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_address_1; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_address_1"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_address_1">&nbsp;<?php echo $shipping_address_1; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_address_2; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_address_2"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_address_2">&nbsp;<?php echo $shipping_address_2; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_city; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_city"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_city">&nbsp;<?php echo $shipping_city; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_postcode; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_postcode"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_postcode">&nbsp;<?php echo $shipping_postcode; ?></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_zone; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_zone"><?php echo $edit_note; ?><br></div><div id="shipping_zone">&nbsp;<?php echo $shipping_zone; ?></div><div id="zonedrop" style="display: none;"><select name="shipping_zone_id" id="shipping_zone_id" onchange="setzone();">
                <option value=""></option>
                      </select></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_country; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_country"><?php echo $edit_note; ?><br></div><div id="shipping_country">&nbsp;<?php echo $shipping_country; ?></div><div id="countrydrop" style="display: none;"><select name="shipping_country_id" id="shipping_country_id" onchange="setshipping();">
                        <option value=""></option>
                        <?php foreach ($countries as $country) { ?>
                        <?php if ($country['country_id'] == $shipping_country_id) { ?>
                        <option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
                        <?php } else { ?>
                        <option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
                        <?php } ?>
                        <?php } ?>
                      </select></div></td>]]></add>
                 </operation>
                 <operation>
                            <search position="replace" ><![CDATA[<td><?php echo $shipping_method; ?></td>]]></search>
                            <add><![CDATA[<td><div class="note" id="note_shipping_method"><?php echo $edit_note; ?><br></div><div class="edit" id="shipping_method">&nbsp;<?php echo $shipping_method; ?></div></td>]]></add>
                 </operation>
                 <operation>
                <search position="before" offset="2"><![CDATA[<div id="tab-product" class="vtabs-content">]]></search>
                <add><![CDATA[<script type="text/javascript">
                $('select[name=\'shipping_zone_id\']').load('index.php?route=sale/order/zone&token=<?php echo $token; ?>&country_id=<?php echo $shipping_country_id; ?>&zone_id=<?php echo $shipping_zone_id; ?>');
                </script> ]]></add>
                </operation>
                <operation>
                            <search position="replace" offset="46" ><![CDATA[<div id="tab-product" class="vtabs-content">]]></search>
                            <add><![CDATA[<div id="tab-product" class="vtabs-content">
          <p>
            <a id="button-add" class="button" onclick="$('#product-row-add').fadeIn();$('#button-add').fadeOut();"><span><?php echo $edit_add_product_button; ?></span></a></p>
          <form id="addproduct">
            <table id="product" class="list">
              <thead>
                <tr>
                    <td></td>
                  <td class="left"><?php echo $column_product; ?></td>
                  <td class="left"><?php echo $column_model; ?></td>
                  <td class="right"><?php echo $column_quantity; ?></td>
                  <td class="right"><?php echo $column_price; ?></td>
                  <td class="right"><?php echo $column_total; ?></td>
                </tr>
              </thead>
              <?php foreach ($products as $product) { ?>
              <tbody id="product-row<?php echo $product['order_product_id']; ?>">
              <tr>
                  <td class="left"><img src="<?php echo HTTP_CATALOG;?>catalog/view/theme/default/image/close.png" title="<?php echo $edit_delete; ?>" boarder="0" onClick="remove('<?php echo $product['order_product_id']; ?>', '<?php echo $this->db->escape($product['name']); ?>');"> </td><td class="left">&nbsp; <?php if (!$product['product_id']) { ?>
                    <a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
                    <?php } else { ?>
                    <div class="note" id="note_name_<?php echo $product['order_product_id']; ?>"><?php echo $edit_note; ?><br></div><div class="edititem" id="name_<?php echo $product['order_product_id']; ?>"><?php echo $product['name']; ?></div>
                    <?php } ?>
                    <?php foreach ($product['option'] as $option) { ?>
                    <br />
                    <?php if ($option['type'] != 'file') { ?>
                    &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
                    <?php } else { ?>
                    &nbsp;<small> - <?php echo $option['name']; ?>: <a href="<?php echo $option['href']; ?>"><?php echo $option['value']; ?></a></small>
                    <?php } ?>
                    <?php } ?></td>
                  <td class="left"><div class="note" id="note_model_<?php echo $product['order_product_id']; ?>"><?php echo $edit_note; ?><br></div><div class="edititem" id="model_<?php echo $product['order_product_id']; ?>"><?php echo $product['model']; ?></div></td>
                  <td class="right"><div class="note" id="note_quantity_<?php echo $product['order_product_id']; ?>"><?php echo $edit_note; ?><br></div><div class="edititem" id="quantity_<?php echo $product['order_product_id']; ?>"><?php echo $product['quantity']; ?></div></td>
                  <td class="right"><div class="note" id="note_price_<?php echo $product['order_product_id']; ?>"><?php echo $edit_note; ?><br></div><div class="edititem" id="price_<?php echo $product['order_product_id']; ?>"><?php echo $product['price']; ?></div></td>
                  <td class="right"><div class="note" id="note_shipping"><?php echo $edit_note; ?><br></div><div class="edititem" id="total_<?php echo $product['order_product_id']; ?>"><?php echo $product['total']; ?></div></td>
                </tr>
                <?php } ?>
                <?php foreach ($vouchers as $voucher) { ?>
                <tr>
                  <td class="left"><a href="<?php echo $voucher['href']; ?>"><?php echo $voucher['description']; ?></a></td>
                  <td class="left"></td>
                  <td class="right">1</td>
                  <td class="right"><?php echo $voucher['amount']; ?></td>
                  <td class="right"><?php echo $voucher['amount']; ?></td>
                </tr>
                <?php } ?>
              </tbody>
              <tbody id="product-row-add" style="display: none;">
              <tr>
                  <td></td>
                <td class="left"><input type="text" name="product" size="50" id="add_product_name" value="" /><input type="hidden" id="add_product_id" name="product_id" size="50" value="" /></td>
                  <td><div id="productoptions"><input type="hidden" name="product_option_id" id="product_option_id" value="" /><input type="hidden" name="product_option" id="product_option" value="" /></div></td>
                  <td class="right"><input type="text" id="add_quantity" name="add_quantity" size="4" value="1" /></td>
                  <td></td>
                  <td class="right"><a id="button-add-now" class="button" onclick="addproduct();"><span><?php echo $edit_add_button; ?></span></a></td>
              </tr>
              </tbody>
             
              <?php foreach ($totals as $totals) { ?>
              <tbody id="totals">
                <tr>
                  <td colspan="5" class="right"><?php echo $totals['title'];// . "code=" . $totals['code']; ?>:</td>
                  <td class="right"><?php if($totals['code'] == 'shipping'){?><div class="note" id="note_shipping"><?php echo $edit_note; ?><br></div><?php } ?><div id="<?php echo $totals['code']; ?>"><?php echo $totals['text']; ?></div><input id="val_<?php echo $totals['code'];?>" value="<?php echo $totals['value'];?>" type="hidden" /></td>
                </tr>
              </tbody>
              <?php } ?>
            </table>
            <input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
            </form>]]></add>
                 </operation>
                 <operation>
                <search position="after" offset="5"><![CDATA[<td><?php echo $error; ?></td>]]></search>
                <add><![CDATA[</form>]]></add>
            </operation>
            <operation>
                <search position="after" index="1"><![CDATA[<script type="text/javascript"><!--]]></search>
                <add><![CDATA[
    var edititem_clicked=new Array();
    
    $(".edititem").click(function() {
                var field_id = $(this).attr("id");           
               
                if (edititem_clicked[field_id] != '1'){
               
                    edititem_clicked[field_id] = '1';
               
                    $(this).html('<input id="aved_'+field_id+'" type="text" value="'+ $(this).html()+'" />');
                    $('#aved_'+field_id).focus();
                    $('#aved_'+field_id).select();
                    $('#note_'+field_id).html('<?php echo $edit_save; ?><br>');
    
                   
                }else{
                   
                    if ($('#aved_'+field_id).val() != ''){
                   
                    edititem_clicked[field_id] = '0';
                   
                    $.ajax({
                        url: 'index.php?route=sale/order/ajaxupdateitem&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&field='+field_id+'&val='+$('#aved_'+field_id).val(),
                        type: 'get',
                        dataType: 'json',
                   
                        success: function(json) {
                            $('#note_'+field_id).html('<?php echo $edit_saved; ?><br>');
                           
                            if ($('#tax').length > 0) {$('#tax').html(json['tax']);}
                            if (json['total']){$('#total').html(json['total']);$('#info_total').html(json['total']);}
                            if (json['sub_total']){$('#sub_total').html(json['sub_total']);}
                           
                            if (json['auto_discount']){$('#auto_discount').html(json['auto_discount']);}
                            if (json['coupon']){$('#coupon').html(json['coupon']);}
                           
                            if (json['product_price']){$('#price_'+json['order_product_id']).html(json['product_price']);}
                            if (json['product_total']){$('#total_'+json['order_product_id']).html(json['product_total']);}
                           
                           
                           
                           
                        }
                    });
                   
                    $(this).html($('#aved_'+field_id).val());
                   
                    }else{
                        alert('You have not entered anything.');
                    }
                   
                   
                }
    
    
            });
    
    
    $('input[name=\'product\']').autocomplete({
        delay: 0,
        source: function(request, response) {
            $.ajax({
                url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name='+  encodeURIComponent(request.term),
                dataType: 'json',
                success: function(data) {       
                    response($.map(data, function(item) {
                        return {
                            label: item.name,
                            value: item.product_id
                        }
                    }));
                }
            });
           
        },
        select: function(event, ui) {
            $('#add_product_id').val(ui.item.value);
            $('#add_product_name').val(ui.item.label);
           
            $('#productoptions').load('index.php?route=sale/order/productoptions&token=<?php echo $token; ?>&product_id=' + ui.item.value);
           
           
            return false;
        }
    });
    
    function addproduct(){
        if ($('#add_product_id').val() != ''){
        $url = 'index.php?route=sale/order/addproduct&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&product_id='+$('#add_product_id').val()+'&quantity='+$('#add_quantity').val();
        if ($('#product_option_id')){
            $url = $url + '&product_option_id=' + $('#product_option_id').val() + '&product_option=' + $('#product_option').val();
        }
        $.ajax({       
            url: $url,
            type: 'post',
        data: $('#addproduct input[type=\'text\'], #addproduct input[type=\'hidden\'], #addproduct input[type=\'checkbox\']:checked, #addproduct input[type=\'radio\']:checked, #addproduct select'),
            dataType: 'json',
                   
            success: function(json) {
                location = 'index.php?route=sale/order/info&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>';
                }
        });
        }else{
            alert('Please enter a Valid Product to add');
        }
    }
    
    $("#shipping").click(function() {
                var field_id = $(this).attr("id");           
                if (edit_clicked[field_id] != '1'){
               
                    edit_clicked[field_id] = '1';
               
                    $(this).html('<input id="aved_'+field_id+'" type="text" value="'+ $('#val_shipping').val()+'" size="8" />');
                    $('#aved_'+field_id).focus();
                    $('#aved_'+field_id).select();
                    $('#note_'+field_id).html('<?php echo $edit_save; ?><br>');
    
                   
                }else{
    
                    edit_clicked[field_id] = '0';
    
                    $.ajax({
                        url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&shipping='+$('#aved_'+field_id).val(),
                        type: 'get',
                        dataType: 'json',
                   
                        success: function(json) {
                            $('#val_shipping').val($('#aved_'+field_id).val());
                            $('#note_'+field_id).html('<?php echo $edit_saved; ?><br>');
                            $('#shipping').html(json['shipping']);
                            if ($('#tax').length > 0) {$('#tax').html(json['tax']);}
                            $('#total').html(json['total']);
                            $('#info_total').html(json['total']);
                           
                        }
                    });
                   
                   
                }
    
    
            });
    
    
    function remove($hide,$name){   
        if(confirm("<?php echo $edit_delete_confirm;?>\n\n"+$name+"?\n")) {
           
            $.ajax({
                url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&delete_product='+$hide,
                type: 'get',
                dataType: 'json',
                   
                success: function(json) {
                        $('#sub_total').html(json['sub_total']);
                        if ($('#tax').length > 0) {$('#tax').html(json['tax']);}
                        $('#total').html(json['total']);
                        $('#info_total').html(json['total']);
                       
                    }
                });   
            $('#product-row'+$hide).fadeOut();
           
        }
       
    }
    
    
    $("#shipping_country").click(function() {
        $("#shipping_country").hide();
        $("#countrydrop").fadeIn();
        $('#note_country').html('<?php echo $edit_select_save; ?><br>');
       
    });
    $("#payment_country").click(function() {
        $("#payment_country").hide();
        $("#paycountrydrop").fadeIn();
        $('#note_paycountry').html('<?php echo $edit_select_save; ?><br>');
       
    });
    
    function setshipping(){
        $.ajax({
                url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&shipping_country_id='+$('#shipping_country_id').val(),
                type: 'get',
                dataType: 'json',
                   
                success: function(json) {
                        $("#shipping_zone").hide();
                        $('select[name=\'shipping_zone_id\']').load('index.php?route=sale/order/zone&token=<?php echo $token; ?>&country_id=' + $('#shipping_country_id').val() + '&zone_id=<?php echo $shipping_zone_id; ?>');
                        $("#zonedrop").fadeIn();
                        $("#countrydrop").hide();
                        $("#shipping_country").html(json['country']);
                        $("#shipping_country").fadeIn();
                        $('#note_country').html('<?php echo $edit_saved; ?><br>');
                        $('#note_zone').html('<?php echo $edit_select_save; ?><br>');
                           
                    }
                });   
    }
    
    function setshippingpay(){
        $.ajax({
                url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&payment_country_id='+$('#payment_country_id').val(),
                type: 'get',
                dataType: 'json',
                   
                success: function(json) {
                        $("#payment_zone").hide();
                        $('select[name=\'payment_zone_id\']').load('index.php?route=sale/order/zone&token=<?php echo $token; ?>&country_id=' + $('#payment_country_id').val() + '&zone_id=<?php echo $payment_zone_id; ?>');
                        $("#payzonedrop").fadeIn();
                        $("#paycountrydrop").hide();
                        $("#payment_country").html(json['country']);
                        $("#payment_country").fadeIn();
                        $('#note_paycountry').html('<?php echo $edit_saved; ?><br>');
                        $('#note_payzone').html('<?php echo $edit_select_save; ?><br>');
                           
                    }
                });   
    }
    
    function setzonepay(){
        $.ajax({
                url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&payment_zone_id='+$('#payment_zone_id').val(),
                type: 'get',
                dataType: 'json',
                   
                success: function(json) {
                        $("#payzonedrop").hide();
                        $("#paycountrydrop").hide();
                        $("#payment_zone").html(json['zone']);
                        $("#payment_zone").fadeIn();
                        $('#note_payzone').html('<?php echo $edit_saved; ?><br>');
                           
                    }
                });   
    }
    
    function setzone(){
        $.ajax({
                url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&shipping_zone_id='+$('#shipping_zone_id').val(),
                type: 'get',
                dataType: 'json',
                   
                success: function(json) {
                        $("#zonedrop").hide();
                        $("#countrydrop").hide();
                        $("#shipping_zone").html(json['zone']);
                        $("#shipping_zone").fadeIn();
                        $('#note_zone').html('<?php echo $edit_saved; ?><br>');
                           
                    }
                });   
    }
    
    
    $("#shipping_zone").click(function() {
        $("#shipping_zone").hide();
        $("#zonedrop").fadeIn();
        $('#note_zone').html('<?php echo $edit_select_save; ?><br>');
       
    });
    $("#payment_zone").click(function() {
        $("#payment_zone").hide();
        $("#payzonedrop").fadeIn();
        $('#note_payzone').html('<?php echo $edit_select_save; ?><br>');
       
    });
    
    var edit_clicked=new Array();
    
    $(".edit").click(function() {
                var field_id = $(this).attr("id");
               
                if (edit_clicked[field_id] != '1'){
               
                    edit_clicked[field_id] = '1';
               
                    $(this).html('<input id="aved_'+field_id+'" type="text" value="'+ $(this).html()+'" />');
                    $('#aved_'+field_id).focus();
                    $('#aved_'+field_id).select();
                    $('#note_'+field_id).html('<?php echo $edit_save; ?><br>');
    
                   
                }else{
    
                    edit_clicked[field_id] = '0';
                   
                    $.ajax({
                        url: 'index.php?route=sale/order/ajaxupdate&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&field='+field_id+'&val='+$('#aved_'+field_id).val(),
                        type: 'get',
                        dataType: 'json',
                   
                        success: function(json) {
                            $('#note_'+field_id).html('<?php echo $edit_saved; ?><br>');
                           
                        }
                    });
                   
                    $(this).html($('#aved_'+field_id).val());
                   
                }
    
    
            });]]></add>
            </operation>
    
            </file>
           
            <file name="admin/language/*/sale/order.php">
            <operation>
                <search position="before" offset="1"><![CDATA[// Entry]]></search>
                <add><![CDATA[$_['edit_note']               = 'Click to Edit';
    $_['edit_save']                = 'Click to Save';
    $_['edit_delete']                = 'Delete';
    $_['edit_select_save']        = 'Change to Save';
    $_['edit_saved']                = 'Saved';
    $_['edit_delete_confirm']     = 'Are you sure you want to perminantly delete';
    $_['edit_add_product_button'] = 'Add Product to Order';
    $_['edit_add_button']           = 'Add';]]></add>
            </operation>   
            </file>
           
    
    
           
            <file name="admin/controller/sale/order.php">
            <operation>
                            <search position="after" ><![CDATA[$this->data['tab_history'] = $this->language->get('tab_history');]]></search>
                            <add><![CDATA[$this->data['edit_note'] = $this->language->get('edit_note');
                $this->data['edit_save'] = $this->language->get('edit_save');
                $this->data['edit_delete'] = $this->language->get('edit_delete');
                $this->data['edit_saved'] = $this->language->get('edit_saved');
                $this->data['edit_select_save'] = $this->language->get('edit_select_save');
                $this->data['edit_delete_confirm'] = $this->language->get('edit_delete_confirm');
                $this->data['edit_add_product_button'] = $this->language->get('edit_add_product_button');
                $this->data['edit_add_button'] = $this->language->get('edit_add_button');
                $this->data['payment_country_id'] = $order_info['payment_country_id'];
                $this->data['payment_zone_id'] = $order_info['payment_zone_id'];
                $this->data['shipping_country_id'] = $order_info['shipping_country_id'];
                $this->data['shipping_zone_id'] = $order_info['shipping_zone_id'];
                $this->load->model('localisation/country');
                $this->data['countries'] = $this->model_localisation_country->getCountries();]]></add>
                  </operation>
                 <operation>
                <search position="before" offset="1"><![CDATA[protected function validateForm() {]]></search>
                <add><![CDATA[public function addproduct() {
        $json = array();
        $this->load->model('catalog/product');
    
        $product_id = $this->request->get['product_id'];
        $order_id = $this->request->post['order_id'];
        $quantity = $this->request->post['add_quantity'];
    
        $product = $this->model_catalog_product->getProduct($product_id);
           
        if (isset($this->request->post['option'])) {
          $options = $this->request->post['option'];
        } else {
          $options = array();
        }
       
        if ($product['tax_class_id'] > 0) {
          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rule WHERE tax_class_id = '" . (int) $product['tax_class_id'] . "'");
          $tax_rate = $query->rows;
    
          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rate WHERE tax_rate_id = '" . (int) $tax_rate[0]['tax_rate_id'] . "'");
          if ($query->row) {
            $tax_rate = $query->row;
            $tax = $tax_rate['rate'];
          } else {
            $tax = '0';
          }
        } else {
          $tax = '0';
        }
       
        if (count($options) > 0){
          foreach ($options as $product_option_id => $option_values){
          if (is_array($option_values)){
            foreach ($option_values as $key => $product_option_value_id){
    
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_value_id = '" . (int) $product_option_value_id . "'");
              $option = $query->row;
    
              if (isset($option['price'])) {
                if ($option['price_prefix'] == '+') {
                  $product['price'] = $product['price'] + $option['price'];
                } else if ($option['price_prefix'] == '-') {
                  $product['price'] = $product['price'] - $option['price'];
                }
              }
            }
          }
        }
        }
    
    
        $actual_tax = ($product['price'] * $quantity) * ($tax / 100);
    
        $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int) $order_id . "', product_id = '" . (int) $product_id . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int) $quantity . "', price = '" . $this->db->escape($product['price']) . "', total = '" . $this->db->escape($product['price'] * $quantity) . "', tax = '" . $this->db->escape($actual_tax) . "'");
       
        if (count($options) > 0){
          $order_product_id = $this->db->getLastId();
    
          foreach ($options as $product_option_id => $option_values){
          if (is_array($option_values)){
            foreach ($option_values as $key => $product_option_value_id){
    
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_value_id = '" . (int) $product_option_value_id . "'");
              $option = $query->row;
             
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_value_description WHERE option_value_id = '" . (int) $option['option_value_id'] . "' AND language_id = '" . (int) $this->config->get('config_language_id') . "'");
              $option_value_description = $query->row;
    
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_description WHERE option_id = '" . (int) $option['option_id'] . "' AND language_id = '" . (int) $this->config->get('config_language_id') . "'");
              $option_description = $query->row;
             
              $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int) $order_id . "', order_product_id = '" . (int) $order_product_id . "', product_option_id = '" . (int) $product_option_id . "', product_option_value_id = '" . (int) $product_option_value_id . "', name = '" . $this->db->escape($option_description['name']) . "', value = '" . $this->db->escape($option_value_description['name']) . "', type = 'select'");
             
            }
            }else{
             
              $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option` WHERE product_option_id = '" . (int) $product_option_id . "'");
              $option = $query->row;
             
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_value_id = '" . (int) $option_values . "'");
              $option_value = $query->row;
             
              if (isset($option_value['option_value_id'])){
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_value_description WHERE option_value_id = '" . $this->db->escape($option_value['option_value_id']) . "' AND language_id = '" . (int) $this->config->get('config_language_id') . "'");
              $option_value_description = $query->row;
             
                if ($option_value_description){
                  $option_values = $option_value_description['name'];
                }
              }
             
             
              $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_description WHERE option_id = '" . (int) $option['option_id'] . "' AND language_id = '" . (int) $this->config->get('config_language_id') . "'");
              $option_description = $query->row;
             
              $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int) $order_id . "', order_product_id = '" . (int) $order_product_id . "', product_option_id = '" . (int) $product_option_id . "', product_option_value_id = '0', name = '" . $this->db->escape($option_description['name']) . "', value = '" . $this->db->escape($option_values) . "'");
            }
            }
          }
       
    
    
        $value = $product['price'] * $quantity;
        $tax_value = ($product['price'] * $quantity) * ($tax / 100);
    
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='sub_total' AND order_id = '" . (int) $order_id . "'");
        $sub_total = $query->row;
    
        $new_sub_total = $sub_total['value'] + $value;
    
        $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_sub_total . "', text = '" . $this->currency->format($new_sub_total) . "' WHERE order_total_id = '" . (int) $sub_total['order_total_id'] . "'");
    
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='auto_discount' AND order_id = '" . (int) $order_id . "'");
        $new_auto_discount_difference = 0;
        if ($query->row) {
          $total = $query->row;
    
          $auto_discount_amount = preg_replace('/[^0-9]/Uis', '', $total['title']);
          $new_auto_discount -= $new_sub_total * ($auto_discount_amount / 100);
          $new_auto_discount_difference = $new_auto_discount - $total['value'];
    
          $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_auto_discount . "', text = '" . $this->currency->format($new_auto_discount) . "' WHERE order_total_id = '" . (int) $total['order_total_id'] . "'");
          $json['auto_discount'] = $this->currency->format($new_auto_discount);
        }
    
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='coupon' AND order_id = '" . (int) $order_id . "'");
        $new_coupon_total_difference = 0;
        if ($query->row) {
          $total = $query->row;
    
          $coupon_code = preg_replace('/Coupon\(/Uis', '', $total['title']);
          $coupon_code = preg_replace('/\)/Uis', '', $coupon_code);
    
          $couponquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code='" . $coupon_code . "'");
          $coupon = $couponquery->row;
    
          if ($coupon['type'] == "P") {
            $new_coupon_total -= $new_sub_total * ($coupon['discount'] / 100);
            $new_coupon_total_difference = $new_coupon_total - $total['value'];
    
            $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_coupon_total . "', text = '" . $this->currency->format($new_coupon_total) . "' WHERE order_total_id = '" . (int) $total['order_total_id'] . "'");
            $json['coupon'] = $this->currency->format($new_coupon_total);
          }
        }
    
        $new_tax_total = '';
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='tax' AND order_id = '" . (int) $order_id . "'");
        if ($query->row) {
          $tax_total = $query->row;
    
          $new_tax_total = $tax_total['value'] + $tax_value;
    
          $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_tax_total . "', text = '" . $this->currency->format($new_tax_total) . "' WHERE order_total_id = '" . (int) $tax_total['order_total_id'] . "'");
        }
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='total' AND order_id = '" . (int) $order_id . "'");
        $total = $query->row;
    
        $totalsquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code !='total' AND order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC");
    
        $totals = $totalsquery->rows;
    
        $new_total = 0;
        foreach ($totals as $total2) {
          $new_total += $total2['value'];
        }
    
    
        $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_total . "', text = '" . $this->currency->format($new_total) . "' WHERE order_total_id = '" . (int) $total['order_total_id'] . "'");
    
        $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . $new_total . "' WHERE order_id = '" . (int) $order_id . "'");
    
        $json['sub_total'] = $this->currency->format($new_sub_total);
        $json['tax'] = $this->currency->format($new_tax_total);
        $json['total'] = $this->currency->format($new_total);
        $json['refesh'] = 1;
    
        $this->response->setOutput(json_encode($json));
      }
     
      public function productoptions() {
        $this->load->library('customer');
        $this->registry->set(('customer'), new Customer($this->registry));
    
        $this->load->library('tax');
        $this->registry->set(('tax'), new Tax($this->registry));
    
        $this->load->library('cart');
        $this->registry->set(('cart'), new Cart($this->registry));
       
        $this->load->language('catalog/product');
    
        $this->load->model('catalog/product');
    
        $this->load->model('tool/image');
    
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE `product_id` = '" . $this->request->get['product_id'] . "'");
        $product_info = $query->row;
    
        $options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
    
    
        $this->data['options'] = array();
    
        foreach ($options as $option) {
          if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
            $option_value_data = array();
    
            foreach ($option['product_option_value'] as $option_value) {
              if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
                $option_value_data[] = array(
                    'product_option_value_id' => $option_value['product_option_value_id'],
                    'option_value_id' => $option_value['option_value_id'],
                    'name' => $option_value['name'],
                    'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
                    'price' => (float) $option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
                    'price_prefix' => $option_value['price_prefix']
                );
              }
            }
    
            $this->data['options'][] = array(
                'product_option_id' => $option['product_option_id'],
                'option_id' => $option['option_id'],
                'name' => $option['name'],
                'type' => $option['type'],
                'option_value' => $option_value_data,
                'required' => $option['required']
            );
          } elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
            $this->data['options'][] = array(
                'product_option_id' => $option['product_option_id'],
                'option_id' => $option['option_id'],
                'name' => $option['name'],
                'type' => $option['type'],
                'option_value' => $option['option_value'],
                'required' => $option['required']
            );
          }
        }
    
        $this->data['text_select'] = $this->language->get('text_select');
        $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
        $this->data['text_model'] = $this->language->get('text_model');
        $this->data['text_reward'] = $this->language->get('text_reward');
        $this->data['text_points'] = $this->language->get('text_points');
        $this->data['text_discount'] = $this->language->get('text_discount');
        $this->data['text_stock'] = $this->language->get('text_stock');
        $this->data['text_price'] = $this->language->get('text_price');
        $this->data['text_tax'] = $this->language->get('text_tax');
        $this->data['text_discount'] = $this->language->get('text_discount');
        $this->data['text_option'] = $this->language->get('text_option');
        $this->data['text_qty'] = $this->language->get('text_qty');
        $this->data['text_or'] = $this->language->get('text_or');
        $this->data['text_write'] = $this->language->get('text_write');
        $this->data['text_note'] = $this->language->get('text_note');
        $this->data['text_share'] = $this->language->get('text_share');
        $this->data['text_wait'] = $this->language->get('text_wait');
        $this->data['text_tags'] = $this->language->get('text_tags');
        $this->data['button_upload'] = $this->language->get('button_upload');
    
        $this->template = 'sale/options.tpl';
    
        $this->response->setOutput($this->render());
      }
    
       
        public function ajaxupdateitem() {
            $json = array();
           
            $updatetotals = 0;
            if (isset($this->request->get['order_id']) && isset($this->request->get['field'])) {
                $this->load->model('catalog/product');
                $order_id = $this->request->get['order_id'];
                $field = $this->request->get['field'];
                $field_value = $this->request->get['val'];
                $order_product_id = preg_replace('/[^0-9]/Uis','', $field);
               
               
                // get item
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_product_id='" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
                   
                $order_product = $query->row;
                //order_product_id     order_id     product_id     name     model     quantity     price     total     tax
               
                $tax_rate = round($order_product['tax']/$order_product['price'],3);
               
                if (strpos($field, 'quantity_') === 0){
               
                    $order_product_total = $order_product['price'] * $field_value;
                   
                    // new tax
                    $new_tax_total = $order_product_total * $tax_rate;
                   
                    // update db
                    $this->db->query("UPDATE `" . DB_PREFIX . "order_product` SET quantity = '" . (int)$field_value . "', total = '" . $this->db->escape($order_product_total) . "' WHERE order_product_id = '" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
    
                    $json['ok'] = 1;
                    $json['product_quantity'] = $field_value;
                    $json['product_total'] = $this->currency->format($order_product_total);
                   
                    // update totals
                    $updatetotals = 1;
                   
                }
                if (strpos($field, 'price_') === 0){
                    $field_value = preg_replace('/[^0-9\.]/Uis','', $field_value);
    
                    $order_product_total = $order_product['quantity'] * $field_value;
                   
                    // new tax
                    $new_tax_total = $order_product_total * $tax_rate;
                    $new_tax_value = $field_value * $tax_rate;
                   
                    // update db
                    $this->db->query("UPDATE `" . DB_PREFIX . "order_product` SET price = '" . $field_value . "', total = '" . $this->db->escape($order_product_total) . "', tax='".$this->db->escape($new_tax_value)."' WHERE order_product_id = '" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
                    $json['ok'] = 1;
                    $json['product_price'] = $this->currency->format($field_value);
                    $json['product_total'] = $this->currency->format($order_product_total);
                   
                    // update totals
                    $updatetotals = 1;
                   
                }
                if (strpos($field, 'total_') === 0){
                    $field_value = preg_replace('/[^0-9\.]/Uis','', $field_value);
                   
                    $order_product_price = round(($field_value / $order_product['quantity']), 2)  ;
                   
                    $order_product_total = $field_value;
                   
                    // new tax
                    $new_tax_total = $order_product_total * $tax_rate;
                    $new_tax_value = $order_product_price * $tax_rate;
                   
                    // update db
                    $this->db->query("UPDATE `" . DB_PREFIX . "order_product` SET price = '" . $order_product_price . "', total = '" . $this->db->escape($order_product_total) . "', tax='".$this->db->escape($new_tax_value)."' WHERE order_product_id = '" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
                    $json['ok'] = 1;
                    $json['product_price'] = $this->currency->format($order_product_price);
                    $json['product_total'] = $this->currency->format($order_product_total);
                   
                    // update totals
                    $updatetotals = 1;
                   
                }
               
                if (strpos($field, 'name_') === 0){
                    $this->db->query("UPDATE `" . DB_PREFIX . "order_product` SET name = '" . $this->db->escape($field_value) . "' WHERE order_product_id = '" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
    
                    $json['ok'] = 1;
                }
               
                if (strpos($field, 'model_') === 0){
                    $this->db->query("UPDATE `" . DB_PREFIX . "order_product` SET model = '" . $this->db->escape($field_value) . "' WHERE order_product_id = '" . (int)$order_product_id . "' AND order_id = '" . (int)$order_id . "'");
                    $json['ok'] = 1;
                }
               
               
                if ($updatetotals == 1){
               
                    $tax_difference = $new_tax_total-($order_product['tax']*$order_product['quantity']);//($order_product_total - $order_product['total']) * ($order_product['tax']/100);
                    $sub_total_difference = $order_product_total - $order_product['total'];
                    $total_difference = $sub_total_difference + $tax_difference;
               
                    // Get the tax
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='tax' AND order_id = '" . (int)$order_id . "'");
                    $tax_total = $query->row;
               
                    if (isset($tax_total['value'])){
                        $new_tax_total = $tax_total['value'] + $tax_difference;
                        $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_tax_total . "', text = '" . $this->currency->format($new_tax_total) . "' WHERE order_total_id = '" . (int)$tax_total['order_total_id'] . "'");
                    }else{
                        $new_tax_total = 0;
                    }
                   
                    // Get the sub_total
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='sub_total' AND order_id = '" . (int)$order_id . "'");
                    $total = $query->row;
               
                    $new_sub_total = $total['value'] + $sub_total_difference;
               
                    $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_sub_total . "', text = '" . $this->currency->format($new_sub_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
                   
                    // Get the auto_discount
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='auto_discount' AND order_id = '" . (int)$order_id . "'");
                    $new_auto_discount_difference = 0;
                    if ($query->row){
                    $total = $query->row;
                   
                    $auto_discount_amount = preg_replace('/[^0-9]/Uis','', $total['title']);
                    $new_auto_discount -= $new_sub_total * ($auto_discount_amount/100);
                    $new_auto_discount_difference = $new_auto_discount - $total['value'];
                   
                    $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_auto_discount . "', text = '" . $this->currency->format($new_auto_discount) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
                    $json['auto_discount'] = $this->currency->format($new_auto_discount);
                    }
                   
                    // Get the coupon
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='coupon' AND order_id = '" . (int)$order_id . "'");
                    $new_coupon_total_difference = 0;
                    if ($query->row){
                    $total = $query->row;
                   
                    //Coupon(NEW5OFF)
                    $coupon_code = preg_replace('/Coupon\(/Uis','',$total['title']);
                    $coupon_code = preg_replace('/\)/Uis','',$coupon_code);
    
                        // get coupon details
                        $couponquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code='" . $coupon_code . "'");
                        $coupon = $couponquery->row;
                       
                        if ($coupon['type'] == "P"){
                            $new_coupon_total -= $new_sub_total * ($coupon['discount']/100);
                            $new_coupon_total_difference = $new_coupon_total - $total['value'];
                           
                            $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_coupon_total . "', text = '" . $this->currency->format($new_coupon_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
                            $json['coupon'] = $this->currency->format($new_coupon_total);
                        }
    
                    }
                   
                    // Get the total
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='total' AND order_id = '" . (int)$order_id . "'");
                    $total = $query->row;
                   
                    // Get totals and recalc
                    $totalsquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code !='total' AND order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
                   
                    $totals = $totalsquery->rows;
                   
                    $new_total = 0;
                    foreach ($totals as $total2) {
                        if ($total2['code'] == 'auto_discount' && $total2['value'] > 1){$total2['value'] = 0 - $total2['value'];}
                        $new_total += $total2['value'];
                    }
                   
                    //$new_total = $total['value'] + $total_difference + $new_auto_discount_difference + $new_coupon_total_difference;
               
                    $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_total . "', text = '" . $this->currency->format($new_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
               
                    // Update order total on order.           
                    $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . $new_total . "' WHERE order_id = '" . (int)$order_id . "'");
                   
                    $json['sub_total'] = $this->currency->format($new_sub_total);
                    $json['tax'] = $this->currency->format($new_tax_total);
                    $json['total'] = $this->currency->format($new_total);
                   
                    $json['order_product_id'] = $order_product_id;
                   
                }
               
            }
    
           
            $this->response->setOutput(json_encode($json));
       
        }
       
       
        public function ajaxupdate() {
            $json = array();
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['field'])) {
                $this->load->model('catalog/product');
               
                $order_id = $this->request->get['order_id'];
                $field_id = $this->request->get['field'];
                $field_value = $this->request->get['val'];
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET " . $field_id . " = '" . $this->db->escape($field_value) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                   
                    $json[] = array(
                        'ok' => 1,
                    );   
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['shipping_country_id'])) {
           
                $order_id = $this->request->get['order_id'];
                $shipping_country_id = $this->request->get['shipping_country_id'];
               
                $this->load->model('localisation/country');
           
                $shipping_country = $this->model_localisation_country->getCountry($shipping_country_id);
               
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET shipping_country_id = '" . (int)$shipping_country_id . "', shipping_country = '" . $this->db->escape($shipping_country['name']) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                $json['country'] = $shipping_country['name'];
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['shipping_zone_id'])) {
           
                $order_id = $this->request->get['order_id'];
                $shipping_zone_id = $this->request->get['shipping_zone_id'];
               
                $this->load->model('localisation/zone');
           
                $shipping_zone = $this->model_localisation_zone->getZone($shipping_zone_id);
               
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET shipping_zone_id = '" . (int)$shipping_zone_id . "', shipping_zone = '" . $this->db->escape($shipping_zone['name']) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                $json['zone'] = $shipping_zone['name'];
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['payment_country_id'])) {
           
                $order_id = $this->request->get['order_id'];
                $payment_country_id = $this->request->get['payment_country_id'];
               
                $this->load->model('localisation/country');
           
                $payment_country = $this->model_localisation_country->getCountry($payment_country_id);
               
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET payment_country_id = '" . (int)$payment_country_id . "', payment_country = '" . $this->db->escape($payment_country['name']) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                $json['country'] = $payment_country['name'];
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['payment_zone_id'])) {
           
                $order_id = $this->request->get['order_id'];
                $payment_zone_id = $this->request->get['payment_zone_id'];
               
                $this->load->model('localisation/zone');
           
                $payment_zone = $this->model_localisation_zone->getZone($payment_zone_id);
               
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET payment_zone_id = '" . (int)$payment_zone_id . "', payment_zone = '" . $this->db->escape($payment_zone['name']) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                $json['zone'] = $payment_zone['name'];
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['shipping'])) {
           
                $order_id = $this->request->get['order_id'];
                $shipping = $this->request->get['shipping'];
               
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='shipping' AND order_id = '" . (int)$order_id . "'");
                $shipping_old = $query->row;
               
                $shipping_difference = $shipping - $shipping_old['value'];
               
                $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "'");
                $order_info = $order_query->row;
               
                $this->load->model('setting/setting');
                $shipping_tax_class = $this->model_setting_setting->getSetting('shipping', $order_info['store_id']);
               
                if (isset($shipping_tax_class['shipping_default_tax_class'])){
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rate WHERE tax_rate_id = '" . (int)$shipping_tax_class['shipping_default_tax_class'] . "'");
           
                $shipping_tax_value = $query->rows;
                if (isset($shipping_tax_value[0])){
                    $tax_difference = $shipping_difference * ($shipping_tax_value[0]['rate']/100);
                }else{
                    $tax_difference = 0;
                }
                }else{
                    $tax_difference = 0;
                }
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='tax' AND order_id = '" . (int)$order_id . "'");
                $tax_total = $query->row;
               
                if (isset($tax_total['value'])){
                    $new_tax_total = $tax_total['value'] + $tax_difference;
                    $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_tax_total . "', text = '" . $this->currency->format($new_tax_total) . "' WHERE order_total_id = '" . (int)$tax_total['order_total_id'] . "'");
                }else{
                    $new_tax_total = 0;
                }
               
                $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $this->db->escape($shipping) . "', text = '" . $this->currency->format($shipping) . "' WHERE order_id = '" . (int)$order_id . "' AND code='shipping'");
               
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='total' AND order_id = '" . (int)$order_id . "'");
                $total = $query->row;
               
                    $totalsquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code !='total' AND order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
                   
                    $totals = $totalsquery->rows;
                   
                    $new_total = 0;
                    foreach ($totals as $total2) {
                    if ($total2['code'] == 'auto_discount' && $total2['value'] > 1){$total2['value'] = 0 - $total2['value'];}
                        $new_total += $total2['value'];
                    }
                           
                $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_total . "', text = '" . $this->currency->format($new_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . $new_total . "' WHERE order_id = '" . (int)$order_id . "'");
               
               
                $json['shipping'] = $this->currency->format($shipping);
                $json['tax'] = $this->currency->format($new_tax_total);
                $json['total'] = $this->currency->format($new_total);
           
               
            }
           
            if (isset($this->request->get['order_id']) && isset($this->request->get['delete_product'])) {
           
                $order_id = $this->request->get['order_id'];
                $order_product_id = $this->request->get['delete_product'];
               
                $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_product_id = '" . (int)$order_product_id . "'");
               
                $order_product = $order_product_query->row;
               
                $value = $order_product['quantity'] * $order_product['price'];
                $tax = $order_product['tax'];
               
               
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='sub_total' AND order_id = '" . (int)$order_id . "'");
                $sub_total = $query->row;
               
                $new_sub_total = $sub_total['value'] - $value;
               
                $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_sub_total . "', text = '" . $this->currency->format($new_sub_total) . "' WHERE order_total_id = '" . (int)$sub_total['order_total_id'] . "'");
               
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='auto_discount' AND order_id = '" . (int)$order_id . "'");
                    $new_auto_discount_difference = 0;
                    if ($query->row){
                    $total = $query->row;
                   
                    $auto_discount_amount = preg_replace('/[^0-9]/Uis','', $total['title']);
                    $new_auto_discount -= $new_sub_total * ($auto_discount_amount/100);
                    $new_auto_discount_difference = $new_auto_discount - $total['value'];
                   
                    $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_auto_discount . "', text = '" . $this->currency->format($new_auto_discount) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
                    $json['auto_discount'] = $this->currency->format($new_auto_discount);
                    }
                   
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='coupon' AND order_id = '" . (int)$order_id . "'");
                    $new_coupon_total_difference = 0;
                    if ($query->row){
                    $total = $query->row;
                   
                    $coupon_code = preg_replace('/Coupon\(/Uis','',$total['title']);
                    $coupon_code = preg_replace('/\)/Uis','',$coupon_code);
    
                        $couponquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code='" . $coupon_code . "'");
                        $coupon = $couponquery->row;
                       
                        if ($coupon['type'] == "P"){
                            $new_coupon_total -= $new_sub_total * ($coupon['discount']/100);
                            $new_coupon_total_difference = $new_coupon_total - $total['value'];
                           
                            $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_coupon_total . "', text = '" . $this->currency->format($new_coupon_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
                            $json['coupon'] = $this->currency->format($new_coupon_total);
                        }
    
                    }
               
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='tax' AND order_id = '" . (int)$order_id . "'");
                $tax_total = $query->row;
                if ($query->row){
                $new_tax_total = $tax_total['value'] - $tax;
               
                $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_tax_total . "', text = '" . $this->currency->format($new_tax_total) . "' WHERE order_total_id = '" . (int)$tax_total['order_total_id'] . "'");
                }else{
                $new_tax_total = 0;
                }
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code='total' AND order_id = '" . (int)$order_id . "'");
                $total = $query->row;
               
                    $totalsquery = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE code !='total' AND order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
                   
                    $totals = $totalsquery->rows;
                   
                    $new_total = 0;
                    foreach ($totals as $total2) {
                    if ($total2['code'] == 'auto_discount' && $total2['value'] > 1){$total2['value'] = 0 - $total2['value'];}
                        $new_total += $total2['value'];
                    }
               
               
                $this->db->query("UPDATE " . DB_PREFIX . "order_total SET value = '" . $new_total . "', text = '" . $this->currency->format($new_total) . "' WHERE order_total_id = '" . (int)$total['order_total_id'] . "'");
               
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . $new_total . "' WHERE order_id = '" . (int)$order_id . "'");
               
                $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_product_id = '" . (int)$order_product_id . "'");
               
               
                $json['sub_total'] = $this->currency->format($new_sub_total);
                $json['tax'] = $this->currency->format($new_tax_total);
                $json['total'] = $this->currency->format($new_total);
                $json['deleted'] = $order_product_id;
               
            }
           
           
            $this->response->setOutput(json_encode($json));
           
        }
       
    
        public function zone() {
        $output = '<option value="">' . $this->language->get('text_select') . '</option>';
    
        $this->load->model('localisation/zone');
    
        $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
    
        foreach ($results as $result) {
          $output .= '<option value="' . $result['zone_id'] . '"';
    
          if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
            $output .= ' selected="selected"';
          }
    
          $output .= '>' . $result['name'] . '</option>';
        }
    
        if (!$results) {
          $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
        }
    
        $this->response->setOutput($output);
      }
    
       
    ]]></add>
                    </operation>
             </file>
    </modification>
    и вот код model
    admin/model/sale/order.php
    Код:
    <?php
    class ModelSaleOrder extends Model {
        public function addOrder($data) {
            $this->load->model('setting/store');
           
            $store_info = $this->model_setting_store->getStore($data['store_id']);
           
            if ($store_info) {
                $store_name = $store_info['name'];
                $store_url = $store_info['url'];
            } else {
                $store_name = $this->config->get('config_name');
                $store_url = HTTP_CATALOG;
            }
           
            $this->load->model('setting/setting');
           
            $setting_info = $this->model_setting_setting->getSetting('setting', $data['store_id']);
               
            if (isset($setting_info['invoice_prefix'])) {
                $invoice_prefix = $setting_info['invoice_prefix'];
            } else {
                $invoice_prefix = $this->config->get('config_invoice_prefix');
            }
           
            $this->load->model('localisation/country');
           
            $this->load->model('localisation/zone');
           
            $country_info = $this->model_localisation_country->getCountry($data['shipping_country_id']);
           
            if ($country_info) {
                $shipping_country = $country_info['name'];
                $shipping_address_format = $country_info['address_format'];
            } else {
                $shipping_country = '';   
                $shipping_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
            }   
           
            $zone_info = $this->model_localisation_zone->getZone($data['shipping_zone_id']);
           
            if ($zone_info) {
                $shipping_zone = $zone_info['name'];
            } else {
                $shipping_zone = '';           
            }   
                       
            $country_info = $this->model_localisation_country->getCountry($data['payment_country_id']);
           
            if ($country_info) {
                $payment_country = $country_info['name'];
                $payment_address_format = $country_info['address_format'];           
            } else {
                $payment_country = '';   
                $payment_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';                   
            }
       
            $zone_info = $this->model_localisation_zone->getZone($data['payment_zone_id']);
           
            if ($zone_info) {
                $payment_zone = $zone_info['name'];
            } else {
                $payment_zone = '';           
            }   
    
            $this->load->model('localisation/currency');
    
            $currency_info = $this->model_localisation_currency->getCurrencyByCode($this->config->get('config_currency'));
           
            if ($currency_info) {
                $currency_id = $currency_info['currency_id'];
                $currency_code = $currency_info['code'];
                $currency_value = $currency_info['value'];
            } else {
                $currency_id = 0;
                $currency_code = $this->config->get('config_currency');
                $currency_value = 1.00000;           
            }
             
              $this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($invoice_prefix) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($store_name) . "',store_url = '" . $this->db->escape($store_url) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($payment_country) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($payment_zone) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($payment_address_format) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($shipping_country) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($shipping_zone) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($shipping_address_format) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', order_status_id = '" . (int)$data['order_status_id'] . "', affiliate_id  = '" . (int)$data['affiliate_id'] . "', language_id = '" . (int)$this->config->get('config_language_id') . "', currency_id = '" . (int)$currency_id . "', currency_code = '" . $this->db->escape($currency_code) . "', currency_value = '" . (float)$currency_value . "', date_added = NOW(), date_modified = NOW()");
             
              $order_id = $this->db->getLastId();
           
              if (isset($data['order_product'])) {       
                  foreach ($data['order_product'] as $order_product) {
           
            /*suppler*/
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "suppler_base_price WHERE `product_id` = " . (int)$product["product_id"] . "");
               
            if (empty($query->rows)) $query->rows[0]["bprice"] = 0;
       
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', bprice = '" . (float)$query->rows[0]["bprice"] . "', /*suppler*/ tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "'");
               
                    $order_product_id = $this->db->getLastId();
                   
                    $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");
                   
                    if (isset($order_product['order_option'])) {
                        foreach ($order_product['order_option'] as $order_option) {
                            $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$order_option['product_option_id'] . "', product_option_value_id = '" . (int)$order_option['product_option_value_id'] . "', name = '" . $this->db->escape($order_option['name']) . "', `value` = '" . $this->db->escape($order_option['value']) . "', `type` = '" . $this->db->escape($order_option['type']) . "'");
                           
                            $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_option_value_id = '" . (int)$order_option['product_option_value_id'] . "' AND subtract = '1'");
                        }
                    }
                   
                    if (isset($order_product['order_download'])) {
                        foreach ($order_product['order_download'] as $order_download) {
                            $this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($order_download['name']) . "', filename = '" . $this->db->escape($order_download['filename']) . "', mask = '" . $this->db->escape($order_download['mask']) . "', remaining = '" . (int)$order_download['remaining'] . "'");
                        }
                    }
                }
            }
           
            if (isset($data['order_voucher'])) {   
                foreach ($data['order_voucher'] as $order_voucher) {   
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_voucher SET order_id = '" . (int)$order_id . "', voucher_id = '" . (int)$order_voucher['voucher_id'] . "', description = '" . $this->db->escape($order_voucher['description']) . "', code = '" . $this->db->escape($order_voucher['code']) . "', from_name = '" . $this->db->escape($order_voucher['from_name']) . "', from_email = '" . $this->db->escape($order_voucher['from_email']) . "', to_name = '" . $this->db->escape($order_voucher['to_name']) . "', to_email = '" . $this->db->escape($order_voucher['to_email']) . "', voucher_theme_id = '" . (int)$order_voucher['voucher_theme_id'] . "', message = '" . $this->db->escape($order_voucher['message']) . "', amount = '" . (float)$order_voucher['amount'] . "'");
               
                      $this->db->query("UPDATE " . DB_PREFIX . "voucher SET order_id = '" . (int)$order_id . "' WHERE voucher_id = '" . (int)$order_voucher['voucher_id'] . "'");
                }
            }
    
            // Get the total
            $total = 0;
           
            if (isset($data['order_total'])) {       
                  foreach ($data['order_total'] as $order_total) {   
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($order_total['code']) . "', title = '" . $this->db->escape($order_total['title']) . "', text = '" . $this->db->escape($order_total['text']) . "', `value` = '" . (float)$order_total['value'] . "', sort_order = '" . (int)$order_total['sort_order'] . "'");
                }
               
                $total += $order_total['value'];
            }
    
            // Affiliate
            $affiliate_id = 0;
            $commission = 0;
           
            if (!empty($this->request->post['affiliate_id'])) {
                $this->load->model('sale/affiliate');
               
                $affiliate_info = $this->model_sale_affiliate->getAffiliate($this->request->post['affiliate_id']);
               
                if ($affiliate_info) {
                    $affiliate_id = $affiliate_info['affiliate_id'];
                    $commission = ($total / 100) * $affiliate_info['commission'];
                }
            }
           
            // Update order total             
            $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . (float)$total . "', affiliate_id = '" . (int)$affiliate_id . "', commission = '" . (float)$commission . "' WHERE order_id = '" . (int)$order_id . "'");     
        }
       
        public function editOrder($order_id, $data) {
            $this->load->model('localisation/country');
           
            $this->load->model('localisation/zone');
           
            $country_info = $this->model_localisation_country->getCountry($data['shipping_country_id']);
           
            if ($country_info) {
                $shipping_country = $country_info['name'];
                $shipping_address_format = $country_info['address_format'];
            } else {
                $shipping_country = '';   
                $shipping_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
            }   
           
            $zone_info = $this->model_localisation_zone->getZone($data['shipping_zone_id']);
           
            if ($zone_info) {
                $shipping_zone = $zone_info['name'];
            } else {
                $shipping_zone = '';           
            }   
                       
            $country_info = $this->model_localisation_country->getCountry($data['payment_country_id']);
           
            if ($country_info) {
                $payment_country = $country_info['name'];
                $payment_address_format = $country_info['address_format'];           
            } else {
                $payment_country = '';   
                $payment_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';                   
            }
       
            $zone_info = $this->model_localisation_zone->getZone($data['payment_zone_id']);
           
            if ($zone_info) {
                $payment_zone = $zone_info['name'];
            } else {
                $payment_zone = '';           
            }           
    
            // Restock products before subtracting the stock later on
            $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND order_id = '" . (int)$order_id . "'");
    
            if ($order_query->num_rows) {
                $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
    
                foreach($product_query->rows as $product) {
                    $this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "' AND subtract = '1'");
    
                    $option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
    
                    foreach ($option_query->rows as $option) {
                        $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
                    }
                }
            }
    
              $this->db->query("UPDATE `" . DB_PREFIX . "order` SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($payment_country) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($payment_zone) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($payment_address_format) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "',  shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($shipping_country) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($shipping_zone) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($shipping_address_format) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', order_status_id = '" . (int)$data['order_status_id'] . "', affiliate_id  = '" . (int)$data['affiliate_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
                   
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
               $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
           
              if (isset($data['order_product'])) {       
                  foreach ($data['order_product'] as $order_product) {   
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_product_id = '" . (int)$order_product['order_product_id'] . "', order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "'");
               
                    $order_product_id = $this->db->getLastId();
    
                    $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");
       
                    if (isset($order_product['order_option'])) {
                        foreach ($order_product['order_option'] as $order_option) {
                            $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_option_id = '" . (int)$order_option['order_option_id'] . "', order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$order_option['product_option_id'] . "', product_option_value_id = '" . (int)$order_option['product_option_value_id'] . "', name = '" . $this->db->escape($order_option['name']) . "', `value` = '" . $this->db->escape($order_option['value']) . "', `type` = '" . $this->db->escape($order_option['type']) . "'");
                           
                           
                            $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_option_value_id = '" . (int)$order_option['product_option_value_id'] . "' AND subtract = '1'");
                        }
                    }
                   
                    if (isset($order_product['order_download'])) {
                        foreach ($order_product['order_download'] as $order_download) {
                            $this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_download_id = '" . (int)$order_download['order_download_id'] . "', order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($order_download['name']) . "', filename = '" . $this->db->escape($order_download['filename']) . "', mask = '" . $this->db->escape($order_download['mask']) . "', remaining = '" . (int)$order_download['remaining'] . "'");
                        }
                    }
                }
            }
           
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher WHERE order_id = '" . (int)$order_id . "'");
           
            if (isset($data['order_voucher'])) {   
                foreach ($data['order_voucher'] as $order_voucher) {   
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_voucher SET order_voucher_id = '" . (int)$order_voucher['order_voucher_id'] . "', order_id = '" . (int)$order_id . "', voucher_id = '" . (int)$order_voucher['voucher_id'] . "', description = '" . $this->db->escape($order_voucher['description']) . "', code = '" . $this->db->escape($order_voucher['code']) . "', from_name = '" . $this->db->escape($order_voucher['from_name']) . "', from_email = '" . $this->db->escape($order_voucher['from_email']) . "', to_name = '" . $this->db->escape($order_voucher['to_name']) . "', to_email = '" . $this->db->escape($order_voucher['to_email']) . "', voucher_theme_id = '" . (int)$order_voucher['voucher_theme_id'] . "', message = '" . $this->db->escape($order_voucher['message']) . "', amount = '" . (float)$order_voucher['amount'] . "'");
               
                    $this->db->query("UPDATE " . DB_PREFIX . "voucher SET order_id = '" . (int)$order_id . "' WHERE voucher_id = '" . (int)$order_voucher['voucher_id'] . "'");
                }
            }
           
            // Get the total
            $total = 0;
                   
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
           
            if (isset($data['order_total'])) {       
                  foreach ($data['order_total'] as $order_total) {   
                      $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_total_id = '" . (int)$order_total['order_total_id'] . "', order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($order_total['code']) . "', title = '" . $this->db->escape($order_total['title']) . "', text = '" . $this->db->escape($order_total['text']) . "', `value` = '" . (float)$order_total['value'] . "', sort_order = '" . (int)$order_total['sort_order'] . "'");
                }
               
                $total += $order_total['value'];
            }
           
            // Affiliate
            $affiliate_id = 0;
            $commission = 0;
           
            if (!empty($this->request->post['affiliate_id'])) {
                $this->load->model('sale/affiliate');
               
                $affiliate_info = $this->model_sale_affiliate->getAffiliate($this->request->post['affiliate_id']);
               
                if ($affiliate_info) {
                    $affiliate_id = $affiliate_info['affiliate_id'];
                    $commission = ($total / 100) * $affiliate_info['commission'];
                }
            }
                     
            $this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . (float)$total . "', affiliate_id = '" . (int)$affiliate_id . "', commission = '" . (float)$commission . "' WHERE order_id = '" . (int)$order_id . "'");
        }
       
        public function deleteOrder($order_id) {
            $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND order_id = '" . (int)$order_id . "'");
    
            if ($order_query->num_rows) {
                $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
    
                foreach($product_query->rows as $product) {
                    $this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "' AND subtract = '1'");
    
                    $option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
    
                    foreach ($option_query->rows as $option) {
                        $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
                    }
                }
            }
    
            $this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
              $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher WHERE order_id = '" . (int)$order_id . "'");
              $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "order_fraud WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "customer_transaction WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
            $this->db->query("DELETE FROM " . DB_PREFIX . "affiliate_transaction WHERE order_id = '" . (int)$order_id . "'");
        }
    
        public function getOrder($order_id) {
            $order_query = $this->db->query("SELECT *, (SELECT CONCAT(c.firstname, ' ', c.lastname) FROM " . DB_PREFIX . "customer c WHERE c.customer_id = o.customer_id) AS customer FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'");
    
            if ($order_query->num_rows) {
                $reward = 0;
               
                $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
           
                foreach ($order_product_query->rows as $product) {
                    $reward += $product['reward'];
                }           
               
                $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'");
    
                if ($country_query->num_rows) {
                    $payment_iso_code_2 = $country_query->row['iso_code_2'];
                    $payment_iso_code_3 = $country_query->row['iso_code_3'];
                } else {
                    $payment_iso_code_2 = '';
                    $payment_iso_code_3 = '';
                }
    
                $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
    
                if ($zone_query->num_rows) {
                    $payment_zone_code = $zone_query->row['code'];
                } else {
                    $payment_zone_code = '';
                }
               
                $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
    
                if ($country_query->num_rows) {
                    $shipping_iso_code_2 = $country_query->row['iso_code_2'];
                    $shipping_iso_code_3 = $country_query->row['iso_code_3'];
                } else {
                    $shipping_iso_code_2 = '';
                    $shipping_iso_code_3 = '';
                }
    
                $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
    
                if ($zone_query->num_rows) {
                    $shipping_zone_code = $zone_query->row['code'];
                } else {
                    $shipping_zone_code = '';
                }
           
                if ($order_query->row['affiliate_id']) {
                    $affiliate_id = $order_query->row['affiliate_id'];
                } else {
                    $affiliate_id = 0;
                }               
                   
                $this->load->model('sale/affiliate');
                   
                $affiliate_info = $this->model_sale_affiliate->getAffiliate($affiliate_id);
                   
                if ($affiliate_info) {
                    $affiliate_firstname = $affiliate_info['firstname'];
                    $affiliate_lastname = $affiliate_info['lastname'];
                } else {
                    $affiliate_firstname = '';
                    $affiliate_lastname = '';               
                }
    
                $this->load->model('localisation/language');
               
                $language_info = $this->model_localisation_language->getLanguage($order_query->row['language_id']);
               
                if ($language_info) {
                    $language_code = $language_info['code'];
                    $language_filename = $language_info['filename'];
                    $language_directory = $language_info['directory'];
                } else {
                    $language_code = '';
                    $language_filename = '';
                    $language_directory = '';
                }
               
                return array(
                    'order_id'                => $order_query->row['order_id'],
                    'invoice_no'              => $order_query->row['invoice_no'],
                    'invoice_prefix'          => $order_query->row['invoice_prefix'],
                    'store_id'                => $order_query->row['store_id'],
                    'store_name'              => $order_query->row['store_name'],
                    'store_url'               => $order_query->row['store_url'],
                    'customer_id'             => $order_query->row['customer_id'],
                    'customer'                => $order_query->row['customer'],
                    'customer_group_id'       => $order_query->row['customer_group_id'],
                    'firstname'               => $order_query->row['firstname'],
                    'lastname'                => $order_query->row['lastname'],
                    'telephone'               => $order_query->row['telephone'],
                    'fax'                     => $order_query->row['fax'],
                    'email'                   => $order_query->row['email'],
                    'payment_firstname'       => $order_query->row['payment_firstname'],
                    'payment_lastname'        => $order_query->row['payment_lastname'],
                    'payment_company'         => $order_query->row['payment_company'],
                    'payment_company_id'      => $order_query->row['payment_company_id'],
                    'payment_tax_id'          => $order_query->row['payment_tax_id'],
                    'payment_address_1'       => $order_query->row['payment_address_1'],
                    'payment_address_2'       => $order_query->row['payment_address_2'],
                    'payment_postcode'        => $order_query->row['payment_postcode'],
                    'payment_city'            => $order_query->row['payment_city'],
                    'payment_zone_id'         => $order_query->row['payment_zone_id'],
                    'payment_zone'            => $order_query->row['payment_zone'],
                    'payment_zone_code'       => $payment_zone_code,
                    'payment_country_id'      => $order_query->row['payment_country_id'],
                    'payment_country'         => $order_query->row['payment_country'],
                    'payment_iso_code_2'      => $payment_iso_code_2,
                    'payment_iso_code_3'      => $payment_iso_code_3,
                    'payment_address_format'  => $order_query->row['payment_address_format'],
                    'payment_method'          => $order_query->row['payment_method'],
                    'payment_code'            => $order_query->row['payment_code'],               
                    'shipping_firstname'      => $order_query->row['shipping_firstname'],
                    'shipping_lastname'       => $order_query->row['shipping_lastname'],
                    'shipping_company'        => $order_query->row['shipping_company'],
                    'shipping_address_1'      => $order_query->row['shipping_address_1'],
                    'shipping_address_2'      => $order_query->row['shipping_address_2'],
                    'shipping_postcode'       => $order_query->row['shipping_postcode'],
                    'shipping_city'           => $order_query->row['shipping_city'],
                    'shipping_zone_id'        => $order_query->row['shipping_zone_id'],
                    'shipping_zone'           => $order_query->row['shipping_zone'],
                    'shipping_zone_code'      => $shipping_zone_code,
                    'shipping_country_id'     => $order_query->row['shipping_country_id'],
                    'shipping_country'        => $order_query->row['shipping_country'],
                    'shipping_iso_code_2'     => $shipping_iso_code_2,
                    'shipping_iso_code_3'     => $shipping_iso_code_3,
                    'shipping_address_format' => $order_query->row['shipping_address_format'],
                    'shipping_method'         => $order_query->row['shipping_method'],
                    'shipping_code'           => $order_query->row['shipping_code'],
                    'comment'                 => $order_query->row['comment'],
                    'total'                   => $order_query->row['total'],
                    'reward'                  => $reward,
                    'order_status_id'         => $order_query->row['order_status_id'],
                    'affiliate_id'            => $order_query->row['affiliate_id'],
                    'affiliate_firstname'     => $affiliate_firstname,
                    'affiliate_lastname'      => $affiliate_lastname,
                    'commission'              => $order_query->row['commission'],
                    'language_id'             => $order_query->row['language_id'],
                    'language_code'           => $language_code,
                    'language_filename'       => $language_filename,
                    'language_directory'      => $language_directory,               
                    'currency_id'             => $order_query->row['currency_id'],
                    'currency_code'           => $order_query->row['currency_code'],
                    'currency_value'          => $order_query->row['currency_value'],
                    'ip'                      => $order_query->row['ip'],
                    'forwarded_ip'            => $order_query->row['forwarded_ip'],
                    'user_agent'              => $order_query->row['user_agent'],   
                    'accept_language'         => $order_query->row['accept_language'],                   
                    'date_added'              => $order_query->row['date_added'],
                    'date_modified'           => $order_query->row['date_modified']
                );
            } else {
                return false;
            }
        }
       
        public function getOrders($data = array()) {
            $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
    
            if (isset($data['filter_order_status_id']) && !is_null($data['filter_order_status_id'])) {
                $sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
            } else {
                $sql .= " WHERE o.order_status_id > '0'";
            }
    
            if (!empty($data['filter_order_id'])) {
                $sql .= " AND o.order_id = '" . (int)$data['filter_order_id'] . "'";
            }
    
            if (!empty($data['filter_customer'])) {
                $sql .= " AND CONCAT(o.firstname, ' ', o.lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
            }
    
            if (!empty($data['filter_date_added'])) {
                $sql .= " AND DATE(o.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
            }
           
            if (!empty($data['filter_date_modified'])) {
                $sql .= " AND DATE(o.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
            }
           
            if (!empty($data['filter_total'])) {
                $sql .= " AND o.total = '" . (float)$data['filter_total'] . "'";
            }
    
            $sort_data = array(
                'o.order_id',
                'customer',
                'status',
                'o.date_added',
                'o.date_modified',
                'o.total'
            );
    
            if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
                $sql .= " ORDER BY " . $data['sort'];
            } else {
                $sql .= " ORDER BY o.order_id";
            }
    
            if (isset($data['order']) && ($data['order'] == 'DESC')) {
                $sql .= " DESC";
            } else {
                $sql .= " ASC";
            }
    
            if (isset($data['start']) || isset($data['limit'])) {
                if ($data['start'] < 0) {
                    $data['start'] = 0;
                }
    
                if ($data['limit'] < 1) {
                    $data['limit'] = 20;
                }
    
                $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
            }
    
            $query = $this->db->query($sql);
    
            return $query->rows;
        }
           
        public function getOrderWarranty($product_id) {
            $n1 = "Warranty";
            $n2 = "Гаран";
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_attribute a LEFT JOIN " . DB_PREFIX . "attribute_description d ON (d.attribute_id = a.attribute_id) WHERE a.product_id = '" . $product_id . "' AND (d.name LIKE '" . $n1 . "%' OR d.name LIKE '" . $n2 . "%')");
           
            return $query->row;       
        } /*suppler*/
           
        public function getOrderProducts($order_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
           
            return $query->rows;
        }
       
        public function getOrderOption($order_id, $order_option_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_option_id = '" . (int)$order_option_id . "'");
    
            return $query->row;
        }
       
        public function getOrderOptions($order_id, $order_product_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
    
            return $query->rows;
        }
    
        public function getOrderDownloads($order_id, $order_product_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
    
            return $query->rows;
        }
       
        public function getOrderVouchers($order_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_voucher WHERE order_id = '" . (int)$order_id . "'");
           
            return $query->rows;
        }
       
        public function getOrderVoucherByVoucherId($voucher_id) {
              $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE voucher_id = '" . (int)$voucher_id . "'");
    
            return $query->row;
        }
                   
        public function getOrderTotals($order_id) {
            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order");
    
            return $query->rows;
        }
    
        public function getTotalOrders($data = array()) {
              $sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order`";
    
            if (isset($data['filter_order_status_id']) && !is_null($data['filter_order_status_id'])) {
                $sql .= " WHERE order_status_id = '" . (int)$data['filter_order_status_id'] . "'";
            } else {
                $sql .= " WHERE order_status_id > '0'";
            }
    
            if (!empty($data['filter_order_id'])) {
                $sql .= " AND order_id = '" . (int)$data['filter_order_id'] . "'";
            }
    
            if (!empty($data['filter_customer'])) {
                $sql .= " AND CONCAT(firstname, ' ', lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
            }
    
            if (!empty($data['filter_date_added'])) {
                $sql .= " AND DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
            }
           
            if (!empty($data['filter_date_modified'])) {
                $sql .= " AND DATE(o.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
            }
           
            if (!empty($data['filter_total'])) {
                $sql .= " AND total = '" . (float)$data['filter_total'] . "'";
            }
    
            $query = $this->db->query($sql);
    
            return $query->row['total'];
        }
    
        public function getTotalOrdersByStoreId($store_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE store_id = '" . (int)$store_id . "'");
    
            return $query->row['total'];
        }
    
        public function getTotalOrdersByOrderStatusId($order_status_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$order_status_id . "' AND order_status_id > '0'");
    
            return $query->row['total'];
        }
    
        public function getTotalOrdersByLanguageId($language_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE language_id = '" . (int)$language_id . "' AND order_status_id > '0'");
    
            return $query->row['total'];
        }
    
        public function getTotalOrdersByCurrencyId($currency_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE currency_id = '" . (int)$currency_id . "' AND order_status_id > '0'");
    
            return $query->row['total'];
        }
       
        public function getTotalSales() {
              $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0'");
    
            return $query->row['total'];
        }
    
        public function getTotalSalesByYear($year) {
              $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND YEAR(date_added) = '" . (int)$year . "'");
    
            return $query->row['total'];
        }
    
        public function createInvoiceNo($order_id) {
            $order_info = $this->getOrder($order_id);
               
            if ($order_info && !$order_info['invoice_no']) {
                $query = $this->db->query("SELECT MAX(invoice_no) AS invoice_no FROM `" . DB_PREFIX . "order` WHERE invoice_prefix = '" . $this->db->escape($order_info['invoice_prefix']) . "'");
       
                if ($query->row['invoice_no']) {
                    $invoice_no = $query->row['invoice_no'] + 1;
                } else {
                    $invoice_no = 1;
                }
           
                $this->db->query("UPDATE `" . DB_PREFIX . "order` SET invoice_no = '" . (int)$invoice_no . "', invoice_prefix = '" . $this->db->escape($order_info['invoice_prefix']) . "' WHERE order_id = '" . (int)$order_id . "'");
               
                return $order_info['invoice_prefix'] . $invoice_no;
            }
        }
       
        public function addOrderHistory($order_id, $data) {
            $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$data['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
    
            $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$data['order_status_id'] . "', notify = '" . (isset($data['notify']) ? (int)$data['notify'] : 0) . "', comment = '" . $this->db->escape(strip_tags($data['comment'])) . "', date_added = NOW()");
    
            $order_info = $this->getOrder($order_id);
    
            // Send out any gift voucher mails
            if ($this->config->get('config_complete_status_id') == $data['order_status_id']) {
                $this->load->model('sale/voucher');
    
                $results = $this->getOrderVouchers($order_id);
               
                foreach ($results as $result) {
                    $this->model_sale_voucher->sendVoucher($result['voucher_id']);
                }
            }
    
              if ($data['notify']) {
                $language = new Language($order_info['language_directory']);
                $language->load($order_info['language_filename']);
                $language->load('mail/order');
    
                $subject = sprintf($language->get('text_subject'), $order_info['store_name'], $order_id);
    
                $message  = $language->get('text_order') . ' ' . $order_id . "\n";
                $message .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n\n";
               
                $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$data['order_status_id'] . "' AND language_id = '" . (int)$order_info['language_id'] . "'");
                   
                if ($order_status_query->num_rows) {
                    $message .= $language->get('text_order_status') . "\n";
                    $message .= $order_status_query->row['name'] . "\n\n";
                }
               
                if ($order_info['customer_id']) {
                    $message .= $language->get('text_link') . "\n";
                    $message .= html_entity_decode($order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id, ENT_QUOTES, 'UTF-8') . "\n\n";
                }
               
                if ($data['comment']) {
                    $message .= $language->get('text_comment') . "\n\n";
                    $message .= strip_tags(html_entity_decode($data['comment'], ENT_QUOTES, 'UTF-8')) . "\n\n";
                }
    
                $message .= $language->get('text_footer');
    
                $mail = new Mail();
                $mail->protocol = $this->config->get('config_mail_protocol');
                $mail->parameter = $this->config->get('config_mail_parameter');
                $mail->hostname = $this->config->get('config_smtp_host');
                $mail->username = $this->config->get('config_smtp_username');
                $mail->password = $this->config->get('config_smtp_password');
                $mail->port = $this->config->get('config_smtp_port');
                $mail->timeout = $this->config->get('config_smtp_timeout');
                $mail->setTo($order_info['email']);
                $mail->setFrom($this->config->get('config_email'));
                $mail->setSender($order_info['store_name']);
                $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
                $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
                $mail->send();
            }
        }
           
        public function getOrderHistories($order_id, $start = 0, $limit = 10) {
            if ($start < 0) {
                $start = 0;
            }
           
            if ($limit < 1) {
                $limit = 10;
            }   
                   
            $query = $this->db->query("SELECT oh.date_added, os.name AS status, oh.comment, oh.notify FROM " . DB_PREFIX . "order_history oh LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id WHERE oh.order_id = '" . (int)$order_id . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
    
            return $query->rows;
        }
       
        public function getTotalOrderHistories($order_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
    
            return $query->row['total'];
        }   
           
        public function getTotalOrderHistoriesByOrderStatusId($order_status_id) {
              $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "order_history WHERE order_status_id = '" . (int)$order_status_id . "'");
    
            return $query->row['total'];
        }   
       
        public function getEmailsByProductsOrdered($products, $start, $end) {
            $implode = array();
    
            foreach ($products as $product_id) {
                $implode[] = "op.product_id = '" . (int)$product_id . "'";
            }
    
            $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0' AND o.email <> '' LIMIT " . (int)$start . "," . (int)$end);
    
            return $query->rows;
        }
    
        public function getTotalEmailsByProductsOrdered($products) {
            $implode = array();
    
            foreach ($products as $product_id) {
                $implode[] = "op.product_id = '" . (int)$product_id . "'";
            }
    
            $query = $this->db->query("SELECT DISTINCT email FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE (" . implode(" OR ", $implode) . ") AND o.order_status_id <> '0' AND o.email <> ''");   
    
            return $query->rows;
        }   
    }
    ?>
    
     
    Lasted edited by : 4 янв 2016
  6. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    А зачем мне код модели admin/model/sale/order.php?
    Я просил строку, в которой объявляется массив $options, вот эта строка из vQmod:
    PHP:
    $options $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
    Как не сложно заметить, опции загружает модель admin/model/catalog/product. Соответственно, и смотреть нужно в ней, а именно метод getProductOptions.
     
  7. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    Даже в таком случае я не совсем понимаю что необходимо сделать что бы опции корректно выводились с названиями

    если не трудно можете подсказать что именно нужно дописать или переписать что бы всё заработало как нужно?
     
  8. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Я не телепат. Вы выложили не ту модель, я указал, какую надо, вы вместо того, чтоб её выложить, задаёте вопросы, на которые я не могу дать ответ не видя нужную модель.
     
  9. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40

    модель admin/model/catalog/product метод getProductOptions
    PHP:
    public function getProductOptions($product_id) {
            
    $product_option_data = array();
          
            
    $product_option_query $this->db->query("SELECT * FROM `" DB_PREFIX "product_option` po LEFT JOIN `" DB_PREFIX "option` o ON (po.option_id = o.option_id) LEFT JOIN `" DB_PREFIX "option_description` od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "'");
          
            foreach (
    $product_option_query->rows as $product_option) {
                
    $product_option_value_data = array();  
                  
                
    $product_option_value_query $this->db->query("SELECT * FROM " DB_PREFIX "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'");
                  
                foreach (
    $product_option_value_query->rows as $product_option_value) {
                    
    $product_option_value_data[] = array(
                        
    'product_option_value_id' => $product_option_value['product_option_value_id'],
                        
    'option_value_id'         => $product_option_value['option_value_id'],
                        
    'quantity'                => $product_option_value['quantity'],
                        
    'subtract'                => $product_option_value['subtract'],
                        
    'price'                   => $product_option_value['price'],
                        
    'price_prefix'            => $product_option_value['price_prefix'],
                        
    'points'                  => $product_option_value['points'],
                        
    'points_prefix'           => $product_option_value['points_prefix'],                      
                        
    'weight'                  => $product_option_value['weight'],
                        
    "optsku"                    => $product_option_value["optsku"], /*suppler*/
                        
    'weight_prefix'           => $product_option_value['weight_prefix']                  
                    );
                }
                  
                
    $product_option_data[] = array(
                    
    'product_option_id'    => $product_option['product_option_id'],
                    
    'option_id'            => $product_option['option_id'],
                    
    'name'                 => $product_option['name'],
                    
    'type'                 => $product_option['type'],          
                    
    'product_option_value' => $product_option_value_data,
                    
    'option_value'         => $product_option['option_value'],
                    
    'required'             => $product_option['required']              
                );
            }
          
            return 
    $product_option_data;
        }
     
    Lasted edited by : 6 янв 2016
  10. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Приведите эту строку:
    PHP:
    $product_option_value_query $this->db->query("SELECT * FROM " DB_PREFIX "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'");
    к такому виду:
    PHP:
    $product_option_value_query $this->db->query("SELECT * FROM " DB_PREFIX "product_option_value pov LEFT JOIN `" DB_PREFIX "option_value_description` ovd ON (pov.option_value_id = ovd.option_value_id) WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
    и добавьте после
    PHP:
    'option_value_id' => $product_option_value['option_value_id'],
    это:
    PHP:
    'name' => $product_option_value['name'],
     
  11. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    Огромное спасибо названия опций выводятся

    но вот осталась ошибка с image и ещё когда в опции присутствует + к цене при добавлении она не учитывается.
    (то есть если цена товара к примеру 1273 а цена размера на 25 грн. выше то при нажатии на ADD - указывается цена 1273 грн. ) можно каким то образом это исправить?
    [​IMG]
     
    Lasted edited by : 7 янв 2016
  12. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Нужно опять отредактировать тот же запрос:
    PHP:
    $product_option_value_query $this->db->query("SELECT * FROM " DB_PREFIX "product_option_value pov 
    LEFT JOIN `" 
    DB_PREFIX "option_value` ov ON (pov.option_value_id = ov.option_value_id) 
    LEFT JOIN `" 
    DB_PREFIX "option_value_description` ovd ON (pov.option_value_id = ovd.option_value_id) 
    WHERE product_option_id = '" 
    . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); 
    И добавить, как и в случае с именем, это:
    PHP:
    'image' => $product_option_value['image'],
     
  13. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    а можно ли сделать таким образом что бы работал вот этот код
    PHP:
    public function productoptions() {
        
    $this->load->library('customer');
        
    $this->registry->set(('customer'), new Customer($this->registry));

        
    $this->load->library('tax');
        
    $this->registry->set(('tax'), new Tax($this->registry));

        
    $this->load->library('cart');
        
    $this->registry->set(('cart'), new Cart($this->registry));
      
        
    $this->load->language('catalog/product');

        
    $this->load->model('catalog/product');

        
    $this->load->model('tool/image');

        
    $query $this->db->query("SELECT * FROM " DB_PREFIX "product WHERE `product_id` = '" $this->request->get['product_id'] . "'");
        
    $product_info $query->row;

        
    $options $this->model_catalog_product->getProductOptions($this->request->get['product_id']);


        
    $this->data['options'] = array();

        foreach (
    $options as $option) {
          if (
    $option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
            
    $option_value_data = array();

            foreach (
    $option['product_option_value'] as $option_value) {
              if (!
    $option_value['subtract'] || ($option_value['quantity'] > 0)) {
                
    $option_value_data[] = array(
                    
    'product_option_value_id' => $option_value['product_option_value_id'],
                    
    'option_value_id' => $option_value['option_value_id'],
                    
    'name' => $option_value['name'],
                    
    'image' => $this->model_tool_image->resize($option_value['image'], 5050),
                    
    'price' => (float) $option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
                    
    'price_prefix' => $option_value['price_prefix']
                );
              }
            }

            
    $this->data['options'][] = array(
                
    'product_option_id' => $option['product_option_id'],
                
    'option_id' => $option['option_id'],
                
    'name' => $option['name'],
                
    'type' => $option['type'],
                
    'option_value' => $option_value_data,
                
    'required' => $option['required']
            );
          } elseif (
    $option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
            
    $this->data['options'][] = array(
                
    'product_option_id' => $option['product_option_id'],
                
    'option_id' => $option['option_id'],
                
    'name' => $option['name'],
                
    'type' => $option['type'],
                
    'option_value' => $option['option_value'],
                
    'required' => $option['required']
            );
          }
        }

        
    $this->data['text_select'] = $this->language->get('text_select');
        
    $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
        
    $this->data['text_model'] = $this->language->get('text_model');
        
    $this->data['text_reward'] = $this->language->get('text_reward');
        
    $this->data['text_points'] = $this->language->get('text_points');
        
    $this->data['text_discount'] = $this->language->get('text_discount');
        
    $this->data['text_stock'] = $this->language->get('text_stock');
        
    $this->data['text_price'] = $this->language->get('text_price');
        
    $this->data['text_tax'] = $this->language->get('text_tax');
        
    $this->data['text_discount'] = $this->language->get('text_discount');
        
    $this->data['text_option'] = $this->language->get('text_option');
        
    $this->data['text_qty'] = $this->language->get('text_qty');
        
    $this->data['text_or'] = $this->language->get('text_or');
        
    $this->data['text_write'] = $this->language->get('text_write');
        
    $this->data['text_note'] = $this->language->get('text_note');
        
    $this->data['text_share'] = $this->language->get('text_share');
        
    $this->data['text_wait'] = $this->language->get('text_wait');
        
    $this->data['text_tags'] = $this->language->get('text_tags');
        
    $this->data['button_upload'] = $this->language->get('button_upload');

        
    $this->template 'sale/options.tpl';

        
    $this->response->setOutput($this->render());
      }
    без правки в admin/model/catalog/product метод getProductOptions потому как при переходе в товар всплывают ошибки
     
    Lasted edited by : 8 янв 2016
  14. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Ну, можно отдельный метод в модели сделать конкретно для этого случая (просто скопировать getProductOptions и изменить название).
    А какие ошибки?
     
  15. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    получается так что вот эта строка ( $this->template = 'sale/options.tpl'; ) обращается к отдельному файлу options.tpl

    который содержит код admin/view/template/sale/options.tpl
    Код:
    <?php if ($options) { ?>
          <div class="options">
            <?php foreach ($options as $option) { ?>
            <?php if ($option['type'] == 'select') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <select name="option[<?php echo $option['product_option_id']; ?>]">
                <option value=""><?php echo $text_select; ?></option>
                <?php foreach ($option['option_value'] as $option_value) { ?>
                <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
                </option>
                <?php } ?>
              </select>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'radio') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
              <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
              </label>
              <br />
              <?php } ?>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'checkbox') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
              <label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                <?php } ?>
              </label>
              <br />
              <?php } ?>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'image') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
                <table class="option-image">
                  <?php foreach ($option['option_value'] as $option_value) { ?>
                  <tr>
                    <td style="width: 1px;"><input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" /></td>
                    <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" /></label></td>
                    <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                        <?php if ($option_value['price']) { ?>
                        (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                        <?php } ?>
                      </label></td>
                  </tr>
                  <?php } ?>
                </table>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'text') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'textarea') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <textarea name="option[<?php echo $option['product_option_id']; ?>]" cols="40" rows="5"><?php echo $option['option_value']; ?></textarea>
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'date') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="date" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'datetime') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="datetime" />
            </div>
            <br />
            <?php } ?>
            <?php if ($option['type'] == 'time') { ?>
            <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <b><?php echo $option['name']; ?>:</b><br />
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="time" />
            </div>
            <br />
            <?php } ?>
            <?php } ?>
          </div>
          <?php } ?>
    
    Ошибки больше нету в карточке товара.

    Только осталась ошибка и image и пересчётом стоимости в опциях. Ещё былоб здорово корректно настроить удаление товаров с заказа поскольку на данный момент оно не работает.
     
    Последнее редактирование: 9 янв 2016
  16. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    помогите пожалуйста отредактировать код что бы исчезла ошибка. Не силён в програмировани
    [​IMG]
     
    Последнее редактирование: 3 фев 2016
  17. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Если после этой правки ошибка не исчезла, значит вы что-то сделали не так.
     
  18. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40

    я не знаю как правильно сделать вот такой запрос 'image' => $product_option_value['image'],

    в этом поле
    Код:
    $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov
    LEFT JOIN `" . DB_PREFIX . "option_value` ov ON (pov.option_value_id = ov.option_value_id)
    LEFT JOIN `" . DB_PREFIX . "option_value_description` ovd ON (pov.option_value_id = ovd.option_value_id)
    WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
    
     
    Последнее редактирование: 3 фев 2016
  19. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    2.054
    Симпатии:
    779
    Ох.
    Я же написал, куда это вписывать:
    Для названия вы подобную строку куда вписывали?
     
  20. maetus

    maetus

    Регистрация:
    24 фев 2013
    Сообщения:
    216
    Симпатии:
    40
    PHP:
    foreach ($product_option_value_query->rows as $product_option_value) {
                    
    $product_option_value_data[] = array(
                        
    'product_option_value_id' => $product_option_value['product_option_value_id'],
                        
    'option_value_id'         => $product_option_value['option_value_id'],
                        
    'name' => $product_option_value['name'],
                        
    'quantity'                => $product_option_value['quantity'],
                        
    'subtract'                => $product_option_value['subtract'],
                        
    'price'                   => $product_option_value['price'],
                        
    'price_prefix'            => $product_option_value['price_prefix'],
                        
    'points'                  => $product_option_value['points'],
                        
    'points_prefix'           => $product_option_value['points_prefix'],                      
                        
    'weight'                  => $product_option_value['weight'],
                        
    "optsku"                  => $product_option_value["optsku"], /*suppler*/
                        
    'weight_prefix'           => $product_option_value['weight_prefix']                  
                    );
                }
    вот сюда я вставил строку
    'name' => $product_option_value['name'],
     
    Lasted edited by : 4 фев 2016