- Is it possible to add a quantity field, for how many items you have in stock, which is subtracted for every order of that product? Or, alternatively, to automatically unpublish a product when it's purchased?
- Can an email notification be sent to the administrator every time an order is placed?
Fort this you need to go to minishop2 settings, go to the status tab and set the 'Subject of email to manager' and 'Chunk of email to manager' settings for each order status.
[2013-11-15 18:44:08] (ERROR @ /assets/components/minishop2/connector.php) Error caching lexicon topic lexicon/sv/core/chunk
[[!update_stock? &product=`[[+id]]` &qty=`[[+count]]`]]
<?php
//set vars
$tvId = 29;
$tvName = "stock_count";
$stockCount = 0;
$resourceId = (int) $modx->getOption('product', $scriptProperties);
$qtyOrdered = (int) $modx->getOption('qty', $scriptProperties, 1);
if(!empty($resourceId))
{
//Get Absolute Current Stock (bypass cache)
$tvr = $modx->getObject('modTemplateVarResource', array(
'tmplvarid' => $tvId,
'contentid' => $resourceId
));
if ($tvr) {
$stockCount = $tvr->get('value');
}else {
$tv = $modx->getObject('modTemplateVar', $tvId);
if ($tv) $stockCount = $tv->get('default_text');
}
//Set New Stock Value
$stockCount = $stockCount - $qtyOrdered;
$page = $modx->getObject('modResource', $resourceId);
if (!$page->setTVValue($tvName, $stockCount)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'There was a problem saving your TV...');
}
}else{
$modx->log(xPDO::LOG_LEVEL_ERROR, 'No resource ID');
}
[[!msGetOrder? &tplRow=`tpl.msCart.SuccessfulOrder.row`]]
[[!*stock_count]]
So I know this is a slightly old thread... but for anyone wanting stock management - at a VERY basic level - I made a really simple TV + snippet to control it for a small club shop.
NOTE - the problem with calling the snippet at this stage is should the user keep revisiting the same page/refreshing it, the stock will be deducted each time.
Anyway, for for it's worth:
TV name "stock_count" (my ID 29) - assign to shop product template(s)
Snippet:
[[!update_stock? &product=`[[+id]]` &qty=`[[+count]]`]]
<!--?php //set vars $tvId = 29; $tvName = "stock_count"; $stockCount = 0; $resourceId = (int) $modx--->getOption('product', $scriptProperties); $qtyOrdered = (int) $modx->getOption('qty', $scriptProperties, 1); if(!empty($resourceId)) { //Get Absolute Current Stock (bypass cache) $tvr = $modx->getObject('modTemplateVarResource', array( 'tmplvarid' => $tvId, 'contentid' => $resourceId )); if ($tvr) { $stockCount = $tvr->get('value'); }else { $tv = $modx->getObject('modTemplateVar', $tvId); if ($tv) $stockCount = $tv->get('default_text'); } //Set New Stock Value $stockCount = $stockCount - $qtyOrdered; $page = $modx->getObject('modResource', $resourceId); if (!$page->setTVValue($tvName, $stockCount)) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'There was a problem saving your TV...'); } }else{ $modx->log(xPDO::LOG_LEVEL_ERROR, 'No resource ID'); }
I call the snippet in a custom &tplRow on the "successful order" page:
[[!msGetOrder? &tplRow=`tpl.msCart.SuccessfulOrder.row`]]
You can display the stock on the product page calling the TV uncached:
[[!*stock_count]]
Might help somebody... or maybe someone can tell me where's a better place to call the snippet.
Cheers
Kyle