Skip to content

Commit

Permalink
Merge pull request #458 from mpysiak/SYL-4168-add-twig-components
Browse files Browse the repository at this point in the history
Remove partials, add twig components
  • Loading branch information
GSadee authored Dec 9, 2024
2 parents 7db8ea3 + 6c4512f commit df8a5a0
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 75 deletions.
11 changes: 0 additions & 11 deletions config/admin_routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ sylius_refund_credit_memo:
icon: inbox
type: sylius.resource

sylius_refund_order_credit_memos_list:
path: /orders/{orderId}/credit-memos
methods: [GET]
defaults:
_controller: sylius_refund.controller.credit_memo::indexAction
_sylius:
template: "@SyliusRefundPlugin/admin/order/credit_memo/list.html.twig"
repository:
method: findByOrderId
arguments: $orderId

sylius_refund_credit_memo_details:
path: /orders/{orderNumber}/credit-memos/{id}
methods: [GET]
Expand Down
2 changes: 1 addition & 1 deletion config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sylius_mailer:
emails:
units_refunded:
subject: Units refunded
template: "@SyliusRefundPlugin/Email/unitsRefunded.html.twig"
template: "@SyliusRefundPlugin/email/units_refunded.html.twig"

framework:
messenger:
Expand Down
5 changes: 4 additions & 1 deletion config/app/twig_hooks/admin/order/show.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ sylius_twig_hooks:
template: '@SyliusRefundPlugin/admin/order/content/sections/credit_memos/header.html.twig'
priority: 100
items:
template: '@SyliusRefundPlugin/admin/order/content/sections/credit_memos/items.html.twig'
component: 'sylius_refund:admin:credit_memos'
props:
order: '@=_context.order'
template: '@SyliusRefundPlugin/admin/order/credit_memo/list.html.twig'
priority: 0

'sylius_admin.order.show.content.sections.credit_memos.header':
Expand Down
7 changes: 5 additions & 2 deletions config/app/twig_hooks/shop/account/order/show.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
sylius_twig_hooks:
hooks:
'sylius_shop.account.order.show.content.main':
credit_memos: #TODO: Change this to twig component
template: '@SyliusRefundPlugin/shop/order/credit_memos.html.twig'
credit_memos:
component: 'sylius_refund:shop:account:credit_memos'
props:
order: '@=_context.order'
template: '@SyliusRefundPlugin/shop/order/credit_memos.html.twig'
priority: -100

'sylius_shop.account.order.show.content.main.credit_memos':
Expand Down
2 changes: 1 addition & 1 deletion config/services/generators.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<service id="sylius_refund.generator.credit_memo_pdf_file" class="Sylius\RefundPlugin\Generator\CreditMemoPdfFileGenerator">
<argument type="service" id="sylius_refund.repository.credit_memo" />
<argument type="service" id="file_locator" />
<argument>@SyliusRefundPlugin/Download/creditMemo.html.twig</argument>
<argument>@SyliusRefundPlugin/download/credit_memo.html.twig</argument>
<argument>%sylius_refund.template.logo_file%</argument>
<argument type="service" id="sylius_refund.generator.twig_to_pdf" />
<argument type="service" id="sylius_refund.generator.credit_memo_file_name" />
Expand Down
32 changes: 32 additions & 0 deletions config/services/twig_components.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->

<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="sylius_refund.twig_component.customer_credit_memos" class="Sylius\RefundPlugin\Twig\Component\OrderCreditMemosComponent">
<argument type="service" id="sylius_refund.repository.credit_memo" />
<tag
name="sylius.twig_component"
key="sylius_refund:shop:account:credit_memos"
/>
<tag
name="sylius.twig_component"
key="sylius_refund:admin:credit_memos"
/>
</service>
</services>
</container>
11 changes: 0 additions & 11 deletions config/shop_routing.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
sylius_refund_plugin_shop_order_credit_memos_partial:
path: /_partial/orders/{orderId}/credit-memos/
methods: [GET]
defaults:
_controller: sylius_refund.controller.credit_memo::indexAction
_sylius:
template: "@SyliusRefundPlugin/shop/order/_creditMemos.html.twig"
repository:
method: findByOrder
arguments: $orderId

