+++
+++
Order Item Model
The Order Item model represents a product that is an item on
an order for your shop. For each product that is part of an
order, there will be an order item. In other words, order items
connect products to orders. Furthermore, an order item
also defines the quantity of the product being ordered, as well
as the actual price the product is being sold for on that order.
Using OrderItems can be a little confusing at first. You need to
understand that OrderItems attached to an Order that you have
retrieved from the API are complete objects and have
all of their fields setup properly, including a complete Product
object. On the other hand, when you are creating a new order,
or updating an existing order, the OrderItem does not need a
complete Product object to function properly - it only needs
the order item's id for updating the price or quantity, and it
only needs a Product object with an id when creating a new
order item. Please see the example code provided for more details.
Model Attributes
- id
-
Unique numeric ID of the order item.
Methods:
integer getId()
object setId( integer )
- price
-
The price of the order item. This is used to set the specific
price of this item for this order.
Methods:
integer getPrice()
object setPrice( integer )
- quantity
-
The number of order items purchased in this order.
Methods:
integer getQuantity()
object setQuantity( integer )
API Calls
- array OrderItem::forOrder( Order $order )
-
Get all of the order items attached to $order.
Returns:
An array of OrderItem objects attached to the order.
This function simply calls OrderItem::forOrderId()
.
- array OrderItem::forOrderId( integer $order_id )
-
Get all of the order items attached to the order identified
by $order_id.
Returns:
An array of OrderItem objects attached to the order
that has the id $order_id.
- object update()
-
Update an existing order item.
The OrderItem object that you use to call this method
requires a valid id to identiy the order item that
will be updated. Other than the id, you only need to
provide the attributes that you wish to update. If an
attribute is not set, then it will not be updated in
the database, and it will keep it's original value.
It is not possible to change the product that the OrderItem
points to with this method.
Returns:
The OrderItem object that was updated.
- object delete()
-
Delete an existing order item.
The OrderItem object that you use to call this method
requires a valid id to identiy the order item that
will be deleted.
Returns:
The OrderItem object that was deleted.