2017-02-17 80 views
1

我正在從Sylius結帳中刪除運送和付款方式步驟。有關如何從Sylius文檔中包含的結帳中刪除裝運步驟的指南,請點擊此處:http://docs.sylius.org/en/latest/cookbook/checkout.html在Sylius中刪除結帳步驟

我按照本指南進行了其他更改,以移除付款方式步驟(我的商店將始終使用一個付款方式,無需用戶選擇此項)。發生什麼事是,當我點擊「地址」步驟中的下一步時,我將進入「完成」步驟,但隨後我立即再次重定向到「地址」步驟,沒有錯誤。我的推測是,我需要讓系統知道要使用哪種裝運和支付方式,但我沒有在任何地方的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> 

app/Resources/S yliusShopBundle /配置/路由/ 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我回到地址步驟而沒有錯誤。

回答

3

我可以在配置文件中發現一個錯誤:

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

完整的轉換應該從addressed狀態而非payment_selected(這並不在你的配置存在)來完成。它應該解決你的問題。

你也是對的,默認的方法解析器還沒有記錄。有兩個類負責分配默認的運輸和付款方式(DefaultPaymentMethodResolver和DefaultShippingMethodResolver)。兩者都將分配第一個可用的方法。如果只有一種方法可用,它應該是預期的行爲。但隨時可以覆蓋這些類,以提供您的自定義邏輯:)

+1

謝謝,這正是我的問題,並解決了它! :d – carbide20