cirandas.net

commit d44c065f719405366a4810f021c461f79ade8d7c

Author: Braulio Bhavamitra <braulio@prout.io>

Add stores_app plugin

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/.ruby-version b/.ruby-version
index 0bee604df761bde7de6502876b5cb0504dfa8701..8e8299dcc068356889b365e23c948b92c6dfcd78 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.3.3
+2.4.2




diff --git a/Gemfile.lock b/Gemfile.lock
index ecfde0a40d9c2c9cc4934ea7a3040887fe8a842e..b0e4641b75e737850b425ad9fe2c46ad59155a46 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,10 +1,3 @@
-GIT
-  remote: git://github.com/coletivoEITA/acts_as_solr_reloaded.git
-  revision: a04ff0c8b48e6c128166bc9e95b9ab1b865f45e8
-  ref: a04ff0c
-  specs:
-    acts_as_solr_reloaded (1.6.0)
-
 PATH
   remote: vendor/contacts
   specs:
@@ -169,7 +162,6 @@     arel (6.0.4)
     assets_live_compile (0.2.1)
       activesupport (>= 3.1)
       rails (>= 3.1)
-    attr_required (1.0.1)
     axiom-types (0.1.1)
       descendants_tracker (~> 0.0.4)
       ice_nine (~> 0.11.0)
@@ -182,10 +174,6 @@     babel-source (5.8.35)
     babel-transpiler (0.7.0)
       babel-source (>= 4.0, < 6)
       execjs (~> 2.0)
-    better_errors (2.1.1)
-      coderay (>= 1.0.0)
-      erubis (>= 2.6.6)
-      rack (>= 0.9.0)
     binding_of_caller (0.7.2)
       debug_inspector (>= 0.0.1)
     browser (2.4.0)
@@ -244,22 +232,8 @@     exception_notification (4.0.1)
       actionmailer (>= 3.0.4)
       activesupport (>= 3.0.4)
     execjs (2.7.0)
-    facebook-signed-request (0.2.7)
-    faraday (0.11.0)
-      multipart-post (>= 1.2, < 3)
     fast_blank (1.0.0)
     fast_gettext (0.9.2)
-    fb_graph (2.7.17)
-      httpclient (>= 2.4)
-      multi_json (>= 1.3)
-      rack-oauth2 (>= 0.14.4)
-      tzinfo
-    fb_graph2 (0.9.1)
-      activesupport (>= 3.2)
-      httpclient (>= 2.4)
-      multi_json
-      rack-oauth2 (>= 1.1)
-      url_safe_base64
     ffi (1.9.18)
     flamegraph (0.9.5)
     geocoder (1.4.4)
@@ -303,7 +277,6 @@       ruby_parser (~> 3.5)
     htmlentities (4.3.4)
     http-cookie (1.0.3)
       domain_name (~> 0.5)
-    httpclient (2.8.3)
     i18n (0.8.1)
     i18n-js (3.0.0)
       i18n (~> 0.6, >= 0.6.6)
@@ -312,12 +285,6 @@     js-routes (1.2.6)
       railties (>= 3.2)
       sprockets-rails
     json (2.1.0)
-    jsonify (0.3.1)
-      multi_json (~> 1.0)
-    jsonify-rails (0.3.2)
-      actionpack
-      jsonify (< 0.4.0)
-    jwt (1.5.6)
     kgio (2.11.0)
     launchy (2.4.3)
       addressable (~> 2.3)
@@ -351,45 +318,15 @@       metaclass (~> 0.0.1)
     multi_json (1.12.1)
     multi_test (0.1.2)
     multi_xml (0.6.0)
-    multipart-post (2.0.0)
     mustermann (1.0.0)
     mustermann-grape (1.0.0)
       mustermann (~> 1.0.0)
     netrc (0.11.0)
     newrelic_rpm (4.2.0.334)
-    nokogiri (1.6.8.1)
+    nokogiri (1.7.2)
       mini_portile2 (~> 2.1.0)
-    oauth (0.5.3)
-    oauth2 (1.3.1)
-      faraday (>= 0.8, < 0.12)
-      jwt (~> 1.0)
-      multi_json (~> 1.3)
-      multi_xml (~> 0.5)
-      rack (>= 1.2, < 3)
     oj (2.17.5)
     oj_mimic_json (1.0.1)
