Class Amazon::AWS::ShoppingCart::Cart
In: lib/amazon/aws/shoppingcart.rb
Parent: Amazon::AWS::Search::Request

Methods

active?   add   cart_add   cart_clear   cart_create   cart_get   cart_modify   clear   contain?   create   each   each_item   get   include?   modify   new   saved?   saved_for_later?  

Included Modules

Enumerable

External Aliases

cart_items -> items
saved_for_later_items -> saved_items
saved_for_later_items -> saved

Attributes

cart_id  [R]  cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
cart_items  [R]  cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
hmac  [R]  cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
purchase_url  [R]  cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.
saved_for_later_items  [R]  cart_id is an alphanumeric token that uniquely identifies a remote shopping-cart. hmac is a Hash Message Authentication Code. This is an encrypted alphanumeric token used to authenticate requests. purchase_url is the URL to follow in order to complete the purchase of the items in the shopping-cart. cart_items is an Array of items in the active area of the cart and saved_for_later_items is an Array of items in the Save For Later area of the cart.

Public Class methods

Create a new instance of a remote shopping-cart. See Amazon::AWS::Search::Request.new for details of the parameters.

Example:

 cart = Cart.new

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 46
        def initialize(key_id=nil, associate=nil, locale=nil,
                       user_agent=USER_AGENT)

          @cart_items = []
          @saved_for_later_items = []

          # Note the *false* as the fourth parameter to _super_, because we
          # never want to cache shopping-cart transactions.
          #
          super( key_id, associate, locale, false, user_agent )
        end

Public Instance methods

Returns whether or not an item is present in the active area of the cart.

item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.

If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.

Example:

 cart.active?( :ASIN, 'B00151HZA6' )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 207
        def active?(item_id_type, item_id)
          in_area?( @cart_items, item_id_type, item_id )
        end
add(id_type, item_id, quantity=1, *more_items)

Alias for cart_add

Add one or more new items to the remote shopping-cart. This can not be used to update quantities of items already in the cart. For that, you must use Cart#cart_modify instead.

id_type is a String, either ASIN or OfferListingId. item_id is the actual ASIN or offer listing ID in question, and quantity is the quantity of the item to add to the cart.

more_items is an optional list of Hash objects describing additional items to add to the cart.

Example:

 cart.cart_add( :ASIN, 'B0014C2BL4', 3,
               { 'B00006BCKL' => 2 },
               { 'B000VVE2UW' => 1 } )

or:

 cart.cart_add( :ASIN, 'B0014C2BL4', 3,
               { 'B00006BCKL' => 2,
                 'B000VVE2UW' => 1 } )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 129
        def cart_add(id_type, item_id, quantity=1, *more_items)
          ca = CartAdd.new( id_type, item_id, quantity, *more_items )
          ca.response_group = @rg
          ca.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } )

          cart = search( ca ).cart_add_response.cart
          @cart_items = cart.cart_items.cart_item
        end

Remove all items from the shopping-cart.

Example:

 cart.cart_clear

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 375
        def cart_clear
          cc = CartClear.new
          cc.response_group = @rg
          cc.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } )

          cart = search( cc ).cart_clear_response.cart

          @cart_items = []
          @saved_for_later_items = []
        
        end

Prepare the remote shopping-cart for use and place one or more items in it.

id_type is a String, either ASIN or OfferListingId. item_id is the actual ASIN or offer listing ID in question, quantity is the quantity of the item to add to the cart, and merge_cart is whether or not the remote shopping-cart should be merged with the local cart on the Amazon retail site upon check-out.

more_items is an optional list of Hash objects describing additional items to place in the cart.

Example:

 cart.cart_create( :ASIN, 'B00151HZA6', 1,
                  { 'B000WC4AH0' => 2 },
                  { 'B000PY32OM' => 3 } )

or:

 cart.cart_create( :ASIN, 'B00151HZA6', 1,
                  { 'B000WC4AH0' => 2,
                    'B000PY32OM' => 3 } )

Please note that it‘s not yet possible to update a wishlist at purchase time by referring to the item‘s ListItemId when adding that item to the cart.

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 87
        def cart_create(id_type, item_id, quantity=1, merge_cart=false,
                        *more_items)
          cc = CartCreate.new( id_type, item_id, quantity, merge_cart, nil,
                               *more_items )

          @rg = ResponseGroup.new( :Cart )
          cc.response_group = @rg

          cart = search( cc ).cart_create_response.cart

          @cart_id = cart.cart_id
          @hmac = cart.hmac
          @purchase_url = cart.purchase_url
          @cart_items = cart.cart_items.cart_item
        end

Retrieve a remote shopping-cart. This is especially useful when needing to resurrect a cart at a later time, when the Cart object containing the original data no longer exists.

cart_id is the unique ID of the cart to be retrieved and hmac is the cart‘s hash message authentication code. These details can be obtained from an existing cart using the @cart_id and @hmac instance variables.

