Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add support for SyliusAdminOrderCreationPlugin #15

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@
"keywords": ["sylius", "sylius-plugin", "click-and-collect", "pickup", "shipping", "covid-19"],
"description": "Click and Collect plugin for Sylius, to sell and deliver securely during the COVID-19 pandemic.",
"license": "AGPL-3.0-or-later",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dunglas/AdminOrderCreationPlugin"
},
{
"type": "vcs",
"url": "https://github.com/dew326/FOSJsRoutingBundle"
}
],
"require": {
"php": "^7.4",
"simshaun/recurr": "^4.0",
"sylius/sylius": "^1.7",
"symfony/lock": "^4.4 || ^5.0"
},
"require-dev": {
"friendsofsymfony/jsrouting-bundle": "dev-fix-duplicated-port-in-absolute-path as 2.5.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.0",
"phpstan/phpstan-doctrine": "^0.12.0",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "^0.12.0",
"phpunit/phpunit": "^8.0",
"sensiolabs/security-checker": "^6.0",
"sylius/admin-order-creation-plugin": "dev-patch-1",
"sylius-labs/coding-standard": "^3.1",
"symfony/browser-kit": "^4.4",
"symfony/debug-bundle": "^4.4",
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true],
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
Sylius\AdminOrderCreationPlugin\SyliusAdminOrderCreationPlugin::class => ['all' => true],
CoopTilleuls\SyliusClickNCollectPlugin\CoopTilleulsSyliusClickNCollectPlugin::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Expand Down
3 changes: 3 additions & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ imports:

- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }


- { resource: "@SyliusAdminOrderCreationPlugin/Resources/config/app/config.yml" }

parameters:
sylius_core.public_dir: '%kernel.project_dir%/public'

Expand Down
3 changes: 3 additions & 0 deletions tests/Application/config/routes/sylius_admin.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sylius_admin:
resource: "@SyliusAdminBundle/Resources/config/routing.yml"
prefix: /admin

sylius_admin_order_creation:
resource: "@SyliusAdminOrderCreationPlugin/Resources/config/app/routing.yml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}

