Blog Sections Open

Updating TV Values from Shopkeeper During Frontend Events

Sometimes ecommerce logic spills into content fields. The original Shopkeeper topic behind this article showed how a frontend event plugin could inspect purchase data and write changes back into a TV. Typical Event if ($

Sometimes ecommerce logic spills into content fields. The original Shopkeeper topic behind this article showed how a frontend event plugin could inspect purchase data and write changes back into a TV.

Typical Event

if ($e->name == 'OnSHKFrontendInit') {
    if (isset($_SESSION['purchases'])) {
        $purchases = unserialize($_SESSION['purchases']);
        foreach ($purchases as $value) {
            // inspect product ID, count, price
        }
    }
}

Typical TV Update

$query = "UPDATE `modx_site_tmplvar_contentvalues`
SET value = value + 1
WHERE tmplvarid = 46 AND contentid = " . $value[0];

This kind of pattern can work, but it should be used carefully. Once business counters or inventory-like values are updated through frontend hooks, concurrency and data integrity become real concerns.

The rule of thumb is simple: if a TV is becoming transactional state, treat it more like application data and less like presentation metadata.

Newer post

Building Custom AjaxSearch Configurations for Filtered Listings

How to use a custom AjaxSearch configuration file when a project needs several coordinated filters instead of one plain text query.

Older post

Using splitPagination to Reshape Ditto Page Links

How splitPagination can restyle and restructure standard Ditto pagination without rewriting the whole listing layer.