dabit / acts_as_shopping_cart Goto Github PK
View Code? Open in Web Editor NEWSimple Shopping Cart implementation
License: MIT License
Simple Shopping Cart implementation
License: MIT License
ShoppingCart#cart_items WILL BE DEPRECATED IN LATER VERSIONS OF acts_as_shopping_cart, please use ShoppingCart#shopping_cart_items instead
Ruby: 2.5.0
Rails 5.2.4
When you use the migrations helper mentioned on README, it doesn't add an index to the table
create_table :cart_items do |t|
t.shopping_cart_item_fields # Creates the cart items fields
end
This helper should also trigger add_index :cart_items, [:owner_id, :owner_type]
I added the Rails-money gem to the app to use it for currencies etc. When playing around with the app I noticed that if I call the total method on the cart it doesnt return the total value of the cart but instead a Money object. When I setup the DB I manually created the shopping_cart_items table. Not sure if that is the reason? This is mentioned in another issue as a way to deal with currency types that this gem doesnt solve. Any help would be great. Not sure if this is a bug or not but its doesnt seem like the desired result. Thanks
create_table :shopping_cart_items do |t| t.integer :owner_id t.string :owner_type t.integer :quantity t.integer :item_id t.string :item_type t.monetize :price t.timestamps end
`irb(main):002:0> shopping_cart = ShoppingCart.create
(0.2ms) BEGIN
ShoppingCart Create (42.5ms) INSERT INTO "shopping_carts" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2020-04-08 13:11:54.235042"], ["updated_at", "2020-04-08 13:11:54.235042"]]
(1.0ms) COMMIT
=> #<ShoppingCart id: 2, created_at: "2020-04-08 13:11:54", updated_at: "2020-04-08 13:11:54">
irb(main):003:0> shopping_cart.add(template, template.standard_license_price)
ShoppingCartItem Load (0.4ms) SELECT "shopping_cart_items".* FROM "shopping_cart_items" WHERE "shopping_cart_items"."owner_id" = $1 AND "shopping_cart_items"."owner_type" = $2 AND "shopping_cart_items"."item_type" = $3 AND "shopping_cart_items"."item_id" = $4 ORDER BY "shopping_cart_items"."id" ASC LIMIT $5 [["owner_id", 2], ["owner_type", "ShoppingCart"], ["item_type", "TemplateProduct"], ["item_id", 5], ["LIMIT", 1]]
(0.2ms) BEGIN
ShoppingCartItem Create (41.5ms) INSERT INTO "shopping_cart_items" ("owner_id", "owner_type", "quantity", "item_id", "item_type", "price_cents", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["owner_id", 2], ["owner_type", "ShoppingCart"], ["quantity", 1], ["item_id", 5], ["item_type", "TemplateProduct"], ["price_cents", 9054], ["created_at", "2020-04-08 13:12:16.696867"], ["updated_at", "2020-04-08 13:12:16.696867"]]
(2.1ms) COMMIT
=> #<ShoppingCartItem id: 2, owner_id: 2, owner_type: "ShoppingCart", quantity: 1, item_id: 5, item_type: "TemplateProduct", price_cents: 9054, price_currency: "USD", created_at: "2020-04-08 13:12:16", updated_at: "2020-04-08 13:12:16">
irb(main):004:0> shopping_cart.total
ShoppingCartItem Load (0.6ms) SELECT "shopping_cart_items".* FROM "shopping_cart_items" WHERE "shopping_cart_items"."owner_id" = $1 AND "shopping_cart_items"."owner_type" = $2 [["owner_id", 2], ["owner_type", "ShoppingCart"]]
"#Money fractional:9801 currency:USD"
irb(main):005:0> `
Hi,
I'm using the GEM on a rails 5 project.
Everything is working perfectly but i cannot change the currency to eur.
i have in my MoneyRails initializer
config.default_currency = :eur
but still does not work.
Thanks !
Francis
Does this work with rails 6 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.