Class: EcwidApi::Api::Products
- Defined in:
- lib/ecwid_api/api/products.rb
Instance Method Summary collapse
-
#all(params = {}) ⇒ Object
Public: Get all of the Product objects for the Ecwid store params - a hash of request parameters.
-
#create(params) ⇒ Object
Public: Creates a new Product.
-
#find(id, params = {}) ⇒ Object
Public: Finds a single product by product ID.
-
#find_by_sku(sku, params = {}) ⇒ Object
Public: Finds a single Product by SKU.
-
#update(id, params) ⇒ Object
Public: Updates an existing Product.
Methods inherited from Base
Constructor Details
This class inherits a constructor from EcwidApi::Api::Base
Instance Method Details
#all(params = {}) ⇒ Object
Public: Get all of the Product objects for the Ecwid store params - a hash of request parameters. Parameters can be
keyword string Search term. Use quotes to search for exact match.
Ecwid searches products over multiple fields:
* title
* description
* SKU
* product
* category name
* gallery image descriptions
* attribute values (except for hidden attributes).
If your keywords contain special characters,
it may make sense to URL encode them before making a request
priceFrom number Minimum product price
priceTo number Maximum product price
category number Category ID. To get Store Front Page products, specify `&category=0` in the request
withSubcategories boolean `true/false`: defines whether Ecwid should search in subcategories of the
category you set in `category` field. Ignored if `category` field is not set.
`false` is the default value
sortBy string Sort order. Supported values:
* `RELEVANCE` default
* `DEFINED_BY_STORE_OWNER`
* `ADDED_TIME_DESC`
* `ADDED_TIME_ASC`
* `NAME_ASC`
* `NAME_DESC`
* `PRICE_ASC`
* `PRICE_DESC`
* `UPDATED_TIME_ASC`
* `UPDATED_TIME_DESC`
. If request is applicable to a specific category (i.e. `category` is set),
then `DEFINED_BY_STORE_OWNER` sort method is used
offset number Offset from the beginning of the returned items list (for paging)
limit number Maximum number of returned items. Maximum allowed value: `100`. Default value: `100`
createdFrom string Product creation date/time (lower bound). Supported formats:
* UNIX
Examples:
* `1447804800`
createdTo string Product creation date/time (upper bound). Supported formats:
* UNIX
updatedFrom string Product last update date/time (lower bound). Supported formats:
* UNIX
updatedTo string Product last update date/time (upper bound). Supported formats:
* UNIX
enabled boolean `true` to get only enabled products, `false` to get only disabled products
inStock boolean `true` to get only products in stock, `false` to get out of stock products
sku string Product or variation SKU. Ecwid will return details of a product containing that SKU,
if SKU value is an exact match. If SKU is specified, other search parameters are ignored,
except for product ID.
productId number Internal Ecwid product ID or multiple productIds separated by a comma. If this field is
specified, other search parameters are ignored.
baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
If not specified, Ecwid will use the storefront URL specified in the store settings
cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash `'#'`) in the `url` field.
If `false`, Ecwid will return URL in the old format (with hash `'#'`). We recommend using
`true` value if merchant
Returns an Array of Product objects
79 80 81 82 83 |
# File 'lib/ecwid_api/api/products.rb', line 79 def all(params = {}) PagedEcwidResponse.new(client, "products", params) do |product_hash| Product.new(product_hash, client: client) end end |
#create(params) ⇒ Object
Public: Creates a new Product
params - a Hash
Raises an Error if there is a problem
Returns a Product object
129 130 131 132 |
# File 'lib/ecwid_api/api/products.rb', line 129 def create(params) response = client.post("products", params) find(response.body["id"]) end |
#find(id, params = {}) ⇒ Object
Public: Finds a single product by product ID
id - an Ecwid product ID params - a hash of request parameters. Parameters can be
baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
If not specified, Ecwid will use the storefront URL specified in the
cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash '#')
in the url field. If `false`, Ecwid will return URL in the old format (with hash '#').
We recommend using `true` value if merchant
Returns a Product object, or nil if one can’t be found
98 99 100 101 102 103 |
# File 'lib/ecwid_api/api/products.rb', line 98 def find(id, params = {}) response = client.get("products/#{id}", params) if response.success? Product.new(response.body, client: client) end end |
#find_by_sku(sku, params = {}) ⇒ Object
Public: Finds a single Product by SKU
sku - a SKU of a product params - a hash of request parameters. Parameters can be
baseUrl string Storefront URL for Ecwid to use when returning product URLs in the url field.
If not specified, Ecwid will use the storefront URL specified in the
cleanUrls boolean If `true`, Ecwid will return the SEO-friendly clean URL (without hash '#')
in the url field. If `false`, Ecwid will return URL in the old format (with hash '#').
We recommend using `true` value if merchant
Returns a Product object, or nil if one can’t be found
118 119 120 |
# File 'lib/ecwid_api/api/products.rb', line 118 def find_by_sku(sku, params = {}) all(params.merge(keyword: sku)).find { |product| product[:sku] == sku } end |
#update(id, params) ⇒ Object
Public: Updates an existing Product
id - the Ecwid product ID params - a Hash
Raises an Error if there is a problem
Returns a Product object
142 143 144 145 |
# File 'lib/ecwid_api/api/products.rb', line 142 def update(id, params) client.put("products/#{id}", params) find(id) end |