Class: FlexCommerce::Product

Inherits:
FlexCommerceApi::ApiBase show all
Defined in:
app/models/product.rb

Overview

A flex commerce Product model

This model provides access to the flex commerce products. As managing the products is the job of the administration panel, this model is read only.

It is used much like an active record model.

Examples:

# Fetching all products

FlexCommerce::Product.all #fetches all products(actually the first page in case there are thousands)

# Pagination

FlexCommerce::Product.paginate(page:2).all # Fetches page 2 of products.
The page size is predefined on the server side

# Finding products

FlexCommerce::Product.find("my-product-slug") # Finds the product with this unique id

# Finding nested variants of the product

FlexCommerce::Product.find("my-product-slug").variants

Constant Summary

Constants inherited from FlexCommerceApi::BaseResource

FlexCommerceApi::BaseResource::PRIVATE_ATTRIBUTES, FlexCommerceApi::BaseResource::RELATED_META_RESOURCES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FlexCommerceApi::ApiBase

endpoint_version

Methods inherited from FlexCommerceApi::BaseResource

all, append_version, #as_json_api, capture_surrogate_keys, create!, endpoint_version, find, find_all, #freeze, #initialize, load, #meta_attribute, #method_missing, paginate, password, #public_attributes, reconfigure, reconfigure_all, reconfigure_api_base, reload_connection_if_required, #save!, username

Constructor Details

This class inherits a constructor from FlexCommerceApi::BaseResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FlexCommerceApi::BaseResource

Class Method Details

.path(params, *args) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'app/models/product.rb', line 71

def path(params, *args)
  if params[:filter] && params[:filter].key?(:category_id) && params[:filter].key?(:category_tree_id)
    category_tree_id = params[:filter].delete(:category_tree_id)
    category_id = params[:filter].delete(:category_id)
    params.delete(:filter) if params[:filter].empty?
    "category_trees/#{category_tree_id}/categories/#{category_id}/products"
  else
    super
  end
end

Instance Method Details

#add_asset_files(asset_files) ⇒ Object

Relationship accessors



92
93
94
# File 'app/models/product.rb', line 92

def add_asset_files(asset_files)
  self.class.requestor.custom("relationships/asset_files", {request_method: :post}, {id: id, data: asset_files.map(&:as_relation)})
end

#allFlexCommerce::Product[]

Returns all products

Returns:



# File 'app/models/product.rb', line 41

#current_max_priceObject



83
84
85
# File 'app/models/product.rb', line 83

def current_max_price
  variants.map(&:current_price).max
end

#current_min_priceObject



87
88
89
# File 'app/models/product.rb', line 87

def current_min_price
  variants.map(&:current_price).min
end

#findFlexCommerce::Product

Finds a product

Parameters:

  • spec (String)

Returns:

Raises:



# File 'app/models/product.rb', line 35

#paginateObject

Paginates the list of products by a preset page size

Parameters:

  • options (Hash)

    The options to paginate with

  • options (Numeric|String)

    :page The page to fetch



# File 'app/models/product.rb', line 45

#skuObject

TODO Decide where sku really comes from - its in the variant but not at product level like in matalan direct appears to be



65
66
67
# File 'app/models/product.rb', line 65

def sku
  reference
end

#variantsFlexCommerce::Variant[]

Provides a list of associated variants

Returns:



# File 'app/models/product.rb', line 50