-    omniauth (1.6.1)
-      hashie (>= 3.4.6, < 3.6.0)
-      rack (>= 1.6.2, < 3)
-    omniauth-facebook (4.0.0)
-      omniauth-oauth2 (~> 1.2)
-    omniauth-github (1.3.0)
-      omniauth (~> 1.5)
-      omniauth-oauth2 (>= 1.4.0, < 2.0)
-    omniauth-google-oauth2 (0.4.1)
-      jwt (~> 1.5.2)
-      multi_json (~> 1.3)
-      omniauth (>= 1.1.1)
-      omniauth-oauth2 (>= 1.3.1)
-    omniauth-oauth (1.1.0)
-      oauth
-      omniauth (~> 1.0)
-    omniauth-oauth2 (1.4.0)
-      oauth2 (~> 1.0)
-      omniauth (~> 1.2)
-    omniauth-twitter (1.4.0)
-      omniauth-oauth (~> 1.1)
-      rack
     pg (0.20.0)
     pothoven-attachment_fu (3.2.18)
     power_assert (1.0.2)
@@ -406,6 +343,8 @@     pry (0.10.4)
       coderay (~> 1.1.0)
       method_source (~> 0.8.1)
       slop (~> 3.4)
+    pry-rails (0.3.6)
+      pry (>= 0.10.4)
     public_suffix (2.0.5)
     puma (3.8.2)
     puma_worker_killer (0.1.0)
@@ -418,12 +357,6 @@     rack-contrib (1.4.0)
       git-version-bump (~> 0.15)
       rack (~> 1.4)
     rack-cors (0.4.1)
-    rack-oauth2 (1.6.2)
-      activesupport (>= 2.3)
-      attr_required (>= 0.0.5)
-      httpclient (>= 2.4)
-      multi_json (>= 1.3.6)
-      rack (>= 1.1)
     rack-test (0.6.3)
       rack (>= 1.0)
     rack-timeout (0.4.2)
@@ -457,7 +390,6 @@       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
     raindrops (0.18.0)
     rake (12.0.0)
-    rakismet (1.5.3)
     redis (3.3.3)
     redis-actionpack (5.0.1)
       actionpack (>= 4.0, < 6)
@@ -568,7 +500,6 @@       raindrops (~> 0.7)
     unicorn-worker-killer (0.4.4)
       get_process_mem (~> 0)
       unicorn (>= 4, < 6)
-    url_safe_base64 (0.2.2)
     utf8-cleaner (0.2.5)
       activesupport
     virtus (1.0.5)
@@ -600,13 +531,11 @@   activerecord-jdbcpostgresql-adapter
   activerecord-session_store (= 1.0.0.pre)
   acts-as-taggable-on (~> 3.5)
   acts_as_list (= 0.0.0)!
-  acts_as_solr_reloaded!
   acts_as_tree (= 0.0.0)!
   acts_as_versioned (> 0.0.0)!
   api-pagination (>= 4.1.1)
   assets_live_compile (>= 0.2.1)
   axlsx
-  better_errors
   binding_of_caller
   browser
   capybara (~> 2.2)
@@ -625,11 +554,8 @@   dotenv
   eita-jrails (~> 0.10.0)
   exception_notification (~> 4.0.1)
   ezcrypto (= 0.0.0)!
-  facebook-signed-request
   fast_blank
   fast_gettext (~> 0.9)
-  fb_graph
-  fb_graph2
   flamegraph
   gdata (> 0.0.0)!
   geocoder
@@ -643,7 +569,6 @@   html2haml
   i18n-js
   i18n_deprecation (= 0.0.0)!
   js-routes (= 1.2.6)
-  jsonify-rails
   kandadaboggu-vote_fu (> 0.0.0)!
   launchy
   liquid (>= 3.0.3)
@@ -655,20 +580,15 @@   minitest-reporters
   mocha (~> 1.1.0)
   monkey_patches (= 0.0.0)!
   newrelic_rpm
-  nokogiri (~> 1.6.0)
+  nokogiri (~> 1.7.0)
   oj (~> 2.0)
   oj_mimic_json
-  omniauth
-  omniauth-facebook
-  omniauth-github
-  omniauth-google-oauth2
-  omniauth-oauth2
-  omniauth-twitter
   pg
   pothoven-attachment_fu (~> 3.2.16)
   premailer-rails
   protected_attributes
   pry
