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 %} -
- {{ 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 %} +
+ {{ product.get_regular_price }} {{ fn('get_woocommerce_currency_symbol') }} +
++ {{ ((product.get_regular_price - product.get_price) / product.get_regular_price * 100)|round }} +
++ {{ product.get_price }} {{ fn('get_woocommerce_currency_symbol') }}
-{{ function('pll_e', 'ОПИСАНИЕ') }} @@ -130,7 +152,9 @@
@@ -145,7 +169,9 @@
@@ -198,7 +224,8 @@
@@ -246,10 +273,8 @@
- {{ function('pll_e', 'вашему питомцу может понравиться') }} -
-+ {{ function('pll_e', 'вашему питомцу может понравиться') }} +
+ +