我正在努力从Sylius的结帐中删除运费和付款方式步骤。有关如何从Sylius文档中包含的结帐中删除送货步骤的指南:http://docs.sylius.org/en/latest/cookbook/checkout.html
我已按照本指南进行了其他更改以删除付款方式步骤(我的商店将始终使用一种付款方式,用户无需选择此选项)。发生的事情是,当我点击“地址”步骤的下一步时,我进入“完成”步骤,但随后我立即重新定向回“地址”步骤,没有错误。我的假设是,我需要让系统知道要使用哪种运费和付款方式,但我没有在Sylius文档中看到任何代码。
以下是我的更改:
应用程序/资源/ SyliusCoreBundle /配置/应用程序/ 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
应用程序/配置/ config.yml:
sylius_shop:
checkout_resolver:
route_map:
cart:
route: sylius_shop_checkout_address
addressed:
route: sylius_shop_checkout_complete
应用程序/资源/ SyliusShopBundle /视图/结帐/ _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>
应用程序/资源/ SyliusShopBundle /配置/路由/ 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'
我清除了我的缓存,并且从我可以告诉的结账中删除了两个额外的步骤。单击地址步骤旁边的下一步会将我发送到最后的“结账”步骤,只需302就可以回到地址步骤而不会出现错误。
答案 0 :(得分:3)
我可以在您的配置文件中发现一个错误:
states:
cart: ~
addressed: ~
completed: ~
transitions:
address:
from: [cart, addressed]
to: addressed
complete:
from: [payment_selected] # <- here
to: completed
完整转换应该从addressed
状态而不是payment_selected
(在您的配置中不存在)完成。它应该可以解决你的问题。
您也是对的,尚未记录默认方法解析器。有两个类负责分配默认的送货方式和付款方式(DefaultPaymentMethodResolver和DefaultShippingMethodResolver)。两者都将分配第一个可用的方法。如果您只有一种方法,那么它应该是预期的行为。但是可以随意覆盖这些类以提供自定义逻辑:)