+  pry-rails
   puma_worker_killer
   rack-contrib
   rack-cors
@@ -678,7 +598,6 @@   rails-observers
   rails_autolink (~> 1.1.5)
   rails_rcov (= 0.0.0)!
   rake
-  rakismet (~> 1.5.0)
   recaptcha (> 0.0.0)!
   redis-rails
   rest-client (~> 1.6)
@@ -713,4 +632,4 @@   wirble
   xss_terminate (= 0.0.0)!
 
 BUNDLED WITH
-   1.13.6
+   1.14.6




diff --git a/config/application.rb b/config/application.rb
index da1943588b95a575e76e5a5c20574f568c2e57b9..61abdd2e159cf8a528b22418ade56a221ff91d2e 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -77,6 +77,7 @@     # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
     # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
     config.i18n.available_locales = Noosfero.available_locales
     config.i18n.default_locale = nil
+    config.i18n.enforce_available_locales = false
 
     # Configure the default encoding used in templates for Ruby 1.9.
     config.encoding = "utf-8"




diff --git a/config/routes/50_plugins.rb b/config/routes/50_plugins.rb
index dffe48a6dddcc132fb58edfdc23576532d6d598b..9745e7f24eeba34cd1ead74bce460c0ca33c0ec8 100644
--- a/config/routes/50_plugins.rb
+++ b/config/routes/50_plugins.rb
@@ -1,7 +1,7 @@
 paths              = {}
 profile_format     = /#{Noosfero.identifier_format}/i
 plugins_root       = if Rails.env.test? then 'plugins' else '{baseplugins,config/plugins}' end
-controllers_paths  = "#{Rails.root}/#{plugins_root}/*/{app/,}controllers"
+plugins_paths      = "#{Rails.root}/#{plugins_root}/*/"
 prefixes_by_folder = {
   public:    'plugin',
   profile:   'profile(/:profile)/plugin',
@@ -9,56 +9,59 @@   myprofile: 'myprofile(/:profile)/plugin',
   admin:     'admin/plugin',
 }
 
-Dir[controllers_paths].each do |controllers_dir|
-  plugin_name = File.basename File.dirname controllers_dir
+Dir[plugins_paths].each do |plugin_dir|
+  plugin_name       = File.basename plugin_dir
+  controllers_paths = "#{plugin_dir}/{app/,}controllers"
 
-  controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
-    path = "#{controllers_dir}/#{folder}/"
-    hash[folder] = Dir.glob("#{path}{*.rb,#{plugin_name}_plugin/*.rb}").map do |filename|
-      filename.gsub(path, '').gsub(/[_\/]controller.rb$/, '')
+  Dir[controllers_paths].each do |controllers_dir|
+    controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
+      path = "#{controllers_dir}/#{folder}/"
+      hash[folder] = Dir.glob("#{path}{*.rb,#{plugin_name}_plugin/*.rb}").map do |filename|
+        filename.gsub(path, '').gsub(/[_\/]controller.rb$/, '')
+      end
+      hash
     end
-    hash
-  end
 
-  controllers_by_folder.each do |folder, controllers|
-    controllers.each do |controller|
-      controller_name = controller.gsub(/#{plugin_name}_plugin[_\/]?/, '')
-      controller_path = if controller_name.present? then "/#{controller_name}" else '' end
+    controllers_by_folder.each do |folder, controllers|
+      controllers.each do |controller|
+        controller_name = controller.gsub(/#{plugin_name}_plugin[_\/]?/, '')
+        controller_path = if controller_name.present? then "/#{controller_name}" else '' end
 
-      as  = controller.tr '/','_'
-      url = "#{prefixes_by_folder[folder]}/#{plugin_name}#{controller_path}(/:action(/:id))"
+        as  = controller.tr '/','_'
+        url = "#{prefixes_by_folder[folder]}/#{plugin_name}#{controller_path}(/:action(/:id))"
 
-      paths[url] = {
-        controller: controller,
-        via:        :all,
-        as:         as,
-      }
-      paths[url][:profile] = profile_format if folder.to_s.in? %w[profile myprofile]
+        paths[url] = {
+          controller: controller,
+          via:        :all,
+          as:         as,
+        }
+        paths[url][:profile] = profile_format if folder.to_s.in? %w[profile myprofile]
+      end
     end
-  end
 
-  # DEPRECATED default controllers
-  paths.reverse_merge!(
-    "plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin",
-      via:        :all,
-    },
-    "admin/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_admin",
-      via:        :all,
-    },
+    # DEPRECATED default controllers
+    paths.reverse_merge!(
+      "plugin/#{plugin_name}(/:action(/:id))" => {
+        controller: "#{plugin_name}_plugin",
+          via:        :all,
+      },
+      "admin/plugin/#{plugin_name}(/:action(/:id))" => {
+        controller: "#{plugin_name}_plugin_admin",
+          via:        :all,
+      },
 
-    "profile(/:profile)/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_profile",
-      via:        :all,
-      profile:    profile_format,
-    },
-    "myprofile(/:profile)/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_myprofile",
-      via:        :all,
-      profile:    profile_format,
-    },
-  )
+      "profile(/:profile)/plugin/#{plugin_name}(/:action(/:id))" => {
+        controller: "#{plugin_name}_plugin_profile",
+          via:        :all,
+          profile:    profile_format,
+      },
+      "myprofile(/:profile)/plugin/#{plugin_name}(/:action(/:id))" => {
+        controller: "#{plugin_name}_plugin_myprofile",
+          via:        :all,
+          profile:    profile_format,
+      },
+    )
+  end
 end
 
 Noosfero::Application.routes.draw do




