Skip to content

Commit

Permalink
Add templates extending from the core app to make sure items are mark…
Browse files Browse the repository at this point in the history
…ed as samples when shown
  • Loading branch information
mbabker committed Jul 15, 2022
1 parent 40fad85 commit 9002f80
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ babdev_sylius_product_samples:
request_a_free_sample: 'Request a Free Sample'
request_a_paid_sample: 'Request a Sample (%price%)'
request_a_sample: 'Request a Sample'
sample: 'Sample'
sample_of_product: 'Sample - %product%'
27 changes: 27 additions & 0 deletions src/Resources/views/Admin/Product/_info.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="ui header">
{% include '@SyliusAdmin/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_admin_product_tiny_thumbnail'} %}
<div class="content">
<div class="sylius-product-name" title="{{ item.productName }}">{{ item.productName }}</div>
<span class="sub header sylius-product-variant-code" title="{{ variant.code }}">
{{ variant.code }}
</span>
</div>
</div>
{% if product.hasOptions() %}
<div class="ui horizontal divided list sylius-product-options">
{% for optionValue in variant.optionValues %}
<div class="item" data-sylius-option-name="{{ optionValue.name }}">
{{ optionValue.value }}
</div>
{% endfor %}
</div>
{% elseif item.variantName is not null %}
<div class="ui horizontal divided list">
<div class="item sylius-product-variant-name">
{{ item.variantName }}
</div>
</div>
{% endif %}
{% if variant.sampleOf is not null %}
<span class="ui small blue tag label">{{ 'babdev_sylius_product_samples.ui.sample'|trans }}</span>
{% endif %}
21 changes: 21 additions & 0 deletions src/Resources/views/Shop/Cart/Widget/_popup.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

{% if cart.empty %}
{{ 'sylius.ui.your_cart_is_empty'|trans }}.
{% else %}
<div class="ui list">
{% for item in cart.items %}
<div class="item">
{% if item.variant.sampleOf is null %}
{{ item.quantity }} x <strong>{{ item.product }}</strong> {{ money.convertAndFormat(item.unitPrice) }}
{% else %}
{{ item.quantity }} x <strong>{{ 'babdev_sylius_product_samples.ui.sample_of_product'|trans({'%product%': item.product}) }}</strong> {{ money.convertAndFormat(item.unitPrice) }}
{% endif %}
</div>
{% endfor %}
<div class="item"><strong>{{ 'sylius.ui.subtotal'|trans }}</strong>: {{ money.convertAndFormat(cart.itemsTotal) }}</div>
</div>
<a href="{{ path('sylius_shop_cart_summary') }}" class="ui fluid basic text button">{{ 'sylius.ui.view_and_edit_cart'|trans }}</a>
<div class="ui divider"></div>
<a href="{{ path('sylius_shop_checkout_start') }}" class="ui fluid primary button">{{ 'sylius.ui.checkout'|trans }}</a>
{% endif %}
94 changes: 94 additions & 0 deletions src/Resources/views/Shop/Checkout/_summary.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

{% set itemsSubtotal = sylius_order_items_subtotal(order) %}
{% set taxIncluded = sylius_order_tax_included(order) %}
{% set taxExcluded = sylius_order_tax_excluded(order) %}

