I think setting the amount to 0 is a hack and we should probably have a
more elegant way to handle this. Do you have any suggestions about a
possible way we could do that?

On Sun, Oct 6, 2013 at 6:36 PM, Stephane wrote:

Hi,

I have the following usecase since 1.3.X:

frontend :
1) a customer complete an order with with backorderable items

backend :
2) items are not available so line item is set to 0 to keep track of
canceled item
3) state is credit_owned so refund customers using payments

It was possible to have line_items with quantity = 0 before spree 2.0

However since Spree 2.0.X, line items are destroyed due to
Spree::OrderContents


def remove_from_line_item(line_item, variant, quantity, shipment=nil)
line_item.quantity += -quantity
line_item.target_shipment= shipment

if line_item.quantity == 0
Spree::OrderInventory.new(order).verify(line_item, shipment)
line_item.destroy
else
line_item.save!
end

order.reload
line_item
end


I added the following decorator :
Spree::OrderContents.class_eval do
def remove_from_line_item(line_item, variant, quantity, shipment=nil)
line_item.quantity += -quantity
line_item.target_shipment= shipment

line_item.save!

order.reload
line_item
end
end

The main goal to have line item with quantity with 0 is to let customer
know which item have been canceled etc...

Thanks,

Stephane.

--

Ryan Bigg
Community Manager
Spree Commerce, Inc.

Search Discussions

  • Stephane at Oct 8, 2013 at 10:46 am
    Ryan,

    Another solution would be using acts_as_paranoid and display deleted
    line_items WDYT ?

    Stephane.
    On Monday, October 7, 2013 3:44:24 AM UTC+2, Ryan Bigg wrote:

    I think setting the amount to 0 is a hack and we should probably have a
    more elegant way to handle this. Do you have any suggestions about a
    possible way we could do that?


    On Sun, Oct 6, 2013 at 6:36 PM, Stephane <stephan...@gmail.com<javascript:>
    wrote:
    Hi,

    I have the following usecase since 1.3.X:

    frontend :
    1) a customer complete an order with with backorderable items

    backend :
    2) items are not available so line item is set to 0 to keep track of
    canceled item
    3) state is credit_owned so refund customers using payments

    It was possible to have line_items with quantity = 0 before spree 2.0

    However since Spree 2.0.X, line items are destroyed due to
    Spree::OrderContents


    def remove_from_line_item(line_item, variant, quantity, shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    if line_item.quantity == 0
    Spree::OrderInventory.new(order).verify(line_item, shipment)
    line_item.destroy
    else
    line_item.save!
    end

    order.reload
    line_item
    end


    I added the following decorator :
    Spree::OrderContents.class_eval do
    def remove_from_line_item(line_item, variant, quantity, shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    line_item.save!

    order.reload
    line_item
    end
    end

    The main goal to have line item with quantity with 0 is to let customer
    know which item have been canceled etc...

    Thanks,

    Stephane.

    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.
  • Ryan Bigg at Oct 9, 2013 at 5:12 am
    We're already using my paranoia gem inside of Spree in more recent versions
    of Spree. It's totally possible to do that, it's just that the tricky part
    is going to be displaying them to the users in the most sensible way.

    How would these line items show up in the order interface in the backend? I
    would imagine they would need to be shown as separate from the "real" line
    items in the order already. I don't have any solid ideas about how to do
    this at the moment.

    On Tue, Oct 8, 2013 at 9:46 PM, Stephane wrote:

    Ryan,

    Another solution would be using acts_as_paranoid and display deleted
    line_items WDYT ?

    Stephane.
    On Monday, October 7, 2013 3:44:24 AM UTC+2, Ryan Bigg wrote:

    I think setting the amount to 0 is a hack and we should probably have a
    more elegant way to handle this. Do you have any suggestions about a
    possible way we could do that?

    On Sun, Oct 6, 2013 at 6:36 PM, Stephane wrote:

    Hi,

    I have the following usecase since 1.3.X:

    frontend :
    1) a customer complete an order with with backorderable items

    backend :
    2) items are not available so line item is set to 0 to keep track of
    canceled item
    3) state is credit_owned so refund customers using payments

    It was possible to have line_items with quantity = 0 before spree 2.0

    However since Spree 2.0.X, line items are destroyed due to
    Spree::OrderContents


    def remove_from_line_item(line_**item, variant, quantity,
    shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    if line_item.quantity == 0
    Spree::OrderInventory.new(**order).verify(line_item, shipment)
    line_item.destroy
    else
    line_item.save!
    end

    order.reload
    line_item
    end


    I added the following decorator :
    Spree::OrderContents.class_**eval do
    def remove_from_line_item(line_**item, variant, quantity,
    shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    line_item.save!

    order.reload
    line_item
    end
    end

    The main goal to have line item with quantity with 0 is to let customer
    know which item have been canceled etc...

    Thanks,

    Stephane.

    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.

    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.
  • Stéphane Bounmy at Oct 9, 2013 at 8:22 am
    I guess I will need to use paranoia and decorator for the time being :) !

    Thanks for your time.
    Stéphane.
    On Oct 9, 2013, at 7:12 AM, Ryan Bigg wrote:

    We're already using my paranoia gem inside of Spree in more recent versions of Spree. It's totally possible to do that, it's just that the tricky part is going to be displaying them to the users in the most sensible way.

    How would these line items show up in the order interface in the backend? I would imagine they would need to be shown as separate from the "real" line items in the order already. I don't have any solid ideas about how to do this at the moment.


    On Tue, Oct 8, 2013 at 9:46 PM, Stephane wrote:
    Ryan,

    Another solution would be using acts_as_paranoid and display deleted line_items WDYT ?

    Stephane.

    On Monday, October 7, 2013 3:44:24 AM UTC+2, Ryan Bigg wrote:
    I think setting the amount to 0 is a hack and we should probably have a more elegant way to handle this. Do you have any suggestions about a possible way we could do that?


    On Sun, Oct 6, 2013 at 6:36 PM, Stephane wrote:
    Hi,

    I have the following usecase since 1.3.X:

    frontend :
    1) a customer complete an order with with backorderable items

    backend :
    2) items are not available so line item is set to 0 to keep track of canceled item
    3) state is credit_owned so refund customers using payments

    It was possible to have line_items with quantity = 0 before spree 2.0

    However since Spree 2.0.X, line items are destroyed due to Spree::OrderContents


    def remove_from_line_item(line_item, variant, quantity, shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    if line_item.quantity == 0
    Spree::OrderInventory.new(order).verify(line_item, shipment)
    line_item.destroy
    else
    line_item.save!
    end

    order.reload
    line_item
    end


    I added the following decorator :
    Spree::OrderContents.class_eval do
    def remove_from_line_item(line_item, variant, quantity, shipment=nil)
    line_item.quantity += -quantity
    line_item.target_shipment= shipment

    line_item.save!

    order.reload
    line_item
    end
    end

    The main goal to have line item with quantity with 0 is to let customer know which item have been canceled etc...

    Thanks,

    Stephane.




    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.



    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
categoriesrubyonrails
postedOct 7, '13 at 1:44a
activeOct 9, '13 at 8:22a
posts4
users2
websitespreecommerce.com
irc#RubyOnRails

2 users in discussion

Stéphane Bounmy: 2 posts Ryan Bigg: 2 posts

People

Translate

site design / logo © 2022 Grokbase