diff --git a/plugins/products/lib/ext/community.rb b/plugins/products/lib/ext/community.rb
new file mode 100644
index 0000000000000000000000000000000000000000..42be7d208c51e538e409d2f1a6647dfda0225fb9
--- /dev/null
+++ b/plugins/products/lib/ext/community.rb
@@ -0,0 +1,3 @@
+require_relative 'profile'
+require_dependency 'community'
+




diff --git a/plugins/products/models/products_plugin/product.rb b/plugins/products/models/products_plugin/product.rb
index 4f28585af4b39c60c25525549533c88545c1981d..513ef64a9f46406ade937f22cc92ec4231500192 100644
--- a/plugins/products/models/products_plugin/product.rb
+++ b/plugins/products/models/products_plugin/product.rb
@@ -1,3 +1,5 @@
+require 'products_plugin'
+
 module ProductsPlugin
   class Product < ApplicationRecord
 




diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb
new file mode 100644
index 0000000000000000000000000000000000000000..68e9905bbc2be947ef443cf0fe6b11cf865b5c2c
--- /dev/null
+++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/api_controller.rb
@@ -0,0 +1,19 @@
+module StoresAppPlugin
+  class ApiController < ::ApplicationController
+
+    layout false
+
+    needs_profile
+    before_filter :allow_cors
+
+    protected
+
+    def allow_cors
+      headers['Access-Control-Allow-Origin']   = '*'
+      headers['Access-Control-Allow-Methods']  = 'POST, PUT, DELETE, GET, OPTIONS'
+      headers['Access-Control-Request-Method'] = '*'
+      headers['Access-Control-Allow-Headers']  = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
+    end
+
+  end
+end




diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/catalog_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/catalog_controller.rb
new file mode 100644
index 0000000000000000000000000000000000000000..316375f57c716da29d49007a4efde69449b408f5
--- /dev/null
+++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/catalog_controller.rb
@@ -0,0 +1,11 @@
+module StoresAppPlugin
+  class CatalogController < ApiController
+
+    def listing
+      render json: CatalogSerializer.new(profile).to_hash
+    end
+
+    protected
+
+  end
+end




diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/cycles_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/cycles_controller.rb
new file mode 100644
index 0000000000000000000000000000000000000000..67dad6709aa7e4ee3bae6e35046f6f419577b43a
--- /dev/null
+++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/cycles_controller.rb
@@ -0,0 +1,11 @@
+module StoresAppPlugin
+  class CyclesController < ApiController
+
+    def index
+      render json: {data: 'ok'}
+    end
+
+    protected
+
+  end
+end




diff --git a/plugins/stores_app/app/controllers/profile/stores_app_plugin/orders_controller.rb b/plugins/stores_app/app/controllers/profile/stores_app_plugin/orders_controller.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a883861ec15c4625136151b40ffd14a8625cb2c1
--- /dev/null
+++ b/plugins/stores_app/app/controllers/profile/stores_app_plugin/orders_controller.rb
@@ -0,0 +1,23 @@
+module StoresAppPlugin
+  class OrdersController < ApiController
+
+    def last
+      render json: OrderSerializer.new(last_order, scope: self).to_hash
+    end
+
+    protected
+
+    def last_order
+      profile.sales
+        .of_user(session.id, user)
+        .order('created_at DESC')
+        .first
+    end
+
+    def user
+      user = User.find_by email: 'brauliobo@gmail.com'
+      user.person
+    end
+
+  end
+end




