Extending an API helper

174 views
Skip to first unread message

Jeremy Rottman

unread,
Aug 9, 2012, 3:25:02 PM8/9/12
to spree...@googlegroups.com
I am trying to find documenation on how to extend an existing API helper. Currently I am using https://github.com/nebulab/spree-subscriptions to handle recurring billing. I would like to add the subscribable  attribute to the returned json response. 

I have tried adding the spree_site.rb to the application and then added the helper app/helper/spree/api/api_helpers.rb but this didn't seem to do the trick.

Any help with this is greatly appreciated.

Jeremy Rottman

unread,
Aug 9, 2012, 3:31:55 PM8/9/12
to spree...@googlegroups.com
Welp nevermind, right after I posted this I got it figured out.

Here is what I did:

Add /lib/spree_site.rb

spree_site.rb

Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|

  Rails.configuration.cache_classes ? require(c) : load(c)

end

Add the following file: app/helpers/spree/api/api_helpers_decorator.rb

api_helpers_decorator.rb

Spree::Api::ApiHelpers.class_eval do  

   def product_attributes

        [:id, :name, :description, :price, :available_on, :permalink, :subscribable

          :count_on_hand, :meta_description, :meta_keywords, :taxon_ids]

   end 

end

Thomas Mulloy

unread,
Aug 26, 2014, 1:06:02 PM8/26/14
to spree...@googlegroups.com
would something like this achieve the same?

Spree::Api::ApiHelpers.class_eval do
  
  product_attributes << :subscribable

end

Peter Berkenbosch

unread,
Aug 27, 2014, 5:09:43 AM8/27/14
to spree...@googlegroups.com
Hi Thomas,

Yes, that should work as well.

Peter.
--

Peter Berkenbosch
Spree Commerce, Inc.

Reply all
Reply to author
Forward
0 new messages