<![CDATA[ Product quantity/stock and email order notification in MiniShop2 - My Forums]]> https://forums.modx.com/thread/?thread=87740 <![CDATA[Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483107
A couple of questions:

- 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?]]>
sketchi Nov 15, 2013, 11:50 AM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483107
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-561179 Quote from: kctechsoln at Sep 15, 2015, 05:48 AM
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

Excuse me can you help me step by step to setup this?
I create the TV and Snippet, but don't know how to combine it with minishop2.
Sorry for my poor English and programming.]]>
stzero Aug 28, 2018, 08:10 AM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-561179
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-531525
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]]>
kctechsoln Sep 15, 2015, 05:48 AM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-531525
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-491624
I didn't unfortunately. As I don't write PHP and my client didn't have a budget for me to hire a programmer, they decided to manage their stock manually for now. This solution is fine for a shop like theirs with a low turnover I guess, but for others stock handling would be a necessity, so it sure would be a nice feature. I imagine it would be quite easily solved with some PHP skills.

If you find a solution that you are happy to share, I'd love to hear about it smiley]]>
sketchi Mar 03, 2014, 03:13 AM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-491624
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-491608
I was just looking for the same thing, adding a stock quantity field and being able to subtract from the figure in the product details page, did you manage to achieve this?

Also, it would also be nice to be able to list for products with a "low stock" status which you can define, i.e. less than 5 items.

Cheers - Zaphodx]]>
zaphodx Mar 02, 2014, 04:21 PM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-491608
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483156 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.

I see, thanks! I looked at the New status and both subject and chunk are already filled in, and email user and email manager are ticked. Still not getting any mail. Getting this in the error log though:

[2013-11-15 18:44:08] (ERROR @ /assets/components/minishop2/connector.php) Error caching lexicon topic lexicon/sv/core/chunk


Something to do with my site being in Swedish I guess. When I look at the minishop2 lexicon posts under System > Lexicon management I only see the languages de, en, fr and ru. I'll add a Swedish lexicon and see if that helps smiley]]>
sketchi Nov 15, 2013, 06:05 PM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483156
<![CDATA[Re: Product quantity/stock and email order notification in MiniShop2]]> https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483129 - 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?
You'd need to create a TV and create a custom order handler for that. Not that simple a task if you're not offay with php.

- 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.
]]>
absent42 Nov 15, 2013, 02:58 PM https://forums.modx.com/thread/87740/product-quantity-stock-and-email-order-notification-in-minishop2#dis-post-483129