PHP code example of blesta / items

1. Go to this page and download the library: Download blesta/items 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/ */

    

blesta / items example snippets


$item = new Item();

$fields = [
    'key' => 'item1',
    'value' => 'Item'
];
$item->setFields($fields);
$item->setField('custom', 'ABC123');
$item->removeField('value');
print_r($item->getFields());

// Create the item
$fields = [
    'domain' => 'domain.com',
    'amount' => 100.0000,
    'override_amount' => 150.0000,
    'custom' => 'ABC123'
];
$item = new Item();
$item->setFields($fields);

// Create an item to use for field mapping
$mapFields = [
    'value' => 'domain',
    'price' => ['override_amount', 'amount']
    'type' => 'generic'
];
$mapItem = new Item();
$mapItem->setFields($mapFields);

$map = new ItemMap();
$newItem = $map->combine($item, $mapItem);
print_r($newItem->getFields());

$collection = new ItemCollection();

$item1 = new Item();
$item2 = new Item();
$collection->append($item1)->append($item2);
$total = $collection->count(); // 2

$collection->remove($item1);
$total = $collection->count(); // 1

foreach ($collection as $item) {
    print_r($item->getFields()); // stdClass object of fields
}