Class: EPlat::Woocommerce::Product
- Defined in:
- lib/e_plat/resource/platform_specific/woocommerce/product.rb,
lib/e_plat/resource/platform_specific/woocommerce/product/image.rb,
lib/e_plat/resource/platform_specific/woocommerce/product/option.rb,
lib/e_plat/resource/platform_specific/woocommerce/product/variant.rb,
lib/e_plat/resource/platform_specific/woocommerce/product/variant/option_value.rb
Defined Under Namespace
Classes: Image, Option, Variant
Constant Summary
Constants inherited from Product
Product::INITIAL_SHOPIFY_IMAGE_LIMIT, Product::INITIAL_SHOPIFY_VARIANT_LIMIT
Constants inherited from Base
Constants included from Concerns::GraphQLable
Concerns::GraphQLable::FILTER_ARGS, Concerns::GraphQLable::QUERY_ARG_ARGS
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Concerns::Aliases
Instance Method Summary collapse
- #common_product_variant_attributes ⇒ Object
- #dup ⇒ Object
-
#initialize(attributes = {}, persisted = false) ⇒ Product
constructor
A new instance of Product.
- #lazy_load_variants ⇒ Object
Methods inherited from Product
#find_variant, #handle, #load_all_variants, #status, #variants_collection
Methods included from Concerns::Metafieldable
#add_metafield, #find_metafield, #metafields
Methods inherited from Base
cached_shopify_webhook?, client, #client, element_name_plural?, exclude_from_json, #formatted_id, #graphql_input, #headers, #include_root_in_json, inherited, initialize_singleton!, #mapped?, #native_keys, platform_specific_class?, prefix=, #read_only?, #string_to_consistent_id
Methods included from Countable
Methods included from Concerns::GraphQLable
#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from
Methods included from Concerns::Aliases
Methods included from Concerns::FullJson
Methods included from Concerns::OverwriteRequestMethods
#collection_path, #element_path, included
Methods included from Concerns::OverwriteInstanceMethods
#as_eplat_json, #as_json, #create, #create_resource_for, #to_eplat_json, #to_json, #update
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Product
Returns a new instance of Product.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/e_plat/resource/platform_specific/woocommerce/product.rb', line 5 def initialize(attributes = {}, persisted = false) super # Ensure options have correct IDs based on name (more stable than position) if self..present? self..each do |option| if (option.attributes["id"].nil? || option.attributes["id"] == 0) && option.name.present? # Use a deterministic ID generation method option.attributes["id"] = string_to_consistent_id(option.name) end end end end |
Instance Method Details
#common_product_variant_attributes ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/e_plat/resource/platform_specific/woocommerce/product.rb', line 41 def common_product_variant_attributes [ "body_html", "name", "description", "permalink", "sku", "price", "regular_price", "sale_price", "date_on_sale_from", "date_on_sale_from_gmt", "date_on_sale_to", "date_on_sale_to_gmt", "on_sale", "status", "purchasable", "virtual", "downloadable", "downloads", "download_limit", "download_expiry", "tax_status", "tax_class", "manage_stock", "stock_quantity", "stock_status", "backorders", "backorders_allowed", "backordered", "weight", "dimensions", "shipping_class", "shipping_class_id", "attributes", "menu_order", "meta_data" ] end |
#dup ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/e_plat/resource/platform_specific/woocommerce/product.rb', line 33 def dup self.class.new.tap do |resource| resource.attributes = @attributes resource.attributes.delete("id") resource. = @prefix_options end end |
#lazy_load_variants ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/e_plat/resource/platform_specific/woocommerce/product.rb', line 19 def lazy_load_variants # Woo products natively just return an array of ids under the 'variations' key @variants_collection ||= EPlat::Product::Variant.find( :all, from: "#{ client.url_prefix }products/#{id}/variations" ).presence || EPlat::Collection.new([generate_default_variant]) @variants_collection.each do |variant| variant.product = self variant.product_id = id end @variants_collection end |