diff --git a/plugins/stores_app/app/controllers/stores_app_plugin/application_controller.rb b/plugins/stores_app/app/controllers/stores_app_plugin/application_controller.rb
deleted file mode 100644
index b53e2e3011c244791ba09dc184382d0666e2b2f4..0000000000000000000000000000000000000000
--- a/plugins/stores_app/app/controllers/stores_app_plugin/application_controller.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module StoresAppPlugin
-
-  class ApplicationController < ApplicationController
-
-    layout 'stores_app_plugin/layout'
-
-    needs_profile
-
-    def index
-      render action: :index
-    end
-
-    protected
-
-  end
-end




diff --git a/plugins/stores_app/app/serializers/stores_app_plugin/catalog_serializer.rb b/plugins/stores_app/app/serializers/stores_app_plugin/catalog_serializer.rb
index 8417da256cc5496b2aa62a34f5990da121938fbe..415b21ae427b827601116414487b13f4a35f9df7 100644
--- a/plugins/stores_app/app/serializers/stores_app_plugin/catalog_serializer.rb
+++ b/plugins/stores_app/app/serializers/stores_app_plugin/catalog_serializer.rb
@@ -1,11 +1,13 @@
-class StoresAppPlugin::CatalogSerializer < ApplicationSerializer
+module StoresAppPlugin
+  class CatalogSerializer < ApplicationSerializer
 
-  alias_method :profile, :object
+    alias_method :profile, :object
 
-  has_many :products, serializer: ProductSerializer
+    has_many :products, serializer: ProductSerializer
 
-  def products
-    profile.distributed_products.unarchived.available
+    def products
+      profile.products.supplied.unarchived.available
+    end
+
   end
-
 end




diff --git a/plugins/stores_app/app/serializers/stores_app_plugin/item_serializer.rb b/plugins/stores_app/app/serializers/stores_app_plugin/item_serializer.rb
new file mode 100644
index 0000000000000000000000000000000000000000..8ba8f1db4744df595e974717ceac1378faa46ccb
--- /dev/null
+++ b/plugins/stores_app/app/serializers/stores_app_plugin/item_serializer.rb
@@ -0,0 +1,62 @@
+module StoresAppPlugin
+  class ItemSerializer < ApplicationSerializer
+
+    alias_method :item, :object
+
+    attribute :id
+    attribute :name
+    attribute :supplier_name
+    attribute :unit_name
+    attribute :image
+
+    attribute :price
+    attribute :status_quantity
+    attribute :status_quantity_localized
+
+    attribute :status
+    attribute :flags
+    attribute :statuses
+
+    attribute :quantity_consumer_ordered_more_than_stored
+
+    def image
+      image_filename :big
+    end
+
+    def flags
+      quantity_price_data[:flags]
+    end
+
+    def statuses
+      quantity_price_data[:statuses]
+    end
+
+    def quantity_consumer_ordered_more_than_stored
+      scope.instance_variable_get :@quantity_consumer_ordered_more_than_stored
+    end
+
+    protected
+
+    def image_filename size
+      i = product.own_image || product.supplier_image
+      i&.public_filename size
+    end
+
+    def product
+      item.product
+    end
+
+    def quantity_price_data
+      @quantity_price_data ||= item.quantity_price_data actor_name
+    end
+
+    def actor_name
+      instance_options[:actor_name]
+    end
+
+    def admin
+      scope.instance_variable_get :@admin
+    end
+
+  end
+end




