This application can be used to keep track of orders - whether
utilizing online payment or not. It will help you send out emails to the
customer as the order moves through the various states in its life,
create invoices automatically, and to some degree M2_Order
integrates with M2_Payment
.
M2_Order::create($data)
You use this method to create an order in the system. The
order knows nothing about payment and you can choose to move on to
M2_Order::getPaymentWizard()
, or you can just leave
it there if you don't accept online payments.
Orders will appear in the administration where you can perform further actions on them.
$data
is an associative array, holding the keys
in the table below:
Table 14. Array keys for the first parameter to M2_Order::create()
Key | Description | Required |
---|---|---|
customerData | An array of contact and shipping information holding the following keys:
| Yes |
lines | An array of order lines. Each line is an array itself, holding the following keys:
Please note that the
All amounts should use decimal comma only. For example, use 1024.50 instead of 1.024,50 | Yes |
currency | The currency of the order, according to http://www.xe.com/iso4217.php. | Yes |
shipping_amount | Shipping fee, specified in the currency for the order. | No |
shipping_vat_percent | VAT percentage of shipping amount that must be added. | No |
state | Initial state of the order:
If you use online payment via
The ImportantMoski2.net will automatically purge any orders
in The rest of the states are shifted between manually in the administration. If no state is provided, the
default is | No |
files | You may wish to attach one or more files to an order - say you have a shop where people can upload pictures that you will print on T-shirts and ship to them. This parameter is also an array of files where each file is an array itself, holding the following keys:
| No |
customData | Arbitrary data you wish to store with the order - this must be an associative array in only one dimension. | No |
emailNotifications | An array of emails, each made up of an array with the keys described in the table below. | No |
createInvoiceTrigger | Determine when to create an invoice for the order. If this parameter is supplied, Moski2.net will attempt to create a PDF invoice when the order moves into the chosen state. Available states:
| No |
extraInvoiceText | An optional extra string that will be printed on the PDF invoice. | No |
Each email supplied in emailNotification
is
made up of an array with the following keys:
Table 15. Associative array keys when describing emails sent by M2_Order
Key | Description | Required | Default |
---|---|---|---|
trigger | The event that will trigger sending this email. Possible values are:
| No | CREATED |
emailTo | The email address to send a notification email to. Can also be an array of addresses. | Yes | |
emailCc | An optional email address to CC. Can also be an array of addresses. | No | |
emailBcc | An optional email address to BCC. Can also be an array of addresses. | No | |
emailFrom | The sender address. | No | [email protected] |
emailFromName | The sender name. | No | [email protected] |
emailReplyTo | Reply-to address. | No |
|
emailSubject | The subject of the email. You can use the
same placeholders as described in | No | 'Order @ yourdomain.tld' |
emailBody | The body of the confirmation email. You can use this placeholder in the text:
In addition, any keys from your
So, if you have a
array( 'customerName' => 'Bill Hanson', 'shippingAddress' => 'Somewhere' ); You can then set $options['emailBody'] = "Hi there, %%customerName%%. We will ship your order number %%ORDER_NUMBER%% to this address: %%shippingAddress%%."; NoteIf your | Yes | |
attachments | An array of optional attachments. The names
of the attachments must be the values from the
| No | |
attachInvoice | Set to 1 if the email should get a PDF
invoice attached. This will only work if an invoice is
created before the mail goes out. You determine when to
create an invoice with the
| No | 0 |
Here is a complete example of creating an order
<?php ?>
M2_Order::getPaymentWizard($orderNumber,
[$wizardArgs])
This method returns a payment wizard as known from
M2_Payment
, but all you need to provide is the order
number.
$orderNumber
is the order number as returned
from M2_Order::create()
.
$wizardArgs
lets you send along any extra
arguments to the payment wizard. You can not overwrite the order
number, but besides that, you supply any parameter that the
payment wizard accepts.
M2_Order::getDetails($orderNumber,
[$includeEmailNotifications = FALSE])
Allows you to retrieve the known details about the order.
$orderNumber
is the order number as returned
from M2_Order::create()
.
$includeEmailNotifications
can be set to
TRUE
if you want to include the details about email
notifications - you will simply get back what you put in when
calling M2_Order::create()
.
M2_Order::getStatistics($start, $end)
M2_Order::setState($orderNumber, $state)
Sets the state of the order.
If you have assigned any email to be triggered by the state you are changing to, these emails will be sent, regardless of whether they have been sent before.