On Github devinterface / spree_presentation
Permette di leggere/scrivere ogni risorsa dell'ecommerce
Dipende dai permessi dell'API KEY utilizzata, quindi dai permessi dell'utente
Ritorna un JSON di risposta
GET /api/products/1 $ curl http://demo.cloud-ecommerce.it/api/products/1.json?token=YOUR_KEY_HERE
{ "id": 1, "name": "Ruby on Rails Tote", "description": "Autem omnis quos esse at incidunt odio. Quia in quam odio architecto cum tempora non. Nesciunt magni doloremque adipisci. Neque assumenda fugiat ad.", "price": "14.0", "display_price": "€14,00 EUR", "available_on": "2014-02-18T18:04:37.870Z", "permalink": "ruby-on-rails-tote", "meta_description": null, "meta_keywords": null, "shipping_category_id": 1, "taxon_ids": [ 3, 11, 14, 15 ], "variants": [ { "id": 1, "name": "Ruby on Rails Tote", "sku": "ROR-00011", "price": "14.0", "weight": null, "height": null, "width": null, "depth": null, "is_master": true, "cost_price": "17.0", "permalink": "ruby-on-rails-tote", "description": "Autem omnis quos esse at incidunt odio. Quia in quam odio architecto cum tempora non. Nesciunt magni doloremque adipisci. Neque assumenda fugiat ad.", "option_values": [], "images": [ { "id": 21, "position": 1, "attachment_content_type": "image/jpeg", "attachment_file_name": "ror_tote.jpeg", "type": "Spree::Image", "attachment_updated_at": "2014-02-18T18:06:53.628Z", "attachment_width": 360, "attachment_height": 360, "alt": null, "viewable_type": "Spree::Variant", "viewable_id": 1, "mini_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/21/mini/ror_tote.jpeg?1392746813", "small_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/21/small/ror_tote.jpeg?1392746813", "product_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/21/product/ror_tote.jpeg?1392746813", "large_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/21/large/ror_tote.jpeg?1392746813" }, { "id": 22, "position": 2, "attachment_content_type": "image/jpeg", "attachment_file_name": "ror_tote_back.jpeg", "type": "Spree::Image", "attachment_updated_at": "2014-02-18T18:06:58.446Z", "attachment_width": 360, "attachment_height": 360, "alt": null, "viewable_type": "Spree::Variant", "viewable_id": 1, "mini_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/22/mini/ror_tote_back.jpeg?1392746818", "small_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/22/small/ror_tote_back.jpeg?1392746818", "product_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/22/product/ror_tote_back.jpeg?1392746818", "large_url": "http://s3-eu-west-1.amazonaws.com/cloud-ecommerce-demo/app/public/spree/products/22/large/ror_tote_back.jpeg?1392746818" } ] } ], "option_types": [], "product_properties": [ { "id": 25, "product_id": 1, "property_id": 9, "value": "Tote", "property_name": "Type" }, { "id": 26, "product_id": 1, "property_id": 10, "value": "15\" x 18\" x 6\"", "property_name": "Size" }, { "id": 27, "product_id": 1, "property_id": 11, "value": "Canvas", "property_name": "Material" } ] }
Override delle views:
# app/views/spree/home/index.html.erb <div data-hook="homepage_products"> <ul id="products" class="inline product-listing" data-hook=""> <li id="product_2" class="columns three alpha" data-hook="products_list_item" itemscope="" itemtype="http://schema.org/Product"> <div class="product-image"><a href="/products/apple" itemprop="url"><img alt="Apple" itemprop="image" src="/spree/products/2/small/Red_Apple.jpg?1376258869"></a> </div> <a href="/products/apple" class="info" itemprop="name" title="Apple">Apple</a><span class="price selling" itemprop="price">£1.99</span> </li> </ul> </div>
# app/overrides/homepage_contents.rb Deface::Override.new(:virtual_path => "spree/home/index", :replace => "[data-hook='homepage_products']", :name => "homepage_contents", :partial => "home/homepage_contents")
# app/models/spree/product_decorator.rb Spree::Product.class_eval do def some_method end end
# app/controllers/spree/products_controller_decorator.rb Spree::ProductsController.class_eval do def some_action end end
# app/controllers/spree/products_controller_decorator.rb Spree::ProductsController.class_eval do respond_override :index => { :html => { :success => lambda { render 'shared/some_file' } } } end
Spree::Image.class_eval do attachment_definitions[:attachment][:styles] = { :mini => '48x48>', # thumbs under image :small => '100x100>', # images on category view :product => '240x240>', # full product image :large => '600x600>' # light box image } end
# config/application.rb module Mistercucina class Application < Rails::Application config.to_prepare do # Load application's model / class decorators Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| Rails.configuration.cache_classes ? require(c) : load(c) end # Load application's view overrides Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c| Rails.configuration.cache_classes ? require(c) : load(c) end end end end
spree extension spree_monetaweb rails g migration add_monetaweb_payment_id_to_payments # Gemfile gem 'spree_monetaweb', :path => '../spree_monetaweb' bundle install rails g spree_monetaweb:install
engine.rb
https://github.com/devinterface/spree_monetaweb/blob/master/lib/spree_monetaweb/engine.rb
moneta_web.rb
checkout_controller_decorator.rb
monetaweb_controller.rb
engine.rb
https://github.com/devinterface/spree_solr/blob/2-2-stable/lib/spree_solr/engine.rb
solr.rb
https://github.com/devinterface/spree_solr/blob/2-2-stable/lib/spree/search/solr.rb
product_decorator.rb
https://github.com/devinterface/spree_solr/blob/2-2-stable/app/models/spree/product_decorator.rb
PRO
CONTRO
Stefano Mancini
DevInterface (http://www.devinterface.com)