Last active
April 24, 2017 21:05
-
-
Save AugustMiller/191fb81d99a31b8d424a876f779ecf97 to your computer and use it in GitHub Desktop.
Sprout Form + Solspace Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? namespace Craft; | |
class SfscPlugin extends BasePlugin | |
{ | |
public function getName() | |
{ | |
return Craft::t('Event Attendance'); | |
} | |
public function getVersion() | |
{ | |
return '1.0'; | |
} | |
public function getDeveloper() | |
{ | |
return 'oof. Studio'; | |
} | |
public function getDeveloperUrl() | |
{ | |
return 'http://oof.studio/'; | |
} | |
public function hasCpSection() | |
{ | |
return false; | |
} | |
# Hook to events, etc. emitted by other plugins | |
public function init() | |
{ | |
craft()->on('sproutForms.onBeforeSaveEntry', function (Event $e) { | |
// Store the submission data temporarily: | |
$submission = $e->params['entry']; | |
// Fetch your Calendar Event by getting its ID off the $event: | |
$event = craft()->calendar_events->getEventById(craft()->request->getParam('yoda')); | |
// Get current quantity and subtract the specified `quantity`. | |
$currentQty = $event->getContent()->stockQty; | |
$newQty = $currentQty - $submission->quantity; | |
// Update the stock, and save. | |
$event->getContent()->setAttribute('stockQty', $newQty); | |
craft()->calendar_events->saveEvent($event); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment