Generate a user discount after customer registration

The intention is to apply a discount to the customer who registers

My attempt to generate a user discount from a snippet :sweat_smile:

<?php

$users = array('8');
$fields = array();
$fields['id'] = '';
$fields['users'] = $users;
$fields['from_amount'] = '100.5';
$fields['product_restrict'] = '132';
$fields['discount_percent'] = '25';
$fields['used_allowed'] = '1';
$fields['expires'] = '2016-03-31 23:45:00';

$response = $modx->runProcessor('mgr/userdiscounts/createuser', $fields, array('processors_path' => '/home/../core/components/simplecart/processors/') );

if ($response->isError()) {
    return $response->getMessage();
}

return;

Log error
[2016-03-09 11:00:18] (ERROR @ /index.php) Could not load class: simpleCartUserDiscount from mysql.simplecartuserdiscount.
[2016-03-09 11:00:18] (ERROR @ /index.php) Could not load class: simpleCartUserDiscount from mysql.simplecartuserdiscount.
[2016-03-09 11:00:18] (ERROR @ /index.php) Could not load class simpleCartUserDiscount
[2016-03-09 11:00:18] (ERROR @ /index.php) Could not load class: simpleCartUserDiscount from mysql.simplecartuserdiscount.

I don’t have the necessary knowledge to make the best choice to do it…
Some idea?

Thanks in advance

Hi @PMedusa - sorry for not responding sooner, I’ve not been feeling well and must’ve marked the notification as read before making a mental note to respond!

It looks like you’re almost there, but you just need to load the SimpleCart package before calling $modx->runProcessor. Adding this should do the trick:

$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return 'Could not load SimpleCart';

Hi @mhamstra
it wasn’t urgent.
I hope you’re feeling better

Thank you

Yeah, starting to feel better now :slight_smile: Hope you get it working!

Sure, it works great!