villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 (edited) {get_featured_new_products var=featured_new_products limit=10}Вы плагин для Смарти get_featured_new_products реализовали?В принципе можно сделать так:{get_new_products var=featured_new_products sort='position' featured_new=1 limit=10} В админ панели отмечаю чекбокс в базу передается но не делается отмеченным.Смарти не реализовывал.После {get_new_products var=featured_new_products sort='position' featured_new=1 limit=10}Выводится новинки (последние загруженныеА я делаю вывод товаров как рекомендуемые и назвал их Новинки.То есть я хочу реализовать вывод товаров, отмеченных в админке - аналогично рекомендуемым и назвать их новинки Добавил Смартиview/View.php $this->design->smarty->registerPlugin("function", "get_featured_new_products", array($this, 'get_featured_new_products_plugin')); ниже public function get_featured_new_products_plugin($params, &$smarty) { if(!isset($params['visible'])) { $params['visible'] = 1; } $params['featured_new'] = 1; if(!empty($params['var'])) { foreach($this->products->get_products($params) as $p) { $products[$p->id] = $p; } if(!empty($products)) { // id выбраных товаров $products_ids = array_keys($products); // Выбираем варианты товаров $variants = $this->variants->get_variants(array('product_id'=>$products_ids)); // Для каждого варианта foreach($variants as $variant) { // добавляем вариант в соответствующий товар $products[$variant->product_id]->variants[] = $variant; } // Выбираем изображения товаров $images = $this->products->get_images(array('product_id'=>$products_ids)); foreach($images as $image) { $products[$image->product_id]->images[] = $image; } foreach($products as $product) { if(isset($product->variants[0])) { $product->variant = $product->variants[0]; } if(isset($product->images[0])) { $product->image = $product->images[0]; } } } $smarty->assign($params['var'], $products); } } Edited April 2, 2016 by villain1988 Quote Link to post Share on other sites
mishanya Posted April 2, 2016 Report Share Posted April 2, 2016 В админ панели отмечаю чекбокс в базу передается но не делается отмеченным.Смарти не реализовывал.После {get_new_products var=featured_new_products sort='position' featured_new=1 limit=10}Выводится новинки (последние загруженныеА я делаю вывод товаров как рекомендуемые и назвал их Новинки.То есть я хочу реализовать вывод товаров, отмеченных в админке - аналогично рекомендуемым и назвать их новинки из п4 поле для выборки надо добавлять в две ф-и. get_products, get_product p.featured, p.featured_new, из п3 <a class="featured_new" title="Новинки" href="#"></a> нужно еще добавить к этому аякс запрос, в products.tpl по аналогии с запросом строка 436 // Сделать новинкой $("a.featured_new").click(function() { var icon = $(this); var line = icon.closest("div.row"); var id = line.find('input[type="checkbox"][name*="check"]').val(); var state = line.hasClass('featured_new')?0:1; icon.addClass('loading_icon'); $.ajax({ type: 'POST', url: 'ajax/update_object.php', data: {'object': 'product', 'id': id, 'values': {'featured_new': state}, 'session_id': '{/literal}{$smarty.session.id}{literal}'}, success: function(data){ icon.removeClass('loading_icon'); if(state) line.addClass('featured_new'); else line.removeClass('featured_new'); }, dataType: 'json' }); return false; }); + вы в п2 дописали код для множественного добавления в новинки, но он не для п3 (для вашего п3 я выше написал ajax)а для этого в в products.tpl надо дописать после (строка 120 примерно) <option value="set_featured">Сделать рекомендуемым</option> <option value="unset_featured">Отменить рекомендуемый</option> дописать ваши 2 строки <option value="set_featured_new">Сделать новинкой</option> <option value="unset_featured_new">Отменить новинку</option> Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 из п4 поле для выборки надо добавлять в две ф-и. get_products, get_product p.featured, p.featured_new, из п3 <a class="featured_new" title="Новинки" href="#"></a> нужно еще добавить к этому аякс запрос, в products.tpl по аналогии с запросом строка 436 // Сделать новинкой $("a.featured_new").click(function() { var icon = $(this); var line = icon.closest("div.row"); var id = line.find('input[type="checkbox"][name*="check"]').val(); var state = line.hasClass('featured_new')?0:1; icon.addClass('loading_icon'); $.ajax({ type: 'POST', url: 'ajax/update_object.php', data: {'object': 'product', 'id': id, 'values': {'featured_new': state}, 'session_id': '{/literal}{$smarty.session.id}{literal}'}, success: function(data){ icon.removeClass('loading_icon'); if(state) line.addClass('featured_new'); else line.removeClass('featured_new'); }, dataType: 'json' }); return false; }); + вы в п2 дописали код для множественного добавления в новинки, но он не для п3 (для вашего п3 я выше написал ajax)а для этого в в products.tpl надо дописать после (строка 120 примерно) <option value="set_featured">Сделать рекомендуемым</option> <option value="unset_featured">Отменить рекомендуемый</option> дописать ваши 2 строки <option value="set_featured_new">Сделать новинкой</option> <option value="unset_featured_new">Отменить новинку</option> Я все это сделал изначально, видимо не полностью все описал. Сейчас все отображается но проблема с фильтром в админке, он не работает.И проблема: я на странице отмечаю новинку и на сайте она отображается, но как только я обновляю страницу в админке - чекбокс почему-то не отмеченный, как будто и не ставил, то есть не получается с товара снять эту новинку Quote Link to post Share on other sites
Kosjak76 Posted April 2, 2016 Report Share Posted April 2, 2016 Какого типа поле в базе? Quote Link to post Share on other sites
mishanya Posted April 2, 2016 Report Share Posted April 2, 2016 Я все это сделал изначально, видимо не полностью все описал. Сейчас все отображается но проблема с фильтром в админке, он не работает.И проблема: я на странице отмечаю новинку и на сайте она отображается, но как только я обновляю страницу в админке - чекбокс почему-то не отмеченный, как будто и не ставил, то есть не получается с товара снять эту новинку вы о карточке товара сейчас? чекбокс там как передается? Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 Какого типа поле в базе?Аналог поля featured 14 featured_new tinyint(1) Да NULL Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 вы о карточке товара сейчас? чекбокс там как передается? В админ панели открываю все товары и там отмечаю чекбокс. Без перегрузки страницы (F5) он работает, но если я ставлю чекбокс и обновляю страницу он перестает быть отмеченным, но при этом в базе в поле -1 и на сайте товар отображается. Как следствие не выходит снова снять товар (то есть снять чекбокс, потому что он уже снят) Quote Link to post Share on other sites
Kosjak76 Posted April 2, 2016 Report Share Posted April 2, 2016 Какой чекбокс? Откуда в списке товаров чекбокс? Quote Link to post Share on other sites
Kosjak76 Posted April 2, 2016 Report Share Posted April 2, 2016 Кажется я понял в чем проблема <a class="featured_new" title="Новинки" href="#"></a> Там надо еще добавить класс к row и проверку, по аналогии с featured Quote Link to post Share on other sites
mishanya Posted April 2, 2016 Report Share Posted April 2, 2016 В админ панели открываю все товары и там отмечаю чекбокс. Без перегрузки страницы (F5) он работает, но если я ставлю чекбокс и обновляю страницу он перестает быть отмеченным, но при этом в базе в поле -1 и на сайте товар отображается. Как следствие не выходит снова снять товар (то есть снять чекбокс, потому что он уже снят) тогда вы еще окончательно запутали меня. вы написали выше что В шаблоне админки products.tpl добавил иконку и отредактировал стили<a class="featured_new" title="Новинки" href="#"></a> какой это чекбокс? прикрепите ваши файлы или дайте доступ фтп в личку, так фиг пойми Quote Link to post Share on other sites
mishanya Posted April 2, 2016 Report Share Posted April 2, 2016 Кажется я понял в чем проблема <a class="featured_new" title="Новинки" href="#"></a> Там надо еще добавить класс к row и проверку, по аналогии с featured точно), у вас стоит проверка? class="{if !$product->visible}invisible{/if} {if $product->featured}featured{/if} {if $product->featured_new}featured_new{/if} row" Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 (edited) точно), у вас стоит проверка? class="{if !$product->visible}invisible{/if} {if $product->featured}featured{/if} {if $product->featured_new}featured_new{/if} row" Да, да, да!Спасибо большое! Теперь работает.Я добавил еще фильтр для сортировки таких товаров <li {if $filter=='featured'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured'}">Хиты продаж</a> </li> <li {if $filter=='featured_new'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured_new'}">Новинки</a> </li> Он тоже где-то дополнительно проверку проходит? В файлеapi/Products.php для фильтра сделал следующее: $is_featured_filter = ''; $is_featured_new_filter = ''; и if(isset($filter['featured'])) { $is_featured_filter = $this->db->placehold('AND p.featured=?', intval($filter['featured'])); } if(isset($filter['featured_new'])) { $is_featured_new_filter = $this->db->placehold('AND p.featured_new=?', intval($filter['featured_new'])); } Ниже $query = "SELECT DISTINCT p.id, p.url, p.brand_id, p.position, p.created as created, p.visible, p.featured, p.featured_new, p.rating, p.votes, p.last_modify, $lang_sql->fields FROM __products p $lang_sql->join $category_id_filter $variant_join $currency_join $yandex_filter WHERE 1 $product_id_filter $brand_id_filter $features_filter $keyword_filter $is_featured_filter $is_featured_new_filter $discounted_filter $in_stock_filter $visible_filter $price_filter $group_by ORDER BY $order $sql_limit "; И в методе count_products аналогично Edited April 2, 2016 by villain1988 Quote Link to post Share on other sites
mishanya Posted April 2, 2016 Report Share Posted April 2, 2016 Да, да, да!Спасибо большое! Теперь работает.Я добавил еще фильтр для сортировки таких товаров <li {if $filter=='featured'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured'}">Хиты продаж</a> </li> <li {if $filter=='featured_new'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured_new'}">Новинки</a> </li> Он тоже где-то дополнительно проверку проходит? он у вас вроде добавлен if($f = $this->request->get('filter', 'string')) { if($f == 'featured') { $filter['featured'] = 1; } elseif($f == 'featured_new') { $filter['featured_new'] = 1; Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 Да, да, да!Спасибо большое! Теперь работает.Я добавил еще фильтр для сортировки таких товаров <li {if $filter=='featured'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured'}">Хиты продаж</a> </li> <li {if $filter=='featured_new'}class="selected"{/if}> <a href="{url keyword=null brand_id=null category_id=null page=null limit=null filter='featured_new'}">Новинки</a> </li> Он тоже где-то дополнительно проверку проходит? Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 он у вас вроде добавлен if($f = $this->request->get('filter', 'string')) { if($f == 'featured') { $filter['featured'] = 1; } elseif($f == 'featured_new') { $filter['featured_new'] = 1; Добавлен но не фильтрует Quote Link to post Share on other sites
Kosjak76 Posted April 2, 2016 Report Share Posted April 2, 2016 Ну, тогда нужно разбираться - почему не работает.Распечетывать переменную $filter и $query, например.И смотреть, что именно там не так. Quote Link to post Share on other sites
villain1988 Posted April 2, 2016 Report Share Posted April 2, 2016 Ну, тогда нужно разбираться - почему не работает.Распечетывать переменную $filter и $query, например.И смотреть, что именно там не так. Для тех, кто реализовывает, необходимо отредактировать фильтры в simpla/ProductsAdmin.php // Текущий фильтр if($f = $this->request->get('filter', 'string')) { if($f == 'featured') { $filter['featured'] = 1; } elseif($f == 'featured_new') { $filter['featured_new'] = 1; } elseif($f == 'discounted') { $filter['discounted'] = 1; } elseif($f == 'visible') { $filter['visible'] = 1; } elseif($f == 'hidden') { $filter['visible'] = 0; } elseif($f == 'outofstock') { $filter['in_stock'] = 0; } elseif($f == 'in_yandex') { $filter['yandex'] = 1; } elseif($f == 'out_yandex') { $filter['yandex'] = 0; } $this->design->assign('filter', $f); } Quote Link to post Share on other sites
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.