Task 6679 | Доработал подробную страницу товара + вывел таблицу с рекомендациями через отдельный тип записями

dev_10_refactoring
Your Name 2 months ago
parent 830948cf05
commit 0253ba2472
  1. 6
      wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css
  2. 55
      wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php
  3. 68
      wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig

@ -872,6 +872,12 @@ main{
display: flex;
align-items: center;
}
.detail__label-wrap {
display: flex;
flex-wrap: wrap;
gap: 5px;
align-items: center;
}
.detail__label .product-item-label__tag:last-child{
margin-left: auto;
}

@ -1,19 +1,37 @@
<?php
// add_filter('timber/context', function($context) {
// $context['test'] = 111111111;
// return $context;
// });
add_filter('timber/context', function($context) {
if (function_exists('is_product') && is_product()) {
// $product->is_type('variable')
$product;
$product_type;
$context_for_twig;
if (function_exists('is_product') && is_product()) {
$product_id = get_the_ID();
$product = wc_get_product($product_id);
if ($product) {
$attributes = [];
$product_attributes = $product->get_attributes();
/* Получение категорий */
$tags = get_the_terms($product_id, 'product_cat');
if (!empty($tags) && !is_wp_error($tags)) {
foreach ($tags as $tag) {
$context_for_twig['product_tags'][] = $tag->name;
}
}
/* Получение атрибутов */
if (!empty($product_attributes)) {
foreach ($product_attributes as $taxonomy => $attribute) {
if ($attribute->is_taxonomy()) {
$terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'all']);
// $tags = wc_get_product_terms( $product_id, 'pa_catalog_tags' );
if (!empty($terms)) {
$attr_values = [];
foreach ($terms as $term) {
@ -25,15 +43,23 @@ add_filter('timber/context', function($context) {
];
}
$attributes[wc_attribute_label($taxonomy)] = $attr_values;
if ($_GET["gp-test"]) {
// ?gp-test=1
echo '<pre>';
print_r($attr_values);
echo '</pre>';
}
}
} else {
$attributes[wc_attribute_label($taxonomy)] = $attribute->get_options();
}
}
}
$context['product_attributes'] = $attributes;
$context_for_twig['product_attributes'] = $attributes;
/* Получение вариаций товара */
if ($product->is_type('variable')) {
$available_variations = $product->get_available_variations();
$variations_data = [];
@ -51,14 +77,14 @@ add_filter('timber/context', function($context) {
];
}
$context['variations'] = $variations_data;
$context_for_twig['variations'] = $variations_data;
}
/* ACF-поля и мета-данные продукта */
$meta_fields = [
'composition' => get_post_meta($product_id, '_composition', true),
'feeding_recommendations' => get_post_meta($product_id, '_feeding_recommendations', true),
'feeding_recommendations_table' => get_field('feeding_recommendations_table', $product_id),
'feeding_recommendations' => get_post_meta($product_id, '_feeding_recommendations', true), // Ранее выводились HTML-полем «Рекомендации по кормлению»
'feeding_recommendations_table' => get_field('feeding_recommendations_table', get_post(get_field('p_tables_field', $product_id))) , // Таблица «Рекомендации по кормлению»
'nutritional_value' => get_post_meta($product_id, '_nutritional_value', true),
'vitamins' => get_post_meta($product_id, '_vitamins', true),
'additives' => get_post_meta($product_id, '_additives', true),
@ -66,9 +92,14 @@ add_filter('timber/context', function($context) {
'important' => get_post_meta($product_id, '_important', true),
];
$context['product_meta'] = $meta_fields;
}
}
$context_for_twig['product_meta'] = $meta_fields;
return $context;
/* Товар оформляется по подписке? */
$context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false;
}
add_filter('timber/context', function ($context) use ($context_for_twig) {
return array_merge($context, $context_for_twig);
});

@ -1,12 +1,9 @@
{% set current_path = template_path ~ '/modules/shop/components/single-product' %}
{% set bodyClass = 'bg-white' %}
{% set mainClass = 'wrapper' %}
{% extends 'layout.twig' %}
{% set bodyClass = 'bg-white' %}
{% set mainClass = 'wrapper' %}
{% extends 'layout.twig' %}
{% block content %}
{% block content %}
<div class="wrapper">
<div class="breadcrumbs">
{% if wc_breadcrumbs %}
@ -33,7 +30,16 @@
</div>
<div class="detail__content">
{# Start | Теги = категории #}
<div class="detail__label">
<div class="detail__label-wrap">
{% for tag in product_tags %}
<div class="product-item-label__tag product-item-label__tag--black">
{{ tag }}
</div>
{% endfor %}
{% if product_attributes.Flavor is defined and product_attributes.Flavor|length > 0 %}
<div class="product-item-label__tag product-item-label__tag--black">
{{ product_attributes.Flavor[0].name }}
@ -50,12 +56,15 @@
<a href="{{ product_attributes.Тег[0].link }}">{{ product_attributes.Тег[0].name }}</a>
</div>
{% endif %}
{% if product.is_on_sale() %}
{% if is_subscription %}
<div class="product-item-label__tag product-item-label__tag--sale">
{{ function('pll_e', 'Распродажа %') }}
</div>
{% endif %}
</div>
</div>
{# End | Теги = категории #}
<h1 class="detail__title">
{{ product.get_title }}
</h1>
@ -73,12 +82,11 @@
<div class="swiper-pagination"></div>
</div>
{# Start | Цена для неподписочного товара #}
{% if product.get_price %}
<div class="detail__block-price">
<p class="detail-block-price__price">
{{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }}
</p>
{% if product.is_on_sale() %}
{% if is_subscription %}
{% if product.get_regular_price %}
<div class="detail-block-price__sale">
<p class="detail-block-price-sale__text">
{{ product.get_regular_price }} {{ fn('get_woocommerce_currency_symbol') }}
@ -87,8 +95,19 @@
{{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }}
</p>
</div>
{% else %}
не задана цена по подписке
{% endif %}
{% else %}
<p class="detail-block-price__price">
{{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }}
</p>
{% endif %}
</div>
{% endif %}
{# End | Цена для неподписочного товара #}
{# Start | Кнопка добавить в корзину + варинанты подписки на товар #}
<form action="" class="detail-block__form" data-product-id="{{ product.id }}">
{% set collection = fn('wc_get_product_terms', product.id, 'pa_collection') %}
{% if collection %}
@ -113,11 +132,14 @@
</div>
{% endif %}
{% endif %}
</form>
{{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }}
{# End | Кнопка добавить в корзину + варинанты подписки на товар #}
{# Start | Табы с информацией #}
<div class="detail__toggle">
{# Start | Описание товара #}
<div class="toggle">
<p class="toggle__title">
{{ function('pll_e', 'ОПИСАНИЕ') }}
@ -130,7 +152,9 @@
</div>
</div>
</div>
{# End | Описание товара #}
{# Start | Состав товара #}
{% if product_meta.composition %}
<div class="toggle">
<p class="toggle__title">
@ -145,7 +169,9 @@
</div>
</div>
{% endif %}
{# End | Состав товара #}
{# Start | Рекомендации по кормлению #}
{% if product_meta.feeding_recommendations_table %}
<div class="toggle">
<p class="toggle__title">
@ -198,6 +224,7 @@
</div>
</div>
{% endif %}
{# End | Рекомендации по кормлению #}
{% if product_meta.nutritional_value or product_meta.vitamins or product_meta.additives or product_meta.energy_value %}
<div class="toggle">
@ -246,10 +273,8 @@
</div>
</div>
{% endif %}
</div>
{# End | Табы с информацией #}
<div class="detail__warning">
<div class="detail-warning__content">
@ -259,7 +284,9 @@
</p>
</div>
</div>
</div>
<div class="product__main">
{% set recommended_products = function('get_field', 'recommended_products', product.id) %}
{% set related_products = recommended_products ? recommended_products : function('wc_get_related_products', product.id, 4) %}
@ -295,7 +322,7 @@
</span>
{% endif %}
{% if wc_product.is_on_sale() %}
{% if is_subscription %}
<span href="#" class="product-item-label__tag product-item-label__tag--sale">
{{ function('pll_e', 'Распродажа %') }}
</span>
@ -409,6 +436,7 @@
</div>
</div>
<div class="gallery">
<button class="gallery__close gallery-button">
<img src="{{ theme.uri }}/static/shop/img/svg/main/black-x.svg" alt="">
@ -447,4 +475,4 @@
</div>
</div>
{% endblock %}
{% endblock %}
Loading…
Cancel
Save