-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module.php
122 lines (112 loc) · 3.69 KB
/
Module.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace SpeckShipping;
use SpeckShipping\Entity\ShippingClassResolver\CatalogProductResolver;
class Module
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include(__DIR__ . '/config/module.config.php');
}
public function getServiceConfig()
{
return array(
'factories' => array(
'speckshipping_config' => function ($sm) {
$config = $sm->get('Config');
return $config['speck_shipping'];
},
'catalog_product_sc_resolver' => function ($sm) {
$resolver = new CatalogProductResolver();
$resolver->setShippingClassMapper($sm->get('speckshipping_sc_mapper'));
$resolver->setProductMapper($sm->get('speckshipping_p_sc_mapper'));
$resolver->setCategoryMapper($sm->get('speckshipping_c_sc_mapper'));
$resolver->setWebsiteMapper($sm->get('speckshipping_w_sc_mapper'));
return $resolver;
},
),
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'speckShipping' => function($sm) {
$sm = $sm->getServiceLocator();
$helper = new \SpeckShipping\View\Helper\Shipping;
$helper->setShippingService($sm->get('speckshipping_shipping_service'));
return $helper;
},
),
);
}
public function onBootstrap($e)
{
$app = $e->getParam('application');
$sl = $app->getServiceManager();
$em = $app->getEventManager()->getSharedManager();
/*
* some events you may wish to attach to..
*
* SpeckCheckout\Strategy\Step\UserInformation
* setComplete
*
* SpeckCatalogCart\Service\CartService
* persistItem, addItemToCart
*
*/
$shipping = new \SpeckShipping\Event\ShippingClassEvents();
$shipping->setServiceLocator($sl);
$em->attach(
'SpeckShipping\Service\Shipping',
'getShippingClass',
function ($e) use ($shipping) {
return $shipping->shippingClassForCartItem($e);
}
);
$em->attach(
'SpeckShipping\Service\Shipping',
'getShippingClassCost',
function ($e) use ($shipping) {
$shipping->shippingClassCostModifiers($e);
}
);
//cart shipping cost events
$em->attach(
'SpeckShipping\Service\Shipping',
'getShippingCost',
function ($e) {
$handler = new \SpeckShipping\Event\IncrementalQtyCost($e);
$handler->adjustCosts();
},
300
);
$em->attach(
'SpeckShipping\Service\Shipping',
'getShippingCost',
function ($e) {
$handler = new \SpeckShipping\Event\ShippingPriority($e);
$handler->adjustCosts();
},
200
);
$em->attach(
'SpeckShipping\Service\Shipping',
'getShippingCost',
function ($e) {
$handler = new \SpeckShipping\Event\CartShippingCost($e);
return $handler->getShippingCost();
},
100
);
}
}