IteraResearch_AnyRate - Version 1.0.1

Version Notes

Has no sql setup, supports multi-store, rates can be assigned per customer group. Package content fixed.

Download this release

Release Info

Developer IteraResearch
Extension IteraResearch_AnyRate
Version 1.0.1
Comparing to
See all releases


Code changes from version 1.0.0 to 1.0.1

app/code/community/IteraResearch/AnyRate/Block/Adminhtml/Form/Field/Group.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of AnyRate extension.
4
+ *
5
+ * @category IteraResearch
6
+ * @package IteraResearch_AnyRate
7
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
8
+ * @license http://www.gnu.org/licenses Lesser General Public License
9
+ */
10
+
11
+ class IteraResearch_AnyRate_Block_Adminhtml_Form_Field_Group extends Mage_Core_Block_Html_Select
12
+ {
13
+ /**
14
+ * Customer groups cache
15
+ *
16
+ * @var array
17
+ */
18
+ private $_customerGroups;
19
+
20
+ /**
21
+ * Retrieve customer groups option array
22
+ *
23
+ * @return array
24
+ */
25
+ protected function _getCustomerGroups()
26
+ {
27
+ if (is_null($this->_customerGroups)) {
28
+ $this->_customerGroups = Mage::getResourceModel('customer/group_collection')
29
+ ->loadData()->toOptionArray();
30
+ }
31
+ return $this->_customerGroups;
32
+ }
33
+
34
+ public function setInputName($value)
35
+ {
36
+ return $this->setName($value);
37
+ }
38
+
39
+ /**
40
+ * Render block HTML
41
+ *
42
+ * @return string
43
+ */
44
+ public function _toHtml()
45
+ {
46
+ if (!$this->getOptions()) {
47
+ foreach ($this->_getCustomerGroups() as $group) {
48
+ $this->addOption($group['value'], $group['label']);
49
+ }
50
+ }
51
+ return parent::_toHtml();
52
+ }
53
+ }
app/code/community/IteraResearch/AnyRate/Block/Adminhtml/Form/Field/Rates.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of AnyRate extension.
4
+ *
5
+ * @category IteraResearch
6
+ * @package IteraResearch_AnyRate
7
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
8
+ * @license http://www.gnu.org/licenses Lesser General Public License
9
+ */
10
+
11
+ class IteraResearch_AnyRate_Block_Adminhtml_Form_Field_Rates extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
12
+ {
13
+ /**
14
+ * @var IteraResearch_AnyRate_Block_Adminhtml_Form_Field_Group
15
+ */
16
+ protected $_groupRenderer;
17
+
18
+ /**
19
+ * Retrieve customer groups renderer
20
+ *
21
+ * @return IteraResearch_AnyRate_Block_Adminhtml_Form_Field_Group
22
+ */
23
+ protected function _getGroupRenderer()
24
+ {
25
+ if (!$this->_groupRenderer) {
26
+ $this->_groupRenderer = $this->getLayout()->createBlock(
27
+ 'anyrate/adminhtml_form_field_group', '',
28
+ array('is_render_to_js_template' => true)
29
+ );
30
+ $this->_groupRenderer->setExtraParams('style="width:120px"');
31
+ }
32
+ return $this->_groupRenderer;
33
+ }
34
+
35
+ /**
36
+ * Prepare to render
37
+ */
38
+ protected function _prepareToRender()
39
+ {
40
+ $this->addColumn('title', array(
41
+ 'label' => Mage::helper('adminhtml')->__('Title'),
42
+ 'style' => 'width:180px',
43
+ 'class' => 'required-entry',
44
+ ));
45
+ $this->addColumn('price', array(
46
+ 'label' => Mage::helper('adminhtml')->__('Price'),
47
+ 'style' => 'width:40px',
48
+ 'class' => 'required-entry validate-number validate-zero-or-greater'
49
+ ));
50
+ $this->addColumn('customer_group', array(
51
+ 'label' => Mage::helper('adminhtml')->__('Customer Group'),
52
+ 'renderer' => $this->_getGroupRenderer(),
53
+ ));
54
+ $this->_addAfter = false;
55
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Rate');
56
+ }
57
+
58
+ /**
59
+ * Prepare existing row data object
60
+ *
61
+ * @param Varien_Object
62
+ */
63
+ protected function _prepareArrayRow(Varien_Object $row)
64
+ {
65
+ $row->setData(
66
+ 'option_extra_attr_' . $this->_getGroupRenderer()->calcOptionHash($row->getData('customer_group')),
67
+ 'selected="selected"'
68
+ );
69
+ }
70
+ }
app/code/community/IteraResearch/AnyRate/Model/AnyRate.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of AnyRate extension.
4
+ *
5
+ * @category IteraResearch
6
+ * @package IteraResearch_AnyRate
7
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
8
+ * @license http://www.gnu.org/licenses Lesser General Public License
9
+ */
10
+
11
+ /**
12
+ * Any rate shipping model
13
+ *
14
+ */
15
+ class IteraResearch_AnyRate_Model_AnyRate
16
+ extends Mage_Shipping_Model_Carrier_Abstract
17
+ implements Mage_Shipping_Model_Carrier_Interface
18
+ {
19
+ protected $_code = 'anyrate';
20
+ protected $_isFixed = true;
21
+
22
+ /**
23
+ * Enter description here...
24
+ *
25
+ * @param Mage_Shipping_Model_Rate_Request
26
+ * @return Mage_Shipping_Model_Rate_Result
27
+ */
28
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
29
+ {
30
+ if (!$this->getConfigFlag('active')) {
31
+ return false;
32
+ }
33
+ $freeBoxes = 0;
34
+ if ($request->getAllItems()) {
35
+ foreach ($request->getAllItems() as $item) {
36
+ if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
37
+ continue;
38
+ }
39
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
40
+ foreach ($item->getChildren() as $child) {
41
+ if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
42
+ $freeBoxes += $item->getQty() * $child->getQty();
43
+ }
44
+ }
45
+ } elseif ($item->getFreeShipping()) {
46
+ $freeBoxes += $item->getQty();
47
+ }
48
+ }
49
+ }
50
+ if (Mage::app()->getStore()->isAdmin()) {
51
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
52
+ $customerGroupId = $quote->getCustomerGroupId();
53
+ } else {
54
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
55
+ $customerGroupId = $quote->getCustomerGroupId();
56
+ }
57
+ $this->setFreeBoxes($freeBoxes);
58
+ $result = Mage::getModel('shipping/rate_result');
59
+ $customRates = unserialize($this->getConfigData('rates'));
60
+ foreach ($customRates as $customRate) {
61
+ $rateAvailable = false;
62
+ if ($customRate['customer_group'] == Mage_Customer_Model_Group::NOT_LOGGED_IN_ID || $customRate['customer_group'] == $customerGroupId){
63
+ $rateAvailable = true;
64
+ }
65
+ if ($rateAvailable) {
66
+ if ($this->getConfigData('type') == 'O') { // per order
67
+ $shippingPrice = $customRate['price'];
68
+ } elseif ($this->getConfigData('type') == 'I') { // per item
69
+ $shippingPrice = ($request->getPackageQty() * $customRate['price']) - ($this->getFreeBoxes() * $customRate['price']);
70
+ } else {
71
+ $shippingPrice = false;
72
+ }
73
+ $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
74
+ if ($shippingPrice !== false) {
75
+ $method = Mage::getModel('shipping/rate_result_method');
76
+ $method->setCarrier('anyrate');
77
+ $method->setCarrierTitle($this->getConfigData('title'));
78
+ $method->setMethod($customRate['code']);
79
+ $method->setMethodTitle($customRate['title']);
80
+ if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
81
+ $shippingPrice = '0.00';
82
+ }
83
+ $method->setPrice($shippingPrice);
84
+ $method->setCost($shippingPrice);
85
+ $result->append($method);
86
+ }
87
+ }
88
+ }
89
+ return $result;
90
+ }
91
+
92
+ public function getAllowedMethods()
93
+ {
94
+ return array (
95
+ 'anyrate' => $this->getConfigData('name')
96
+ );
97
+ }
98
+ }
app/code/community/IteraResearch/AnyRate/Model/System/Config/Backend/Rates.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file is part of AnyRate extension.
4
+ *
5
+ * @category IteraResearch
6
+ * @package IteraResearch_AnyRate
7
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
8
+ * @license http://www.gnu.org/licenses Lesser General Public License
9
+ */
10
+
11
+ class IteraResearch_AnyRate_Model_System_Config_Backend_Rates extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
12
+ {
13
+ /**
14
+ * Prepare data before save
15
+ */
16
+ protected function _beforeSave()
17
+ {
18
+ $value = $this->getValue();
19
+ foreach ($value as $code => $rate) {
20
+ if ($code != '__empty' && empty($value[$code]['code']) ) {
21
+ $value[$code]['code'] = $code;
22
+ }
23
+ }
24
+ $this->setValue($value);
25
+ parent::_beforeSave();
26
+ }
27
+ }
app/code/community/IteraResearch/AnyRate/etc/config.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * This file is part of AnyRate extension.
5
+ *
6
+ * @category IteraResearch
7
+ * @package IteraResearch_AnyRate
8
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
9
+ * @license http://www.gnu.org/licenses Lesser General Public License
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <IteraResearch_AnyRate>
15
+ <version>1.0.1</version>
16
+ </IteraResearch_AnyRate>
17
+ </modules>
18
+ <global>
19
+ <models>
20
+ <anyrate>
21
+ <class>IteraResearch_AnyRate_Model</class>
22
+ </anyrate>
23
+ </models>
24
+ <blocks>
25
+ <anyrate>
26
+ <class>IteraResearch_AnyRate_Block</class>
27
+ </anyrate>
28
+ </blocks>
29
+ <sales>
30
+ <shipping>
31
+ <carriers>
32
+ <anyrate>
33
+ <class>IteraResearch_AnyRate_Model_AnyRate</class>
34
+ </anyrate>
35
+ </carriers>
36
+ </shipping>
37
+ </sales>
38
+ </global>
39
+ <default>
40
+ <carriers>
41
+ <anyrate>
42
+ <model>anyrate/anyrate</model>
43
+ <active>1</active>
44
+ <sallowspecific>0</sallowspecific>
45
+ <title>Any Rate</title>
46
+ <type>I</type>
47
+ <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
48
+ <handling_type>F</handling_type>
49
+ </anyrate>
50
+ </carriers>
51
+ </default>
52
+ </config>
app/code/community/IteraResearch/AnyRate/etc/system.xml ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * This file is part of AnyRate extension.
5
+ *
6
+ * @category IteraResearch
7
+ * @package IteraResearch_AnyRate
8
+ * @copyright Copyright (c) 2003-2015 Itera Research, Inc. All rights reserved. (http://www.itera-research.com/)
9
+ * @license http://www.gnu.org/licenses Lesser General Public License
10
+ */
11
+ -->
12
+ <config>
13
+ <sections>
14
+ <carriers>
15
+ <groups>
16
+ <anyrate translate="label" module="adminhtml">
17
+ <label>AnyRate</label>
18
+ <frontend_type>text</frontend_type>
19
+ <sort_order>200</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ <fields>
24
+ <active translate="label">
25
+ <label>Enabled</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </active>
33
+ <title translate="label">
34
+ <label>Title</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>20</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
+ </title>
41
+ <type translate="label">
42
+ <label>Type</label>
43
+ <frontend_type>select</frontend_type>
44
+ <source_model>adminhtml/system_config_source_shipping_flatrate</source_model>
45
+ <sort_order>4</sort_order>
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
+ </type>
50
+ <rates translate="label">
51
+ <label>Rates</label>
52
+ <frontend_model>anyrate/adminhtml_form_field_rates</frontend_model>
53
+ <backend_model>anyrate/system_config_backend_rates</backend_model>
54
+ <sort_order>6</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>1</show_in_store>
58
+ </rates>
59
+ <handling_type translate="label">
60
+ <label>Calculate Handling Fee</label>
61
+ <frontend_type>select</frontend_type>
62
+ <source_model>shipping/source_handlingType</source_model>
63
+ <sort_order>7</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ </handling_type>
68
+ <handling_fee translate="label">
69
+ <label>Handling Fee</label>
70
+ <frontend_type>text</frontend_type>
71
+ <validate>validate-number validate-zero-or-greater</validate>
72
+ <sort_order>8</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>0</show_in_store>
76
+ </handling_fee>
77
+ <specificerrmsg translate="label">
78
+ <label>Displayed Error Message</label>
79
+ <frontend_type>textarea</frontend_type>
80
+ <sort_order>190</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </specificerrmsg>
85
+ <sallowspecific translate="label">
86
+ <label>Ship to Applicable Countries</label>
87
+ <frontend_type>select</frontend_type>
88
+ <sort_order>200</sort_order>
89
+ <frontend_class>shipping-applicable-country</frontend_class>
90
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>1</show_in_website>
93
+ <show_in_store>0</show_in_store>
94
+ </sallowspecific>
95
+ <specificcountry translate="label">
96
+ <label>Ship to Specific Countries</label>
97
+ <frontend_type>multiselect</frontend_type>
98
+ <sort_order>210</sort_order>
99
+ <source_model>adminhtml/system_config_source_country</source_model>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ <show_in_store>0</show_in_store>
103
+ <can_be_empty>1</can_be_empty>
104
+ </specificcountry>
105
+ <showmethod translate="label">
106
+ <label>Show Method if Not Applicable</label>
107
+ <frontend_type>select</frontend_type>
108
+ <sort_order>230</sort_order>
109
+ <frontend_class>shipping-skip-hide</frontend_class>
110
+ <source_model>adminhtml/system_config_source_yesno</source_model>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>0</show_in_store>
114
+ </showmethod>
115
+ <sort_order translate="label">
116
+ <label>Sort Order</label>
117
+ <frontend_type>text</frontend_type>
118
+ <sort_order>240</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>1</show_in_website>
121
+ <show_in_store>0</show_in_store>
122
+ </sort_order>
123
+ </fields>
124
+ </anyrate>
125
+ </groups>
126
+ </carriers>
127
+ </sections>
128
+ </config>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IteraResearch_AnyRate</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/licenses">Lesser General Public License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>AnyRate - Custom Shipping Rates</summary>
10
  <description>Allow to define multiple shipping rates with custom rate title and price. Each rate can be assigned to particular customer group, so customers from assigned group only can see the rate at the shipping method step in the checkout page.</description>
11
- <notes>Has no sql setup, supports multi-store, rates can be assigned per customer group.</notes>
12
  <authors><author><name>IteraResearch</name><user>IteraResearch</user><email>magentocommerce@itera-research.com</email></author></authors>
13
- <date>2015-06-02</date>
14
- <time>17:57:50</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="IteraResearch_AnyRate.xml" hash="83d3932fd48c92d54453ce92c0c35330"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9.1.0</max></package><extension><name>Core</name><min/><max/></extension></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IteraResearch_AnyRate</name>
4
+ <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/licenses">Lesser General Public License</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>AnyRate - Custom Shipping Rates</summary>
10
  <description>Allow to define multiple shipping rates with custom rate title and price. Each rate can be assigned to particular customer group, so customers from assigned group only can see the rate at the shipping method step in the checkout page.</description>
11
+ <notes>Has no sql setup, supports multi-store, rates can be assigned per customer group. Package content fixed.</notes>
12
  <authors><author><name>IteraResearch</name><user>IteraResearch</user><email>magentocommerce@itera-research.com</email></author></authors>
13
+ <date>2015-06-19</date>
14
+ <time>10:58:17</time>
15
+ <contents><target name="magecommunity"><dir name="IteraResearch"><dir name="AnyRate"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Group.php" hash="a92b48601aa4b0e9822c9259c6baf9f8"/><file name="Rates.php" hash="9e57b4f9f5139e962ccd71d33ee11f86"/></dir></dir></dir></dir><dir name="Model"><file name="AnyRate.php" hash="28613d909113fc30897f17628f075bd9"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Rates.php" hash="81d22e1a8ca77f7a6048516f94b5dc3b"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="5b0db614cf27994deb80d701946822ae"/><file name="system.xml" hash="ce1cad213d730205ef3a97572bfe910d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="IteraResearch_AnyRate.xml" hash="83d3932fd48c92d54453ce92c0c35330"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9.1.0</max></package><extension><name>Core</name><min/><max/></extension></required></dependencies>
18
  </package>