Class: SpreeChannable::ReturnImporter
- Inherits:
-
Object
- Object
- SpreeChannable::ReturnImporter
- Defined in:
- lib/spree_channable/return_importer.rb
Class Method Summary collapse
-
.import(return_data) ⇒ Object
{ “status”: “new”, “channel_name”: “bol”, “channel_id”: “61284922”, “channable_id”: 151, “data”: { “item”: { “id”: “11694321”, “order_id”: “4522232111”, “gtin”: “0884500642113”, “title”: “Nike Air Force 1 Winter Premium GS Flax Pack”, “quantity”: 1, “reason”: “Anders, namelijk:”, “comment”: “De schoenen vielen te groot.” }, “customer”: { “gender”: “male”, “first_name”: “Jans”, “last_name”: “Van Janssen”, “email”: “[email protected]” }, “address”: { “first_name”: “Jans”, “last_name”: “Van Janssen”, “email”: “[email protected]”, “street”: “Teststraat”, “house_number”: 12, “address1”: “Teststraat 12”, “adderss2”: “”, “city”: “Utrecht”, “country_code”: “NL”, “zip_code”: “1234 XZ” } } }.
Class Method Details
.import(return_data) ⇒ Object
{
"status": "new",
"channel_name": "bol",
"channel_id": "61284922",
"channable_id": 151,
"data": {
"item": {
"id": "11694321",
"order_id": "4522232111",
"gtin": "0884500642113",
"title": "Nike Air Force 1 Winter Premium GS Flax Pack",
"quantity": 1,
"reason": "Anders, namelijk:",
"comment": "De schoenen vielen te groot."
},
"customer": {
"gender": "male",
"first_name": "Jans",
"last_name": "Van Janssen",
"email": "[email protected]"
},
"address": {
"first_name": "Jans",
"last_name": "Van Janssen",
"email": "[email protected]",
"street": "Teststraat",
"house_number": 12,
"address1": "Teststraat 12",
"adderss2": "",
"city": "Utrecht",
"country_code": "NL",
"zip_code": "1234 XZ"
}
}
}
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spree_channable/return_importer.rb', line 40 def self.import(return_data) order = Spree::Order.find_by_channable_order_id(return_data.data.item.order_id) return_reason_id = Spree::ReturnAuthorizationReason.first.id inventory_unit = order.line_items.detect {|li| li.variant.sku == return_data.data.item.gtin}&.inventory_units&.first if order && inventory_unit = Spree::ReturnAuthorization.create!( order_id: order.id, stock_location: ::SpreeChannable.configuration.stock_location, return_authorization_reason_id: return_reason_id ) Spree::CustomerReturn.create( stock_location: ::SpreeChannable.configuration.stock_location, channable_order_id: return_data.channable_id, return_items_attributes: { return_authorization_id: .id, inventory_unit_id: inventory_unit.id }) end end |