Andrei | рефакторинг проекта (разнес php и twig статических страниц по отдельным директориям)

dev_10_refactoring
parent 97ba6b7497
commit a8c50aa368
  1. 2
      wp-content/themes/cosmopet/modules/static-pages/about/template-about.php
  2. 4
      wp-content/themes/cosmopet/modules/static-pages/front-page/template-front-page.php
  3. 2
      wp-content/themes/cosmopet/modules/static-pages/production/template-prod-page.php
  4. 2
      wp-content/themes/cosmopet/modules/static-pages/where_to_buy/template_wtb.php
  5. 4
      wp-content/themes/cosmopet/temp-functions/modules-logic.php
  6. 0
      wp-content/themes/cosmopet/templates/_pages/about.twig
  7. 0
      wp-content/themes/cosmopet/templates/_pages/front-page.twig
  8. 0
      wp-content/themes/cosmopet/templates/_pages/production.twig
  9. 0
      wp-content/themes/cosmopet/templates/_pages/wtb.twig
  10. 9
      wp-content/themes/cosmopet/templates/archive-product/archive-product-ajaxload.twig
  11. 121
      wp-content/themes/cosmopet/templates/archive-product/archive-product-tease.twig
  12. 157
      wp-content/themes/cosmopet/templates/archive-product/archive-product.twig

@ -34,6 +34,6 @@ $context['e_title'] = get_field('e-title');
$context['e_points'] = get_field('e-points'); $context['e_points'] = get_field('e-points');
$context['faq'] = get_field('faq'); $context['faq'] = get_field('faq');
Timber::render('templates/about/about.twig', $context); Timber::render('_pages/about.twig', $context);
?> ?>

