Class: Workarea::OrderItemDetails
- Inherits:
-
Object
- Object
- Workarea::OrderItemDetails
- Defined in:
- app/queries/workarea/order_item_details.rb
Defined Under Namespace
Classes: InvalidPurchase
Instance Attribute Summary collapse
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#sku ⇒ Object
readonly
Returns the value of attribute sku.
Class Method Summary collapse
Instance Method Summary collapse
- #category_ids ⇒ Object
-
#initialize(product, sku) ⇒ OrderItemDetails
constructor
A new instance of OrderItemDetails.
- #pricing ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(product, sku) ⇒ OrderItemDetails
33 34 35 36 |
# File 'app/queries/workarea/order_item_details.rb', line 33 def initialize(product, sku) @product = product @sku = sku end |
Instance Attribute Details
#product ⇒ Object (readonly)
Returns the value of attribute product.
5 6 7 |
# File 'app/queries/workarea/order_item_details.rb', line 5 def product @product end |
#sku ⇒ Object (readonly)
Returns the value of attribute sku.
5 6 7 |
# File 'app/queries/workarea/order_item_details.rb', line 5 def sku @sku end |
Class Method Details
.find(sku, product_id: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/queries/workarea/order_item_details.rb', line 21 def self.find(sku, product_id: nil) product = if product_id.present? Catalog::Product.where(id: product_id).find_by_sku(sku) else Catalog::Product.find_by_sku(sku) end return nil if product.blank? new(product, sku) end |
.find!(sku, product_id: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/queries/workarea/order_item_details.rb', line 9 def self.find!(sku, product_id: nil) product = if product_id.present? Catalog::Product.where(id: product_id).find_by_sku(sku) else Catalog::Product.find_by_sku(sku) end raise InvalidPurchase, sku unless product && product.purchasable? new(product, sku) end |
Instance Method Details
#category_ids ⇒ Object
38 39 40 |
# File 'app/queries/workarea/order_item_details.rb', line 38 def category_ids Categorization.new(product).to_a end |
#pricing ⇒ Object
42 43 44 |
# File 'app/queries/workarea/order_item_details.rb', line 42 def pricing @pricing ||= Pricing::Sku.find(sku) end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/queries/workarea/order_item_details.rb', line 46 def to_h { product_id: product.id, product_attributes: product.as_document, category_ids: category_ids, discountable: pricing.discountable? } end |