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

Deleting a variant has no direct effect on a shopfront #3629

Closed
RachL opened this issue Mar 20, 2019 · 14 comments · Fixed by #3639
Closed

Deleting a variant has no direct effect on a shopfront #3629

RachL opened this issue Mar 20, 2019 · 14 comments · Fixed by #3639
Assignees
Labels
bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround.

Comments

@RachL
Copy link
Contributor

RachL commented Mar 20, 2019

Description

If you delete a variant, it keeps showing up on the shopfront until you save a second time changes on your product.

If someone attempts to add this deleted variant to cart it gets a infinite loader

I saw this while testing #3619 but could reproduced it on French production

Steps to Reproduce

  1. I deleted a variant that already existed on a staging server
  2. I saw that it was correctly deleted from the OC but not the shopfront (I cleared my browser cache several times)
  3. I've added a new variant to my product. At this stage - as I saved again - the variant previously deleted disappear from the shop. The new variant showed up correctly
  4. I deleted this new variant. Again it did not showed up in the OC, but on the shopfront yes.
  5. I change the price of another variant, hit save. Then my variant is correctly deleted from shop front.

I reproduce all this on French product but this time I also tried to add the deleted variant to card. I got an infinite loader on the add to cart button:

image

Reloading the page stop the loader, but my variant is still showing up. It's the v2 variant bottom page here: https://www.openfoodfrance.org/hub-demo-open-food-france/shop

Animated Gif/Screenshot

image

image

Severity

bug-s2: a non-critical feature is broken, no workaround

Your Environment

  • Version used: v1.28
  • Browser name and version: Firefox 65
  • Operating System and version (desktop or mobile): Ubuntu 18.10
@RachL RachL added the bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround. label Mar 20, 2019
@luisramos0
Copy link
Contributor

This looks like a cache problem. With the new feature to disable cache we can disable cache and see if this happens with the cache disabled :-)

@mkllnk
Copy link
Member

mkllnk commented Mar 21, 2019

This could be a duplicate of #2111. In that case it's no cache problem.

@mkllnk
Copy link
Member

mkllnk commented Mar 21, 2019

Changing the product a second time is a workaround, isn't it? Or first remove it from the order cycle and then delete it.

@mkllnk
Copy link
Member

mkllnk commented Mar 21, 2019

I looked into this and we have all the code to update the cache when a variant is destroyed. But we never call destroy, we call delete for a soft-delete. And that method doesn't touch the cache.

The current implementation:

def destruction
if is_master?
exchange_variants(:reload).destroy_all
yield
product.refresh_products_cache
else
OpenFoodNetwork::ProductsCache.variant_destroyed(self) do
# Remove this association here instead of using dependent: :destroy because
# dependent-destroy acts before this around_filter is called, so ProductsCache
# has no way of knowing which exchanges the variant was a member of.
exchange_variants(:reload).destroy_all
# Destroy the variant
yield
end
end

Where we should apply it:

def delete
if product.variants == [self] # Only variant left on product
errors.add :product, I18n.t(:spree_variant_product_error)
false
else
transaction do
self.update_column(:deleted_at, Time.zone.now)
ExchangeVariant.where(variant_id: self).destroy_all
self
end
end
end

This would be solved with Spree 2 because we get rid of our soft-delete implementation. Spree 2 always soft deletes when calling destroy.

I'm calling it a day now. Feel free to work on this issue. Otherwise I may have time tomorrow to work on this.

@RachL
Copy link
Contributor Author

RachL commented Mar 21, 2019

Changing the product a second time is a workaround, isn't it? Or first remove it from the order cycle and then delete it.

Yes you are right. I'm downgrading to s3.

@RachL RachL added s3 bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround. and removed bug-s2 The bug is affecting any of the non-critical features described in S1 and there is no workaround. s3 labels Mar 21, 2019
@sauloperez
Copy link
Contributor

sauloperez commented Mar 21, 2019

Thanks for the investigation @mkllnk. I think I can take it and fix it given my last week's cache deep-dive.

@sauloperez sauloperez self-assigned this Mar 21, 2019
sauloperez added a commit to coopdevs/openfoodnetwork that referenced this issue Mar 22, 2019
These tests prove that
openfoodfoundation#3629 is
indeed is a bug because we don't refresh the cache when deleting
a variant.
@sauloperez
Copy link
Contributor

#3639 fixes this in master but would you mind testing it in v2 as well? I just checked and there is no bug in v2. I want to be extra sure though. Thanks for taking care of it @mkllnk.

@mkllnk
Copy link
Member

mkllnk commented Mar 29, 2019

I'm not sure whom you asked to test it @sauloperez. Did you mean @RachL or me to test this?

@RachL would you mind testing this when you are next testing v2 anyway?

@RachL
Copy link
Contributor Author

RachL commented Mar 29, 2019

@mkllnk will do!

@RachL
Copy link
Contributor Author

RachL commented Apr 1, 2019

@mkllnk @sauloperez good catch, the issue remains in v2. I will open an issue for it.

@RachL
Copy link
Contributor Author

RachL commented Apr 1, 2019

@mkllnk @sauloperez ok nevermind when I retested again to write the issue i couldn't reproduced it.

@luisramos0
Copy link
Contributor

have you enabled cache in the backoffice?

@RachL
Copy link
Contributor Author

RachL commented Apr 1, 2019

@luisramos0 it is enabled by default I guess? Because I just saw that the bow is ticked, so I guess it was ticked when I did my test?

@luisramos0
Copy link
Contributor

yeah, if it is enabled now, I think it's safe to assume it was enabled when you tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-s3 The bug is stopping a critical or non-critical feature but there is a usable workaround.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants