Closed dieuit07 closed 6 years ago
I try comment code relate to address. No button showing, only image and link popup 'What 's paypal?'
app/views/spree/shared/braintree_vzero/_paypal.js
enableShippingAddress: false,
// shippingAddressOverride: {
// recipientName: '<%# "#{shipping_address.firstname} #{shipping_address.lastname}" %>',
// streetAddress: '<%# shipping_address.address1 %>',
// extendedAddress: '<%# shipping_address.address2 %>',
// locality: '<%# shipping_address.city %>',
// countryCodeAlpha2: '<%# shipping_address.country.try(:iso) %>',
// postalCode: '<%# shipping_address.zipcode %>',
// region: '<%# shipping_address.state.try(:abbr) %>',
// phone: '<%# shipping_address.phone %>',
// editable: false
// },
app/views/spree/braintree_vzero/_paypal_checkout.html.erb
enableShippingAddress: false,
enableBillingAddress: false,
@dieuit07 I'm going to assume you are trying to skip the address step where a customer clicks on the 'checkout with paypal' button from the cart page. Is this correct? (The following explanation is assuming this is the case, note that I required a confirmation step in my checkout flow but you may not need this):
Remove requirement for phone number using an address_decorator (apparently Paypal does not pass back a phone number)
Spree::Address.class_eval do
def require_phone?
false
end
end
Create an order decorator to allow the checkout state to move from 'delivery' to 'confirmation' (note the default remove_transition has been commented out), and create an update payment amount method (or the amount appears blank on the confirmation page).
Spree::Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, if: ->(order) { order.payment_required? }
go_to_state :confirm, if: ->(order) { order.confirmation_required? }
go_to_state :complete
#remove_transition from: :delivery, to: :confirm
end
state_machine.before_transition to: :confirm, do: :update_payment_amount
state_machine.before_transition to: :complete, do: :process_paypal_express_payments
private
def update_payment_amount
return unless paid_with_paypal_express?
payments.last.update(amount: total)
end
end
Create an orders_controller_decorator and push the order state to 'delivery' by changing the following line in the process_paypal_express method: Change this line:
payment_method.push_order_to_state(current_order, 'address', email)
to
payment_method.push_order_to_state(current_order, 'delivery', email)
Hope this helps!
EDIT: One point I neglected to mention is that you need to add the following line to your 'config/initializers/spree.rb' file:
Spree::Config[:always_include_confirm_step] = true
Thanks @mdavo6 . I will try it soon :+1:
I comment 2 step billing and shipping address. So when try go to page checkout, I receive error:
Is there any config to skip that?