Class: Magento::GuestCart
Class Method Summary collapse
-
.add_coupon(id, coupon) ⇒ Object
Add a coupon by code to a specified cart.
- .add_item(id, attributes) ⇒ Object
- .create(load_cart_info: false) ⇒ Object
-
.delete_coupon(id) ⇒ Object
Delete a coupon from a specified cart.
- .find(id) ⇒ Object
-
.payment_information(attributes) ⇒ Object
Set payment information to finish the order using class method.
Instance Method Summary collapse
-
#add_coupon(coupon) ⇒ Object
Add a coupon by code to the current cart.
- #add_item(item_attributes) ⇒ Object
-
#delete_coupon ⇒ Object
Delete cart’s coupon.
-
#payment_information(email:, payment:) ⇒ Object
Set payment information to finish the order.
Methods inherited from Model
api_resource, #delete, delete, entity_name, #id, #save, #update, update
Methods included from ModelParser
Class Method Details
.add_coupon(id, coupon) ⇒ Object
Add a coupon by code to a specified cart.
Example Magento::GuestCart.add_coupon(
'aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN',
'COAU4HXE0I'
)
101 102 103 104 |
# File 'lib/magento/guest_cart.rb', line 101 def add_coupon(id, coupon) url = "#{api_resource}/#{id}/coupons/#{coupon}" request.put(url, nil).parse end |
.add_item(id, attributes) ⇒ Object
85 86 87 88 89 |
# File 'lib/magento/guest_cart.rb', line 85 def add_item(id, attributes) url = "#{api_resource}/#{id}/items" hash = request.post(url, attributes).parse Magento::ModelMapper.map_hash(Magento::Item, hash) end |
.create(load_cart_info: false) ⇒ Object
59 60 61 62 |
# File 'lib/magento/guest_cart.rb', line 59 def create(load_cart_info: false) cart = build(cart_id: request.post(api_resource).parse) find cart.id if load_cart_info end |
.delete_coupon(id) ⇒ Object
Delete a coupon from a specified cart.
Example: Magento::GuestCart.delete_coupon(‘aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN’)
113 114 115 116 |
# File 'lib/magento/guest_cart.rb', line 113 def delete_coupon(id) url = "#{api_resource}/#{id}/coupons" request.delete(url).parse end |
.find(id) ⇒ Object
64 65 66 |
# File 'lib/magento/guest_cart.rb', line 64 def find(id) cart = build request.get("#{api_resource}/#{id}").parse.merge(cart_id: id) end |
.payment_information(attributes) ⇒ Object
Set payment information to finish the order using class method
Example: Magento::GuestCart.payment_information(
cartId: 'aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN',
paymentMethod: { method: 'cashondelivery' },
email: email
)
79 80 81 82 83 |
# File 'lib/magento/guest_cart.rb', line 79 def payment_information(attributes) attributes.transform_keys(&:to_sym) url = "#{api_resource}/#{attributes[:cartId]}/payment-information" request.post(url, attributes).parse end |
Instance Method Details
#add_coupon(coupon) ⇒ Object
Add a coupon by code to the current cart.
Example cart = Magento::GuestCart.find(‘gXsepZcgJbY8RCJXgGioKOO9iBCR20r7’) cart.add_coupon(‘COAU4HXE0I’)
43 44 45 |
# File 'lib/magento/guest_cart.rb', line 43 def add_coupon(coupon) self.class.add_coupon(cart_id, coupon) end |
#add_item(item_attributes) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/magento/guest_cart.rb', line 8 def add_item(item_attributes) attributes = { cartItem: item_attributes.merge(quote_id: cart_id) } item = self.class.add_item(cart_id, attributes) @items = @items.reject {|i| i.item_id == item.item_id} << item if @items item end |
#delete_coupon ⇒ Object
Delete cart’s coupon
Example: cart = Magento::GuestCart.find(‘gXsepZcgJbY8RCJXgGioKOO9iBCR20r7’) cart.delete_coupon()
54 55 56 |
# File 'lib/magento/guest_cart.rb', line 54 def delete_coupon self.class.delete_coupon(cart_id) end |
#payment_information(email:, payment:) ⇒ Object
Set payment information to finish the order
Example: cart = Magento::GuestCart.find(‘gXsepZcgJbY8RCJXgGioKOO9iBCR20r7’)
# or use “build” to not request information from the magento API cart = Magento::GuestCart.build({ ‘cart_id’ => ‘aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN’ })
cart.payment_information(
email: '[email protected]',
payment: { method: 'cashondelivery' }
)
30 31 32 33 |
# File 'lib/magento/guest_cart.rb', line 30 def payment_information(email:, payment:) attributes = { cartId: cart_id, paymentMethod: payment, email: email } self.class.payment_information(attributes) end |