1. Go to this page and download the library: Download netflex/commerce library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
netflex / commerce example snippets
// Creating new order and checking out
$order = Order::create()
->addToSession()
->addCart([
'entry_id' => 10001,
'entry_name' => 'Ticket',
'variant_cost' => 100,
'no_of_entries' => 1,
'tax_percent' => 1.12
])
->checkout([
'firstname' => 'Ola',
'surname' => 'Nordmann'
])
->save([
'status' => 'p',
'currency' => 'NOK',
'customer_mail' => '[email protected]',
'customer_phone' => '99123456'
])
->addData('paymentId', '123456789', 'Payment ID')
->addLog('Customer sent to payment');
// Adding payment and completing order
$order = Order::retrieveBySecret('a72b...12f4')
->addLog('Customer returned from payment')
->addPayment([
'payment_method' => 'stripe',
'amount' => 100,
'status' => 'OK',
'capture_status' => 'OK',
'transaction_id' => '123456789',
'card_type_name' => 'visa',
])
->register()
->lock()
->removeFromSession();
// Empty object. Does NOT create an order in the API.
$order = new Order();
// Creating and getting a new empty order in the API.
$order = Order::create();
// Retrieves an existing order from the API based on an order id. Throws an exception if not found.
$order = Order::retrieve(10001);
// Retrieves an existing order from the API based on a register id. Throws an exception if not found.
$order = Order::retrieveByRegisterId(10001);
// Retrieves an existing order from the API based on an order secret. Throws an exception if not found.
$order = Order::retrieveBySecret('a1234567896e8bf63bbd43e851811234');
// Retrieves an existing order from the API based on an order secret stored in $_SESSION.
// If session or order does not exist, it creates an empty object.
// It does NOT create a new empty order in the API.
// On the next save() or refresh(), it stores the order secret in session.
$order = Order::retrieveBySession();
// Retrieves an existing order from the API based on an order secret stored in $_SESSION.
// If session or order does not exist, it creates a new empty order in the API
// and stores the order secret in session.
$order = Order::retrieveBySessionOrCreate();
// Manually adding the order secret to session.
$order->addToSession();
$order->addCart([
'entry_id' => 10001,
'entry_name' => 'Ticket',
'variant_cost' => 100,
'no_of_entries' => 1,
'tax_percent' => 1.12,
'properties' => [
'someCustomKey' => 'someCustomValue'
]
]);
$order->addLog('This is a log item');
$order->addLogInfo('Log some info');
$order->addLogWarning('Log a warning');
$order->addLogSuccess('Log a success');
$order->addLogDanger('Log danger');
$order->addData('key', 'value', 'Label');
$order->addDiscount([
'scope' => 'item', // cart|item|shipping
'scope_key' => '10001', // cart item id
'label' => '20 % discount on your ticket',
'discount' => 0.20,
'type' => 'percent', // percent|fixed|amount
]);
$order->addPayment([
'payment_method' => 'stripe',
'amount' => 100,
'status' => 'OK',
'capture_status' => 'OK',
'transaction_id' => '123456789',
'card_type_name' => 'visa',
'data' => [
'someCustomKey' => 'someCustomValue'
]
]);
// Updating the order object with added items and calculated totals
$order->refresh();
// Updating the number of entries on cart items with a specific entry_id
foreach ($order->cart->items as $item) {
if ($item->entry_id == 10001) {
$item->no_of_entries = 5;
$item->save();
}
}
foreach ($order->cart->items as $item) {
if ($item->entry_id == 10001) {
$item->save(['no_of_entries' => 5]);
}
}
$order->checkout([
'firstname' => 'Ola',
'surname' => 'Nordmann'
]);
$order->register();
$order->saveStatus('n');
$order->checkoutEnd();
// This does the same as saveStatus('n') and checkoutEnd();
// Saves the status to 'n' and add a checkout_end date.
$order->lock();
$order->removeFromSession();