parent
6e2a763cb7
commit
7499a8aa24
@ -0,0 +1,488 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use Timber; |
||||||
|
use Timber\PostCollection; |
||||||
|
use Timber\Integrations\WooCommerce\Product as TimberProduct; |
||||||
|
|
||||||
|
class CosmopetProduct extends TimberProduct { |
||||||
|
|
||||||
|
protected $sibling_categories = [ |
||||||
|
'pa_age-of-the-cat', |
||||||
|
'pa_age-of-the-dog', |
||||||
|
'pa_compound', |
||||||
|
'pa_reproductive-status', |
||||||
|
'pa_series', |
||||||
|
]; |
||||||
|
|
||||||
|
public function __construct ($pid = null) { |
||||||
|
parent::__construct($pid); |
||||||
|
} |
||||||
|
|
||||||
|
public function getComposition() { |
||||||
|
return get_post_meta($this->id, '_composition', true); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public function getImageGallery($size) { |
||||||
|
// Инициализируем массив для результатов |
||||||
|
$images_array = array(); |
||||||
|
|
||||||
|
// Получаем ID основного изображения товара |
||||||
|
$thumbnail_id = get_post_thumbnail_id($this->id); |
||||||
|
// Добавляем основное изображение |
||||||
|
if ($thumbnail_id) { |
||||||
|
$images_array[] = array( |
||||||
|
'url' => wp_get_attachment_image_url($thumbnail_id, $size), |
||||||
|
'alt' => get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true) |
||||||
|
); |
||||||
|
} else { |
||||||
|
// Используем заглушку, если нет основного изображения |
||||||
|
$images_array[] = array( |
||||||
|
'url' => wc_placeholder_img_src(), |
||||||
|
'alt' => __('Placeholder image', 'woocommerce') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
// Получаем галерею изображений |
||||||
|
if ($this->product && method_exists($this->product, 'get_gallery_image_ids')) { |
||||||
|
$gallery_image_ids = $this->product->get_gallery_image_ids(); |
||||||
|
} else { |
||||||
|
$gallery_image_ids = []; |
||||||
|
} |
||||||
|
|
||||||
|
// Добавляем изображения из галереи |
||||||
|
if (!empty($gallery_image_ids)) { |
||||||
|
foreach ($gallery_image_ids as $image_id) { |
||||||
|
$image_url = wp_get_attachment_image_url($image_id, $size); |
||||||
|
if ($image_url) { |
||||||
|
$images_array[] = array( |
||||||
|
'url' => $image_url, |
||||||
|
'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true) |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $images_array; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public function get_weight() { |
||||||
|
$custom_measurement = get_post_meta($this->id, '_custom_measurement', true) ?: pll__('кг'); |
||||||
|
$custom_size = get_post_meta($this->id, '_size_for_display', true) ?: ''; |
||||||
|
|
||||||
|
if ($custom_size){ |
||||||
|
return $custom_size ? $custom_size . ' ' . $custom_measurement : ''; |
||||||
|
} |
||||||
|
else{ |
||||||
|
if ($this->product && method_exists($this->product, 'get_weight')) { |
||||||
|
return $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; |
||||||
|
} |
||||||
|
return ''; |
||||||
|
} |
||||||
|
return ''; |
||||||
|
} |
||||||
|
|
||||||
|
public function getNumericWeight() { |
||||||
|
$custom_size = get_post_meta($this->id, '_size_for_display', true) ?: ''; |
||||||
|
|
||||||
|
if ($custom_size){ |
||||||
|
return floatval($custom_size); |
||||||
|
} |
||||||
|
else{ |
||||||
|
if ($this->product && method_exists($this->product, 'get_weight')) { |
||||||
|
return floatval($this->product->get_weight()); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Получает CSS класс вкуса для товара |
||||||
|
* @return string CSS класс вкуса (например, --food-fish, --treats-beef) |
||||||
|
*/ |
||||||
|
public function getTasteClass() { |
||||||
|
// Получаем категории товара |
||||||
|
$product_categories = $this->product->get_category_ids(); |
||||||
|
|
||||||
|
$is_food = false; |
||||||
|
$is_treats = false; |
||||||
|
// Определяем тип товара (корм или лакомство) |
||||||
|
foreach ($product_categories as $cat) { |
||||||
|
if ($cat == 365) { |
||||||
|
$is_food = true; |
||||||
|
} elseif ($cat == 367) { |
||||||
|
$is_treats = true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Определяем префикс типа товара |
||||||
|
$type_prefix = ''; |
||||||
|
if ($is_food) { |
||||||
|
$type_prefix = 'food'; |
||||||
|
} elseif ($is_treats) { |
||||||
|
$type_prefix = 'treats'; |
||||||
|
} else { |
||||||
|
$type_prefix = 'acc'; // Дефолтный тип |
||||||
|
} |
||||||
|
|
||||||
|
// Получаем термины атрибута compound (вкус) |
||||||
|
$compound_terms = get_the_terms($this->id, 'pa_compound'); |
||||||
|
$taste_suffix = ''; |
||||||
|
|
||||||
|
if ($compound_terms && !is_wp_error($compound_terms)) { |
||||||
|
foreach ($compound_terms as $term) { |
||||||
|
switch ($term->slug) { |
||||||
|
case 'govyadina': |
||||||
|
$taste_suffix = 'beef'; |
||||||
|
break; |
||||||
|
case 'indejka': |
||||||
|
$taste_suffix = 'turkey'; |
||||||
|
break; |
||||||
|
case 'krolik': |
||||||
|
$taste_suffix = 'rabbit'; |
||||||
|
break; |
||||||
|
case 'losos': |
||||||
|
$taste_suffix = 'salmon'; |
||||||
|
break; |
||||||
|
case 'ryba': |
||||||
|
$taste_suffix = 'fish'; |
||||||
|
break; |
||||||
|
case 'utka': |
||||||
|
$taste_suffix = 'duck'; |
||||||
|
break; |
||||||
|
case 'yagnenok': |
||||||
|
$taste_suffix = 'lamb'; |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
// Если нашли вкус, прерываем цикл |
||||||
|
if ($taste_suffix) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Если вкус не найден, используем дефолтные суффиксы по типу товара |
||||||
|
if (!$taste_suffix) { |
||||||
|
if ($is_food) { |
||||||
|
$taste_suffix = 'fish'; |
||||||
|
} elseif ($is_treats) { |
||||||
|
$taste_suffix = 'beef'; |
||||||
|
} else { |
||||||
|
$taste_suffix = ''; // Дефолтный суффикс |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return '--' . $type_prefix . '-' . $taste_suffix; |
||||||
|
} |
||||||
|
|
||||||
|
public function getSizeSiblings() { |
||||||
|
|
||||||
|
$term = get_the_terms($this->id, 'pa_collection'); |
||||||
|
if ($term) { |
||||||
|
$term = $term[0]->term_id; |
||||||
|
} else { |
||||||
|
return []; |
||||||
|
} |
||||||
|
|
||||||
|
$args = array( |
||||||
|
'posts_per_page' => -1, |
||||||
|
'post_type' => 'product', |
||||||
|
'order' => 'ASC', |
||||||
|
'orderby' => 'name', // Fixed parameter name (was 'order_by') |
||||||
|
'tax_query' => [ |
||||||
|
[ |
||||||
|
'taxonomy' => 'pa_collection', |
||||||
|
'terms' => $term, |
||||||
|
'field' => 'id', |
||||||
|
] |
||||||
|
], |
||||||
|
); |
||||||
|
|
||||||
|
$siblings = Timber::get_posts($args); |
||||||
|
|
||||||
|
// Create array with products and their weights |
||||||
|
$siblings_with_weights = []; |
||||||
|
foreach ($siblings as $sibling) { |
||||||
|
$weight = $sibling->get_weight(); |
||||||
|
$siblings_with_weights[] = [ |
||||||
|
'post' => $sibling, |
||||||
|
'weight' => floatval($weight) // Ensure weight is treated as a number |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
// Sort by weight |
||||||
|
usort($siblings_with_weights, function($a, $b) { |
||||||
|
return $a['weight'] <=> $b['weight']; |
||||||
|
}); |
||||||
|
|
||||||
|
// Extract just the posts in sorted order |
||||||
|
$sorted_siblings = array_map(function($item) { |
||||||
|
return $item['post']; |
||||||
|
}, $siblings_with_weights); |
||||||
|
return $sorted_siblings; |
||||||
|
} |
||||||
|
|
||||||
|
protected function get_category_products(){ |
||||||
|
// Получаем все товары с похожими атрибутами |
||||||
|
$args = array( |
||||||
|
'posts_per_page' => -1, |
||||||
|
'post_type' => 'product', |
||||||
|
'order' => 'ASC', |
||||||
|
'orderby' => 'name', |
||||||
|
'post_status' => 'publish' |
||||||
|
); |
||||||
|
|
||||||
|
error_log("get_category_products: Запрос товаров"); |
||||||
|
$posts = Timber::get_posts($args); |
||||||
|
error_log("get_category_products: Получено товаров: " . (is_array($posts) ? count($posts) : 'не массив')); |
||||||
|
|
||||||
|
// Преобразуем в массив, если это PostCollection или PostQuery |
||||||
|
if ($posts instanceof \Timber\PostCollection || $posts instanceof \Timber\PostQuery) { |
||||||
|
$result = $posts->get_posts(); |
||||||
|
error_log("get_category_products: Преобразовано в массив: " . count($result)); |
||||||
|
return $result; |
||||||
|
} |
||||||
|
|
||||||
|
$result = is_array($posts) ? $posts : []; |
||||||
|
error_log("get_category_products: Возвращаем: " . count($result)); |
||||||
|
return $result; |
||||||
|
} |
||||||
|
|
||||||
|
public function getProductConstructor() { |
||||||
|
$all_products = $this->get_category_products(); |
||||||
|
$constructor = []; |
||||||
|
|
||||||
|
// Получаем атрибуты текущего товара |
||||||
|
$current_product_attributes = []; |
||||||
|
$current_weight = $this->getNumericWeight(); |
||||||
|
|
||||||
|
// Получаем значения атрибутов текущего товара |
||||||
|
foreach ($this->sibling_categories as $taxonomy) { |
||||||
|
$terms = get_the_terms($this->id, $taxonomy); |
||||||
|
if ($terms && !is_wp_error($terms)) { |
||||||
|
$current_product_attributes[$taxonomy] = array_map(function($term) { |
||||||
|
return $term->term_id; |
||||||
|
}, $terms); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Отладочная информация |
||||||
|
error_log("=== Конструктор товара ==="); |
||||||
|
error_log("Текущий товар ID: " . $this->id); |
||||||
|
error_log("Текущий вес (числовой): " . $current_weight); |
||||||
|
error_log("Всего товаров в коллекции: " . count($all_products)); |
||||||
|
error_log("Атрибуты текущего товара: " . print_r($current_product_attributes, true)); |
||||||
|
|
||||||
|
// Группируем товары по атрибутам |
||||||
|
foreach ($this->sibling_categories as $taxonomy) { |
||||||
|
// Проверяем, есть ли у текущего товара значение для этой категории |
||||||
|
if (!isset($current_product_attributes[$taxonomy])) { |
||||||
|
error_log("Пропускаем $taxonomy - нет значения у текущего товара"); |
||||||
|
continue; // Пропускаем, если у товара нет значения для этой категории |
||||||
|
} |
||||||
|
|
||||||
|
$constructor[$taxonomy] = [ |
||||||
|
'taxonomy' => $taxonomy, |
||||||
|
'label' => $this->getAttributeLabel($taxonomy), |
||||||
|
'current_value' => $this->getCurrentAttributeValue($taxonomy), |
||||||
|
'options' => [] |
||||||
|
]; |
||||||
|
|
||||||
|
error_log("Обрабатываем атрибут: $taxonomy"); |
||||||
|
error_log("Атрибуты текущего товара для проверки: " . print_r($current_product_attributes, true)); |
||||||
|
|
||||||
|
foreach ($all_products as $product) { |
||||||
|
// Получаем атрибуты сравниваемого товара |
||||||
|
$compare_attributes = []; |
||||||
|
foreach ($this->sibling_categories as $compare_taxonomy) { |
||||||
|
$terms = get_the_terms($product->id, $compare_taxonomy); |
||||||
|
if ($terms && !is_wp_error($terms)) { |
||||||
|
$compare_attributes[$compare_taxonomy] = array_map(function($term) { |
||||||
|
return $term->term_id; |
||||||
|
}, $terms); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Проверяем, совпадают ли все остальные атрибуты и вес |
||||||
|
$attributes_match = true; |
||||||
|
$differences = []; |
||||||
|
|
||||||
|
// Проверяем только атрибуты из sibling_categories |
||||||
|
foreach ($this->sibling_categories as $compare_taxonomy) { |
||||||
|
if ($compare_taxonomy === $taxonomy) { |
||||||
|
continue; // Пропускаем проверяемую категорию |
||||||
|
} |
||||||
|
|
||||||
|
// Если у текущего товара есть значение для этой категории |
||||||
|
if (isset($current_product_attributes[$compare_taxonomy])) { |
||||||
|
// Проверяем, есть ли у сравниваемого товара значение для этой категории |
||||||
|
if (!isset($compare_attributes[$compare_taxonomy])) { |
||||||
|
$attributes_match = false; |
||||||
|
$differences[] = "Нет атрибута $compare_taxonomy у сравниваемого товара"; |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
// Проверяем, совпадают ли значения |
||||||
|
$current_values = $current_product_attributes[$compare_taxonomy]; |
||||||
|
$compare_values = $compare_attributes[$compare_taxonomy]; |
||||||
|
|
||||||
|
if (array_diff($current_values, $compare_values) !== [] || |
||||||
|
array_diff($compare_values, $current_values) !== []) { |
||||||
|
$attributes_match = false; |
||||||
|
$differences[] = "Не совпадают значения для $compare_taxonomy"; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
// Если у текущего товара НЕТ значения для этой категории, |
||||||
|
// то у сравниваемого товара тоже не должно быть значения |
||||||
|
else { |
||||||
|
if (isset($compare_attributes[$compare_taxonomy])) { |
||||||
|
$attributes_match = false; |
||||||
|
$differences[] = "У сравниваемого товара есть атрибут $compare_taxonomy, а у текущего нет"; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Проверяем вес (числовое сравнение) |
||||||
|
$compare_weight = $product->getNumericWeight(); |
||||||
|
if (abs($current_weight - $compare_weight) > 0.01) { // Используем небольшой допуск для float |
||||||
|
$attributes_match = false; |
||||||
|
$differences[] = "Не совпадает вес: текущий '$current_weight' vs сравниваемый '$compare_weight'"; |
||||||
|
} |
||||||
|
|
||||||
|
// Если все атрибуты и вес совпадают, добавляем товар в группу |
||||||
|
if ($attributes_match) { |
||||||
|
error_log("Товар {$product->id} подходит для атрибута $taxonomy"); |
||||||
|
$product_terms = get_the_terms($product->id, $taxonomy); |
||||||
|
if ($product_terms && !is_wp_error($product_terms)) { |
||||||
|
foreach ($product_terms as $term) { |
||||||
|
$option_key = $term->term_id; |
||||||
|
if (!isset($constructor[$taxonomy]['options'][$option_key])) { |
||||||
|
$constructor[$taxonomy]['options'][$option_key] = [ |
||||||
|
'term_id' => $term->term_id, |
||||||
|
'name' => $term->name, |
||||||
|
'slug' => $term->slug, |
||||||
|
'products' => [] |
||||||
|
]; |
||||||
|
} |
||||||
|
$constructor[$taxonomy]['options'][$option_key]['products'][] = $product; |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
error_log("Товар {$product->id} НЕ подходит для атрибута $taxonomy. Причины: " . implode(', ', $differences)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
error_log("Найдено опций для $taxonomy: " . count($constructor[$taxonomy]['options'])); |
||||||
|
|
||||||
|
// Показываем детали найденных опций |
||||||
|
foreach ($constructor[$taxonomy]['options'] as $option_id => $option) { |
||||||
|
error_log("Опция $option_id ({$option['name']}): " . count($option['products']) . " товаров"); |
||||||
|
foreach ($option['products'] as $product) { |
||||||
|
error_log(" - Товар {$product->id}: {$product->title}"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
error_log("Итоговый конструктор: " . print_r($constructor, true)); |
||||||
|
return $constructor; |
||||||
|
} |
||||||
|
|
||||||
|
protected function getAttributeLabel($taxonomy) { |
||||||
|
$labels = [ |
||||||
|
'pa_age-of-the-cat' => 'ВОЗРАСТ КОШКИ', |
||||||
|
'pa_age-of-the-dog' => 'ВОЗРАСТ СОБАКИ', |
||||||
|
'pa_compound' => 'ВКУС КОРМА', |
||||||
|
'pa_reproductive-status' => 'РЕПРОДУКТИВНЫЙ СТАТУС', |
||||||
|
'pa_series' => 'СЕРИЯ', |
||||||
|
]; |
||||||
|
|
||||||
|
return $labels[$taxonomy] ?? wc_attribute_label($taxonomy); |
||||||
|
} |
||||||
|
|
||||||
|
protected function getCurrentAttributeValue($taxonomy) { |
||||||
|
$terms = get_the_terms($this->id, $taxonomy); |
||||||
|
if ($terms && !is_wp_error($terms)) { |
||||||
|
return $terms[0]->term_id; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public function getAllAttributes() { |
||||||
|
$attributes = []; |
||||||
|
foreach ($this->sibling_categories as $taxonomy) { |
||||||
|
$terms = get_the_terms($this->id, $taxonomy); |
||||||
|
if ($terms && !is_wp_error($terms)) { |
||||||
|
$attributes[$taxonomy] = []; |
||||||
|
foreach ($terms as $term) { |
||||||
|
$attributes[$taxonomy][] = [ |
||||||
|
'term_id' => $term->term_id, |
||||||
|
'name' => $term->name, |
||||||
|
'slug' => $term->slug |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return $attributes; |
||||||
|
} |
||||||
|
|
||||||
|
public function getPrice(){ |
||||||
|
$price = $this->product->get_price() . ' ' . get_woocommerce_currency_symbol(); |
||||||
|
return $price; |
||||||
|
} |
||||||
|
|
||||||
|
public function getRegularPrice(){ |
||||||
|
$regular_price = $this->product->get_regular_price() . ' ' . get_woocommerce_currency_symbol(); |
||||||
|
if ($regular_price != $this->getPrice()){ |
||||||
|
return $regular_price; |
||||||
|
} |
||||||
|
else{ |
||||||
|
return ''; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function getPriceDifferenceInPercent(){ |
||||||
|
$regular_price = $this->product->get_regular_price(); |
||||||
|
$price = $this->product->get_price(); |
||||||
|
$difference = ($regular_price - $price) / $regular_price * 100; |
||||||
|
$difference = round($difference, 0) . '%'; |
||||||
|
return $difference; |
||||||
|
} |
||||||
|
|
||||||
|
public function getReviews(){ |
||||||
|
|
||||||
|
$reviews = get_posts(array( |
||||||
|
'post_type' => 'p_reviews', |
||||||
|
'numberposts' => -1, |
||||||
|
'meta_query' => array( |
||||||
|
array( |
||||||
|
'key' => 'products', |
||||||
|
'value' => '"' . $this->id . '"', |
||||||
|
'compare' => 'LIKE' |
||||||
|
) |
||||||
|
) |
||||||
|
)); |
||||||
|
|
||||||
|
return $reviews; |
||||||
|
} |
||||||
|
|
||||||
|
public function getRelatedProducts(){ |
||||||
|
$related_products = []; |
||||||
|
$related_products_ids = $this->product->get_upsell_ids(); |
||||||
|
if ($related_products_ids) { |
||||||
|
foreach ($related_products_ids as $related_id) { |
||||||
|
$related_product = Timber::get_post($related_id); |
||||||
|
if ($related_product) { |
||||||
|
$related_products[] = $related_product; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return $related_products; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
|
@ -1,29 +1,13 @@ |
|||||||
<?php |
<?php |
||||||
|
use Timber\Timber; |
||||||
|
global $post; |
||||||
|
|
||||||
$context = Timber::get_context(); |
$context = Timber::get_context(); |
||||||
|
|
||||||
|
include_module('shop'); |
||||||
include_component('shop', 'reviews'); |
include_component('shop', 'reviews'); |
||||||
include_component('shop', 'product-card'); |
include_component('shop', 'product-card'); |
||||||
|
|
||||||
$reviews = get_posts(array( |
?> |
||||||
'post_type' => 'p_reviews', |
<?php |
||||||
'numberposts' => -1, |
Timber::render('shop/single-product.twig', $context); |
||||||
)); |
|
||||||
|
|
||||||
$product_id = get_the_ID(); |
|
||||||
$product = wc_get_product($product_id); |
|
||||||
$context['related_products'] = array(); |
|
||||||
$related_products_ids = $product->get_upsell_ids(); |
|
||||||
if ($related_products_ids) { |
|
||||||
foreach ($related_products_ids as $related_id) { |
|
||||||
$related_product = wc_get_product($related_id); |
|
||||||
if ($related_product) { |
|
||||||
$context['related_products'][] = $related_product; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$context['reviews'] = $reviews; |
|
||||||
Timber::render('shop/single-product_page.twig', $context); |
|
@ -1,6 +1,6 @@ |
|||||||
<div class="main-food_products"> |
<div class="main-food_products"> |
||||||
{% for product in product_list %} |
{% for product in product_list %} |
||||||
{% include 'shop/product-card_element.twig' with {_product : fn('wc_get_product', product.product)} %} |
{% include 'shop/product-card.twig' with {_product : fn('wc_get_product', product.product)} %} |
||||||
{% endfor %} |
{% endfor %} |
||||||
{% if section == 'food' %} |
{% if section == 'food' %} |
||||||
<a href="/shop/" class="main-about_banner-btn"><span class="main-about_banner-btn-text">Вся продукция</span><span class="main-about_banner-btn-arrow"></span></a> |
<a href="/shop/" class="main-about_banner-btn"><span class="main-about_banner-btn-text">Вся продукция</span><span class="main-about_banner-btn-arrow"></span></a> |
@ -0,0 +1,321 @@ |
|||||||
|
{% set bodyClass = 'bg-white' %} |
||||||
|
{% set mainClass = '' %} |
||||||
|
{% extends 'layout.twig' %} |
||||||
|
|
||||||
|
{% block content %} |
||||||
|
<div class="product-single"> |
||||||
|
<div class="wrapper"> |
||||||
|
<div class="breadcrumbs"> |
||||||
|
<a href="{{ fn('home_url') }}" class="breadcrumbs__item"> |
||||||
|
{{ fn('pll_e', 'Главная') }} |
||||||
|
</a> |
||||||
|
{% set product_categories = post.get_terms('product_cat') %} |
||||||
|
{% if product_categories %} |
||||||
|
{% set category = product_categories[0] %} |
||||||
|
<a href="{{ category.link }}" class="breadcrumbs__item"> |
||||||
|
{{ category.name }} |
||||||
|
</a> |
||||||
|
{% endif %} |
||||||
|
<a href="{{post.link}}" class="breadcrumbs__item"> |
||||||
|
{{post.title}} |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
<div class="product_main {{ post.getTasteClass() }}"> |
||||||
|
<div class="product-info"> |
||||||
|
<h1 class="product-title --pc"> |
||||||
|
{{post.title}} |
||||||
|
</h1> |
||||||
|
<div class="product-contains"> |
||||||
|
<h2 class="product-block-title">{{ fn('pll_e', 'СОСТАВ') }}</h2> |
||||||
|
<div class="product-contains-text">{{ post.getComposition }}</div> |
||||||
|
</div> |
||||||
|
<div class="product-values"> |
||||||
|
<h2 class="product-values-title">{{ fn('pll_e', 'ПИЩЕВАЯ ЦЕННОСТЬ') }}</h2> |
||||||
|
<div class="product-values-list"> |
||||||
|
|
||||||
|
{% set nutritional_value = post.nutritional_value %} |
||||||
|
{% if nutritional_value.protein %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Сырой белок') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.protein}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.fat %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Сырой жир') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.fat}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.fiber %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Сырая клетчатка') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.fiber}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.ash %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Сырая зола') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.ash}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.wat %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Влажность') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.wat}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.calcium %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Кальций') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.calcium}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.phosphorus %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Фосфор') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.phosphorus}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.omega_6 %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Омега 6') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.omega_6}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% if nutritional_value.omega_3 %} |
||||||
|
<div class="product-values-item"> |
||||||
|
<div class="product-values-item__name">{{ fn('pll_e', 'Омега 3') }}</div> |
||||||
|
<div class="product-values-item-val">{{nutritional_value.omega_3}}</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
{% set vitamins = post.vitamins %} |
||||||
|
{% if vitamins %} |
||||||
|
<div class="product-vitamins"> |
||||||
|
<div class="product-vitamins-title"> |
||||||
|
{{ fn('pll_e', 'Витамины на кг') }} |
||||||
|
</div> |
||||||
|
<div class="product-vitamins-list"> |
||||||
|
|
||||||
|
{% if vitamins.vitamin_a_me %} |
||||||
|
<div class="product-vitamins-item">A, ME — {{vitamins.vitamin_a_me}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.vitamin_d3_me %} |
||||||
|
<div class="product-vitamins-item">D3, ME — {{vitamins.vitamin_d3_me}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.vitamin_e %} |
||||||
|
<div class="product-vitamins-item">E — {{vitamins.vitamin_e}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.tiamin %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Тиамин') }} — {{vitamins.tiamin}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.riboflavin %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Рибофлавин') }} — {{vitamins.riboflavin}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.pantothenic_acid %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Пантотеновая кислота') }} — {{vitamins.pantothenic_acid}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.niaczin %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Ниацин') }} — {{vitamins.niaczin}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.piridoksin %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Пиридоксин') }} — {{vitamins.piridoksin}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.folic_acid %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Фолиевая кислота') }} — {{vitamins.folic_acid}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.vitamin_b12 %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Витамин B12') }} — {{vitamins.vitamin_b12}}</div> |
||||||
|
{% endif %} |
||||||
|
{% if vitamins.holin %} |
||||||
|
<div class="product-vitamins-item">{{ fn('pll_e', 'Холин') }} — {{vitamins.holin}}</div> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="product-show"> |
||||||
|
<div class="product-gallery"> |
||||||
|
<div class="swiper product-gallery__mainSlider"> |
||||||
|
<div class="swiper-wrapper"> |
||||||
|
{% set image_list = post.getImageGallery('full') %} |
||||||
|
{% for image in image_list %} |
||||||
|
<div class="swiper-slide"> |
||||||
|
<img src="{{ image.url }}" alt="{{image.alt}}"> |
||||||
|
</div> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div thumbsSlider="" class="swiper product-gallery__thumbsSlider"> |
||||||
|
<div class="swiper-wrapper"> |
||||||
|
{% set image_list = post.getImageGallery('medium') %} |
||||||
|
{% for image in image_list %} |
||||||
|
<div class="swiper-slide"> |
||||||
|
<img src="{{ image.url }}" alt="{{image.alt}}"> |
||||||
|
</div> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
<div class="product-gallery-arrows"> |
||||||
|
<button class="product-gallery-arrow product-gallery-prev"></button> |
||||||
|
<button class="product-gallery-arrow product-gallery-next"></button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="product-gallery-bullets"></div> |
||||||
|
</div> |
||||||
|
<h1 class="product-title --m"> |
||||||
|
{{post.title}} |
||||||
|
</h1> |
||||||
|
</div> |
||||||
|
<div class="product-constructor"> |
||||||
|
{% set constructor = post.getProductConstructor %} |
||||||
|
{% for taxonomy, attribute_data in constructor %} |
||||||
|
<div class="product-constructor__block"> |
||||||
|
<div class="product-constructor__block-title">{{attribute_data.label}}</div> |
||||||
|
<div class="product-constructor__block-list"> |
||||||
|
{% for option_id, option in attribute_data.options %} |
||||||
|
{% set first_product = option.products[0] %} |
||||||
|
<a href="{{first_product.link}}" class="product-constructor__block-item{% if attribute_data.current_value == option.term_id %} active{% endif %}"> |
||||||
|
{% if taxonomy == 'pa_compound' %} |
||||||
|
{% set icon_map = { |
||||||
|
'govyadina': 'beef', |
||||||
|
'indejka': 'turkey', |
||||||
|
'krolik': 'rabbit', |
||||||
|
'losos': 'salmon', |
||||||
|
'ryba': 'fish', |
||||||
|
'utka': 'duck', |
||||||
|
'yagnenok': 'lamb' |
||||||
|
} %} |
||||||
|
{% set icon_class = icon_map[option.slug] ?? 'default' %} |
||||||
|
<img src="/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/{{icon_class}}.svg" alt="" class="product-constructor__block-item-icon{% if attribute_data.current_value == option.term_id %} active{% endif %} svg"> |
||||||
|
{% elseif taxonomy == 'pa_age-of-the-dog' %} |
||||||
|
<img src="/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/dog-face.svg" alt="" class="product-constructor__block-item-icon{% if attribute_data.current_value == option.term_id %} active{% endif %} svg"> |
||||||
|
{% elseif taxonomy == 'pa_age-of-the-cat' %} |
||||||
|
<img src="/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/cat-face.svg" alt="" class="product-constructor__block-item-icon{% if attribute_data.current_value == option.term_id %} active{% endif %} svg"> |
||||||
|
{% elseif taxonomy == 'pa_reproductive-status' %} |
||||||
|
<img src="/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/heart.svg" alt="" class="product-constructor__block-item-icon{% if attribute_data.current_value == option.term_id %} active{% endif %} svg"> |
||||||
|
{% elseif taxonomy == 'pa_series' %} |
||||||
|
<img src="/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/star.svg" alt="" class="product-constructor__block-item-icon{% if attribute_data.current_value == option.term_id %} active{% endif %} svg"> |
||||||
|
{% endif %} |
||||||
|
<div class="product-constructor__block-item-name">{{option.name}}</div> |
||||||
|
</a> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endfor %} |
||||||
|
|
||||||
|
{% set size_siblings = post.getSizeSiblings %} |
||||||
|
{% if size_siblings %} |
||||||
|
<div class="product-constructor__block"> |
||||||
|
<div class="product-constructor__block-title">{{fn('pll_e', 'ВЕС УПАКОВКИ')}}</div> |
||||||
|
<div class="product-constructor__block-list"> |
||||||
|
{% for sibling in size_siblings %} |
||||||
|
<a href="{{sibling.link}}" class="product-constructor__block-item{% if post.get_weight == sibling.get_weight %} active{% endif %}"> |
||||||
|
<div class="product-constructor__block-item-name">{{sibling.get_weight}}</div> |
||||||
|
</a> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
<div class="product-price"> |
||||||
|
<div class="product-price-main"> |
||||||
|
{{post.getPrice}} |
||||||
|
</div> |
||||||
|
{% if post.getRegularPrice %} |
||||||
|
<div class="product-price-disc"> |
||||||
|
<div class="product-price-old">{{post.getRegularPrice}}</div> |
||||||
|
<div class="product-price-percent"> |
||||||
|
{{ post.getPriceDifferenceInPercent }} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
{% set in_stock = post.meta('_stock_status') == 'instock' %} |
||||||
|
{% if in_stock %} |
||||||
|
{{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} |
||||||
|
{% else %} |
||||||
|
<div class="detail-block-form__item detail-block-form__item--tn"> |
||||||
|
<button type="button" data-pname="{{ product.title }}" class="to-know open-to-know" > |
||||||
|
<p>{{ function('pll_e', 'Узнать о поступлении') }}</p> |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="product-desc"> |
||||||
|
<div class="product-block-title"> |
||||||
|
{{ fn('pll_e', 'ОПИСАНИЕ') }} |
||||||
|
</div> |
||||||
|
<div class="product-desc-text"> |
||||||
|
{{post.content}} |
||||||
|
|
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="product-reviews"> |
||||||
|
<div class="product-reviews__head wrapper"> |
||||||
|
<div class="product-block-title"> |
||||||
|
{{ fn('pll_e', 'Отзывы Специалистов') }} |
||||||
|
</div> |
||||||
|
<div class="product-block-arrows"> |
||||||
|
<button class="slider-button-prev slider-button product-reviews-prev"></button> |
||||||
|
<button class="slider-button-next slider-button product-reviews-next"></button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="product-reviews-slider swiper"> |
||||||
|
<div class="swiper-wrapper"> |
||||||
|
{% for slide in post.getReviews %} |
||||||
|
{% include "shop/reviews-slide_element.twig" with {slide: slide} %} |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="product-block-arrows--m"> |
||||||
|
<button class="slider-button-prev slider-button product-reviews-prev"></button> |
||||||
|
<button class="slider-button-next slider-button product-reviews-next"></button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
{% if post.getRelatedProducts %} |
||||||
|
<div class="product-similar "> |
||||||
|
<div class="product-similar__head wrapper"> |
||||||
|
<div class="product-block-title"> |
||||||
|
{{ fn('pll_e', 'вашему питомцу может понравиться') }} |
||||||
|
</div> |
||||||
|
<div class="product-block-arrows"> |
||||||
|
<button class="slider-button-prev slider-button product-similar-prev"></button> |
||||||
|
<button class="slider-button-next slider-button product-similar-next"></button> |
||||||
|
</div> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div class="product-similar-slider wrapper"> |
||||||
|
<div class="swiper-wrapper"> |
||||||
|
{% for related_product in post.getRelatedProducts %} |
||||||
|
|
||||||
|
{% set class = related_product.getTasteClass %} |
||||||
|
{% set section = class ~ ' swiper-slide' %} |
||||||
|
|
||||||
|
<!-- TO_DO (избавиться от wc_get_product) --> |
||||||
|
{% include 'shop/product-card.twig' with {_product : fn('wc_get_product', related_product.id), section: section} %} |
||||||
|
|
||||||
|
|
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="product-block-arrows--m"> |
||||||
|
<button class="slider-button-prev slider-button product-similar-prev"></button> |
||||||
|
<button class="slider-button-next slider-button product-similar-next"></button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
</div> |
||||||
|
{% for slide in reviews %} |
||||||
|
|
||||||
|
{% include 'modal/rewiew_modal.twig' with {slide : slide} %} |
||||||
|
|
||||||
|
{% endfor %} |
||||||
|
{% endblock %} |
Loading…
Reference in new issue