Sha256: a3aecb30fac63874511e1b47180991a3e6f304a91bdaf87c24d031775ddd4965
Contents?: true
Size: 1.18 KB
Versions: 34
Compression:
Stored size: 1.18 KB
Contents
module Workarea class OrderItemDetails class InvalidPurchase < StandardError; end attr_reader :product, :sku delegate :digital?, to: :product 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 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 def initialize(product, sku) @product = product @sku = sku end def category_ids Categorization.new(product).to_a end def pricing @pricing ||= Pricing::Sku.find(sku) end def to_h { product_id: product.id, product_attributes: product.as_document, category_ids: category_ids, discountable: pricing.discountable? } end end end
Version data entries
34 entries across 34 versions & 1 rubygems