diff --git a/plugins/stores_app/app/serializers/stores_app_plugin/order_serializer.rb b/plugins/stores_app/app/serializers/stores_app_plugin/order_serializer.rb
new file mode 100644
index 0000000000000000000000000000000000000000..f5b216e56c7470be3b5192bd2698df8426d5c73a
--- /dev/null
+++ b/plugins/stores_app/app/serializers/stores_app_plugin/order_serializer.rb
@@ -0,0 +1,74 @@
+module StoresAppPlugin
+  class OrderSerializer < ApplicationSerializer
+
+    alias_method :order, :object
+
+    attribute :currency_unit
+
+    attribute :admin
+    attribute :actor_name
+    attribute :errors
+    attribute :self_supplier
+
+    attribute :may_edit
+    attribute :view_only
+
+    attribute :status
+    attribute :total_price
+    attribute :remaining_total
+
+    has_many :items
+
+    def currency_unit
+      return unless scope.respond_to? :environment, true
+      scope.send(:environment).currency_unit
+    end
+
+    def admin
+      scope.instance_variable_get :@admin
+    end
+
+    def actor_name
+      instance_options[:actor_name]
+    end
+
+    def errors
+      instance_options[:errors]
+    end
+
+    def self_supplier
+      order.self_supplier?
+    end
+
+    def may_edit
+      order.may_edit? user, admin
+    end
+
+    def view_only
+      scope.instance_variable_get :@view
+    end
+
+    def total_price
+      order.total_price actor_name, admin
+    end
+
+    def remaining_total
+      order.remaining_total actor_name, admin
+    end
+
+    def items
+      order.items.map do |item|
+        ItemSerializer.new(item, scope: scope, actor_name: actor_name).to_hash
+      end
+    end
+
+    protected
+
+    def user
+      return unless scope.respond_to? :user, true
+      scope.send :user
+    end
+
+  end
+end
+




diff --git a/plugins/stores_app/app/serializers/stores_app_plugin/product_serializer.rb b/plugins/stores_app/app/serializers/stores_app_plugin/product_serializer.rb
index b70e6001d5e6e982e2f7b42285a08b94ef5c7979..4a6727ce2772617a477c59f1f7bbe13d723baf4b 100644
--- a/plugins/stores_app/app/serializers/stores_app_plugin/product_serializer.rb
+++ b/plugins/stores_app/app/serializers/stores_app_plugin/product_serializer.rb
@@ -1,17 +1,48 @@
-class StoresAppPlugin::ProductSerializer < ApplicationSerializer
+module StoresAppPlugin
+  class ProductSerializer < ApplicationSerializer
+
+    alias_method :product, :object
+
+    attribute :id
+
+    attribute :available
+    attribute :highlighted
+
+    attribute :category
+    #has_many :qualifiers
+
+    attribute :name
+
+    attribute :image
+
+    attribute :distributed
+    attribute :supplier_name
+
+    attribute :created_at
+    attribute :updated_at
+
+    def category
+      product.product_category&.name
+    end
+
+    def image
+      image_filename :big
+    end
 
-  alias_method :product, :object
+    def distributed
+      product.distributed?
+    end
 
-  attribute :available
-  attribute :highlighted
+    def supplier_name
+      product.supplier&.name
+    end
 
-  attribute :category
-  #has_many :qualifiers
+    protected
 
-  attribute :name
+    def image_filename size
+      i = product.own_image || product.supplier_image
+      i&.public_filename size
+    end
 
-  def category
-    product.product_category&.name
   end
-
 end




diff --git a/plugins/stores_app/lib/stores_app_plugin/api.rb b/plugins/stores_app/lib/stores_app_plugin/api.rb
new file mode 100644
index 0000000000000000000000000000000000000000..2c0ae0d5c98b4b0a4b8965400948026e17514fc6
--- /dev/null
+++ b/plugins/stores_app/lib/stores_app_plugin/api.rb
@@ -0,0 +1,9 @@
+module StoresAppPlugin
+  class API < Grape::API
+
+    get '/hello' do
+      present 'teste'
+    end
+
+  end
+end




diff --git a/plugins/stores_app/lib/stores_app_plugin.rb b/plugins/stores_app/lib/stores_app_plugin.rb
index c789f61fa423844dc21c760ac09eae8c2945cc7b..57fed3b42308b3b34bf9993651537b0dc62ed3d2 100644
--- a/plugins/stores_app/lib/stores_app_plugin.rb
+++ b/plugins/stores_app/lib/stores_app_plugin.rb
@@ -1,3 +1,13 @@
 module StoresAppPlugin
 
+  extend Noosfero::Plugin::ParentMethods
+
+  def self.plugin_name
+    I18n.t'stores_api_plugin.lib.plugin.name'
+  end
+
+  def self.plugin_description
+    I18n.t'stores_api_plugin.lib.plugin.description'
+  end
+
 end