PHP code example of justinholtweb / craft-holding

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

    

justinholtweb / craft-holding example snippets


use justinholtweb\holding\events\DocumentEvent;
use justinholtweb\holding\services\Documents;
use yii\base\Event;

Event::on(Documents::class, Documents::EVENT_BEFORE_PUSH_DOCUMENT, function(DocumentEvent $e) {
    // Anything Holded takes that Holding does not know about — a custom field, a project id.
    $e->payload['customFields'] = [['id' => 'abc', 'value' => $e->order->myField]];

    // Or stop the sync entirely.
    if ($e->order->getTotalPrice() < 1) {
        $e->isValid = false;
    }
});

php craft holding/sync/test                  # check the API key
php craft holding/sync/preview <order>       # what would be sent, without sending it
php craft holding/sync/order <order>         # send one order (id, number or reference)
php craft holding/sync/all --since=2026-01-01 --limit=500
php craft holding/sync/retry                 # everything that failed and has attempts left
php craft holding/products/push              # catalogue → Holded
php craft holding/products/stock --apply     # stock ← Holded
php craft holding/log/prune                  # housekeeping, for cron

*/15 * * * * php craft holding/sync/retry
0 4 * * *    php craft holding/log/prune