Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using shipment manifest instead of line_items to handle item exchange #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/spree/shipment_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Spree::Shipment.class_eval do
def self.exportable
query = order(:updated_at).joins(:order).merge(Spree::Order.complete).where.not(spree_shipments: { state: 'canceled' })
easypost = Spree::StockLocation.find_by_name('Easypost')
if easypost.present?
query = order(:updated_at).joins(:order).merge(Spree::Order.complete).where.not(spree_shipments: { state: 'canceled', stock_location_id: easypost.id })
else
query = order(:updated_at).joins(:order).merge(Spree::Order.complete).where.not(spree_shipments: { state: 'canceled' })
end
query = query.ready unless Spree::Config.shipstation_capture_at_notification
query
end
Expand Down
8 changes: 4 additions & 4 deletions app/views/spree/shipstation/export.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ xml.Orders(pages: (@shipments.total_count/50.0).ceil) {
Spree::ExportHelper.address(xml, order, :ship)
}
xml.Items {
shipment.line_items.each do |line|
variant = line.variant
shipment.manifest.each do |item|
variant = item.variant
xml.Item {
xml.SKU variant.sku
xml.Name [variant.product.name, variant.options_text].join(' ')
xml.ImageUrl variant.images.first.try(:attachment).try(:url)
xml.Weight variant.weight.to_f
xml.WeightUnits Spree::Config.shipstation_weight_units
xml.Quantity line.quantity
xml.UnitPrice line.price
xml.Quantity item.quantity
xml.UnitPrice item.line_item.price

if variant.option_values.present?
xml.Options {
Expand Down
2 changes: 1 addition & 1 deletion lib/spree/shipment_notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def ship_it!
unless shipment.shipped?
shipment.reload.ship!
shipment.touch :shipped_at
shipment.order.update!
shipment.order.recalculate
end

true
Expand Down