BrainActs_Rps - Version 1.0.2

Version Notes

First Stable Release

Download this release

Release Info

Developer Tikhonov Alex
Extension BrainActs_Rps
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

app/code/local/AT/Rps/Block/Rewrite/Onepage/Payment/Methods.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AT_Rps_Block_Rewrite_Onepage_Payment_Methods extends Mage_Checkout_Block_Onepage_Payment_Methods
4
+ {
5
+ protected function _canUseMethod($method)
6
+ {
7
+ /** @var AT_Rps_Helper_Data $helper */
8
+ $helper = Mage::helper('rps');
9
+ if ($helper->isRestrictedPayment($method->getCode())) {
10
+ return false;
11
+ }
12
+ return $method && $method->canUseCheckout() && parent::_canUseMethod($method);
13
+ }
14
+ }
15
+
app/code/local/AT/Rps/Helper/Data.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AT_Rps_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ const XML_PATH_ENABLED = 'rps/general/enabled';
6
+
7
+ const XML_PATH_RESTRICTED_PAYMENT = 'rps/payment/methods';
8
+
9
+ const XML_PATH_RESTRICTED_SHIPPING = 'rps/shipping/methods';
10
+
11
+ public function isRestrictedPayment($methodCode)
12
+ {
13
+ if (!$this->isActive()) {
14
+ return false;
15
+ }
16
+
17
+ $paymentString = Mage::getStoreConfig(self::XML_PATH_RESTRICTED_PAYMENT, Mage::app()->getStore()->getId());
18
+ $payments = explode(',', $paymentString);
19
+
20
+ if (is_array($payments) && in_array($methodCode, $payments)) {
21
+ return true;
22
+ } else if ($payments == $methodCode) {
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+
28
+ public function isActive()
29
+ {
30
+ return (bool)Mage::getStoreConfig(self::XML_PATH_ENABLED, Mage::app()->getStore()->getId());
31
+ }
32
+
33
+
34
+ public function isRestrictedShippingMethod($carrierCode, $carrierMethod)
35
+ {
36
+ if (Mage::getDesign()->getArea() === Mage_Core_Model_App_Area::AREA_FRONTEND) {
37
+ $shippingCode = $carrierCode . '_' . $carrierMethod;
38
+
39
+ $methodsString = Mage::getStoreConfig(self::XML_PATH_RESTRICTED_SHIPPING, Mage::app()->getStore()->getId());
40
+ $methods = explode(',', $methodsString);
41
+
42
+ if (empty($methods)) {
43
+ return false;
44
+ }
45
+ if (is_array($methods) && in_array($shippingCode, $methods)) {
46
+ return true;
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+ }
app/code/local/AT/Rps/Model/Rewrite/Shipping/Rate/Result.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magento.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magento.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Shipping
24
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class AT_Rps_Model_Rewrite_Shipping_Rate_Result extends Mage_Shipping_Model_Rate_Result
28
+ {
29
+
30
+ public function append($result)
31
+ {
32
+ /** @var AT_Rps_Helper_Data $helper */
33
+ $helper = Mage::helper('rps');
34
+ if (!$helper->isActive()) {
35
+ return parent::append($result);
36
+ }
37
+
38
+ if ($result instanceof Mage_Shipping_Model_Rate_Result_Error) {
39
+ $this->setError(true);
40
+ }
41
+ if ($result instanceof Mage_Shipping_Model_Rate_Result_Abstract) {
42
+ $this->_rates[] = $result;
43
+ } elseif ($result instanceof Mage_Shipping_Model_Rate_Result) {
44
+ $rates = $result->getAllRates();
45
+ foreach ($rates as $rate) {
46
+ if (!$helper->isRestrictedShippingMethod($rate->getCarrier(), $rate->getMethod())) {
47
+ $this->append($rate);
48
+ }
49
+ }
50
+ }
51
+ return $this;
52
+ }
53
+ }
app/code/local/AT/Rps/Model/System/Config/Source/Payment/Methods.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AT_Rps_Model_System_Config_Source_Payment_Methods
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $store = null;
8
+ $websiteCode = Mage::app()->getRequest()->getParam('website', false);
9
+ if ($websiteCode) {
10
+ /** @var Mage_Core_Model_Website $website */
11
+ $website = Mage::getModel('core/website')->load($websiteCode);
12
+ $store = $website->getDefaultStore();
13
+ }
14
+
15
+ /** @var Mage_Payment_Model_Config $configModel */
16
+ $configModel = Mage::getSingleton('payment/config');
17
+
18
+ $payments = $configModel->getActiveMethods($store);
19
+
20
+ $methods = array(array('value' => '', 'label' => Mage::helper('adminhtml')->__('-- None --')));
21
+
22
+ foreach ($payments as $paymentCode => $paymentModel) {
23
+
24
+ $paymentTitle = Mage::getStoreConfig('payment/' . $paymentCode . '/title');
25
+
26
+ if ($paymentCode == 'free') {
27
+ continue; //skip free method as block this method could create issue on frontend
28
+ }
29
+
30
+ $methods[$paymentCode] = array(
31
+ 'label' => $paymentTitle,
32
+ 'value' => $paymentCode,
33
+ );
34
+ }
35
+
36
+ return $methods;
37
+ }
38
+
39
+ }
app/code/local/AT/Rps/Model/System/Config/Source/Shipping/Methods.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magento.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magento.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Adminhtml
24
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class AT_Rps_Model_System_Config_Source_Shipping_Methods
28
+ {
29
+
30
+ public function toOptionArray($isActiveOnlyFlag = false)
31
+ {
32
+
33
+ $store = null;
34
+ $websiteCode = Mage::app()->getRequest()->getParam('website', false);
35
+ if ($websiteCode) {
36
+ /** @var Mage_Core_Model_Website $website */
37
+ $website = Mage::getModel('core/website')->load($websiteCode);
38
+ $store = $website->getDefaultStore();
39
+ }
40
+
41
+
42
+ $methods = array(array('value' => '', 'label' => Mage::helper('adminhtml')->__('-- None --')));
43
+
44
+ /** @var Mage_Shipping_Model_Config $configModel */
45
+ $configModel = Mage::getSingleton('shipping/config');
46
+ $carriers = $configModel->getAllCarriers($store);
47
+ foreach ($carriers as $carrierCode => $carrierModel) {
48
+ if (!$carrierModel->isActive() && (bool)$isActiveOnlyFlag === true) {
49
+ continue;
50
+ }
51
+ $carrierMethods = $carrierModel->getAllowedMethods();
52
+ if (!$carrierMethods) {
53
+ continue;
54
+ }
55
+ $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/title');
56
+ $methods[$carrierCode] = array(
57
+ 'label' => $carrierTitle,
58
+ 'value' => array(),
59
+ );
60
+ foreach ($carrierMethods as $methodCode => $methodTitle) {
61
+ $methods[$carrierCode]['value'][] = array(
62
+ 'value' => $carrierCode . '_' . $methodCode,
63
+ 'label' => '[' . $carrierCode . '] ' . $methodTitle,
64
+ );
65
+ }
66
+ }
67
+
68
+ return $methods;
69
+ }
70
+ }
app/code/local/AT/Rps/etc/adminhtml.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <acl>
5
+ <resources>
6
+ <admin>
7
+ <children>
8
+ <system>
9
+ <children>
10
+ <config>
11
+ <children>
12
+ <rps translate="title">
13
+ <title>Restriction Section</title>
14
+ <sort_order>60</sort_order>
15
+ </rps>
16
+ </children>
17
+ </config>
18
+ </children>
19
+ </system>
20
+ </children>
21
+ </admin>
22
+ </resources>
23
+ </acl>
24
+ </config>
app/code/local/AT/Rps/etc/config.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <AT_Rps>
5
+ <version>1.0.2</version>
6
+ </AT_Rps>
7
+ </modules>
8
+
9
+ <adminhtml>
10
+ <translate>
11
+ <modules>
12
+ <AT_Rps>
13
+ <files>
14
+ <default>AT_Rps.csv</default>
15
+ </files>
16
+ </AT_Rps>
17
+ </modules>
18
+ </translate>
19
+ </adminhtml>
20
+
21
+ <global>
22
+ <models>
23
+ <rps>
24
+ <class>AT_Rps_Model</class>
25
+ </rps>
26
+ <shipping>
27
+ <rewrite>
28
+ <rate_result>AT_Rps_Model_Rewrite_Shipping_Rate_Result</rate_result>
29
+ </rewrite>
30
+ </shipping>
31
+ </models>
32
+
33
+ <blocks>
34
+ <rps>
35
+ <class>AT_Rps_Block</class>
36
+ </rps>
37
+
38
+ <checkout>
39
+ <rewrite>
40
+ <onepage_payment_methods>AT_Rps_Block_Rewrite_Onepage_Payment_Methods</onepage_payment_methods>
41
+ </rewrite>
42
+ </checkout>
43
+
44
+ </blocks>
45
+
46
+ <helpers>
47
+ <rps>
48
+ <class>AT_Rps_Helper</class>
49
+ </rps>
50
+ </helpers>
51
+ </global>
52
+ </config>
app/code/local/AT/Rps/etc/system.xml ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <rps>
5
+ <class>separator-top</class>
6
+ <label>RPS</label>
7
+ <tab>sales</tab>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>900</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <groups>
14
+ <general>
15
+ <label>General</label>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>5</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ <fields>
22
+ <enabled translate="label">
23
+ <label>Enable</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>adminhtml/system_config_source_yesno</source_model>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ </enabled>
31
+ </fields>
32
+ </general>
33
+ <payment translate="label">
34
+ <label>Payment Settings</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>5</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <fields>
41
+ <methods translate="label comment">
42
+ <label>Hide Methods</label>
43
+ <comment>Only active methods allow to select.</comment>
44
+ <frontend_type>multiselect</frontend_type>
45
+ <source_model>rps/system_config_source_payment_methods</source_model>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>0</show_in_store>
49
+ </methods>
50
+ </fields>
51
+ </payment>
52
+
53
+ <shipping translate="label">
54
+ <label>Shipping Settings</label>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>5</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+ <fields>
61
+ <methods translate="label comment">
62
+ <label>Hide Methods</label>
63
+ <comment>Only active carriers allow to select.</comment>
64
+ <frontend_type>multiselect</frontend_type>
65
+ <source_model>rps/system_config_source_shipping_methods</source_model>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ </methods>
70
+ </fields>
71
+ </shipping>
72
+ </groups>
73
+ </rps>
74
+ </sections>
75
+ </config>
app/etc/modules/AT_Rps.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <AT_Rps>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </AT_Rps>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>BrainActs_Rps</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>osm</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>brainacts_rps</summary>
10
+ <description>brainacts_rps</description>
11
+ <notes>First Stable Release</notes>
12
+ <authors><author><name>Aleksandr Tykhnov</name><user>nakilon</user><email>tihonov.sania@gmail.com</email></author></authors>
13
+ <date>2016-10-25</date>
14
+ <time>10:09:54</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="AT_Rps.xml" hash="182076f6572a8398f60bf737e980f279"/></dir></target><target name="magelocal"><dir name="AT"><dir name="Rps"><dir name="Block"><dir name="Rewrite"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="bf84ccfaf1f79984f85e299bc53126b8"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="f041b7bf76992ce281fbd1429b3ec8c2"/></dir><dir name="Model"><dir name="Rewrite"><dir name="Shipping"><dir name="Rate"><file name="Result.php" hash="c673f5d97888b89a76a155698dea8229"/></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Payment"><file name="Methods.php" hash="e4fa39e3f4dff8ed089f3ac021a18264"/></dir><dir name="Shipping"><file name="Methods.php" hash="3b5ba5bf87e83268ff59c4b18dd3bf3e"/></dir></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="d646be01e8a4c58035823eb9a431d69d"/><file name="config.xml" hash="8c567755cb2ca7519fd76d88af9767c0"/><file name="system.xml" hash="e835cde86b3f25e7e6d7ed1029143bee"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>7.0.4</max></php></required></dependencies>
18
+ </package>