Class: EPlat::Woocommerce::Metafield

Inherits:
Metafield
  • Object
show all
Defined in:
lib/e_plat/resource/platform_specific/woocommerce/metafield.rb

Constant Summary

Constants inherited from Metafield

Metafield::BIGCOMMERCE_DEFAULT_PERMISSION_SET, Metafield::READ_ONLY_ATTRIBUTES

Constants inherited from Base

Base::PROTECTED_ATTRIBUTES

Constants included from Concerns::GraphQLable

Concerns::GraphQLable::FILTER_ARGS, Concerns::GraphQLable::QUERY_ARG_ARGS

Instance Attribute Summary collapse

Attributes inherited from Base

#mapped_attributes, #mapping

Attributes included from Concerns::Aliases

#type_coercer

Instance Method Summary collapse

Methods inherited from Metafield

#collection_path, #element_path, #normalize_attributes, #parent_class

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, initialize_singleton!, #mapped?, #native_keys, platform_specific_class?, prefix=, #read_only?, #string_to_consistent_id

Methods included from Countable

#count

Methods included from Concerns::GraphQLable

#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from

Methods included from Concerns::Aliases

#add_aliases!

Methods included from Concerns::FullJson

#as_full_json, #to_full_json

Methods included from Concerns::OverwriteRequestMethods

#collection_path, #element_path, included, #initialize

Methods included from Concerns::OverwriteInstanceMethods

#as_eplat_json, #as_json, #create, #create_resource_for, #to_eplat_json, #to_json, #update

Constructor Details

This class inherits a constructor from EPlat::Base

Instance Attribute Details

#orderObject

Returns the value of attribute order.



11
12
13
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 11

def order
  @order
end

#productObject

Returns the value of attribute product.



11
12
13
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 11

def product
  @product
end

#variantObject

Returns the value of attribute variant.



11
12
13
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 11

def variant
  @variant
end

Instance Method Details

#destroyObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 13

def destroy
	return unless owner.present?
	
	run_callbacks :destroy do
		owner.metafields.each do |m|
			next unless m.id == id
			
			m.value = nil
			m.attribute_will_change!("id")
			m.attribute_will_change!("value")
			m.attribute_will_change!("key")
		end

		owner.attribute_will_change!("metafields")
		owner.save
		self.destroyed = true
	end
end

#ownerObject



32
33
34
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 32

def owner
	product || order || variant
end

#owner=(owner) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/e_plat/resource/platform_specific/woocommerce/metafield.rb', line 36

def owner=(owner)
	return if owner.nil?
	
	case owner.class.name
	when "EPlat::Woocommerce::Product"
		@product = owner
	when "EPlat::Woocommerce::Order"
		@order = owner
	when "EPlat::Woocommerce::Product::Variant"
		@variant = owner
	end
end