Class: EPlat::Woocommerce::Product
- Inherits:
-
Product
- Object
- Product
- 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
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
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 |