Minimumorderamount_Customergroup - Version 1.0.0

Version Notes

Initially minimum order amount is added to the customer group,further more enhancement in next version upload.

Download this release

Release Info

Developer Commerce Bees
Extension Minimumorderamount_Customergroup
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Ameex/MinimumOrderAmount/Block/Customer/Group/Edit/Form.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Block_Customer_Group_Edit_Form extends Mage_Adminhtml_Block_Customer_Group_Edit_Form
3
+ {
4
+ protected function _prepareLayout()
5
+ {
6
+ parent::_prepareLayout();
7
+ $form = new Varien_Data_Form();
8
+ $customerGroup = Mage::registry('current_group');
9
+
10
+ $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('customer')->__('Group Information')));
11
+
12
+ $validateClass = sprintf('required-entry validate-length maximum-length-%d',
13
+ Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH);
14
+ $name = $fieldset->addField('customer_group_code', 'text',
15
+ array(
16
+ 'name' => 'code',
17
+ 'label' => Mage::helper('customer')->__('Group Name'),
18
+ 'title' => Mage::helper('customer')->__('Group Name'),
19
+ 'note' => Mage::helper('customer')->__('Maximum length must be less then %s symbols', Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH),
20
+ 'class' => $validateClass,
21
+ 'required' => true,
22
+ )
23
+ );
24
+
25
+ if ($customerGroup->getId()==0 && $customerGroup->getCustomerGroupCode() ) {
26
+ $name->setDisabled(true);
27
+ }
28
+
29
+ $fieldset->addField('tax_class_id', 'select',
30
+ array(
31
+ 'name' => 'tax_class',
32
+ 'label' => Mage::helper('customer')->__('Tax Class'),
33
+ 'title' => Mage::helper('customer')->__('Tax Class'),
34
+ 'class' => 'required-entry',
35
+ 'required' => true,
36
+ 'values' => Mage::getSingleton('tax/class_source_customer')->toOptionArray()
37
+ )
38
+ );
39
+
40
+ $fieldset->addField('minimum_order_amount', 'text',
41
+ array(
42
+ 'name' => 'minimum_order_amount',
43
+ 'label' => Mage::helper('customer')->__('Minimum Order Amount'),
44
+ 'title' => Mage::helper('customer')->__('Minimum Order Amount'),
45
+ 'class' => 'required-entry',
46
+ 'required' => true,
47
+ )
48
+ );
49
+
50
+ if (!is_null($customerGroup->getId())) {
51
+ // If edit add id
52
+ $form->addField('id', 'hidden',
53
+ array(
54
+ 'name' => 'id',
55
+ 'value' => $customerGroup->getId(),
56
+ )
57
+ );
58
+ }
59
+
60
+ if( Mage::getSingleton('adminhtml/session')->getCustomerGroupData() ) {
61
+ $form->addValues(Mage::getSingleton('adminhtml/session')->getCustomerGroupData());
62
+ Mage::getSingleton('adminhtml/session')->setCustomerGroupData(null);
63
+ } else {
64
+ $form->addValues($customerGroup->getData());
65
+ }
66
+
67
+ $form->setUseContainer(true);
68
+ $form->setId('edit_form');
69
+ $form->setAction($this->getUrl('*/*/save'));
70
+ $this->setForm($form);
71
+ }
72
+ }
app/code/community/Ameex/MinimumOrderAmount/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/community/Ameex/MinimumOrderAmount/Model/MinimumOrderAmount.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Model_Blogpost extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('minimumorderamount/minimumorderamount');
7
+ }
8
+ }
9
+
app/code/community/Ameex/MinimumOrderAmount/Model/Mysql4/MinimumOrderAmount.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Model_Mysql4_Blogpost extends Mage_Core_Model_Mysql4_Abstract{
3
+ protected function _construct()
4
+ {
5
+ $this->_init('minimumorderamount/minimumorderamount', 'id');
6
+ }
7
+ }
app/code/community/Ameex/MinimumOrderAmount/Model/Mysql4/MinimumOrderAmount/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Model_Mysql4_Blogpost_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('minimumorderamount/minimumorderamount');
7
+ }
8
+ }
9
+
app/code/community/Ameex/MinimumOrderAmount/Model/Quote/Address.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Model_Quote_Address extends Mage_Sales_Model_Quote_Address
3
+ {
4
+
5
+ public function validateMinimumAmount()
6
+ {
7
+ $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
8
+ $role = Mage::getSingleton('customer/group')->load($roleId)->getData('minimum_order_amount');
9
+ $role = strtolower($role);
10
+ $storeId = $this->getQuote()->getStoreId();
11
+ if (!Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId)) {
12
+ return true;
13
+ }
14
+
15
+ if ($this->getQuote()->getIsVirtual() && $this->getAddressType() == self::TYPE_SHIPPING) {
16
+ return true;
17
+ } elseif (!$this->getQuote()->getIsVirtual() && $this->getAddressType() != self::TYPE_SHIPPING) {
18
+ return true;
19
+ }
20
+
21
+ $amount = Mage::getSingleton('customer/group')->load($roleId)->getData('minimum_order_amount');
22
+ if ($this->getBaseSubtotalWithDiscount() < $amount) {
23
+ return false;
24
+ }
25
+ return true;
26
+
27
+
28
+
29
+
30
+
31
+
32
+ }
33
+ }
app/code/community/Ameex/MinimumOrderAmount/Model/Resource/Setup.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Ameex_MinimumOrderAmount_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
3
+ {
4
+ }
app/code/community/Ameex/MinimumOrderAmount/controllers/Adminhtml/Customer/GroupController.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Adminhtml/controllers/Customer/GroupController.php';
3
+ class Ameex_MinimumOrderAmount_Adminhtml_Customer_GroupController extends Mage_Adminhtml_Customer_GroupController
4
+ {
5
+ public function saveAction()
6
+ {
7
+ $customerGroup = Mage::getModel('customer/group');
8
+ $id = $this->getRequest()->getParam('id');
9
+ if (!is_null($id)) {
10
+ $customerGroup->load((int)$id);
11
+ }
12
+
13
+ $taxClass = (int)$this->getRequest()->getParam('tax_class');
14
+
15
+ if ($taxClass) {
16
+ try {
17
+ $customerGroupCode = (string)$this->getRequest()->getParam('code');
18
+ //replace "code" with the name of the field
19
+ $minimumOrderAmount = (string)$this->getRequest()->getParam('minimum_order_amount');
20
+
21
+ if (!empty($customerGroupCode)) {
22
+ $customerGroup->setCode($customerGroupCode);
23
+ }
24
+
25
+ $customerGroup->setTaxClassId($taxClass);
26
+ $customerGroup->setMinimumOrderAmount($minimumOrderAmount)->save();
27
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been saved.'));
28
+ $this->getResponse()->setRedirect($this->getUrl('*/customer_group'));
29
+ return;
30
+ } catch (Exception $e) {
31
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
32
+ Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData());
33
+ $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', array('id' => $id)));
34
+ return;
35
+ }
36
+ } else {
37
+ $this->_forward('new');
38
+ }
39
+
40
+ }
41
+
42
+ }
app/code/community/Ameex/MinimumOrderAmount/controllers/CartController.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(Mage::getModuleDir('controllers','Mage_Checkout').DS.'CartController.php');
3
+
4
+ class Ameex_MinimumOrderAmount_CartController extends Mage_Checkout_CartController
5
+ {
6
+ public function indexAction()
7
+ {
8
+ $cart = $this->_getCart();
9
+ if ($cart->getQuote()->getItemsCount()) {
10
+ $cart->init();
11
+ $cart->save();
12
+
13
+ if (!$this->_getQuote()->validateMinimumAmount()) {
14
+ $error_message = Mage::getStoreConfig("sales/minimum_order/error_message");
15
+ $minimumAmount = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())
16
+ ->toCurrency(Mage::getSingleton('customer/group')->load($roleId)->getData('minimum_order_amount'));
17
+
18
+ $warning = Mage::helper('checkout')->__("$error_message %s", $minimumAmount);
19
+
20
+ $cart->getCheckoutSession()->addNotice($warning);
21
+ }
22
+ }
23
+
24
+ // Compose array of messages to add
25
+ $messages = array();
26
+ foreach ($cart->getQuote()->getMessages() as $message) {
27
+ if ($message) {
28
+ // Escape HTML entities in quote message to prevent XSS
29
+ $message->setCode(Mage::helper('core')->escapeHtml($message->getCode()));
30
+ $messages[] = $message;
31
+ }
32
+ }
33
+ $cart->getCheckoutSession()->addUniqueMessages($messages);
34
+
35
+ /**
36
+ * if customer enteres shopping cart we should mark quote
37
+ * as modified bc he can has checkout page in another window.
38
+ */
39
+ $this->_getSession()->setCartWasUpdated(true);
40
+
41
+ Varien_Profiler::start(__METHOD__ . 'cart_display');
42
+ $this
43
+ ->loadLayout()
44
+ ->_initLayoutMessages('checkout/session')
45
+ ->_initLayoutMessages('catalog/session')
46
+ ->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart'));
47
+ $this->renderLayout();
48
+ Varien_Profiler::stop(__METHOD__ . 'cart_display');
49
+ }
50
+
51
+ }
app/code/community/Ameex/MinimumOrderAmount/etc/config.xml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ameex_MinimumOrderAmount>
5
+ <version>1.0.0</version>
6
+ </Ameex_MinimumOrderAmount>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <checkout>
11
+ <args>
12
+ <modules>
13
+ <ameex_minimumorderamount before="Mage_Checkout">Ameex_MinimumOrderAmount</ameex_minimumorderamount>
14
+ </modules>
15
+ </args>
16
+ </checkout>
17
+ </routers>
18
+ </frontend>
19
+ <admin>
20
+ <routers>
21
+ <adminhtml>
22
+ <args>
23
+ <modules>
24
+ <ameex_minimumorderamount before="Mage_Adminhtml">Ameex_MinimumOrderAmount_Adminhtml</ameex_minimumorderamount>
25
+
26
+ </modules>
27
+ </args>
28
+ </adminhtml>
29
+ </routers>
30
+ </admin>
31
+ <global>
32
+ <blocks>
33
+ <minimumorderamount>
34
+ <class>Ameex_MinimumOrderAmount_Block</class>
35
+ </minimumorderamount>
36
+ <adminhtml>
37
+ <rewrite>
38
+ <customer_group_edit_form>Ameex_MinimumOrderAmount_Block_Customer_Group_Edit_Form</customer_group_edit_form>
39
+ </rewrite>
40
+ </adminhtml>
41
+ </blocks>
42
+ <helpers>
43
+ <minimumorderamount>
44
+ <class>Ameex_MinimumOrderAmount_Helper</class>
45
+ </minimumorderamount>
46
+ </helpers>
47
+ <models>
48
+ <minimumorderamount>
49
+ <class>Ameex_MinimumOrderAmount_Model</class>
50
+ </minimumorderamount>
51
+ <sales>
52
+ <rewrite>
53
+ <!-- Model -->
54
+ <quote_address>Ameex_MinimumOrderAmount_Model_Quote_Address</quote_address>
55
+ </rewrite>
56
+ </sales>
57
+ <minimumorderamount>
58
+ <class>Ameex_MinimumOrderAmount_Model</class>
59
+ </minimumorderamount>
60
+ </models>
61
+ <resources>
62
+ <minimumorderamount_setup>
63
+ <setup>
64
+ <module>Ameex_MinimumOrderAmount</module>
65
+ <class>Ameex_MinimumOrderAmount_Model_Resource_Setup</class>
66
+ </setup>
67
+ <connection>
68
+ <use>core_setup</use>
69
+ </connection>
70
+ </minimumorderamount_setup>
71
+ <minimumorderamount_write>
72
+ <connection>
73
+ <use>core_write</use>
74
+ </connection>
75
+ </minimumorderamount_write>
76
+ <minimumorderamount_read>
77
+ <connection>
78
+ <use>core_read</use>
79
+ </connection>
80
+ </minimumorderamount_read>
81
+ </resources>
82
+ </global>
83
+ </config>
app/code/community/Ameex/MinimumOrderAmount/sql/minimumorderamount_setup/install-1.0.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run("ALTER TABLE {$this->getTable('customer/customer_group')} ADD COLUMN `minimum_order_amount`int(11) NOT NULL;");
5
+ $installer->endSetup();
app/etc/modules/Ameex_MinimumOrderAmount.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Ameex_MinimumOrderAmount>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Ameex_MinimumOrderAmount>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Minimumorderamount_Customergroup</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>By using this module we can able to restrict the minimum order amount based on the customer group.</summary>
10
+ <description>This module mainly used to restrict the minimum purchase amount based on the customer group.We have to set the minimum order amount for each customer group.When the customer logged in the site, First the module verifies which group the customer belongs to,After that based on the customer group it will fetch the minimum order amount and restrict the minimum purchase value.</description>
11
+ <notes>Initially minimum order amount is added to the customer group,further more enhancement in next version upload.</notes>
12
+ <authors><author><name>commercebees</name><user>CommerceBees</user><email>support@commercebees.com</email></author><author><name>parthipan p</name><user>parthipan_ameex</user><email>p.parthi001@gmail.com</email></author></authors>
13
+ <date>2015-09-02</date>
14
+ <time>15:34:59</time>
15
+ <contents><target name="magecommunity"><dir><dir name="Ameex"><dir name="MinimumOrderAmount"><dir><dir name="Block"><dir name="Customer"><dir name="Group"><dir name="Edit"><file name="Form.php" hash="69bd79993c3ef210725989ba9f021f36"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0e3bee810ad4de0c7294028750083e83"/></dir><dir name="Model"><file name="MinimumOrderAmount.php" hash="397d0250d17fb96c86a92ffa60494c5d"/><dir name="Mysql4"><dir name="MinimumOrderAmount"><file name="Collection.php" hash="55fbdda7c0ffa86bab7807952246ef99"/></dir><file name="MinimumOrderAmount.php" hash="e11f3b2b11026ee3a7fb0ec8ba09b0a2"/></dir><dir name="Quote"><file name="Address.php" hash="f48f66e866b70d1f071eedef40c8bf18"/></dir><dir name="Resource"><file name="Setup.php" hash="787c23945c0e981d29bbb4022f63e285"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Customer"><file name="GroupController.php" hash="3d009643043ccff2f81eff460619490d"/></dir></dir><file name="CartController.php" hash="f618f9de8d86c5e08f5f749d53f44461"/></dir><dir name="etc"><file name="config.xml" hash="14bcd573ad2b6e62e5199fc7122f98dd"/></dir><dir name="sql"><dir name="minimumorderamount_setup"><file name="install-1.0.0.php" hash="068a5c12703622942320064a42cfff07"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Ameex_MinimumOrderAmount.xml" hash="ccca4c6a6d6513c36972a34f0bc6392b"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>