QNA > H > How To Manually Install Zxp Extensions

How to manually install ZXP extensions

Create new rails project. PostgreSQL database was used here, you can choose as per your requirements.

  1. rails new solidus-example — database=postgresql 

Add the following to gemfile of your rails application.

  1. gem 'solidus'  
  2.  
  3. gem 'solidus_auth_devise' 

As we have added the gems to the gemfile we need to update bundle.

  1. $ bundle install 

In case you encounter nokogiri error you can refer to this link: http://stackoverflow.com/a/20006530

Add the necessary configurations in the config/database.yml like username password.

  1. default: &default 
  2. adapter: postgresql 
  3. encoding: unicode 
  4. pool: 5 
  5. username: postgres 
  6. password: root 
  7. host: localhost 
  8.  
  9. development: 
  10. <<: *default 
  11. database: solidus_example 
  12.  
  13. test: 
  14. <<: *default 
  15. database: solidus_example_test 

Create the database.

  1. $ bundle exec rake db:create 

After this you need to install spree.

  1. $ bundle exec rails g spree:install 

It will ask for email and password (enter you custom) else go with the default ones.

  1. $ bundle exec rake railties:install:migrations 

Now your solidus application is ready to be used. Now you can start your rails server and start exploring the feature and options available.

Creating solidus extension

To know more about extensions and how to write one in Spree refer http://guides.spreecommerce.org/developer/extensions_tutorial.html

Unlike Spree, it is not pretty straight forward in soldius, we need to add gem to our file.

  1. gem 'solidus_cmd' 

And then we need to update bundle.

  1. $ bundle install 

Now we need to move one directory back from the folder of our rails application and run following commands in the console.

  1. $ cd .. # To move one directory back in Linux systems 
  2. $ gem install solidus_cmd 
  3. $ solidus extension my_extension 
  4. $ cd solidus_my_extension 
  5. $ bundle install 

Make sure you are now in solidus_my_extension folder. All the customisation that we need to do in solidus we must do it in this folder without touching the solidus-master code.

Now let’s add new column named as sale_price in the Spree::Variant model.

  1. bundle exec rails g migration add_sale_price_to_spree_variants sale_price:decimal 

NOTE: Don’t run rake db:migrate in this folder.

First we need to update the .gemspec file of this extension. We need to add author, description, summary and email in .gemspec file. Below is sample.

  1. # encoding: UTF-8 
  2. $:.push File.expand_path('../lib', __FILE__) 
  3. require 'solidus_my_extension/version' 
  4.  
  5. Gem::Specification.new do |s| 
  6. s.name = 'solidus_my_extension' 
  7. s.version = SolidusMyExtension::VERSION 
  8. s.summary = 'This is for test summary' 
  9. s.description = 'This is for test description' 
  10. s.license = 'BSD-3-Clause' 
  11.  
  12. s.author = 'Ankur' 
  13. s.email = '[email protected]
  14. # s.homepage = 'http://www.example.com' 
  15.  
  16. s.files = Dir["{app,config,db,lib}/**/*", 'LICENSE', 'Rakefile', 'README.md'] 
  17. s.test_files = Dir['test/**/*'] 
  18.  
  19. s.add_dependency 'solidus_core', '~> 1.0' 
  20.  
  21. s.add_development_dependency 'capybara' 
  22. s.add_development_dependency 'poltergeist' 
  23. s.add_development_dependency 'coffee-rails' 
  24. s.add_development_dependency 'sass-rails' 
  25. s.add_development_dependency 'database_cleaner' 
  26. s.add_development_dependency 'factory_girl' 
  27. s.add_development_dependency 'rspec-rails' 
  28. s.add_development_dependency 'rubocop', '0.37.2' 
  29. s.add_development_dependency 'rubocop-rspec', '1.4.0' 
  30. s.add_development_dependency 'simplecov' 
  31. s.add_development_dependency 'sqlite3' 
  32. end 

Now move to the solidus-example folder.

Now we need to include our created extension in our main rails application. Add the following to the gemfile.

  1. gem 'solidus_my_extension', :path => '../solidus_my_extension' 

Then run following commands.

  1. $ bundle install 
  2. $ rails g solidus_my_extension:install 

It will prompt you run the migrations type ‘Y’ and after the successful migration completion you will have sale_price added.

Per la personalizzazione di Views e Controller puoi seguire i passi descritti dopo http://guides.spreecommerce.org/developer/extensions_tutorial.html#adding-a-controller-action-to-homecontroller

# NOTA: dopo ogni cambiamento nell'estensione dobbiamo riavviare il server solidus-example

Di Nova

Qual è il miglior smartwatch del 2017? :: Quali sono le caratteristiche del Mobvoi Ticwatch S?
Link utili