-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SD-1447] Checkout unshippable items endpoint
- Loading branch information
1 parent
14fff7f
commit 90b61e7
Showing
7 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Spree | ||
module Checkout | ||
class GetUnshippableItems | ||
prepend Spree::ServiceModule::Base | ||
|
||
def call(order:) | ||
run :reload_order | ||
run :ensure_shipping_address | ||
run :ensure_line_items_present | ||
run :return_unshippable_items | ||
end | ||
|
||
private | ||
|
||
def reload_order(order:) | ||
success(order: order.reload) | ||
end | ||
|
||
def ensure_shipping_address(order:) | ||
return failure([], Spree.t('errors.services.get_unshippable_items.no_shipping_address')) if order.ship_address.blank? | ||
|
||
success(order: order) | ||
end | ||
|
||
def ensure_line_items_present(order:) | ||
return failure([], Spree.t('errors.services.get_shipping_rates.no_line_items')) if order.line_items.empty? | ||
|
||
success(order: order) | ||
end | ||
|
||
def return_unshippable_items(order:) | ||
success(unshippable_items(order: order)) | ||
end | ||
|
||
protected | ||
|
||
def unshippable_items(order:) | ||
# TODO: Use `order.store.checkout_zone` | ||
shipping_address_zone_id = Spree::Zone.match(order.shipping_address)&.id | ||
return [] if shipping_address_zone_id.nil? | ||
|
||
order.line_items.select do |item| | ||
item.variant.shipping_category.shipping_methods.any? do |sm| | ||
sm.zone_ids.exclude?(shipping_address_zone_id) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters