Class: Google4R::Checkout::CarrierCalculatedShipping

Inherits:
Object
  • Object
show all
Defined in:
lib/google4r/checkout/shared.rb

Overview

A class that represents the “merchant-calculated” shipping method

Defined Under Namespace

Classes: CarrierCalculatedShippingOption, ShippingPackage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCarrierCalculatedShipping

Returns a new instance of CarrierCalculatedShipping.



950
951
952
953
# File 'lib/google4r/checkout/shared.rb', line 950

def initialize()
  @carrier_calculated_shipping_options = Array.new
  @shipping_packages = Array.new
end

Instance Attribute Details

#carrier_calculated_shipping_optionsObject (readonly)

This encapsulates information about all of the shipping methods for which Google Checkout should obtain shipping costs.



943
944
945
# File 'lib/google4r/checkout/shared.rb', line 943

def carrier_calculated_shipping_options
  @carrier_calculated_shipping_options
end

#shipping_packagesObject (readonly)

This encapsulates information about all of the packages that will be shipped to the buyer. At this time, merchants may only specify one package per order.



948
949
950
# File 'lib/google4r/checkout/shared.rb', line 948

def shipping_packages
  @shipping_packages
end

Instance Method Details

#create_carrier_calculated_shipping_option {|option| ... } ⇒ Object

Yields:

  • (option)


955
956
957
958
959
960
961
962
963
# File 'lib/google4r/checkout/shared.rb', line 955

def create_carrier_calculated_shipping_option(&block)
  option = CarrierCalculatedShippingOption.new(self)
  @carrier_calculated_shipping_options << option
  
  # Pass the newly generated rule to the given block to set its attributes.
  yield(option) if block_given?
  
  return option
end

#create_from_element(element) ⇒ Object

Creates a new CarrierCalculatedShipping from the given REXML::Element instance. For testing only.



978
979
980
981
982
983
984
985
986
# File 'lib/google4r/checkout/shared.rb', line 978

def create_from_element(element)
  result = CarrierCalculatedShipping.new
  element.elements.each('carrier-calculated-shipping-options/carrier-calculated-shipping-option') do |shipping_option_element|
    result.carrier_calculated_shipping_options << CarrierCalculatedShippingOption.create_from_element(self, shipping_option_element)
  end
  element.elements.each('shipping-packages/shipping-package') do |shipping_package_element|
    result.shipping_packages << ShippingPackage.create_from_element(self, shipping_package_element)
  end
end

#create_shipping_package {|package| ... } ⇒ Object

Yields:

  • (package)


965
966
967
968
969
970
971
972
973
# File 'lib/google4r/checkout/shared.rb', line 965

def create_shipping_package(&block)
  package = ShippingPackage.new(self)
  @shipping_packages << package
  
  # Pass the newly generated rule to the given block to set its attributes.
  yield(package) if block_given?
  
  return package
end