sylius_refund_shop_credit_memo_download:
path: /credit-memos/{id}/download
methods: [GET]
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/ORM/CreditMemoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class CreditMemoRepository extends EntityRepository implements CreditMemoRepositoryInterface
{
public function findByOrderId(string $orderId): array
public function findByOrderId(mixed $orderId): array
{
return $this->createQueryBuilder('o')
->andWhere('o.order = :orderId')
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CreditMemoRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
interface CreditMemoRepositoryInterface extends RepositoryInterface
{
/** @return CreditMemoInterface[] */
public function findByOrderId(string $orderId): array;
public function findByOrderId(mixed $orderId): array;
}
41 changes: 41 additions & 0 deletions src/Twig/Component/OrderCreditMemosComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\RefundPlugin\Twig\Component;

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
use Sylius\RefundPlugin\Repository\CreditMemoRepositoryInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;

#[AsTwigComponent]
class OrderCreditMemosComponent
{
public ?OrderInterface $order = null;

public function __construct(private readonly CreditMemoRepositoryInterface $creditMemoRepository)
{
}

/** @return array<CreditMemoInterface> */
#[ExposeInTemplate(name: 'credit_memos')]
public function getCreditMemosForOrder(): array
{
if ($this->order === null || $this->order->getId() === null) {
return [];
}

return $this->creditMemoRepository->findByOrderId($this->order->getId());
}
}
13 changes: 0 additions & 13 deletions templates/Common/Label/refundPaymentState.html.twig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set item = hookable_metadata.context.item %}

<td>
{{ '%0.2f'|format(item.netValue/100) }}
{{ (item.netValue / 100)|number_format(2) }}
</td>
2 changes: 1 addition & 1 deletion templates/admin/credit_memo/show/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<td>{{ credit_memo.issuedAt|date('d-m-Y') }}</td>
<td>
<div class="ui buttons">
{% hook 'sylius_admin.order.show.content.sections.credit_memos.credit_memos.item.actions' %}
{% hook 'sylius_admin.order.show.content.sections.credit_memos.credit_memos.items.actions' %}
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<div class="input-group">
<div class="input-group-text">{{ order.currencyCode|sylius_currency_symbol }}</div>
{% set inputName = "sylius_refund_shipments["~shipping_adjustment.id~"][amount]" %}
<input data-refund-input type="number" step="0.01" class="form-control" name="{{ inputName }}" {% if not can_unit_be_refunded(shipping_adjustment.id, shipment_refund_type) %} disabled{% endif %}/>
{% set input_name = "sylius_refund_shipments["~shipping_adjustment.id~"][amount]" %}
<input data-refund-input type="number" step="0.01" class="form-control" name="{{ input_name }}" {% if not can_unit_be_refunded(shipping_adjustment.id, shipment_refund_type) %} disabled{% endif %}/>
</div>
</td>
<td class="aligned collapsing">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@SyliusRefundPlugin/Download/pdfLayout.html.twig' %}
{% extends '@SyliusRefundPlugin/download/pdf_layout.html.twig' %}

{% set from = creditMemo.from %}
{% set to = creditMemo.to %}
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 0 additions & 25 deletions templates/shop/order/_creditMemos.html.twig

This file was deleted.

28 changes: 25 additions & 3 deletions templates/shop/order/credit_memos.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
{% set order = hookable_metadata.context.order %}

{{ render(url('sylius_refund_plugin_shop_order_credit_memos_partial', {'orderId': order.id})) }}
{% if credit_memos|length > 0 %}
<div class="card border-0 bg-body-tertiary mb-3" id="credit-memos">
<div class="card-header">{{ 'sylius_refund.ui.credit_memos'|trans }}</div>
<div class="card-body">
<table class="table align-middle mb-0">
<tbody>
{% for credit_memo in credit_memos %}
<tr>
<td>
<div class="d-flex flex-column">
<strong>{{ credit_memo.issuedAt|date('d-m-Y') }}</strong>
<span class="text-body-tertiary">{{ credit_memo.number }}</span>
</div>
</td>
<td class="text-end">{{ credit_memo.total|sylius_format_money(credit_memo.currencyCode, credit_memo.localeCode) }}</td>
<td class="w-1">
{% hook 'sylius_shop.account.order.show.content.main.credit_memos' %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}

0 comments on commit df8a5a0

Please sign in to comment.