Andrei | рефакторинг - заменил в карточке товара все вызовы функций на методы класса CosmopetProduct
parent
f062cbf11f
commit
a9f298cbc9
@ -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.twig' with {_product : fn('wc_get_product', product.product)} %} |
{% include 'woocommerce/product-card.twig' with {item : product, addClass: ''} %} |
||||||
{% 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> |
@ -1,84 +0,0 @@ |
|||||||
{# TO_DO: |
|
||||||
|
|
||||||
1) в контроллер вынести получение всех переменных, а не тут выхывать функции fn() |
|
||||||
2) переименовать в файл /shop/product-card.twig |
|
||||||
3) _product, wc_product, s_product -- не понятно почему множество переменных с одинаковым смыслом => |
|
||||||
надо сделать единый контенкст для всех контроллеров и там создать все нужные переменные |
|
||||||
|
|
||||||
#} |
|
||||||
|
|
||||||
{% set thumbnail = _product.get_image_id() ? function('wp_get_attachment_image_url', _product.get_image_id(), 'medium') : function('wc_placeholder_img_src') %} |
|
||||||
{% set images = _product.get_gallery_image_ids() %} |
|
||||||
{% set compound = fn('wc_get_product_terms', _product.get_id(), 'pa_compound') %} |
|
||||||
|
|
||||||
<div class="main-food_products-card {{section}} {% for item in compound %}{% set term = get_term(item) %}{{ fn('map_attr_slugs_to_class', term.slug) }} {% endfor %}"> |
|
||||||
<a href="{{_product.get_permalink()}}" class="main-food_products-card-slider"> |
|
||||||
|
|
||||||
<div class="swiper-wrapper"> |
|
||||||
<div class="swiper-slide"> |
|
||||||
<div class="main-food_products-card-img"> |
|
||||||
<img src="{{ thumbnail }}" alt="{{_product.get_name()}}"> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
{% if images %} |
|
||||||
{% for image in images %} |
|
||||||
<div class="swiper-slide"> |
|
||||||
<div class="main-food_products-card-img"> |
|
||||||
<img src="{{ function('wp_get_attachment_image_url', image, 'medium') }}" alt="{{ _product.get_title() }}"> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
{% endfor %} |
|
||||||
{% endif %} |
|
||||||
<div class="swiper-dots"></div> |
|
||||||
</div> |
|
||||||
</a> |
|
||||||
<div class=""> |
|
||||||
{% set collection = fn('wc_get_product_terms', _product.id, 'pa_collection') %} |
|
||||||
|
|
||||||
|
|
||||||
{% set cur_weight = function('get_product_info', _product.id, 'weight') %} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a href="{{_product.get_permalink()}}" class="main-food_products-card-title"> |
|
||||||
{{_product.get_name()}} |
|
||||||
</a> |
|
||||||
|
|
||||||
{% if collection %} |
|
||||||
|
|
||||||
<div class="main-food_products-card__weight"> |
|
||||||
{% 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 s_product = TimberPost(sibling.ID) %} |
|
||||||
{% set wc_product = fn('wc_get_product', sibling.ID) %} |
|
||||||
{% set s_in_stock = s_product.meta('_stock_status') == 'instock' %} |
|
||||||
{% set s_thumbnail = wc_product.get_image_id() ? function('wp_get_attachment_image_url', wc_product.get_image_id(), 'medium') : function('wc_placeholder_img_src') %} |
|
||||||
{% set s_images = wc_product.get_gallery_image_ids() %} |
|
||||||
{% set s_title = wc_product.get_title() %} |
|
||||||
{% set all_images = [s_thumbnail]|merge(s_images|map(image => function('wp_get_attachment_image_url', image, 'medium'))) %} |
|
||||||
{% if s_in_stock %} |
|
||||||
{% set class = '' %} |
|
||||||
{% if weight == cur_weight %} |
|
||||||
{% set class = 'active' %} |
|
||||||
{% endif %} |
|
||||||
{% if weight %} |
|
||||||
<button class="main-food_products-card__weight-item {{ class }}" data-image-set='{{ all_images|json_encode() }}' data-product_id="{{sibling.ID}}" data-product_price="{{ function('get_product_info', sibling.ID, 'price') }} {{ fn('get_woocommerce_currency_symbol') }}" data-title="{{s_title}}"> |
|
||||||
{{ weight }} |
|
||||||
</button> |
|
||||||
{% endif %} |
|
||||||
{% endif %} |
|
||||||
{% endfor %} |
|
||||||
{% endfor %} |
|
||||||
</div>{% endif %} |
|
||||||
<div class="main-food_products-card-bottom"> |
|
||||||
<div class="main-food_products-card-bottom-price">{{ _product.get_price() }} {{ fn('get_woocommerce_currency_symbol') }}</div> |
|
||||||
<a href="{{ _product.add_to_cart_url }}" class="main-food_products-cardbottom-btn ajax_add_to_cart add_to_cart_button" data-product_id="{{ _product.id }}" |
|
||||||
data-product_sku="{{ _product.sku|e('html_attr') }}">{{ fn('pll_e', 'В корзину') }}</a> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
@ -0,0 +1,56 @@ |
|||||||
|
{# TO_DO: |
||||||
|
|
||||||
|
1) в контроллер вынести получение всех переменных, а не тут выхывать функции fn() |
||||||
|
2) переименовать в файл /shop/product-card.twig |
||||||
|
3) _product, wc_product, s_product -- не понятно почему множество переменных с одинаковым смыслом => |
||||||
|
надо сделать единый контенкст для всех контроллеров и там создать все нужные переменные |
||||||
|
|
||||||
|
#} |
||||||
|
|
||||||
|
<div class="main-food_products-card {{addClass}} {{ item.getTasteClass() }}"> |
||||||
|
<a href="{{item.link}}" class="main-food_products-card-slider"> |
||||||
|
<div class="swiper-wrapper"> |
||||||
|
{% set image_list = item.getImageGallery('medium') %} |
||||||
|
{% if image_list %} |
||||||
|
{% for image in image_list %} |
||||||
|
<div class="swiper-slide"> |
||||||
|
<div class="main-food_products-card-img"> |
||||||
|
<img src="{{ image.url }}" alt="{{ image.alt }}"> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{% endfor %} |
||||||
|
{% endif %} |
||||||
|
<div class="swiper-dots"></div> |
||||||
|
</div> |
||||||
|
</a> |
||||||
|
<div class=""> |
||||||
|
|
||||||
|
|
||||||
|
<a href="{{item.link}}" class="main-food_products-card-title"> |
||||||
|
{{item.title}} |
||||||
|
</a> |
||||||
|
|
||||||
|
{% set size_siblings = post.getSizeSiblings %} |
||||||
|
{% if size_siblings %} |
||||||
|
<div class="main-food_products-card__weight"> |
||||||
|
|
||||||
|
{% for sibling in size_siblings %} |
||||||
|
{% set class = '' %} |
||||||
|
{% if sibling.get_weight == item.get_weight %} |
||||||
|
{% set class = 'active' %} |
||||||
|
{% endif %} |
||||||
|
{% if sibling.get_weight %} |
||||||
|
<button class="main-food_products-card__weight-item {{ class }}" data-image-set='{{ sibling.getImageGallery('medium')|json_encode() }}' data-product_id="{{sibling.id}}" data-product_price="{{sibling.getPrice}}" data-title="{{sibling.title}}"> |
||||||
|
{{ sibling.get_weight }} |
||||||
|
</button> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{% endfor %} |
||||||
|
</div>{% endif %} |
||||||
|
<div class="main-food_products-card-bottom"> |
||||||
|
<div class="main-food_products-card-bottom-price">{{item.getPriceWithCurrency}}</div> |
||||||
|
<a href="{{ item.product.add_to_cart_url }}" class="main-food_products-cardbottom-btn ajax_add_to_cart add_to_cart_button" data-product_id="{{ item.id }}" |
||||||
|
data-product_sku="{{ item.sku|e('html_attr') }}">{{ fn('pll_e', 'В корзину') }}</a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
Loading…
Reference in new issue