diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css b/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css index 77d7532..fd4e729 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css +++ b/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/css/gp-style-desktop.css @@ -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; } diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php index e5aca87..e635834 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php @@ -1,74 +1,105 @@ get_attributes(); - - if (!empty($product_attributes)) { - foreach ($product_attributes as $taxonomy => $attribute) { - if ($attribute->is_taxonomy()) { - $terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'all']); - if (!empty($terms)) { - $attr_values = []; - foreach ($terms as $term) { - $attr_values[] = [ - 'name' => $term->name, - 'slug' => $term->slug, - 'term_id' => $term->term_id, - 'link' => get_term_link($term->term_id, $taxonomy), - ]; - } - $attributes[wc_attribute_label($taxonomy)] = $attr_values; - } - } else { - $attributes[wc_attribute_label($taxonomy)] = $attribute->get_options(); - } - } - } - - $context['product_attributes'] = $attributes; - - if ($product->is_type('variable')) { - $available_variations = $product->get_available_variations(); - $variations_data = []; +// $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); + + $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' ); - foreach ($available_variations as $variation) { - $variation_id = $variation['variation_id']; - $variation_obj = wc_get_product($variation_id); - - $variations_data[] = [ - 'variation_id' => $variation_id, - 'price' => $variation_obj->get_price(), - 'regular_price' => $variation_obj->get_regular_price(), - 'sale_price' => $variation_obj->get_sale_price(), - 'attributes' => $variation['attributes'] - ]; + if (!empty($terms)) { + $attr_values = []; + foreach ($terms as $term) { + $attr_values[] = [ + 'name' => $term->name, + 'slug' => $term->slug, + 'term_id' => $term->term_id, + 'link' => get_term_link($term->term_id, $taxonomy), + ]; + } + $attributes[wc_attribute_label($taxonomy)] = $attr_values; + if ($_GET["gp-test"]) { + // ?gp-test=1 + echo '
';
+                        print_r($attr_values);
+                        echo '
'; + } } - - $context['variations'] = $variations_data; + } else { + $attributes[wc_attribute_label($taxonomy)] = $attribute->get_options(); } - $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), + } + } + + $context_for_twig['product_attributes'] = $attributes; - '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), - 'energy_value' => get_post_meta($product_id, '_energy_value', true), - 'important' => get_post_meta($product_id, '_important', true), - ]; + /* Получение вариаций товара */ + if ($product->is_type('variable')) { + $available_variations = $product->get_available_variations(); + $variations_data = []; + + foreach ($available_variations as $variation) { + $variation_id = $variation['variation_id']; + $variation_obj = wc_get_product($variation_id); - $context['product_meta'] = $meta_fields; + $variations_data[] = [ + 'variation_id' => $variation_id, + 'price' => $variation_obj->get_price(), + 'regular_price' => $variation_obj->get_regular_price(), + 'sale_price' => $variation_obj->get_sale_price(), + 'attributes' => $variation['attributes'] + ]; } + + $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), // Ранее выводились 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), + 'energy_value' => get_post_meta($product_id, '_energy_value', true), + 'important' => get_post_meta($product_id, '_important', true), + ]; - return $context; -}); \ No newline at end of file + $context_for_twig['product_meta'] = $meta_fields; + + /* Товар оформляется по подписке? */ + $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); +}); + diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig index 974cdfe..31ee619 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig +++ b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-template.twig @@ -1,13 +1,10 @@ {% 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 %} +
+ + {# Start | Теги = категории #}
- {% if product_attributes.Flavor is defined and product_attributes.Flavor|length > 0 %} +
+ {% for tag in product_tags %} +
+ {{ tag }} +
+ {% endfor %} + + {% if product_attributes.Flavor is defined and product_attributes.Flavor|length > 0 %} +
+ {{ product_attributes.Flavor[0].name }} +
+ {% endif %} + {% if product_attributes.Вкус is defined and product_attributes.Вкус|length > 0 %}
- {{ product_attributes.Flavor[0].name }} + {{ product_attributes.Вкус[0].name }}
- {% endif %} - {% if product_attributes.Вкус is defined and product_attributes.Вкус|length > 0 %} - - {% endif %} + {% endif %} - {% if product_attributes.Тег is defined and product_attributes.Тег|length > 0 %} - + {% if product_attributes.Тег is defined and product_attributes.Тег|length > 0 %} + + {% endif %} + {% if is_subscription %} +
+ {{ function('pll_e', 'Распродажа %') }} +
{% endif %} - {% if product.is_on_sale() %} -
- {{ function('pll_e', 'Распродажа %') }} -
- {% endif %} +
+ {# End | Теги = категории #} +

{{ product.get_title }}

@@ -73,22 +82,32 @@
-
-

- {{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }} -

- - {% if product.is_on_sale() %} -
-

- {{ product.get_regular_price }} {{ fn('get_woocommerce_currency_symbol') }} -

-

- {{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }} + {# Start | Цена для неподписочного товара #} + {% if product.get_price %} +

+ {% if is_subscription %} + {% if product.get_regular_price %} +
+

+ {{ product.get_regular_price }} {{ fn('get_woocommerce_currency_symbol') }} +

+

+ {{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }} +

+
+ {% else %} + не задана цена по подписке + {% endif %} + {% else %} +

+ {{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }}

-
- {% endif %} -
+ {% endif %} +
+ {% endif %} + {# End | Цена для неподписочного товара #} + + {# Start | Кнопка добавить в корзину + варинанты подписки на товар #}
{% set collection = fn('wc_get_product_terms', product.id, 'pa_collection') %} {% if collection %} @@ -113,11 +132,14 @@
{% endif %} {% endif %} - - {{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} + {# End | Кнопка добавить в корзину + варинанты подписки на товар #} + + {# Start | Табы с информацией #}
+ + {# Start | Описание товара #}

{{ function('pll_e', 'ОПИСАНИЕ') }} @@ -130,7 +152,9 @@

- + {# End | Описание товара #} + + {# Start | Состав товара #} {% if product_meta.composition %}

@@ -145,7 +169,9 @@

{% endif %} - + {# End | Состав товара #} + + {# Start | Рекомендации по кормлению #} {% if product_meta.feeding_recommendations_table %}

@@ -198,7 +224,8 @@

{% endif %} - + {# End | Рекомендации по кормлению #} + {% if product_meta.nutritional_value or product_meta.vitamins or product_meta.additives or product_meta.energy_value %}

@@ -246,10 +273,8 @@

{% endif %} - - - + {# End | Табы с информацией #}
@@ -259,156 +284,159 @@

+ -
- {% 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) %} - {% if related_products %} -
-
-
-

- {{ function('pll_e', 'вашему питомцу может понравиться') }} -

-
- +
+ {% 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) %} + {% if related_products %} +
+
+
+

+ {{ function('pll_e', 'вашему питомцу может понравиться') }} +

+ +
+ - + +
-
-
- {% for related_product in related_products %} -
- {% set post_id = related_product.ID is defined ? related_product.ID : related_product %} - {% set wc_product = fn('wc_get_product', post_id) %} - {% if wc_product %} -
-
- {% if wc_product.get_date_created|date('Y-m-d') >= criteria_for_new_product %} - - {{ function('pll_e', 'Новинка') }} - - {% endif %} +
+ {% for related_product in related_products %} +
+ {% set post_id = related_product.ID is defined ? related_product.ID : related_product %} + {% set wc_product = fn('wc_get_product', post_id) %} + {% if wc_product %} +
+
+ {% if wc_product.get_date_created|date('Y-m-d') >= criteria_for_new_product %} + + {{ function('pll_e', 'Новинка') }} + + {% endif %} - {% if wc_product.is_on_sale() %} - - {{ function('pll_e', 'Распродажа %') }} - - {% endif %} -
- - {{ wc_product.get_name() }} - -
-
- {% set compound = fn('wc_get_product_terms', post_id, 'pa_compound') %} - {% for option in compound %} - {% set term = get_term(option) %} - {{ term.name }} - {% endfor %} -
- {{ wc_product.get_name() }} -
-

{{ wc_product.get_price() }} {{ fn('get_woocommerce_currency_symbol') }}

+ {% if is_subscription %} + + {{ function('pll_e', 'Распродажа %') }} + + {% endif %}
-
- -
-
-
-
- {{ wc_product.get_name() }} -
    - {% set features = fn('wc_get_product_terms', post_id, 'pa_features') %} - {% for option in features %} + + {{ wc_product.get_name() }} + +
    +
    + {% set compound = fn('wc_get_product_terms', post_id, 'pa_compound') %} + {% for option in compound %} {% set term = get_term(option) %} -
  • {{ term.name }}
  • + {{ term.name }} {% endfor %} -
+
+ {{ wc_product.get_name() }} +
+

{{ wc_product.get_price() }} {{ fn('get_woocommerce_currency_symbol') }}

+
+
+ +
- -
-
-
-

Объем

+
+
+ {{ wc_product.get_name() }} +
    + {% set features = fn('wc_get_product_terms', post_id, 'pa_features') %} + {% for option in features %} + {% set term = get_term(option) %} +
  • {{ term.name }}
  • + {% endfor %} +
+
+ + +
+
+

Объем

-
- {% set cur_weight = function('get_product_info', post_id, 'weight') %} - -
-
    - {% set collection = fn('wc_get_product_terms', post_id, 'pa_collection') %} - {% for option in collection %} - {% set term = get_term(option) %} - {% if term %} - {% set siblings = function('get_collection_siblings', term.term_id) %} +
    + {% set cur_weight = function('get_product_info', post_id, 'weight') %} + +
    +
      + {% set collection = fn('wc_get_product_terms', post_id, 'pa_collection') %} + {% for option in collection %} + {% set term = get_term(option) %} + {% if term %} + {% set siblings = function('get_collection_siblings', term.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 %} -
    • - -
    • - {% endfor %} - {% endif %} - {% endfor %} -
    + {% for sibling in siblings %} + {% set weight = function('get_product_info', sibling.ID, 'weight') %} + + {% set class = '' %} + {% if weight == cur_weight %} + {% set class = 'active' %} + {% endif %} +
  • + +
  • + {% endfor %} + {% endif %} + {% endfor %} +
+
-
-
-

Количество

+
+

Количество

-
- - - +
+ + + +
-
-

- {{ wc_product.get_price() }} -

-
-
- {{ function('get_add_to_cart_button', post_id) }} -
-
- -

{{ function('pll_e', 'Подробнее') }}

-
+

+ {{ wc_product.get_price() }} +

+
+
+ {{ function('get_add_to_cart_button', post_id) }} +
+
-
- + +
-
- {% endif %} -
- {% endfor %} + {% endif %} +
+ {% endfor %} +
-
- {% endif %} + {% endif %} +
-
+
-
- {% endblock %} \ No newline at end of file +
+{% endblock %} \ No newline at end of file