@ -7,7 +7,7 @@
<?php <?php
var_dump('test123tesst123');
function theme_enqueue_scripts() { function theme_enqueue_scripts() {
// Swiper // Swiper
wp_enqueue_style('gp-front-page-carousel', get_template_directory_uri() . '/static/front-page/css/carousel.css'); wp_enqueue_style('gp-front-page-carousel', get_template_directory_uri() . '/static/front-page/css/carousel.css');
@ -82,6 +82,6 @@ $context['reviews'] = get_field('reviews');
$context['sub_title'] = get_field('sub_title'); $context['sub_title'] = get_field('sub_title');
$context['sub_text'] = get_field('sub_text'); $context['sub_text'] = get_field('sub_text');
Timber::render('templates/front-page/front-page.twig', $context); Timber::render('_pages/front-page.twig', $context);
?> ?>

@ -23,6 +23,6 @@ $context['desc'] = get_field('desc');
$context['steps_1'] = get_field('steps_1'); $context['steps_1'] = get_field('steps_1');
$context['steps_2'] = get_field('steps_2'); $context['steps_2'] = get_field('steps_2');
Timber::render('templates/production/production.twig', $context); Timber::render('_pages/production.twig', $context);
?> ?>

@ -132,5 +132,5 @@ $context['partners_logos'] = $partners_logos_formatted;
add_filter('wpcf7_autop_or_not', '__return_false'); add_filter('wpcf7_autop_or_not', '__return_false');
// Рендеринг шаблона // Рендеринг шаблона
Timber::render('templates/where_to_buy/wtb.twig', $context); Timber::render('_pages/wtb.twig', $context);
?> ?>

@ -217,7 +217,7 @@ function include_module($module_name) {
*/ */
add_filter('theme_page_templates', function ($templates) { add_filter('theme_page_templates', function ($templates) {
// Путь к папке с шаблонами // Путь к папке с шаблонами
$custom_templates_dir = get_template_directory() . '/templates/'; $custom_templates_dir = get_template_directory() . '/modules/static-pages/';
// Ищем ВСЕ PHP-файлы в /templates/ и подпапках // Ищем ВСЕ PHP-файлы в /templates/ и подпапках
$all_templates = new RecursiveIteratorIterator( $all_templates = new RecursiveIteratorIterator(
@ -237,7 +237,7 @@ add_filter('theme_page_templates', function ($templates) {
$template_name = str_replace(['/', '.php'], [' - ', ''], $relative_path); $template_name = str_replace(['/', '.php'], [' - ', ''], $relative_path);
// Добавляем в список шаблонов // Добавляем в список шаблонов
$templates['templates/' . $relative_path] = $template_name; $templates['/modules/static-pages/' . $relative_path] = $template_name;
} }
return $templates; return $templates;

@ -0,0 +1,9 @@
{% for post in posts %}
{% include 'archive-product/archive-product-tease.twig' with {post: post} %}
{% endfor %}
{% if not ended %}
<button class="button button--white" id="load-more-products" data-category_id="{{ get_category }}" data-category_type="{{ get_category_type }}">
{{ function('pll_e', 'Загрузить еще') }}
</button>
{% endif %}

@ -0,0 +1,121 @@
{% if post.id is defined and post.id %}
{% set cur_product = fn('wc_get_product', post.id) %}
{% set attrs = post.product.get_attributes() %}
{% set cur_weight = function('get_product_info', post.id, 'weight') %}
<div class="product__item">
<div class="product-item__label">
{% if post.date('Y-m-d') >= criteria_for_new_product %}
<span class="product-item-label__tag product-item-label__tag--new">
{{ function('pll_e', 'Новинка') }}
</span>
{% endif %}
{% if post._sale_price %}
<span class="product-item-label__tag product-item-label__tag--sale">
{{ function('pll_e', 'Распродажа %') }}
</span>
{% endif %}
</div>
<a href="{{ post.link }}" class="product-item__product-card">
<img src="{{ post.thumbnail.src('shop_single') }}" alt="{{ post.title }}" class="product-item__images">
</a>
<div class="product-item__content-card">
<div class="compound">
{% set compound = fn('wc_get_product_terms', post.id, 'pa_compound') %}
{% for option in compound %}
{% set term = get_term(option) %}
<a href="/compound/{{ term.slug }}" class="compound__item">{{ term.name }}</a>
{% endfor %}
</div>
<a href="{{ post.link }}" class="product-item__title">{{ post.title }}</a>
<div class="product-item__price">
<p>{{ post._price() }} {{ fn('get_woocommerce_currency_symbol') }}</p>
</div>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">
{{ function('pll_e', 'Купить') }}
</button>
</div>
</div>
<div class="product-item__overlay">
<div class="product-item-overlay__header">
<a href="{{ post.link }}" class="product-item__title">{{ post.title }}</a>
<ul class="product-item-overlay__tags">
{% set features = fn('wc_get_product_terms', post.id, 'pa_features') %}
{% for option in features %}
{% set term = get_term(option) %}
<li>{{ term.name }}</li>
{% endfor %}
</ul>
</div>
<form class="product-item__form" method="post" action="/send-telegram.php">
<div class="product-item-overlay__input-block">
{% set collection = fn('wc_get_product_terms', post.id, 'pa_collection') %}
{% if collection %}
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title">{{ fn('pll_e', 'Объем') }}</p>
<div class="select">
<input type="text" class="select__state" value="{{ cur_weight }}" readonly data-product_id="{{post.id}}" data-product_price="{{ post._price() }}">
<div class="state__block">
<ul class="state__content">
{% for option in collection %}
{% set term = get_term(option) %}
{% set siblings = function('get_collection_siblings' , term.id) %}
{% for sibling in siblings %}
{% set weight = function('get_product_info', sibling.ID, 'weight') %}
{% set class = '' %}
{% if weight == cur_weight %}
{% set class = 'active' %}
{% endif %}
<li>
<button class="state__button {{ class }}" data-product_id="{{sibling.ID}}" data-product_price="{{ function('get_product_info', sibling.ID, 'price') }}">
{{ weight }}
</button>
</li>
{% endfor %}
{% endfor %}
</ul>
</div>
</div>
</div>
{% endif %}
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title">{{ fn('pll_e', 'Количество') }}</p>
<div class="counter">
<button class="counter__button minus">
<img src="{{ theme.link }}/woocommerce/assets/img/svg/main/minus.svg" alt="">
</button>
<input type="text" class="counter__input" value="1">
<button class="counter__button plus">
<img src="{{ theme.link }}/woocommerce/assets/img/svg/main/plus.svg" alt="">
</button>
</div>
</div>
</div>
<p class="product-item-overlay__price">
{{ post._price() }}
</p>
<div class="product-item-overlay__block-button">
<div class="product-item-overlay__button">
{{ function('get_add_to_cart_button', post.id) }}
</div>
<div class="product-item-overlay__more_button">
<a class="to-know button--100-perc" href="{{ post.link }}">
<p>{{ function('pll_e', 'Подробнее') }}</p>
</a>
</div>
</div>
</form>
</div>
</div>
{% endif %}

@ -0,0 +1,157 @@
{% set bodyClass = 'bg-white' %}
{% set mainClass = 'wrapper' %}
{% extends 'layout.twig' %}
{% block content %}
{% if site_region == 'ru' %}
<style>
.product-item-overlay__price::after{
content: '₽';
}
</style>
{% endif %}
<div class="breadcrumbs">
<a href="/" class="breadcrumbs__item">
{{ function('pll_e', 'Главная') }}
</a>
<a href="/shop" class="breadcrumbs__item">
{{ function('pll_e', 'Продукция') }}
</a>
{% if category %}
<a href="{{ category_link }}" class="breadcrumbs__item">
{{ category_title }}
</a>
{% endif %}
</div>
<div class="product">
<div class="product__header">
<h1 class="product__title">
{% if category %}
{{ category.name }}
{% else %}
{{ function('pll_e', 'Продукция') }}
{% endif %}
</h1>
<button class="button button--gradient button--high button--icon button--filter">
{{ function('pll_e', 'Фильтры') }}
</button>
</div>
{% if active_filters|length > 0 %}
<div class="active-filters">
{% if active_filters is not empty %}
<div class="active-filters">
{% for filter in active_filters %}
<span class="active-filter-tag" data-filter-id="{{ filter.id }}" data-filter-slug="{{ filter.slug }}" data-filter-taxonomy="{{ filter.taxonomy }}">
{{ filter.name }} ×
</span>
{% endfor %}
</div>
{% endif %}
<button class="active-filters__clear button button--white">
{{ function('pll_e', 'Очистить все') }}
</button>
</div>
{% endif %}
<div class="product__main">
{% for post in posts %}
{% include 'archive-product/archive-product-tease.twig' with {post: post} %}
{% endfor %}
</div>
<div class="product__footer product__footer--error">
{% if posts_per_page < count %}
<button class="button button--white" id="load-more-products" data-category_id="{{ category_id }}" data-category_type="{{ category_type }}">
{{ function('pll_e', 'Загрузить еще') }}
</button>
{% endif %}
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const filterButtons = document.querySelectorAll('.product-tagitem');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const slug = button.dataset.slug;
const taxonomy = button.dataset.taxonomy;
const param = 'wpf_filter_' + taxonomy;
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
if (params.has(param)) {
let values = params.get(param).split(',');
values = values.filter(v => v !== slug);
if (values.length > 0) {
params.set(param, values.join(','));
} else {
params.delete(param);
}
url.search = params.toString();
window.location.href = url.toString();
}
});
});
// Обработка клика на отдельные теги активных фильтров
const activeFilterTags = document.querySelectorAll('.active-filter-tag');
activeFilterTags.forEach(tag => {
tag.addEventListener('click', () => {
const slug = tag.dataset.filterSlug;
const taxonomy = tag.dataset.filterTaxonomy;
// Убираем префикс pa_ если есть для формирования параметра URL
const rawTaxonomy = taxonomy.replace('pa_', '');
const param = 'wpf_filter_' + rawTaxonomy;
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
if (params.has(param)) {
let values = params.get(param).split(',');
values = values.filter(v => v !== slug);
if (values.length > 0) {
params.set(param, values.join(','));
} else {
params.delete(param);
}
}
url.search = params.toString();
window.location.href = url.toString();
});
});
// Обработка кнопки "Очистить все"
const clearAllBtn = document.querySelector('.active-filters__clear');
if (clearAllBtn) {
clearAllBtn.addEventListener('click', () => {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
for (const key of Array.from(params.keys())) {
if (key.startsWith('wpf_')) {
params.delete(key);
}
}
url.search = params.toString();
window.location.href = url.toString();
});
}
});
</script>
{% endblock %}
Loading…
Cancel
Save