{% set orderPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT') %}
{% set unitPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT') %}
{% set shippingAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::SHIPPING_ADJUSTMENT') %}
{% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %}
{% set orderItemDiscountAdjustment = constant('Sylius\\AdminOrderCreationPlugin\\Form\\Type\\AdjustmentType::ORDER_ITEM_DISCOUNT_ADJUSTMENT') %}

{% set variant = item.variant %}
{% set product = variant.product %}

{% set unitDiscount = item.units.first.adjustmentsTotal(unitPromotionAdjustment) + item.getAdjustmentsTotalRecursively(orderItemDiscountAdjustment) / item.quantity %}
{% set discountedUnitPrice = item.fullDiscountedUnitPrice + item.getAdjustmentsTotalRecursively(orderItemDiscountAdjustment) / item.quantity %}
{% set subtotal = item.quantity * (item.unitPrice + item.units.first.adjustmentsTotal(unitPromotionAdjustment) + item.units.first.adjustmentsTotal(orderPromotionAdjustment)) + item.getAdjustmentsTotalRecursively(orderItemDiscountAdjustment) %}

{% set taxIncluded = sylius_admin_order_unit_tax_included(item) %}
{% set taxExcluded = sylius_admin_order_unit_tax_excluded(item) %}

<tr>
<td class="single line">
{% include '@SyliusAdmin/Product/_info.html.twig' %}
</td>
<td class="right aligned unit-price">
{{ money.format(item.unitPrice, order.currencyCode) }}
</td>
<td class="right aligned unit-discount">
{{ money.format(unitDiscount, order.currencyCode) }}
</td>
<td class="right aligned unit-order-discount">
<span style="font-style: italic;">{{ money.format(item.units.first.adjustmentsTotal(orderPromotionAdjustment), order.currencyCode) }}</span>
</td>
<td class="right aligned discounted-unit-price">
{{ money.format(discountedUnitPrice, order.currencyCode) }}
</td>
<td class="right aligned quantity">
{{ item.quantity }}
</td>
<td class="right aligned subtotal">
{{ money.format(subtotal, order.currencyCode) }}
</td>
<td class="right aligned tax">
<div class="tax-excluded">{{ money.format(taxExcluded, order.currencyCode) }}</div>
<div class="tax-disabled">
<div class="tax-included"> {{ money.format(taxIncluded, order.currencyCode) }}
</div>
<small>({{ 'sylius.ui.included_in_price'|trans }})</small>
</div>
</td>
<td class="right aligned total">
{{ money.format(item.total, order.currencyCode) }}
</td>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}

{% set orderPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT') %}
{% set orderShippingPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT') %}
{% set itemPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT') %}
{% set shippingAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::SHIPPING_ADJUSTMENT') %}
{% set taxAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::TAX_ADJUSTMENT') %}
{% set orderDiscountAdjustment = constant('Sylius\\AdminOrderCreationPlugin\\Form\\Type\\AdjustmentType::ORDER_DISCOUNT_ADJUSTMENT') %}

{% set orderShippingPromotions = sylius_aggregate_adjustments(order.getAdjustmentsRecursively(orderShippingPromotionAdjustment)) %}

<tr>
<th colspan="7"></th>
<th colspan="1" id="tax-total" class="right aligned">
<strong>{{ 'sylius.ui.tax_total'|trans }}</strong>:
{{ money.format(order.taxTotal, order.currencyCode) }}
</th>
<th colspan="1" id="items-total" class="right aligned">
<strong>{{ 'sylius.ui.items_total'|trans }}</strong>:
{{ money.format(order.itemsTotal, order.currencyCode) }}
</th>
</tr>
<tr>
<td colspan="{{ orderShippingPromotions ? 2 : 5 }}" id="shipping-charges">
{% if not order.adjustments(shippingAdjustment).isEmpty() %}
<div class="ui relaxed divided list">
<div class="item"><strong>{{ 'sylius.ui.shipping'|trans }}:</strong></div>
{% for adjustment in order.adjustments(shippingAdjustment) %}
<div class="item">
<div id="shipping-base-value" class="right floated">{{ money.format(adjustment.amount, order.currencyCode) }}</div>
<div class="content">
<div id="shipping-adjustment-label" class="description">
<strong>{{ adjustment.label }}</strong>:
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<p><small>{{ 'sylius.ui.no_shipping_charges'|trans }}</small></p>
{% endif %}
</td>
{% if not orderShippingPromotions is empty %}
<td colspan="3" id="promotion-shipping-discounts">
<div class="ui relaxed divided list">
<div class="item"><strong>{{ 'sylius.ui.shipping_discount'|trans }}:</strong></div>
{% for label, amount in orderShippingPromotions %}
<div class="item">
<div id="shipping-discount-value" class="right floated">
{{ money.format(amount, order.currencyCode) }}
</div>
</div>
{% endfor %}
</div>
</td>
{% endif %}
<td colspan="4" id="shipping-total" class="right aligned">
<strong>{{ 'sylius.ui.shipping_total'|trans }}</strong>:
{{ money.format(order.shippingTotal, order.currencyCode) }}
</td>
</tr>
<tr>
<td colspan="9" id="discount-total" class="right aligned">
<strong>{{ 'sylius_admin_order_creation.ui.order_discount'|trans }}</strong>:
{{ money.format(order.getAdjustmentsTotalRecursively(orderDiscountAdjustment), order.currencyCode) }}
</td>
</tr>
<tr>
<td colspan="9" id="total" class="ui large header right aligned">
<strong>{{ 'sylius.ui.order_total'|trans }}</strong>:
{{ money.format(order.total, order.currencyCode) }}
</td>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}
{% import '@SyliusUi/Macro/labels.html.twig' as label %}

<div class="item">
<div class="right floated content">
{% include '@SyliusAdmin/Common/Label/paymentState.html.twig' with {'data': payment.state} %}
</div>
<i class="large payment icon"></i>
<div class="content">
<div class="header">
{{ payment.method }}
</div>
<div class="description">
{{ money.format(payment.amount, payment.order.currencyCode) }}
</div>
</div>
{% if sm_can(payment, 'complete', 'sylius_payment') %}
<div class="ui segment">
<form action="{{ path('sylius_admin_order_payment_complete', {'orderId': order.id, 'id': payment.id}) }}" method="post" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_csrf_token" value="{{ csrf_token(payment.id) }}" />
<button type="submit" class="ui icon labeled tiny blue fluid loadable button"><i class="check icon"></i> {{ 'sylius.ui.complete'|trans }}</button>
</form>
</div>
{% if payment.details['payment-link'] is defined %}
<div class="ui segment">
<a href="{{ payment.details['payment-link'] }}">
<button type="submit" id="payment-link" class="ui icon labeled tiny yellow fluid loadable button">
<i class="money icon"></i> {{ 'sylius.ui.pay'|trans }}
</button>
</a>
</div>
{% endif %}
{% endif %}
{% if sm_can(payment, 'refund', 'sylius_payment') %}
<div class="ui segment">
<form action="{{ path('sylius_admin_order_payment_refund', {'orderId': order.id, 'id': payment.id}) }}" method="post" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_csrf_token" value="{{ csrf_token(payment.id) }}" />
<button type="submit" class="ui icon labeled tiny yellow fluid loadable button"><i class="reply all icon"></i> {{ 'sylius.ui.refund'|trans }}</button>
</form>
</div>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends '@!SyliusAdminOrderCreationPlugin/Order/create.html.twig' %}

{% block content %}
{{ parent() }}

{# json_encode(65) is for JSON_UNESCAPED_SLASHES|JSON_HEX_TAG to avoid JS XSS #}
<script type="application/json" id="calendar_config">{{ {
locale: app.request.locale,
unselectedBackgroundColor: 'rgb(55, 136, 216)',
selectedBackgroundColor: 'red',
}|json_encode(65)|raw }}</script>
{% endblock %}

{% block javascripts %}
{{ parent() }}

{% include '@CoopTilleulsSyliusClickNCollectPlugin/fullcalendar/_scripts.html.twig' %}
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/cooptilleulssyliusclickncollectplugin/click_n_collect.js'} %}
{% endblock %}

{% block stylesheets %}
{{ parent() }}

{% include '@CoopTilleulsSyliusClickNCollectPlugin/fullcalendar/_styles.html.twig' %}
{% endblock %}