<div class="ui segment">
<table class="ui very basic table" id="sylius-checkout-subtotal" {{ sylius_test_html_attribute('checkout-subtotal') }}>
<thead>
<tr>
<th class="sylius-table-column-item">{{ 'sylius.ui.item'|trans }}</th>
<th class="sylius-table-column-qty">{{ 'sylius.ui.qty'|trans }}</th>
<th class="sylius-table-column-subtotal">{{ 'sylius.ui.subtotal'|trans }}</th>
</tr>
</thead>
<tbody>
{% for item in order.items %}
<tr>
<td>
{% if item.getVariant.sampleOf is null %}
{{ item.getVariant.product.name }}
{% else %}
{{ 'babdev_sylius_product_samples.ui.sample_of_product'|trans({'%product%': item.getVariant.product.name}) }}
{% endif %}
</td>
<td class="center aligned">
{{ item.quantity }}
</td>
<td class="right aligned" id="sylius-item-{{ item.variant.product.slug }}-subtotal" {{ sylius_test_html_attribute('item-subtotal', item.variant.product.slug) }}>
{{ money.convertAndFormat(item.subtotal) }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="1" style="border-top: 2px solid #ddd;">
<strong>{{ 'sylius.ui.items_total'|trans }}:</strong>
</td>
<td colspan="2" id="sylius-summary-items-subtotal" class="right aligned" style="border-top: 2px solid #ddd;">
{{ money.convertAndFormat(itemsSubtotal) }}
</td>
</tr>
<tr {% if taxIncluded and not taxExcluded %}class="tax-disabled" {% endif %}>
<td colspan="1">
<strong>{{ 'sylius.ui.taxes_total'|trans }}:</strong>
</td>
<td colspan="2" class="right aligned">
{% if not taxIncluded and not taxExcluded %}
<div id="sylius-summary-tax-none">{{ money.convertAndFormat(0) }}</div>
{% endif %}
{% if taxExcluded %}
<div id="sylius-summary-tax-excluded">{{ money.convertAndFormat(taxExcluded) }}</div>
{% endif %}
{% if taxIncluded %}
<div class="tax-disabled">
<span id="sylius-summary-tax-included">{{ money.convertAndFormat(taxIncluded) }}</span>
<div><small>({{ 'sylius.ui.included_in_price'|trans }})</small></div>
</div>
{% endif %}
</td>
</tr>
<tr>
<td colspan="1">
<strong>{{ 'sylius.ui.discount'|trans }}:</strong>
</td>
<td colspan="2" id="sylius-summary-promotion-total" class="right aligned">
{{ money.convertAndFormat(order.orderPromotionTotal) }}
</td>
</tr>
{% if order.shipments is not empty %}
<tr>
<td colspan="1">
<strong>{{ 'sylius.ui.shipping_estimated_cost'|trans }}:</strong>
</td>
<td colspan="2" class="right aligned">
{% if order.getAdjustmentsTotal('shipping') > order.shippingTotal %}
<div class="old-price">{{ money.convertAndFormat(order.getAdjustmentsTotal('shipping')) }}</div>
{% endif %}
<span id="sylius-summary-shipping-total">{{ money.convertAndFormat(order.shippingTotal) }}</span>
</td>
</tr>
{% endif %}
<tr class="ui large header">
<td colspan="1">
<strong>{{ 'sylius.ui.order_total'|trans }}:</strong>
</td>
<td colspan="2" id="sylius-summary-grand-total" class="right aligned">
{{ money.convertAndFormat(order.total) }}
</td>
</tr>
</tfoot>
</table>
</div>
35 changes: 35 additions & 0 deletions src/Resources/views/Shop/Product/_info.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% set product = variant.product %}

<div class="ui header">
{% if variant.hasImages %}
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': variant, 'filter': 'sylius_shop_product_tiny_thumbnail'} %}
{% else %}
{% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product, 'filter': 'sylius_shop_product_tiny_thumbnail'} %}
{% endif %}
<div class="content">
<a href="{{ path('sylius_shop_product_show', {'slug': product.slug}) }}">
<div class="sylius-product-name" {{ sylius_test_html_attribute('product-name', item.productName) }}>{{ item.productName }}</div>
<span class="sub header sylius-product-variant-code" {{ sylius_test_html_attribute('product-variant-code') }}>
{{ variant.code }}
</span>
</a>
</div>
</div>
{% if product.hasOptions() %}
<div class="ui horizontal divided list sylius-product-options" {{ sylius_test_html_attribute('product-options') }}>
{% for optionValue in variant.optionValues %}
<div class="item" data-sylius-option-name="{{ optionValue.name }}" {{ sylius_test_html_attribute('option-name', optionValue.name) }}>
{{ optionValue.value }}
</div>
{% endfor %}
</div>
{% elseif item.variantName is not null %}
<div class="ui horizontal divided list">
<div class="item sylius-product-variant-name" {{ sylius_test_html_attribute('product-variant-name') }}>
{{ item.variantName }}
</div>
</div>
{% endif %}
{% if variant.sampleOf is not null %}
<span class="ui small blue tag label">{{ 'babdev_sylius_product_samples.ui.sample'|trans }}</span>
{% endif %}
16 changes: 16 additions & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ sylius_product:

sylius_ui:
events:
sylius.shop.cart.widget.popup:
blocks:
content:
enabled: false
sample_aware_content:
template: "@BabDevSyliusProductSamplesPlugin/Shop/Cart/Widget/_popup.html.twig"
priority: 10

sylius.shop.checkout.sidebar:
blocks:
summary:
enabled: false
sample_aware_summary:
template: "@BabDevSyliusProductSamplesPlugin/Shop/Checkout/_summary.html.twig"
priority: 20

sylius.shop.layout.javascripts:
blocks:
request_a_sample_javascript:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@BabDevSyliusProductSamplesPlugin/Admin/Product/_info.html.twig' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="ui basic segment">
<div class="ui large text menu">
<div class="ui small image">
<a href="{{ path('sylius_shop_homepage') }}"><img src="{{ asset('build/shop/images/logo.png', 'shop') }}" /></a>
</div>
<div class="right menu">
{% if order.customer.id|default(null) is not null %}
<div class="item" id="purchaser-email" {{ sylius_test_html_attribute('purchaser-name-or-email') }}>{{ 'sylius.ui.checking_out_as'|trans }} {{ app.user is null ? order.customer.email : order.customer.fullName|default(order.customer.email) }}.</div>
{% else %}
<a href="{{ path('sylius_shop_login') }}" class="item">{{ 'sylius.ui.sign_in'|trans }}</a>
{% endif %}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@BabDevSyliusProductSamplesPlugin/Shop/Product/_info.html.twig' %}

0 comments on commit 9002f80

Please sign in to comment.