Simple retail shop interface
mercadona
- Simple retail shop interface.
Table of Contents
- Requirements
- Installation
- Usage
- Customization
- Contributing
- License
- Code of Conduct
- Credits
- Versioning
- Changelog
Requirements
Ruby MRI 2.5.0+
Installation
Add this line to your application's Gemfile
:
gem 'mercadona'
And then execute:
bundle
Or install it yourself as:
gem install mercadona
Usage
require 'mercadona'
# Define discount rules
bogo_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Bogo, condition: '>=', quantity: 2)
quantity_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Quantity, condition: '>=', quantity: 3, discount: 0.5)
bulk_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Bulk, condition: '>=', quantity: 3, discount: 1/3r)
# Define checkout with discount rules specified through product codes
checkout = Mercadona::Checkout.new(
'GR1' => bogo_discount,
'SR1' => quantity_discount,
'CF1' => bulk_discount
)
# Define order items
green_tea = Mercadona::Entity::OrderItem.new(product_code: 'GR1', name: 'Green Tea', price: 3.11)
strawberries = Mercadona::Entity::OrderItem.new(product_code: 'SR1', name: 'Strawberries', price: 5.0)
coffee = Mercadona::Entity::OrderItem.new(product_code: 'CF1', name: 'Coffee', price: 11.23)
# Add order items to checkout
[green_tea, strawberries, coffee].each { |order_item| checkout.scan(order_item) }
# Calculate total amount using current discount rules
checkout.total # => "£19.34"
Customization
You can define your custom discount logic. Please follow the example below:
require 'mercadona'
class YourCustomDiscount < Mercadona::Discount::Base
def call
return amount_without_discount unless discount_case?
# Your logic here...
end
end
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/mercadona. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. Please check the open tickets. Be sure to follow Contributor Code of Conduct below and our Contributing Guidelines.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the mercadona project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Credits
- The Contributors for code and awesome suggestions
- The Stargazers for showing their support
Versioning
mercadona
uses Semantic Versioning 2.0.0