Class: Magento::Cart
Class Method Summary collapse
-
.add_coupon(id, coupon) ⇒ Object
Add a coupon by code to a specified cart.
-
.delete_coupon(id) ⇒ Object
Delete a coupon from a specified cart.
-
.order(attributes) ⇒ Object
Place order for cart.
Instance Method Summary collapse
-
#add_coupon(coupon) ⇒ Object
Add a coupon by code to the current cart.
-
#delete_coupon ⇒ Object
Delete cart’s coupon.
-
#order(email:, payment:) ⇒ Object
Place order for cart.
Methods inherited from Model
api_resource, create, #delete, delete, entity_name, find, #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::Cart.add_coupon(
1,
'COAU4HXE0I'
)
67 68 69 70 |
# File 'lib/magento/cart.rb', line 67 def add_coupon(id, coupon) url = "#{api_resource}/#{id}/coupons/#{coupon}" request.put(url, nil).parse end |
.delete_coupon(id) ⇒ Object
Delete a coupon from a specified cart.
Example:
Magento::Cart.delete_coupon(1)
80 81 82 83 |
# File 'lib/magento/cart.rb', line 80 def delete_coupon(id) url = "#{api_resource}/#{id}/coupons" request.delete(url).parse end |
.order(attributes) ⇒ Object
Place order for cart
Example:
Magento::Cart.order(
cartId: '12345',
paymentMethod: { method: 'cashondelivery' },
email: email
)
97 98 99 100 101 |
# File 'lib/magento/cart.rb', line 97 def order(attributes) attributes.transform_keys(&:to_sym) url = "#{api_resource}/#{attributes[:cartId]}/order" request.put(url, attributes).parse end |
Instance Method Details
#add_coupon(coupon) ⇒ Object
Add a coupon by code to the current cart.
Example:
cart = Magento::Cart.find(1)
cart.add_coupon('COAU4HXE0I')
17 18 19 |
# File 'lib/magento/cart.rb', line 17 def add_coupon(coupon) self.class.add_coupon(id, coupon) end |
#delete_coupon ⇒ Object
Delete cart’s coupon
Example:
cart = Magento::Cart.find(1)
cart.delete_coupon()
30 31 32 |
# File 'lib/magento/cart.rb', line 30 def delete_coupon self.class.delete_coupon(id) end |
#order(email:, payment:) ⇒ Object
Place order for cart
Example:
cart = Magento::Cart.find('12345')
# or use "build" to not request information from the magento API
cart = Magento::GuestCart.build({ 'cart_id' => '12345' })
cart.order(
email: '[email protected]',
payment: { method: 'cashondelivery' }
)
50 51 52 53 |
# File 'lib/magento/cart.rb', line 50 def order(email:, payment:) attributes = { cartId: id, paymentMethod: payment, email: email } self.class.order(attributes) end |