-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
261 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module Shop | ||
module ItemHelper | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# item_id | ||
# qty | ||
# price | ||
|
||
module Shop | ||
class OrderItem < ApplicationRecord | ||
self.table_name = 'shop_orders' | ||
self.table_name = 'shop_order_items' | ||
|
||
validates_uniqueness_of :item_id | ||
|
||
belongs_to :order | ||
belongs_to :item | ||
|
||
def increase_quantity! | ||
self.quantity += 1 | ||
update_price(quantity) | ||
save! | ||
end | ||
|
||
def reduce_quantity! | ||
if self.quantity > 1 | ||
self.quantity -= 1 | ||
update_price(quantity) | ||
save! | ||
else | ||
delete_order_item | ||
end | ||
end | ||
|
||
def delete_order_item | ||
destroy! | ||
end | ||
|
||
def update_price(qty) | ||
self.price = item.price * qty | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class ItemImageUploader < CarrierWave::Uploader::Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
h2.main-header Cart | ||
|
||
.cart_table | ||
- if current_order.present? && current_order.order_items.any? | ||
table | ||
thead | ||
tr | ||
th Image | ||
th.company Name | ||
th.company Price | ||
th.count Count | ||
tbody | ||
- order_items.each do |item| | ||
tr | ||
td= image_tag item.item.item_images.first.image_url(:small).to_s, class: 'card_image' if item.item.item_images.first.try(:image_url) | ||
td= item.item.name | ||
td= item.price | ||
td | ||
div | ||
= link_to shop_order_item_path(item.id), method: :delete do | ||
i.fas.fa-minus | ||
|
||
= item.quantity | ||
|
||
= link_to shop_order_item_path(item.id), method: :put do | ||
i.fas.fa-plus | ||
|
||
.total_sum | ||
h2 Total | ||
h2= current_order.total_sum | ||
- else | ||
h1 Your cart is empty for now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
components/shop/db/migrate/20210611210804_create_orders.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateOrders < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :shop_orders do |t| | ||
t.integer :status, default: 0 | ||
t.text :shipment_address | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
components/shop/db/migrate/20210611211002_create_order_items.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateOrderItems < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :shop_order_items do |t| | ||
t.integer :quantity, default: 1 | ||
t.decimal :price, null: false | ||
t.references :item | ||
t.references :order | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :order, class: Shop::Order do | ||
shipment_address { 'Lviv, Pivorak street' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :order_item, class: Shop::OrderItem do | ||
price { 12 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
# frozen_string_literal: true | ||
# TODO | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe '/shop' do | ||
let!(:active_item) { create(:item, published: true) } | ||
|
||
scenario 'display items' do | ||
visit shop_items_path | ||
|
||
click_button 'Add to cart' | ||
|
||
expect(page).to have_current_path '/shop/items' | ||
# expect(page).to have_button('Added to the cart') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.