Blog Sections Open
Switching Shopkeeper Prices by Quantity with `OnSHKcalcTotalPrice`
How to use `OnSHKcalcTotalPrice` to switch Shopkeeper pricing tiers based on quantity.
Quantity-based pricing is one of the most common ecommerce requirements, and Shopkeeper can handle it cleanly when the recalculation event updates the purchase data before totals are finalized.
The original solution listened to OnSHKcalcTotalPrice and switched between two TVs, price and price2, depending on how many units were in the cart:
if ($e->name == 'OnSHKcalcTotalPrice') {
if (isset($_SESSION['purchases'])) {
$purchases = unserialize($_SESSION['purchases']);
foreach ($purchases as $kk => $val) {
if ($val[1] < 11) $sk = 'price';
if ($val[1] > 10) $sk = 'price2';
$tv = $modx->getTemplateVarOutput(array($sk), $val[0]);
$purchases[$kk][2] = $tv[$sk];
}
$_SESSION['purchases'] = serialize($purchases);
$e->params['purchases'] = $purchases;
}
}
The key line is the last one. Updating $e->params['purchases'] makes sure Shopkeeper continues its calculation using the modified prices instead of stale session data.
This is a good example of a lightweight quantity-tier system that stays inside the existing Evolution CMS + Shopkeeper workflow instead of requiring a separate pricing engine.
Building a Large Multi-Level Menu with Wayfinder and DocLister
How to combine Wayfinder and DocLister for large multi-level menus, and when DLBuildMenu is the cleaner replacement.
Showing TV-Based Images in AjaxSearch Results with phpThumb
How to render TV-based images in AjaxSearch result templates and when phpThumb processing needs extra care.