<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>DearSoft Short Description Attribute</name>
    <code>DearSoft-short-description-attribute</code>
    <version>1.1</version>
    <author>DearSoft</author>
    <link>https://dearsoft.bd</link>

    <file path="admin/controller/catalog/product.php">
        <operation>
            <search><![CDATA[$data['languages'] = $this->model_localisation_language->getLanguages();]]></search>
            <add position="after"><![CDATA[
                //short description attribute start
                $data['short_description_attribute'] = $this->config->get('short_description_attribute');
                $short_description_attribute = $this->config->get('short_description_attribute');
                if(isset($short_description_attribute['status']) && $short_description_attribute['status'] == 1) {     
                    if (isset($this->request->post['product_short_description'])) {
                        $data['short_description_attributes'] = $this->request->post['product_short_description'];
                    } elseif (isset($this->request->get['product_id'])) {
                        $this->load->model('extension/module/short_description_attribute');                 
                        $data['short_description_attributes'] = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($this->request->get['product_id']);
                    } else {
                        $data['short_description_attributes'] = array();       
                    }
                }
                //short description attribute end
            ]]></add>
        </operation>
    </file>


     <file path="admin/view/template/catalog/product_form.twig">
        <operation>
            <search><![CDATA[<label class="col-sm-2 control-label" for="input-meta-title{{ language.language_id }}">{{ entry_meta_title }}</label>]]></search>
            <add position="before" offset="1"><![CDATA[
            {% if short_description_attribute.status and short_description_attribute.status == 1 %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-description{{ language.language_id }}">Short Description</label>
                        <div class="col-sm-10">
                            <div class="table-responsive">
                                <table id="short-attribute" class="table table-striped table-bordered table-hover">
                                  <thead>
                                    <tr>
                                      <td class="text-left">Featured Text</td>
                                      <td class="text-right"><button type="button" onclick="addAttribute1();" data-toggle="tooltip" title="{{ button_attribute_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                                    </tr>
                                  </thead>
                                  <tbody>
                
                                    {% set short_attribute_row = 0 %}
                                    {% for description_attributes in short_description_attributes %}
                                      <tr id="short-attribute-row{{ short_attribute_row }}">
                                        <td class="text-left">
                                            {% for language in languages %}
                                            <div class="input-group"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}"/></span> 
                                            <textarea name="short_description_attribute[{{ language.language_id }}][description][]" rows="1" placeholder="{{ entry_text }}" class="form-control">{{ description_attributes.description ? description_attributes.description }}</textarea>
                                            </div>
                                          {% endfor %}
                                          </td>
                                        <td class="text-right"><button type="button" onclick="$('#short-attribute-row{{ short_attribute_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
                                      </tr>
                                      {% set short_attribute_row = short_attribute_row + 1 %}
                                    {% endfor %}
                                  </tbody>
                
                                </table>
                              </div>
                        </div>
                    </div>
                    {% endif %}
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[var option_row = {{ option_row }};]]></search>
            <add position="before" offset="1">
                <![CDATA[
                <script type="text/javascript">
                  var short_attribute_row = 100;

                  function addAttribute1() {
                      html = '<tr id="short-attribute-row' + short_attribute_row + '">';
                      html += '  <td class="text-left">';
                    {% for language in languages %}
                      html += '<div class="input-group"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span><textarea name="short_description_attribute[{{ language.language_id }}][description][]" rows="1" placeholder="{{ entry_text }}" class="form-control"></textarea></div>';
                    {% endfor %}
                      html += '  </td>';
                      html += '  <td class="text-right"><button type="button" onclick="$(\'#short-attribute-row' + short_attribute_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
                      html += '</tr>';

                      $('#short-attribute tbody').append(html);

                      short_attribute_row++;
                  }
                  </script>
                ]]>
            </add>
        </operation>
    </file>

    <file path="admin/model/catalog/product.php">
        <operation info="when delete product">
            <search><![CDATA[public function deleteProduct($product_id) {]]></search>
            <add position="after" offset="4"><![CDATA[
            $this->db->query("DELETE FROM " . DB_PREFIX . "product_short_description_attribute WHERE product_id = '" . (int)$product_id . "'");
              ]]></add>
        </operation>  

         <!-- <operation info="when copy product">
            <search><![CDATA[$this->addProduct($data);]]></search>
            <add position="before"><![CDATA[
            $this->load->model('extension/module/short_description'); 
            $data['product_short_description'] =  $this->model_extension_module_short_description_attribute->get_desrc_product_copy($product_id);
                        ]]>
            </add>
        </operation> -->
        
        <operation info="when insert new product">
            <search><![CDATA[$product_id = $this->db->getLastId();]]></search>
            <add position="after"><![CDATA[
                   $this->load->model('extension/module/short_description_attribute'); 
        $this->model_extension_module_short_description_attribute->insert($product_id, $data);                       
                ]]>
            </add>
        </operation>            
        <operation info="when eidt product">
            <search><![CDATA[public function editProduct($product_id, $data) {]]></search>
            <add position="after" offset="1"><![CDATA[
                        $this->load->model('extension/module/short_description_attribute'); 
        $this->model_extension_module_short_description_attribute->insert($product_id, $data);                        
                ]]>
            </add>
        </operation> 
    </file>

    <file path="catalog/controller/product/product.php">
        <operation info="change description show">
            <search><![CDATA[$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');]]></search>
            <add position="replace"><![CDATA[
               //short description attribute start
                $product_id = (int)$this->request->get['product_id'];
                $short_description_config = $this->config->get('short_description_attribute'); 
                $data['product_attributes'] = array();
                if(isset($short_description_config['status']) && $short_description_config['status'] == 1 ) {

                    $this->load->model('extension/module/short_description_attribute');
                    
                    $product_attributes_list = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($product_id);
                    $description = array();
                    foreach($product_attributes_list as $row){
                        if($row['description']){
                            $description[] = html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8');
                        }
                    }
                    $data['product_attributes'] = $description;

                }
                
                $attr_table = '';
                if($data['product_attributes']){
                    
                    $attr_table .= '<div class="module-features-description">
                            <ul>';
                    foreach($data['product_attributes'] as $d){
                        $attr_table .='<li>'.$d.'</li>';
                    }
                    $attr_table .= '</ul>
                        </div>';
                }
                //short description attribute end
                
                $data['description'] = $attr_table;
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/product/category.php">
        <operation info="change description show">
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                //short description attribute start
                $product_id = $result['product_id'];
                $short_description_config = $this->config->get('short_description_attribute'); 
                $data['product_attributes'] = array();
                if(isset($short_description_config['status']) && $short_description_config['status'] == 1 ) {
    
                    $this->load->model('extension/module/short_description_attribute');
                    
                    $product_attributes_list = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($product_id);
                    $description = array();
                    foreach($product_attributes_list as $row){
                        if($row['description']){
                            $description[] = html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8');
                        }
                    }
                    $data['product_attributes'] = $description;
    
                }
                //short description attribute end
            ]]></add>
        </operation>
        <operation info="change description show">
            <search><![CDATA['name'        => $result['name'],]]></search>
            <add position="after">
            <![CDATA[
                'product_attributes' => $data['product_attributes'],
                ]]>
            </add>
        </operation>
    </file>

    <file path="catalog/controller/product/search.php">
        <operation info="change description show">
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                //short description attribute start
                $product_id = $result['product_id'];
                $short_description_config = $this->config->get('short_description_attribute'); 
                $data['product_attributes'] = array();
                if(isset($short_description_config['status']) && $short_description_config['status'] == 1 ) {
    
                    $this->load->model('extension/module/short_description_attribute');
                    
                    $product_attributes_list = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($product_id);
                    $description = array();
                    foreach($product_attributes_list as $row){
                        if($row['description']){
                            $description[] = html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8');
                        }
                    }
                    $data['product_attributes'] = $description;
    
                }
                //short description attribute end
            ]]></add>
        </operation>
        <operation info="change description show">
            <search><![CDATA['name'        => $result['name'],]]></search>
            <add position="after">
            <![CDATA[
                'product_attributes' => $data['product_attributes'],
                ]]>
            </add>
        </operation>
    </file>

    <file path="catalog/view/theme/journal3/template/journal3/product_card.twig">
        <operation>
            <search><![CDATA[<div class="description">{{ product.description }}</div>]]></search>
            <add position="replace"><![CDATA[
                
                <style>
                .module-features-description ul{
                padding-inline-start: 20px !important;
                }
                .module-features-description ul ul{
                display: contents;
                }
                .module-features-description ul ul li {
                    list-style-type: disc;
                }

                </style>
                <div class="description">
                    {% if product.product_attributes %}
                        <div class="module-features-description">
                            <ul>
                                {% for short_attribute in product.product_attributes %}
                                    <li>{{ short_attribute }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                        {% endif %}
                    </div>
                ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/journal3/{blocks,product_tabs}.php">
        <operation info="change description show">
            <search><![CDATA[static::$PRODUCT_INFO['short_description'] = utf8_substr(strip_tags(html_entity_decode(static::$PRODUCT_INFO['description'], ENT_QUOTES, 'UTF-8')), 0, (int)$short_description_limit) . '..';]]></search>
            <add position="replace"><![CDATA[
                //short description attribute start
            $product_id = (int)$this->request->get['product_id'];
            $short_description_config = $this->config->get('short_description_attribute'); 
            $data['product_attributes'] = array();
            if(isset($short_description_config['status']) && $short_description_config['status'] == 1 ) {

                $this->load->model('extension/module/short_description_attribute');
                
                $product_attributes_list = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($product_id);
                $description = array();
                foreach($product_attributes_list as $row){
                    if($row['description']){
                        $description[] = html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8');
                    }
                }
                $data['product_attributes'] = $description;

            }
            
            $attr_table = '';
            if($data['product_attributes']){
                
                $attr_table .= '<div class="module-features-description">
                          <ul>';
                foreach($data['product_attributes'] as $d){
                      $attr_table .='<li>'.$d.'</li>';
                }
                $attr_table .= '</ul>
                    </div>';
            }
            //short description attribute end
            
            //$data['description'] = $attr_table;
            static::$PRODUCT_INFO['short_description'] = $attr_table;
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/extension/pc_builder/pc_builder_search.php">
        <operation info="change description show">
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                //short description attribute start
                $product_id = $result['product_id'];
                $short_description_config = $this->config->get('short_description_attribute'); 
                $data['product_attributes'] = array();
                if(isset($short_description_config['status']) && $short_description_config['status'] == 1 ) {
    
                    $this->load->model('extension/module/short_description_attribute');
                    
                    $product_attributes_list = $this->model_extension_module_short_description_attribute->getShortDescriptionAttributes($product_id);
                    $description = array();
                    foreach($product_attributes_list as $row){
                        if($row['description']){
                            $description[] = html_entity_decode($row['description'], ENT_QUOTES, 'UTF-8');
                        }
                    }
                    $data['product_attributes'] = $description;
    
                }
                //short description attribute end

                $attr_table = '';
                if($data['product_attributes']){
                    
                    $attr_table .= '<div class="module-features-description">
                            <ul>';
                    foreach($data['product_attributes'] as $d){
                        $attr_table .='<li>'.$d.'</li>';
                    }
                    $attr_table .= '</ul>
                        </div>';
                }
                //short description attribute end
            ]]></add>
        </operation>

        <operation info="change description show">
            <search><![CDATA['description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',]]></search>
            <add position="after"><![CDATA['description' => $attr_table,]]></add>
        </operation>

    </file>

</modification>
