PHP code example of germania-kg / order-dispatcher
1. Go to this page and download the library: Download germania-kg/order-dispatcher 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/ */
germania-kg / order-dispatcher example snippets
public function createOrder( array $input) : OrderInterface;
public function setItemFactory(ItemFactoryInterface $item_factory);
public function getItemFactory() : ItemFactoryInterface;
public function setItemFactory(ItemFactoryInterface $item_factory);
public function getItemFactory() : ItemFactoryInterface;
use Germania\OrderDispatcher\ArrayOrderFactory;
use Germania\OrderDispatcher\FilterValidator;
$item_factory = ... ;
$logger = ...;
$factory = new ArrayOrderFactory($item_factory, "items");
$factory = new ArrayOrderFactory($item_factory, "items", $logger);
$customer_validation = new FilterValidator(array(
"email" => FILTER_VALIDATE_EMAIL,
"company" => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"retailer_number" => [
"filter" => FILTER_VALIDATE_REGEXP,
"options" => ['regexp'=>"/^[\d\-]+$/"]
],
"privacyAck" => FILTER_VALIDATE_BOOLEAN
));
// Set customer data validation
$factory->setValidator( $customer_validation );
if (200 != $reponse->getStatusCode()) {
echo $resonse->getHeaderLine('X-Order-Dispatch-Message');
// Germania\OrderDispatcher\Exceptions\OrderHandlerRuntimeException
}
use Germania\OrderDispatcher\ItemInterface;
use Germania\OrderDispatcher\Item;
public function createItem( array $order_item ) : ItemInterface;
use Germania\OrderDispatcher\SimpleItemFactory;
$item_factory = new SimpleItemFactory;
$item = $item_factory->createItem([
'sku' => 'foobar',
'quantity' => 100
]);
use Germania\OrderDispatcher\ContainerItemFactory;
use Germania\OrderDispatcher\Exceptions\ItemNotAvailableException;
$available = new Psr11Container( ... );
$item_factory = new ContainerItemFactory($available, "sku");
$item_factory = new ContainerItemFactory($available, "sku", $logger);
$sku = 'foobar';
try {
$item = $item_factory->createItem([
'sku' => $sku,
'quantity' => 100
]);
}
catch (ItemNotAvailableException $e) {
echo "$sku is not available";
}
use Germania\OrderDispatcher\ValidatorItemFactoryDecorator;
use Germania\OrderDispatcher\ContainerItemFactory;
$inner = new ContainerItemFactory($available, "sku");
$validator = new SkuQtyItemValidator;
$item_factory = ValidatorItemFactoryDecorator($inner, $validator);
public function render( string $template, array $context = array()) : ?string;
use Germania\OrderDispatcher\TwigRenderer;
$twig = ... ;
$renderer = new TwigRenderer($twig);
public function handle( OrderInterface $order, array $context = array()) : bool ;