Example:

 old_cart = Cart.new
 old_cart.get_cart( '203-4219703-7532717',
                   'o98sn9Z16JOEF/9eo6OcD8zOZA4=' )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 339
        def cart_get(cart_id, hmac)
          cg = CartGet.new
          @rg = ResponseGroup.new( :Cart )
          cg.response_group = @rg
          cg.params.merge!( { 'CartId' => cart_id, 'HMAC' => hmac } )

          cart = search( cg ).cart_get_response.cart

          @cart_id = cart.cart_id
          @hmac = cart.hmac
          @purchase_url = cart.purchase_url

          if ci = cart.cart_items
            @cart_items = ci.cart_item
          else
            @cart_items = []
          end

          if sfl = cart.saved_for_later_items
            @saved_for_later_items = sfl.saved_for_later_item
          else
            @saved_for_later_items = []
          end

          self
        end

Modify the quantities of one or more products already in the cart. Changing the quantity of an item to 0 effectively removes it from the cart.

item_id_type is the name of the attribute that uniquely identifies an item in the cart, such as ASIN or CartItemId. item_id is the value of the item_id_type of the item to be modified, and quantity is its new quantity.

save_for_later should be set to true if the items in question should be moved to the Save For Later area of the shopping-cart, or false if they should be moved to the active area. save_for_later therefore applies to every item specified by item_id and more_items. Use nil when the location of the items should not be changed.

Current Amazon AWS documentation claims that specifying partial quantities can be used to move some copies of an item from one area of the cart to another, whilst leaving the rest in place. In practice, however, this causes an AWS error that explains that a quantity may not be specified in combination with an instruction to move copies from one area of the cart to another. For this reason, when save_for_later is not nil, item quantities are currently ignored.

more_items is an optional list of Hash objects describing additional items whose quantity should be modified.

Example:

 cart.cart_modify( :ASIN, 'B00151HZA6', 2, false,
                  { 'B0013F2M52' => 1 },
                  { 'B000HCPSR6' => 3 } )

or:

 cart.cart_modify( :ASIN, 'B00151HZA6', 2, true,
                  { 'B0013F2M52' => 1,
                    'B000HCPSR6' => 3 } )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 274
        def cart_modify(item_id_type, item_id, quantity, save_for_later=nil,
                        *more_items)
          item_quantity1 = quantity

          unless cart_item_id1 = self.include?( item_id_type, item_id )
            raise CartError,
              "Can't find item with '#{item_id_type}' of '#{item_id}' in cart."
          end

          more_items.collect! do |extra_item|
            items = []

            extra_item.each do |item|
              item_id, quantity = item
              unless cart_item_id = self.include?( item_id_type, item_id )
                raise CartError,
                  "Can't find item with '#{item_id_type}' of '#{item_id}' in cart."
              end

              items << { cart_item_id => quantity }
            end

            items
          end

          more_items.flatten!

          cm = CartModify.new( cart_item_id1, item_quantity1, save_for_later,
                               *more_items )
          cm.response_group = @rg
          cm.params.merge!( { 'CartId' => @cart_id, 'HMAC' => @hmac } )

          cart = search( cm ).cart_modify_response.cart

          if ci = cart.cart_items
            @cart_items = ci.cart_item
          else
            @cart_items = []
          end

          if sfl = cart.saved_for_later_items
            @saved_for_later_items = sfl.saved_for_later_item
          else
            @saved_for_later_items = []
          end
        end
clear()

Alias for cart_clear

contain?(item_id_type, item_id)

Alias for include?

create(id_type, item_id, quantity=1, merge_cart=false, *more_items)

Alias for cart_create

Iterator for each item in the cart.

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 394
        def each
          @cart_items.each { |item| yield item }
        end
each_item()

Alias for each

get(cart_id, hmac)

Alias for cart_get

Returns whether or not an item is present in the cart, be it in the active or Save For Later area.

item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.

If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.

Example:

 cart.include?( :ASIN, 'B00151HZA6' )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 156
        def include?(item_id_type, item_id)
          active?( item_id_type, item_id ) ||
          saved_for_later?( item_id_type, item_id )
        end
modify(item_id_type, item_id, quantity, save_for_later=nil, *more_items)

Alias for cart_modify

saved?(item_id_type, item_id)

Alias for saved_for_later?

Returns whether or not an item is present in the Save For Later area of the cart.

item_id_type is the name of the attribute that uniquely identifies an item, such as ASIN or CartItemId. item_id is the value of the item_id_type for the item whose presence in the cart is being determined.

If the item is present in the cart, its CartItemId is returned as a String. Otherwise, false is returned.

Example:

 cart.saved_for_later?( :ASIN, 'B00151HZA6' )

[Source]

# File lib/amazon/aws/shoppingcart.rb, line 227
        def saved_for_later?(item_id_type, item_id)
          in_area?( @saved_for_later_items, item_id_type, item_id )
        end

[Validate]