Version Notes
No change the database and any core file will not have influence program
Download this release
Release Info
| Developer | Ivan Zhu |
| Extension | Ivan_GroupSwitcher |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/Ivan/GroupSwitcher/Helper/Data.php +5 -0
- app/code/community/Ivan/GroupSwitcher/Model/Observer.php +76 -0
- app/code/community/Ivan/GroupSwitcher/etc/config.xml +59 -0
- app/code/community/Ivan/GroupSwitcher/etc/system.xml +48 -0
- app/etc/modules/Ivan_GroupSwitcher.xml +9 -0
- package.xml +19 -0
app/code/community/Ivan/GroupSwitcher/Helper/Data.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Ivan_GroupSwitcher_Helper_Data extends Mage_Core_Helper_Abstract {
|
| 3 |
+
|
| 4 |
+
}
|
| 5 |
+
?>
|
app/code/community/Ivan/GroupSwitcher/Model/Observer.php
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Ivan_GroupSwitcher_Model_Observer
|
| 3 |
+
{
|
| 4 |
+
/**
|
| 5 |
+
*发票事件监听方法
|
| 6 |
+
*/
|
| 7 |
+
public function switcherCustomer($observer){
|
| 8 |
+
|
| 9 |
+
$enable=Mage::getStoreConfig('groupswitcher_options/messages/enable');
|
| 10 |
+
if($enable){
|
| 11 |
+
$event = $observer->getEvent();
|
| 12 |
+
$invoice= $event->getInvoice();
|
| 13 |
+
$order=$invoice->getOrder();
|
| 14 |
+
$this->_switcherCustomer($order->getCustomerId());
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* 修改用户组
|
| 21 |
+
*/
|
| 22 |
+
public function _switcherCustomer($customerid){
|
| 23 |
+
$configArray=$this->getConfig();
|
| 24 |
+
$grandTotal=$this->getCustomerOrderTotal($customerid);
|
| 25 |
+
$upGroupId=0;
|
| 26 |
+
foreach($configArray as $key=>$config){
|
| 27 |
+
$switcherArray=explode(':',$config);
|
| 28 |
+
|
| 29 |
+
if($switcherArray && $switcherArray[1]){
|
| 30 |
+
$moneyStep1=explode('-',$switcherArray[1]);
|
| 31 |
+
if($moneyStep1){
|
| 32 |
+
|
| 33 |
+
$groupStart=(int)$moneyStep1[0];
|
| 34 |
+
$groupEnd=(int)$moneyStep1[1];
|
| 35 |
+
if($grandTotal>$groupStart && $grandTotal<$groupEnd ){
|
| 36 |
+
$upGroupId=$switcherArray[0];
|
| 37 |
+
break;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
if($upGroupId!=0){
|
| 43 |
+
$customer=Mage::getModel("customer/customer")->load($customerid);
|
| 44 |
+
$customer->setGroupId($upGroupId);
|
| 45 |
+
$customer->save();
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
*获得 配置信息
|
| 52 |
+
*/
|
| 53 |
+
public function getConfig(){
|
| 54 |
+
$configArray=array();
|
| 55 |
+
$configStr=Mage::getStoreConfig('groupswitcher_options/messages/groupcoupon');
|
| 56 |
+
$configArray=explode(",",$configStr);
|
| 57 |
+
return $configArray;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* 根据客户id获得历史订单总额
|
| 62 |
+
*/
|
| 63 |
+
public function getCustomerOrderTotal($customerid){
|
| 64 |
+
$grandTotalColl = Mage::getResourceModel('sales/order_collection')
|
| 65 |
+
->addFieldToSelect('grand_total')
|
| 66 |
+
->addFieldToFilter('customer_id', $customerid)
|
| 67 |
+
->addFieldToFilter('state', array('in' => array('processing','complete')))
|
| 68 |
+
->setOrder('created_at', 'desc')
|
| 69 |
+
;
|
| 70 |
+
$grandTotal=0;
|
| 71 |
+
foreach($grandTotalColl as $total){
|
| 72 |
+
$grandTotal+=$total['grand_total'];
|
| 73 |
+
}
|
| 74 |
+
return $grandTotal;
|
| 75 |
+
}
|
| 76 |
+
}
|
app/code/community/Ivan/GroupSwitcher/etc/config.xml
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Ivan_GroupSwitcher>
|
| 5 |
+
<version>1.0.0</version>
|
| 6 |
+
</Ivan_GroupSwitcher>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<helpers>
|
| 10 |
+
<groupswitcher>
|
| 11 |
+
<class>Ivan_GroupSwitcher_Helper</class>
|
| 12 |
+
</groupswitcher>
|
| 13 |
+
</helpers>
|
| 14 |
+
<blocks>
|
| 15 |
+
<groupswitcher>
|
| 16 |
+
<class>Ivan_GroupSwitcher_Block</class>
|
| 17 |
+
</groupswitcher>
|
| 18 |
+
</blocks>
|
| 19 |
+
<models>
|
| 20 |
+
<groupswitcher>
|
| 21 |
+
<class>Ivan_GroupSwitcher_Model</class>
|
| 22 |
+
<resourceModel>groupswitcher_mysql4</resourceModel>
|
| 23 |
+
</groupswitcher>
|
| 24 |
+
</models>
|
| 25 |
+
</global>
|
| 26 |
+
<adminhtml>
|
| 27 |
+
<events>
|
| 28 |
+
<sales_order_invoice_pay>
|
| 29 |
+
<observers>
|
| 30 |
+
<groupswitcher>
|
| 31 |
+
<type>singleton</type>
|
| 32 |
+
<class>groupswitcher/observer</class>
|
| 33 |
+
<method>switcherCustomer</method>
|
| 34 |
+
</groupswitcher>
|
| 35 |
+
</observers>
|
| 36 |
+
</sales_order_invoice_pay>
|
| 37 |
+
</events>
|
| 38 |
+
<acl>
|
| 39 |
+
<resources>
|
| 40 |
+
<admin>
|
| 41 |
+
<children>
|
| 42 |
+
<system>
|
| 43 |
+
<children>
|
| 44 |
+
<config>
|
| 45 |
+
<children>
|
| 46 |
+
<groupswitcher_options translate="title" module="groupswitcher">
|
| 47 |
+
<title>Ivan Group Switch Rules</title>
|
| 48 |
+
</groupswitcher_options>
|
| 49 |
+
</children>
|
| 50 |
+
</config>
|
| 51 |
+
|
| 52 |
+
</children>
|
| 53 |
+
</system>
|
| 54 |
+
</children>
|
| 55 |
+
</admin>
|
| 56 |
+
</resources>
|
| 57 |
+
</acl>
|
| 58 |
+
</adminhtml>
|
| 59 |
+
</config>
|
app/code/community/Ivan/GroupSwitcher/etc/system.xml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<groupswitcher translate="label" module="groupswitcher">
|
| 5 |
+
<label>Ivan</label>
|
| 6 |
+
<sort_order>5</sort_order>
|
| 7 |
+
</groupswitcher>
|
| 8 |
+
</tabs>
|
| 9 |
+
|
| 10 |
+
<sections>
|
| 11 |
+
<groupswitcher_options translate="label" module="groupswitcher">
|
| 12 |
+
<label>Customer Group Switcher</label>
|
| 13 |
+
<tab>groupswitcher</tab>
|
| 14 |
+
<sort_order>1</sort_order>
|
| 15 |
+
<show_in_default>1</show_in_default>
|
| 16 |
+
<show_in_website>1</show_in_website>
|
| 17 |
+
<show_in_store>1</show_in_store>
|
| 18 |
+
<groups>
|
| 19 |
+
<messages translate="label">
|
| 20 |
+
<label>Customer Group Switcher Settings</label>
|
| 21 |
+
<sort_order>1</sort_order>
|
| 22 |
+
<show_in_default>1</show_in_default>
|
| 23 |
+
<show_in_website>1</show_in_website>
|
| 24 |
+
<show_in_store>1</show_in_store>
|
| 25 |
+
<fields>
|
| 26 |
+
<enable translate="label">
|
| 27 |
+
<label>Enable Extension</label>
|
| 28 |
+
<frontend_type>select</frontend_type>
|
| 29 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 30 |
+
<sort_order>1</sort_order>
|
| 31 |
+
<show_in_default>1</show_in_default>
|
| 32 |
+
<show_in_website>1</show_in_website>
|
| 33 |
+
<show_in_store>1</show_in_store>
|
| 34 |
+
</enable>
|
| 35 |
+
<groupcoupon translate="label">
|
| 36 |
+
<label>Group Switcher Condition</label>
|
| 37 |
+
<frontend_type>text</frontend_type>
|
| 38 |
+
<sort_order>2</sort_order>
|
| 39 |
+
<show_in_default>1</show_in_default>
|
| 40 |
+
<show_in_website>1</show_in_website>
|
| 41 |
+
<show_in_store>1</show_in_store>
|
| 42 |
+
</groupcoupon>
|
| 43 |
+
</fields>
|
| 44 |
+
</messages>
|
| 45 |
+
</groups>
|
| 46 |
+
</groupswitcher_options>
|
| 47 |
+
</sections>
|
| 48 |
+
</config>
|
app/etc/modules/Ivan_GroupSwitcher.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Ivan_GroupSwitcher>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
</Ivan_GroupSwitcher>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Ivan_GroupSwitcher</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>According to the user history orders automatically upgrade user group</summary>
|
| 10 |
+
<description>According to the user history orders automatically upgrade user group</description>
|
| 11 |
+
<notes>No change the database and any core file will not have influence program
|
| 12 |
+
</notes>
|
| 13 |
+
<authors><author><name>Ivan Zhu</name><user>zlladmin</user><email>13652362259@139.com</email></author></authors>
|
| 14 |
+
<date>2013-04-15</date>
|
| 15 |
+
<time>03:47:37</time>
|
| 16 |
+
<contents><target name="magecommunity"><dir name="Ivan"><dir name="GroupSwitcher"><dir name="Helper"><file name="Data.php" hash="d80f3740ff6b95715282d7a9dc74e905"/></dir><dir name="Model"><file name="Observer.php" hash="ecd4d2a8a4cfa31b7bb3464c06538961"/></dir><dir name="etc"><file name="config.xml" hash="723b178f2f65978bf3629e1b27b747b6"/><file name="system.xml" hash="761ae57697f912722dcc6fc281b094b1"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ivan_GroupSwitcher.xml" hash="5d598e057a9363ce7da9adf84c709fea"/></dir></target></contents>
|
| 17 |
+
<compatible/>
|
| 18 |
+
<dependencies><required><php><min>5.2.0</min><max>5.4.7</max></php></required></dependencies>
|
| 19 |
+
</package>
|
