删除 Sylius 中的结帐步骤

Removing Checkout Steps in Sylius

我正在努力从 Sylius 的结帐中删除运送和付款方式步骤。在此处的 Sylius 文档中有一个关于如何从结帐中删除运输步骤的指南:http://docs.sylius.org/en/latest/cookbook/checkout.html

我已按照本指南进行了其他更改,以删除付款方式步骤(我的商店将始终使用一种付款方式,用户无需 select 这样做)。发生的事情是,当我在 'Address' 步骤上单击下一步时,我被带到 'Complete' 步骤,但随后我又立即被重定向回 'Address' 步骤,没有错误.我的假设是我需要让系统知道要使用哪种运输方式和付款方式,但我在 Sylius 文档的任何地方都看不到该代码。

这是我的更改:

app/Resources/SyliusCoreBundle/config/app/state_machine/sylius_order_checkout.yml:

    states:
        cart: ~
        addressed: ~
        completed: ~
    transitions:
        address:
            from: [cart, addressed]
            to: addressed
        complete:
            from: [payment_selected]
            to: completed

我然后 运行 按照建议使用此命令来验证状态机更新:

php bin/console debug:config winzou_state_machine

我可以成功地看到我的 sylius_order_config:

中的两个步骤被删除了
 sylius_order_checkout:
        class: Sylius\Component\Core\Model\Order
        property_path: checkoutState
        graph: sylius_order_checkout
        state_machine_class: Sylius\Component\Resource\StateMachine\StateMachine
        states:
            cart: null
            addressed: null
            completed: null
        transitions:
            address:
                from:
                    - cart
                    - addressed
                to: addressed
            complete:
                from:
                    - payment_selected
                to: completed

app/config/config.yml:

sylius_shop:
    checkout_resolver:
        route_map:
            cart:
                route: sylius_shop_checkout_address
            addressed:
                route: sylius_shop_checkout_complete

app/Resources/SyliusShopBundle/views/Checkout/_steps.html.twig:

{% if active is not defined or active == 'address' %}
    {% set steps = {'address': 'active', 'complete': 'disabled'} %}
{% else %}
    {% set steps = {'address': 'completed', 'complete': 'active'} %}
{% endif %}

<div class="ui four steps">
    <a class="{{ steps['address'] }} step" href="{{ path('sylius_shop_checkout_address') }}">
        <i class="map icon"></i>
        <div class="content">
            <div class="title">{{ 'sylius.ui.address'|trans }}</div>
            <div class="description">{{ 'sylius.ui.fill_in_your_billing_and_shipping_addresses'|trans }}</div>
        </div>
    </a>

    <div class="{{ steps['complete'] }} step" href="{{ path('sylius_shop_checkout_complete') }}">
        <i class="checkered flag icon"></i>
        <div class="content">
            <div class="title">{{ 'sylius.ui.complete'|trans }}</div>
            <div class="description">{{ 'sylius.ui.review_and_confirm_your_order'|trans }}</div>
        </div>
    </div>
</div>

app/Resources/SyliusShopBundle/config/routing/checkout.yml:

# This file is a part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius_shop_checkout_start:
    path: /
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: sylius_shop_checkout_address

sylius_shop_checkout_address:
    path: /address
    methods: [GET, PUT]
    defaults:
        _controller: sylius.controller.order:updateAction
        _sylius:
            event: address
            flash: false
            template: SyliusShopBundle:Checkout:address.html.twig
            form:
                type: sylius_checkout_address
                options:
                    customer: expr:service('sylius.context.customer').getCustomer()
            repository:
                method: find
                arguments: [expr:service('sylius.context.cart').getCart()]
            state_machine:
                graph: sylius_order_checkout
                transition: address
            redirect:
                route: sylius_shop_checkout_complete
                parameters: []
#
#sylius_shop_checkout_select_shipping:
#    path: /select-shipping
#    methods: [GET, PUT]
#    defaults:
#        _controller: sylius.controller.order:updateAction
#        _sylius:
#            event: select_shipping
#            flash: false
#            template: SyliusShopBundle:Checkout:selectShipping.html.twig
#            form: sylius_checkout_select_shipping
#            repository:
#                method: find
#                arguments: [expr:service('sylius.context.cart').getCart()]
#            state_machine:
#                graph: sylius_order_checkout
#                transition: select_shipping
#            redirect:
#                route: sylius_shop_checkout_select_payment
#                parameters: []
#
#sylius_shop_checkout_select_payment:
#    path: /select-payment
#    methods: [GET, PUT]
#    defaults:
#        _controller: sylius.controller.order:updateAction
#        _sylius:
#            event: payment
#            flash: false
#            template: SyliusShopBundle:Checkout:selectPayment.html.twig
#            form: sylius_checkout_select_payment
#            repository:
#                method: find
#                arguments: [expr:service('sylius.context.cart').getCart()]
#            state_machine:
#                graph: sylius_order_checkout
#                transition: select_payment
#            redirect:
#                route: sylius_shop_checkout_complete
#                parameters: []

sylius_shop_checkout_complete:
    path: /complete
    methods: [GET, PUT]
    defaults:
        _controller: sylius.controller.order:updateAction
        _sylius:
            event: summary
            flash: false
            template: SyliusShopBundle:Checkout:complete.html.twig
            repository:
                method: find
                arguments: [expr:service('sylius.context.cart').getCart()]
            state_machine:
                graph: sylius_order_checkout
                transition: complete
            redirect:
                route: sylius_shop_order_pay
                parameters:
                    paymentId: expr:service('sylius.context.cart').getCart().getLastNewPayment().getId()
            form:
                type: sylius_checkout_complete
                options:
                    validation_groups: 'sylius_checkout_complete'

我清除了缓存,据我所知,两个额外的步骤已从结帐中删除。在地址步骤上单击“下一步”确实会将我转到最后的 'checkout' 步骤,它只是 302 让我正确无误地返回到地址步骤。

我可以在您的配置文件中发现一个错误:

states:
    cart: ~
    addressed: ~
    completed: ~
transitions:
    address:
        from: [cart, addressed]
        to: addressed
    complete:
        from: [payment_selected] # <- here
        to: completed

完整的转换应该从 addressed 状态而不是 payment_selected 状态(您的配置中不存在)完成。它应该可以解决您的问题。

你也是对的,默认方法解析器还没有记录。有两个 类 负责为订单分配默认的送货和付款方式(DefaultPaymentMethodResolver 和 DefaultShippingMethodResolver)。两者都将分配第一个可用的方法。如果您只有一种方法可用,这应该是预期的行为。但是请随意覆盖这些 类 以提供您的自定义逻辑 :)