N98_CustomerGroupCheckout - Version 1.0.2

Version Notes

Initial release.

Download this release

Release Info

Developer netz98 new media GmbH
Extension N98_CustomerGroupCheckout
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

app/code/community/N98/CustomerGroupCheckout/Block/Adminhtml/System/Config/Form.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2011
4
+ * netz98 new media GmbH. All rights reserved.
5
+ *
6
+ * The use and redistribution of this software, either compiled or uncompiled,
7
+ * with or without modifications are permitted provided that the
8
+ * following conditions are met:
9
+ *
10
+ * 1. Redistributions of compiled or uncompiled source must contain the above
11
+ * copyright notice, this list of the conditions and the following disclaimer:
12
+ *
13
+ * 2. All advertising materials mentioning features or use of this software must
14
+ * display the following acknowledgement:
15
+ * "This product includes software developed by the netz98 new media GmbH, Mainz."
16
+ *
17
+ * 3. The name of the netz98 new media GmbH may not be used to endorse or promote
18
+ * products derived from this software without specific prior written permission.
19
+ *
20
+ * 4. License holders of the netz98 new media GmbH are only permitted to
21
+ * redistribute altered software, if this is licensed under conditions that contain
22
+ * a copyleft-clause.
23
+ *
24
+ * This software is provided by the netz98 new media GmbH without any express or
25
+ * implied warranties. netz98 is under no condition liable for the functional
26
+ * capability of this software for a certain purpose or the general usability.
27
+ * netz98 is under no condition liable for any direct or indirect damages resulting
28
+ * from the use of the software.
29
+ * Liability and Claims for damages of any kind are excluded.
30
+ */
31
+
32
+ /**
33
+ * @category n98
34
+ * @package N98_CustomerGroup
35
+ */
36
+ class N98_CustomerGroupCheckout_Block_Adminhtml_System_Config_Form
37
+ extends Mage_Adminhtml_Block_System_Config_Form
38
+ {
39
+ /**
40
+ * @return Netz98_CustomerGroup_Block_Adminhtml_System_Config_Form
41
+ */
42
+ protected function _initObjects()
43
+ {
44
+ parent::_initObjects();
45
+
46
+ $sections = $this->_configFields->getSection($this->getSectionCode(), $this->getWebsiteCode(), $this->getStoreCode());
47
+
48
+ /**
49
+ * Create config field during runtime.
50
+ *
51
+ * Check if we are in sales tab and sub-tab payment or shipping.
52
+ * Then we create SimpleXMLElements for form init.
53
+ */
54
+ if ($sections->tab == 'sales' && in_array($sections->label, array('Payment Methods', 'Shipping Methods'))) {
55
+ foreach ($sections->groups as $group) {
56
+ foreach ($group as $subGroup) {
57
+ if (isset($subGroup->fields)) {
58
+ $customerGroup = $subGroup->fields->addChild('available_for_customer_groups');
59
+ $customerGroup->addAttribute('translate', 'label');
60
+ /* @var $customerGroup Mage_Core_Model_Config_Element */
61
+ $customerGroup->addChild('label', 'Customer Group');
62
+ $customerGroup->addChild('frontend_type', 'multiselect');
63
+ $customerGroup->addChild('source_model', 'adminhtml/system_config_source_customer_group');
64
+ $customerGroup->addChild('sort_order', 1000);
65
+ $customerGroup->addChild('show_in_default', 1);
66
+ $customerGroup->addChild('show_in_website', 1);
67
+ $customerGroup->addChild('show_in_store', 1);
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ return $this;
74
+ }
75
+ }
app/code/community/N98/CustomerGroupCheckout/Model/Payment/Observer.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2011
4
+ * netz98 new media GmbH. All rights reserved.
5
+ *
6
+ * The use and redistribution of this software, either compiled or uncompiled,
7
+ * with or without modifications are permitted provided that the
8
+ * following conditions are met:
9
+ *
10
+ * 1. Redistributions of compiled or uncompiled source must contain the above
11
+ * copyright notice, this list of the conditions and the following disclaimer:
12
+ *
13
+ * 2. All advertising materials mentioning features or use of this software must
14
+ * display the following acknowledgement:
15
+ * "This product includes software developed by the netz98 new media GmbH, Mainz."
16
+ *
17
+ * 3. The name of the netz98 new media GmbH may not be used to endorse or promote
18
+ * products derived from this software without specific prior written permission.
19
+ *
20
+ * 4. License holders of the netz98 new media GmbH are only permitted to
21
+ * redistribute altered software, if this is licensed under conditions that contain
22
+ * a copyleft-clause.
23
+ *
24
+ * This software is provided by the netz98 new media GmbH without any express or
25
+ * implied warranties. netz98 is under no condition liable for the functional
26
+ * capability of this software for a certain purpose or the general usability.
27
+ * netz98 is under no condition liable for any direct or indirect damages resulting
28
+ * from the use of the software.
29
+ * Liability and Claims for damages of any kind are excluded.
30
+ */
31
+
32
+ /**
33
+ * Observer to limit access to customer groups by customer group
34
+ *
35
+ * @category n98
36
+ * @package Netz98_CustomerGroup
37
+ */
38
+ class N98_CustomerGroupCheckout_Model_Payment_Observer
39
+ {
40
+ /**
41
+ * @var string
42
+ */
43
+ const XML_CUSTOMER_GROUP_CONFIG_FIELD = 'available_for_customer_groups';
44
+
45
+ /**
46
+ * Check if customer group can use the payment method
47
+ *
48
+ * @param Varien_Event_Observer $observer
49
+ * @return bool
50
+ */
51
+ public function methodIsAvailable(Varien_Event_Observer $observer)
52
+ {
53
+ $paymentMethodInstance = $observer->getMethodInstance();
54
+ /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */
55
+ $result = $observer->getResult();
56
+
57
+ $customer = Mage::helper('customer')->getCustomer();
58
+ /* @var $customer Mage_Customer_Model_Customer */
59
+
60
+ $customerGroupConfig = $paymentMethodInstance->getConfigData(self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
61
+ if (!empty($customerGroupConfig)) {
62
+ $methodCustomerGroups = explode(',', $customerGroupConfig);
63
+ if (count($methodCustomerGroups) > 0) {
64
+ if (!in_array($customer->getGroupId(), $methodCustomerGroups)) {
65
+ $result->isAvailable = false;
66
+ }
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ }
app/code/community/N98/CustomerGroupCheckout/Model/Shipping/Shipping.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright © 2011
4
+ * netz98 new media GmbH. All rights reserved.
5
+ *
6
+ * The use and redistribution of this software, either compiled or uncompiled,
7
+ * with or without modifications are permitted provided that the
8
+ * following conditions are met:
9
+ *
10
+ * 1. Redistributions of compiled or uncompiled source must contain the above
11
+ * copyright notice, this list of the conditions and the following disclaimer:
12
+ *
13
+ * 2. All advertising materials mentioning features or use of this software must
14
+ * display the following acknowledgement:
15
+ * "This product includes software developed by the netz98 new media GmbH, Mainz."
16
+ *
17
+ * 3. The name of the netz98 new media GmbH may not be used to endorse or promote
18
+ * products derived from this software without specific prior written permission.
19
+ *
20
+ * 4. License holders of the netz98 new media GmbH are only permitted to
21
+ * redistribute altered software, if this is licensed under conditions that contain
22
+ * a copyleft-clause.
23
+ *
24
+ * This software is provided by the netz98 new media GmbH without any express or
25
+ * implied warranties. netz98 is under no condition liable for the functional
26
+ * capability of this software for a certain purpose or the general usability.
27
+ * netz98 is under no condition liable for any direct or indirect damages resulting
28
+ * from the use of the software.
29
+ * Liability and Claims for damages of any kind are excluded.
30
+ */
31
+
32
+ /**
33
+ * Overwrites shipping model of magento an inject test for customer groups
34
+ *
35
+ * @category n98
36
+ * @package N98_CustomerGroupCheckout
37
+ */
38
+ class N98_CustomerGroupCheckout_Model_Shipping_Shipping
39
+ extends Mage_Shipping_Model_Shipping
40
+ {
41
+ /**
42
+ * @var string
43
+ */
44
+ const XML_CUSTOMER_GROUP_CONFIG_FIELD = 'available_for_customer_groups';
45
+
46
+ /**
47
+ * @param string $carrierCode
48
+ * @param Varien_Object $request
49
+ * @return Netz98_CustomerGroupCheckout_Model_Shipping_Shipping
50
+ */
51
+ public function collectCarrierRates($carrierCode, $request)
52
+ {
53
+ if (!$this->_checkCarrierByCustomerGroup($carrierCode)) {
54
+ return $this;
55
+ }
56
+ return parent::collectCarrierRates($carrierCode, $request);
57
+ }
58
+
59
+ /**
60
+ * Check if carrier can be used by customer groups
61
+ *
62
+ * @param Mage_Shipping_Model_Carrier_Abstract $carrier
63
+ * @return boolean
64
+ */
65
+ protected function _checkCarrierByCustomerGroup($carrierCode)
66
+ {
67
+ $customer = Mage::helper('customer')->getCustomer();
68
+ /* @var $customer Mage_Customer_Model_Customer */
69
+
70
+ $carrierCustomerGroupConfig = Mage::getStoreConfig('carriers/' . $carrierCode . '/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
71
+
72
+ if (!empty($carrierCustomerGroupConfig)) {
73
+ $carrierCustomerGroups = explode(',', $carrierCustomerGroupConfig);
74
+ if (count($carrierCustomerGroups) > 0) {
75
+ if (!in_array($customer->getGroupId(), $carrierCustomerGroups)) {
76
+ return false;
77
+ }
78
+ }
79
+ }
80
+
81
+ // If nothing was specified the shipping carrier is not blocked!
82
+ return true;
83
+ }
84
+ }
app/code/community/N98/CustomerGroupCheckout/etc/config.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Netz98
5
+ * @package Netz98_CustomerGroupCheckout
6
+ */
7
+ -->
8
+ <config>
9
+ <modules>
10
+ <Netz98_CustomerGroupCheckout>
11
+ <version>1.0.2</version>
12
+ </Netz98_CustomerGroupCheckout>
13
+ </modules>
14
+ <global>
15
+ <blocks>
16
+ <n98_customergroupcheckout>
17
+ <class>N98_CustomerGroupCheckout_Block</class>
18
+ </n98_customergroupcheckout>
19
+ <adminhtml>
20
+ <rewrite>
21
+ <system_config_form>N98_CustomerGroupCheckout_Block_Adminhtml_System_Config_Form</system_config_form>
22
+ </rewrite>
23
+ </adminhtml>
24
+ </blocks>
25
+ <models>
26
+ <n98_customergroupcheckout>
27
+ <class>N98_CustomerGroupCheckout_Model</class>
28
+ </n98_customergroupcheckout>
29
+ <shipping>
30
+ <rewrite>
31
+ <shipping>N98_CustomerGroupCheckout_Model_Shipping_Shipping</shipping>
32
+ </rewrite>
33
+ </shipping>
34
+ </models>
35
+ </global>
36
+ <frontend>
37
+ <events>
38
+ <payment_method_is_active>
39
+ <observers>
40
+ <customer_group_check>
41
+ <class>n98_customergroupcheckout/payment_observer</class>
42
+ <method>methodIsAvailable</method>
43
+ </customer_group_check>
44
+ </observers>
45
+ </payment_method_is_active>
46
+ </events>
47
+ </frontend>
48
+ </config>
app/etc/modules/N98_CustomerGroupCheckout.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category n98
5
+ * @package N98_CustomerGroupCheckout
6
+ */
7
+ -->
8
+ <config>
9
+ <modules>
10
+ <N98_CustomerGroupCheckout>
11
+ <active>true</active>
12
+ <codePool>community</codePool>
13
+ <depends>
14
+ <Mage_Adminhtml />
15
+ <Mage_Sales />
16
+ <Mage_Shipping />
17
+ </depends>
18
+ </N98_CustomerGroupCheckout>
19
+ </modules>
20
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>N98_CustomerGroupCheckout</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.netz98.de/licenses/opensource.html">netz98 open source license</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Limit access to payments and shipping methods by customer groups.</summary>
10
+ <description>Limit payments and shipping methods by customer groups.</description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>netz98 new media GmbH</name><user>netz98</user><email>magento@netz98.de</email></author></authors>
13
+ <date>2011-08-05</date>
14
+ <time>12:52:14</time>
15
+ <contents><target name="magecommunity"><dir name="N98"><dir name="CustomerGroupCheckout"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Form.php" hash="f87f8c5acb66ccf2db8923cadb8afa4d"/></dir></dir></dir></dir><dir name="Model"><dir name="Payment"><file name="Observer.php" hash="05e0e0f82372bb6dd3c15f8b3544608a"/></dir><dir name="Shipping"><file name="Shipping.php" hash="46c1b8cf5c61f6ead461e2b2260acddb"/></dir></dir><dir name="etc"><file name="config.xml" hash="a9360004700e25b0632515eb2bfe925d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="N98_CustomerGroupCheckout.xml" hash="83c850d7c7fec7ae4a602f325fb9a411"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>