bigo Posted January 22, 2025 at 10:58 PM Share Posted January 22, 2025 at 10:58 PM Здравствуйте сделал вкладку с баннерами но захотел добавить заголовок и ссылку для кнопок по подобию других полей сделал но не сохраняются в базе поля <file path="admin/view/template/catalog/category_form.twig"> <operation error="skip"> <search><![CDATA[{{ tab_data }}</a></li>]]></search> <add position="after"><![CDATA[ <li><a href="#tab-image" data-toggle="tab">Баннеры</a></li> ]]></add> </operation> <operation error="skip"> <search><![CDATA[<div class="tab-pane" id="tab-data">]]></search> <add position="before"><![CDATA[ <div class="tab-pane" id="tab-image"> <div class="table-responsive"> <table id="images" class="table table-striped table-bordered table-hover"> <thead> <tr> <td class="text-left">{{ entry_image }}</td> <td class="text-right">Заголовок кнопки</td> <td class="text-right">Ссылка кнопки</td> <td class="text-right">{{ entry_sort_order }}</td> <td></td> </tr> </thead> <tbody> {% set image_row = 0 %} {% for category_image in category_images %} <tr id="image-row{{ image_row }}"> <td class="text-left"><a href="" id="thumb-image{{ image_row }}" data-toggle="image" class="img-thumbnail"><img src="{{ category_image['thumb'] }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a><input type="hidden" name="category_image[{{ image_row }}][image]" value="{{ category_image['image'] }}" id="input-image{{ image_row }}" /></td> <td class="text-right"><input type="text" name="category_image[{{ image_row }}][banner_title]" value="{{ category_image['sort_orde_t'] }}" placeholder="Заголовок кнопки" class="form-control" /></td> <td class="text-right"><input type="text" name="category_image[{{ image_row }}][banner_link]" value="{{ category_image['banner_link'] }}" placeholder="Ссылка кнопки" class="form-control" /></td> <td class="text-right"><input type="text" name="category_image[{{ image_row }}][sort_order]" value="{{ category_image['sort_order'] }}" placeholder="{{ entry_sort_order }}" class="form-control" /></td> <td class="text-left"><button type="button" onclick="$('#image-row{{ image_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td> </tr> {% set image_row = image_row + 1 %} {% endfor %} </tbody> <tfoot> <tr> <td colspan="4"></td> <td class="text-left"><button type="button" onclick="addImage();" data-toggle="tooltip" title="{{ button_image_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td> </tr> </tfoot> </table> </div> </div> ]]></add> </operation> <operation error="skip"> <search><![CDATA[{{ footer }}]]></search> <add position="before"><![CDATA[ <script type="text/javascript"><!-- var image_row = {{ image_row }}; function addImage() { html = '<tr id="image-row' + image_row + '">'; html += ' <td class="text-left"><a href="" id="thumb-image' + image_row + '"data-toggle="image" class="img-thumbnail"><img src="{{ placeholder }}" alt="" title="" data-placeholder="{{ placeholder }}" /><input type="hidden" name="category_image[' + image_row + '][image]" value="" id="input-image' + image_row + '" /></td>'; html += ' <td class="text-right"><input type="text" name="category_image[' + image_row + '][banner_title]" value="" placeholder="Заголовок кнопки" class="form-control" /></td>'; html += ' <td class="text-right"><input type="text" name="category_image[' + image_row + '][banner_link]" value="" placeholder="Ссылка кнопки" class="form-control" /></td>'; html += ' <td class="text-right"><input type="text" name="category_image[' + image_row + '][sort_order]" value="" placeholder="{{ entry_sort_order }}" class="form-control" /></td>'; html += ' <td class="text-left"><button type="button" onclick="$(\'#image-row' + image_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>'; html += '</tr>'; $('#images tbody').append(html); image_row++; } //--></script> ]]></add> </operation> </file> <file path="admin/controller/catalog/category.php"> <operation error="skip"> <search><![CDATA[$this->load->model('catalog/category');]]></search> <add position="after"><![CDATA[ $this->model_catalog_category->createCategoryImageTable(); ]]></add> </operation> <operation error="skip"> <search><![CDATA[if (isset($this->request->post['category_layout'])) {]]></search> <add position="before"><![CDATA[ if (isset($this->request->post['category_image'])) { $category_images = $this->request->post['category_image']; } elseif (isset($this->request->get['category_id'])) { $category_images = $this->model_catalog_category->getCategoryImages($this->request->get['category_id']); } else { $category_images = array(); } $data['category_images'] = array(); foreach ($category_images as $category_image) { if (is_file(DIR_IMAGE . $category_image['image'])) { $image = $category_image['image']; $thumb = $category_image['image']; } else { $image = ''; $thumb = 'no_image.png'; } $data['category_images'][] = array( 'image' => $image, 'thumb' => $this->model_tool_image->resize($thumb, 100, 100), 'sort_order' => $category_image['sort_order'], 'banner_title' => $banner_title, 'banner_link' => $banner_link ); } ]]></add> </operation> </file> <file path="admin/model/catalog/category.php"> <operation error="skip"> <search><![CDATA[public function getCategoryStores]]></search> <add position="before"><![CDATA[ public function getCategoryImages($category_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_image WHERE category_id = '" . (int)$category_id. "' ORDER BY sort_order ASC"); return $query->rows; } public function createCategoryImageTable() { $query = $this->db->query(" CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "category_image` ( `category_image_id` int(11) NOT NULL AUTO_INCREMENT, `category_id` int(11) NOT NULL, `image` varchar(255) DEFAULT NULL, `sort_order` int(3) NOT NULL DEFAULT '0', `banner_title` varchar(255) DEFAULT NULL, `banner_link` varchar(255) DEFAULT NULL, PRIMARY KEY (`category_image_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; "); } ]]></add> </operation> <operation error="skip"> <search><![CDATA[$category_id = $this->db->getLastId();]]></search> <add position="after"><![CDATA[ if (isset($data['category_image'])) { foreach ($data['category_image'] as $category_image) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_image SET category_id = '" . (int)$category_id . "', image = '" . $this->db->escape($category_image['image']) . "', sort_order = '" . (int)$category_image['sort_order'] . "'"); } } ]]></add> </operation> <operation error="skip"> <search><![CDATA[public function editCategory($category_id, $data) {]]></search> <add position="after"><![CDATA[ $this->db->query("DELETE FROM " . DB_PREFIX . "category_image WHERE category_id = '" . (int)$category_id . "'"); if (isset($data['category_image'])) { foreach ($data['category_image'] as $category_image) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_image SET category_id = '" . (int)$category_id . "', image = '" . $this->db->escape($category_image['image']) . "', sort_order = '" . (int)$category_image['sort_order'] . "'"); } } ]]></add> </operation> <operation error="skip"> <search><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "category WHERE category_id]]></search> <add position="before"><![CDATA[ $this->db->query("DELETE FROM " . DB_PREFIX . "category_image WHERE category_id = '" . (int)$category_id . "'"); ]]></add> </operation> </file> <file path="catalog/model/catalog/category.php"> <operation error="skip"> <search><![CDATA[public function getCategoryLayoutId]]></search> <add position="before"><![CDATA[ public function getCategoryImages($category_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_image WHERE category_id = '" . (int)$category_id . "' ORDER BY sort_order ASC"); return $query->rows; } ]]></add> </operation> </file> Поля добавил 'banner_title' => $banner_title, 'banner_link' => $banner_link Подскажите что делаю не так 0 Quote Link to comment Share on other sites More sharing options...
Tom Posted January 23, 2025 at 04:59 PM Share Posted January 23, 2025 at 04:59 PM Как минимум добавить переменные $banner_title и $banner_link перед их использованием. В файле admin/controller/catalog/category.php . Ну и внимательней пересмотреть модель admin/model/catalog/category.php 0 Quote Link to comment Share on other sites More sharing options...
Solution bigo Posted January 24, 2025 at 09:27 PM Author Solution Share Posted January 24, 2025 at 09:27 PM Спасибо за помощь нашел у себя какой то модуль Изображений для категорий переделал и сделал модуль с выводом как баннера одно так и сделать слайдер category_banner_3.x.ocmod.zip 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.