-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.php
67 lines (53 loc) · 3.23 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Concrete\Package\CommunityStoreEventExample;
use Concrete\Core\Package\Package;
use Whoops\Exception\ErrorException;
use Concrete\Core\Support\Facade\Events;
use Concrete\Core\Support\Facade\Application;
class Controller extends Package {
protected $pkgHandle = 'community_store_event_example';
protected $appVersionRequired = '8.0';
protected $pkgVersion = '2.0';
public function getPackageDescription() {
return t("An example how to use Community Store events");
}
public function getPackageName() {
return t("Community Store Event Example");
}
protected $pkgAutoloaderRegistries = [
'src/CommunityStoreEventExample' => '\Concrete\Package\CommunityStoreEventExample',
];
public function install() {
$app = Application::getFacadeApplication();
$installed = $app->make('Concrete\Core\Package\PackageService')->getInstalledHandles();
if(!(is_array($installed) && in_array('community_store',$installed)) ) {
throw new ErrorException(t('This package requires that Community Store be installed'));
}
parent::install();
}
public function on_start() {
$app = Application::getFacadeApplication();
// orders
$orderListener = $app->make('\Concrete\Package\CommunityStoreEventExample\Event\Order');
Events::addListener('on_community_store_order', array($orderListener, 'orderPlaced'));
Events::addListener('on_community_store_payment_complete', array($orderListener, 'orderPaymentComplete'));
Events::addListener('on_community_store_order_status_update', array($orderListener, 'orderStatusUpdate'));
// products
$productListener = $app->make('\Concrete\Package\CommunityStoreEventExample\Event\Product');
Events::addListener('on_community_store_product_add', array($productListener, 'productAdded'));
Events::addListener('on_community_store_product_update', array($productListener, 'productUpdated'));
Events::addListener('on_community_store_product_delete', array($productListener, 'productDeleted'));
Events::addListener('on_community_store_product_duplicate', array($productListener, 'productDuplicated'));
// cart
$cartListener = $app->make('\Concrete\Package\CommunityStoreEventExample\Event\Cart');
Events::addListener('on_community_store_cart_action', array($cartListener, 'cartAction'));
Events::addListener('on_community_store_cart_pre_add', array($cartListener, 'cartPreAdd'));
Events::addListener('on_community_store_cart_post_add', array($cartListener, 'cartPostAdd'));
Events::addListener('on_community_store_cart_pre_update', array($cartListener, 'cartPreUpdate'));
Events::addListener('on_community_store_cart_post_update', array($cartListener, 'cartPostUpdate'));
Events::addListener('on_community_store_cart_pre_remove', array($cartListener, 'cartPreRemove'));
Events::addListener('on_community_store_cart_post_remove', array($cartListener, 'cartPostRemove'));
Events::addListener('on_community_store_cart_pre_clear', array($cartListener, 'cartPreClear'));
Events::addListener('on_community_store_cart_post_clear', array($cartListener, 'cartPostClear'));
}
}