MyCloud Logo

MyCloud API Documentation

Order Model

The Order model represents an order placed with your shop. Orders consist of OrderItems, which are the Products that are attached to the order. An order can have a Customer attached to it, but this is not required. And order must have a DeliveryMode attached to it to select the method of shipment. The payment attributes are provided for the customer to indicate to the shop when and how payment was made so the shop can verify payment. If payment was received through an online payment system, the shop may store that information in the order if they want.

Model Attributes

Model attributes can be accessed two ways:

Model setters always return the object itself, which allows you to chain setter calls:

	$order->setId(27)
		->setName('Mr. Buyer')
		->setOrderNumber('Shop-00081')
		->setAddress('49 Buyer Lane')
		->setPostcode('10110');
id
Unique numeric ID of the order.
Methods:
integer getId()
object setId( integer )
mc_number
The MyCloud order identification number. This unique number of used internally by MyCloud to identify any order, and is the preferred way to identify orders.
Methods:
integer getMcNumber()
object setMcNumber( integer )
customer_id
The unique numeric ID of the customer attached to this order. If the ID is NULL, then no customer has been attached to this order. This field is only returned by a call to the API to retrieve an order. This field should never be set by the client's code. If you want to set the customer for a new order, or to update an existing order, then you should use setCustomer() with a Customer object.
Methods:
integer getCustomerId()
deliverymode_id
The numeric ID of the delivery mode assigned to this order. If the ID is NULL, then no delivery mode has been assigned to this order. This field is only returned by a call to the API to retrieve an order. This field should never be set by the client's code. If you want to set the delivery mode for a new order, or to update an existing order, then you should use setDeliveryMode() with a DeliveryMode object.
Methods:
integer getDeliveryModeId()
billing_title
The billing title of the order.
Methods:
string getBillingTitle()
object setBillingTitle( string )
customer_ref
The customer reference for this order.
Methods:
string getCustomerReference()
object setCustomerReference( string )
order_number
The customer assigned order number for this order.
Methods:
string getOrderNumber()
object setOrderNumber( string )
create_date
The date this order was created (YYYY-mm-dd). This field is read-only. It will be ignored when you create a new order, or when you update an order. The date will be timestamped by the API server when a new order is created.
Methods:
string getCreateDate()
object setCreateDate( string )
delivery_date
The delivery date of this order (YYYY-mm-dd).
Methods:
string getDeliveryDate()
object setDeliveryDate( string )
email
The email address of the person the order is being shipped to.
Methods:
string getEmail()
object setEmail( string )
phone_number
The phone number of the person the order is being shipped to.
Methods:
string getPhoneNumber()
object setPhoneNumber( string )
name
The name address of the person the order is being shipped to.
Methods:
string getName()
object setName( string )
address
The shipping address for this order.
Methods:
string getAddress()
object setAddress( string )
postcode
The postal code of the shipping address of the order.
Methods:
string getPostcode()
object setPostcode( string )
note
The note the shop has added to the order.
Methods:
string getNote()
object setNote( string )
total_price
The total price for this order.
Methods:
integer getTotalPrice()
object setTotalPrice( integer )
payment_amount
The amount the customer claims to have paid for this order.
Methods:
integer getPaymentAmount()
object setPaymentAmount( integer )
payment_date
The date the customer claims to have paid for this order.
Methods:
string getPaymentDate()
object setPaymentDate( string )
payment_time
The time the customer claims to have paid for this order.
Methods:
string getPaymentTime()
object setPaymentTime( string )
weight
The weight of this order as shipped (Kg).
Methods:
float getWeight()
object setWeight( float )
urgent
Whether or not this order is market as "Urgent" (TRUE or FALSE).
Methods:
boolean getUrgent()
object setUrgent( boolean )

Model Objects

Attachments

Files that are attached to this order.

Method getAttachments() returns an array of the order's attachments when an order is retrieved from the API. Each element of the array is an associative array containing a 'name' and a 'url'. The url can be used to retrieve the attachment using a standard HTTP request.

Method attachFile() is used to attach a new file to an order when creating or updating an order. 'name' is the attachment name used to refer to the attachment during processing of the order. The name must be one that MyCloud will understand, so be sure it is one that is agreed upon with the MyCloud staff. 'filename' is any name you wish to give the file, and is typically the attachment's local file name. 'filetype' indicates what type of file the attachment is, and should typically be a stadard MIME type such as 'image/jpeg' or 'application/pdf'. 'filepath' is the pathname to the local file on the computer that is attaching the file to the order. The filepath must be sufficient for the code to locate the file during processing, so a full path is recommended. Returns the Order object.

Methods:
array getAttachments()
object attachFile( string name, string filename, string filetype, string filepath )
Customer

A shop customer that is attached to the order.

Method getCustomer() returns the Customer that is attached to the order, or NULL if no customer is attached to the order. The Customer object must be obtained from the API, not created by the client's code.

Method setCustomer() is used to attach a new customer to an order when creating or updating an order. Returns the Order object.

Methods:
object getCustomer()
object setCustomer( object Customer )
DeliveryMode

The delivery mode to be used to ship the order.

Method getDeliveryMode() returns the DeliveryMode that is attached to the order, or NULL if no delivery mode is defined for the order. The DeliveryMode object must be obtained from the API, not created by the client's code.

Method setDeliveryMode() is used to define the delivery mode for the order when creating or updating an order. Returns the Order object.

Methods:
object getDeliveryMode()
object setDeliveryMode( object DeliveryMode )
OrderItems

The order items are the products that are being purchased with this order. An OrderItem points to a Product and defines the number of that product being purchased (quantity) and the price being paid for that product (price). When you retrieve an order from the API, the order's items will be attached to the Order object for you. When you are creating a new order, or updating an existing order, you will provide the OrderItems to be added to the order.

Order defines several methods that allow you to attach order items to your order when you are creating or updating an order:

Method addOrderItem() allows you to add an order item using an OrderItem object that you create.

Method addProduct() allows you to create a new order item using a Product object that you have retrieved from the API. It will create the new OrderItem using the Product object's id. You can get this Product object using the API, or you can create a new Product object locally, in which case you only need to provide the id when creating the object.

Method addProductBytId() is the same as addProduct(), but you only need the id of the product. This allows you to keep a list of product ids on your system, so you do not need to retrieve them from the API each time you want to create a new order.

Method addProductBySKU() is the same as addProduct(), but you only need the MyCloud SKU of the product. This allows you to keep a list of product MyCloud SKUs on your system, so you do not need to retrieve them from the API each time you want to create a new order.

Method addProductByShopSKU() is the same as addProduct(), but you only need the Shop SKU of the product. The Shop SKU is the SKU number that your shop has assigned to the product. This allows you to keep a list of product SKUs on your system, so you do not need to retrieve them from the API each time you want to create a new order.

Methods:
array getOrderItems()
object addOrderItem( object OrderItem ) object addProduct( object Product ) object addProductById( integer ) object addProductBySKU( string ) object addProductByShopSKU( string )

API Calls

array Order::all()
Get all order created by your shop.
Returns:
Array containing the list of Order objects that belong to your shop.
object Order::get( integer $id )
Get the order identified by the unique id.
Returns:
The Order object identified by the unique id.
object create()
Create a new order and attach it to your shop. The Order object that you use to call this method does not need an id, and if you provide an id, it will be ignored. All other attributes of the Order object will be saved with the newly created order. All order items that are attached to this Order object will be created also. Each of the order items must have a Product attached to them (using any of the methods described above), or the order item will not be able to be saved. If you provide a Customer object or a DeliveryMode object with this order, they will also be saved.
Returns:
The Order object that was created.
object update()
Update an existing order. The Order object that you use to call this method requires a valid id to identiy the order 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. If you add order items to the order object, they will be updated (when the order item's id matches the id of an order item already attached to this order), or created (when the order id has no id). The same behavior (update or create) will happen for Customer and DeliveryMode. NOTE You cannot change the status of an order after it has entered the "picking" stage of the order processing. Once the order has started the picking stage, all attempts to update the order status will be rejected with an error.
Returns:
The Order object that was updated.
object delete()
Delete an existing order. The Order object that you use to call this method requires a valid id to identiy the order that will be deleted.
Returns:
The Order object that was deleted.