The Wayback Machine - https://web.archive.org/web/20201114062043/https://github.com/solidusio/solidus/issues/3700
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

Not able to change images size #3700

Open
sechix opened this issue Jul 10, 2020 · 6 comments
Open

Not able to change images size #3700

sechix opened this issue Jul 10, 2020 · 6 comments

Comments

@sechix
Copy link

@sechix sechix commented Jul 10, 2020

I am trying to change sizes with this in the initializer:
Spree::Image.attachment_definitions[:attachment][:styles] = {
mini: '48x48>',
small: '100x100>',
product: '240x240>',
large: '600x600>'
}
But 'module Spree::Image::ActiveStorageAttachment' don't take new sizes. How to do it?

Solidus Version:
Last version of master

To Reproduce

@sechix
Copy link
Author

@sechix sechix commented Sep 24, 2020

Hi, any idea? @kennyadsl

@hefan
Copy link
Contributor

@hefan hefan commented Sep 25, 2020

It doesn't seem to work any longer with Rails 6 / Zeitwerk in an initializer.
Somehow it gets overriden again with the default styles from core/app/models/spree/image/paperclip_attachment.rb.
To get it to work with Rails 6 you have to decorate Spree::Image and do something like

module ImageDecorator

  def self.prepended(base)
    base.attachment_definitions[:attachment][:styles] = {
      mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>'
    }
  end

  Spree::Image.prepend self
end

For more details about Decorations: https://guides.solidus.io/developers/customizations/decorators.html

With Rails 5.2 it works fine

@kennyadsl i am not sure how to make it work again in Zeitwerk. Maybe you can suggest something?

@kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Sep 28, 2020

I think it's a filename issue. Where this ImageDecorator lives exactly?

@hefan
Copy link
Contributor

@hefan hefan commented Sep 28, 2020

The Image Decorator would be a workaround. Normally

Spree::Image.attachment_definitions[:attachment][:styles] = {
  mini: '48x48>',
  small: '100x100>',
  product: '240x240>',
  large: '600x600>'
}

should work in an initializer like stated here Product images which seems not to work in rails 6

@kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Sep 28, 2020

Oh, you are right. This seems like a bug then, I'll try to take a look asap.

@EduardoGHdez
Copy link

@EduardoGHdez EduardoGHdez commented Oct 3, 2020

There is another workaround

You are able to set your own image_attachment_module from Spree::Config 😄 , rather than decorating
https://github.com/solidusio/solidus/blob/master/core/lib/spree/app_configuration.rb#L477-L483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.