Skip to content

Commit

Permalink
Do not break if channel price does not exists (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Nov 24, 2023
1 parent 74dca6d commit 254c9f3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

<div class="ui fluid card" {{ sylius_test_html_attribute('product') }}>
<a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="blurring dimmable image">
<div class="ui dimmer">
<div class="content">
<div class="center">
<div class="ui inverted button">{{ 'sylius.ui.view_more'|trans }}</div>
</div>
</div>
</div>
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product} %}
</a>
<div class="content" {{ sylius_test_html_attribute('product-content') }}>
<a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="header sylius-product-name" {{ sylius_test_html_attribute('product-name', product.name) }}>{{ product.name }}</a>

{% if not product.enabledVariants.empty() %}
{% set variant = product|sylius_resolve_variant %}
{% if variant.hasChannelPricingForChannel(sylius.channel) %}
{% set price = money.calculatePrice(variant) %}
{% set originalPrice = money.calculateOriginalPrice(variant) %}
{% set appliedPromotions = variant.getAppliedPromotionsForChannel(sylius.channel) %}

{% include '@SyliusShop/Product/Show/_catalogPromotionLabels.html.twig' with {'appliedPromotions': appliedPromotions, 'withDescription': false} %}

{% if variant|sylius_has_discount({'channel': sylius.channel}) %}
<div class="sylius-product-original-price" {{ sylius_test_html_attribute('product-original-price') }}><del>{{ originalPrice }}</del></div>
{% endif %}
<div class="sylius-product-price" {{ sylius_test_html_attribute('product-price') }}>{{ price }}</div>
{% endif %}
{% endif %}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set variant = product|sylius_resolve_variant %}

{% if variant is not null and variant.hasChannelPricingForChannel(sylius.channel) %}
{% set appliedPromotions = variant.getChannelPricingForChannel(sylius.channel).getAppliedPromotions() %}
{% include '@SyliusShop/Product/Show/_catalogPromotionLabels.html.twig' with {'appliedPromotions': appliedPromotions, 'withDescription': true} %}
{% endif %}

<div class="ui stackable grid" {{ sylius_test_html_attribute('product-price-content') }}>
<div class="seven wide column">
{% if not product.enabledVariants.empty() and variant.hasChannelPricingForChannel(sylius.channel) %}
{% include '@SyliusShop/Product/Show/_price.html.twig' %}
{% endif %}
</div>
<div class="nine wide right aligned column">
<span class="ui sub header">{{ product.code }}</span>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

<table class="ui single line small table" id="sylius-product-variants" {{ sylius_test_html_attribute('product-variants') }}>
<thead>
<tr>
<th>{{ 'sylius.ui.variant'|trans }}</th>
<th>{{ 'sylius.ui.price'|trans }}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for key, variant in product.enabledVariants %}
{% set channelPricing = variant.getChannelPricingForChannel(sylius.channel) %}
<tr {{ sylius_test_html_attribute('product-variants-row') }}>
<td>
{{ variant.name|default(variant.descriptor) }}
{% if product.hasOptions() %}
<div class="ui horizontal divided list">
{% for optionValue in variant.optionValues %}
<div class="item">
{{ optionValue.value }}
</div>
{% endfor %}
</div>
{% endif %}
</td>
{% if variant.hasChannelPricingForChannel(sylius.channel) %}
{% set appliedPromotions = channelPricing.appliedPromotions|map(promotion => ({'label': promotion.label, 'description': promotion.description})) %}
<td class="sylius-product-variant-price" data-applied-promotions="{{ appliedPromotions|json_encode }}" {% if variant|sylius_has_discount({'channel': sylius.channel}) %}data-original-price="{{ money.calculateOriginalPrice(variant) }}"{% endif %}>
{{ money.calculatePrice(variant) }}
</td>
{% else %}
<td class="sylius-product-variant-price">
</td>
{% endif %}
<td class="right aligned">
{{ form_widget(form.cartItem.variant[key], {'label': false}) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

0 comments on commit 254c9f3

Please sign in to comment.