Apt_SalesRule - Version 0.1.1

Version Notes

Initial version

Download this release

Release Info

Developer prax Ahir
Extension Apt_SalesRule
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/local/Apt/SalesRule/Model/Observer.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Apt
6
+ * @package Apt_SalesRule
7
+ */
8
+
9
+ class Apt_SalesRule_Model_Observer
10
+ {
11
+ public function addCustomerField(Varien_Event_Observer $observer)
12
+ {
13
+ $model = Mage::registry('current_promo_quote_rule');
14
+ $form = $observer->getEvent()->getForm();
15
+ $fieldset = $form->getElement('base_fieldset');
16
+ $fieldset->addField('customer_id', 'multiselect', array(
17
+ 'name' => 'customer_id',
18
+ 'label' => Mage::helper('salesrule')->__('Assign Customer'),
19
+ 'title' => Mage::helper('salesrule')->__('Assign Customer'),
20
+ 'required' => true,
21
+ 'values' => $this->getCustomerOption(),
22
+ ),'customer_group_ids');
23
+ $form->setValues($model->getData());
24
+ return $this;
25
+ }
26
+
27
+ protected function getCustomerOption()
28
+ {
29
+ $collection = Mage::getResourceModel('customer/customer_collection')->addAttributeToSelect(array('firstname','lastname'));
30
+ $option = array();
31
+ $option[] = array('value'=> '0', 'label'=>Mage::helper('adminhtml')->__('All Customer'));
32
+ foreach($collection as $_customer) {
33
+ $option[] = array('value'=>$_customer->getId(), 'label'=> $_customer->getName());
34
+ }
35
+ return $option;
36
+ }
37
+ }
app/code/local/Apt/SalesRule/Model/Observer/Customer.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Apt
6
+ * @package Apt_SalesRule
7
+ */
8
+
9
+ class Apt_SalesRule_Model_Observer_Customer
10
+ {
11
+ public function saveCustomer(Varien_Event_Observer $observer)
12
+ {
13
+ $rule = $observer->getEvent()->getRule();
14
+ $customerId = $rule->getCustomerId();
15
+ if(is_array($customerId))
16
+ {
17
+ $rule->setCustomerId(implode(',',$customerId));
18
+ }
19
+ return $this;
20
+ }
21
+
22
+ }
app/code/local/Apt/SalesRule/Model/Validator.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * @category Apt
6
+ * @package Apt_SalesRule
7
+ */
8
+ class Apt_SalesRule_Model_Validator extends Mage_SalesRule_Model_Validator
9
+ {
10
+
11
+ protected function _canProcessRule($rule, $address)
12
+ {
13
+ $customerId = $address->getQuote()->getCustomerId();
14
+ $allowCustomerIds = explode(',',$rule->getCustomerId());
15
+
16
+
17
+
18
+ if(!in_array($customerId, $allowCustomerIds) && !in_array(0, $allowCustomerIds)) {
19
+ $address->getQuote()->setCouponCode(NULL);
20
+ $rule->setIsValidForAddress($address, false);
21
+ return false;
22
+ }
23
+ else{
24
+ return parent::_canProcessRule($rule, $address);
25
+ }
26
+
27
+ }
28
+ }
app/code/local/Apt/SalesRule/etc/config.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * @category Apt
7
+ * @package Apt_SalesRule
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Apt_SalesRule>
13
+ <version>0.1.1</version>
14
+ </Apt_SalesRule>
15
+ </modules>
16
+ <global>
17
+ <resources>
18
+ <apt_salesrule_setup>
19
+ <setup>
20
+ <module>Apt_SalesRule</module>
21
+ <class>Mage_Sales_Model_Resource_Setup</class>
22
+ </setup>
23
+ </apt_salesrule_setup>
24
+ </resources>
25
+ <models>
26
+ <apt_salesrule>
27
+ <class>Apt_SalesRule_Model</class>
28
+ </apt_salesrule>
29
+ <salesrule>
30
+ <rewrite>
31
+ <validator>Apt_SalesRule_Model_Validator</validator>
32
+ </rewrite>
33
+ </salesrule>
34
+ </models>
35
+ </global>
36
+ <adminhtml>
37
+ <events>
38
+ <adminhtml_promo_quote_edit_tab_main_prepare_form>
39
+ <observers>
40
+ <apt_salesrule_add_customer>
41
+ <class>Apt_SalesRule_Model_Observer</class>
42
+ <method>addCustomerField</method>
43
+ </apt_salesrule_add_customer>
44
+ </observers>
45
+ </adminhtml_promo_quote_edit_tab_main_prepare_form>
46
+
47
+ <salesrule_rule_save_before>
48
+ <observers>
49
+ <apt_salesrule_add_customer>
50
+ <class>Apt_SalesRule_Model_Observer_Customer</class>
51
+ <method>saveCustomer</method>
52
+ </apt_salesrule_add_customer>
53
+ </observers>
54
+ </salesrule_rule_save_before>
55
+
56
+ </events>
57
+ </adminhtml>
58
+ </config>
app/code/local/Apt/SalesRule/sql/apt_salesrule_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Medma Avatar Module.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Team
8
+ * that is bundled with this package of Medma Infomatix Pvt. Ltd.
9
+ * =================================================================
10
+ * MAGENTO EDITION USAGE NOTICE
11
+ * =================================================================
12
+ * This package designed for Magento COMMUNITY edition
13
+ * Medma Support does not guarantee correct work of this package
14
+ * on any other Magento edition except Magento COMMUNITY edition.
15
+ * =================================================================
16
+ */
17
+ ?>
18
+ <?php
19
+
20
+ $installer = $this;
21
+ $installer->startSetup();
22
+
23
+ //$setup = Mage::getModel('customer/entity_setup', 'core_setup');
24
+
25
+ $installer->getConnection()
26
+ ->addColumn(
27
+ $installer->getTable('salesrule/rule'),
28
+ 'customer_id',
29
+ array(
30
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
31
+ 'length' => '255',
32
+ 'nullable' => false,
33
+ 'default' => 0,
34
+ 'comment' => 'Customer Id',
35
+ )
36
+ );
37
+
38
+ $installer->endSetup();
app/etc/modules/Apt_SalesRule.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Apt
5
+ * @package Apt_SalesRule
6
+ */
7
+ -->
8
+ <config>
9
+ <modules>
10
+ <Apt_SalesRule>
11
+ <active>true</active>
12
+ <codePool>local</codePool>
13
+ </Apt_SalesRule>
14
+ </modules>
15
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Apt_SalesRule</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Customer wise coupon.</summary>
10
+ <description>Customer wise coupon. admin can assign a coupon to customer.</description>
11
+ <notes>Initial version</notes>
12
+ <authors><author><name>prax Ahir</name><user>praxahir</user><email>info@aptwebdesign.com</email></author></authors>
13
+ <date>2014-07-01</date>
14
+ <time>07:07:43</time>
15
+ <contents><target name="magelocal"><dir name="Apt"><dir name="SalesRule"><dir name="Model"><dir name="Observer"><file name="Customer.php" hash="9658ea4c118e75b59c833075ed24cf44"/></dir><file name="Observer.php" hash="af848ae392158a6a2b89307802a89710"/><file name="Validator.php" hash="a5f7d32dd1a91a4f649d9d1531f0a853"/></dir><dir name="etc"><file name="config.xml" hash="7e5b661f3ea1360590122b40944e7ee0"/></dir><dir name="sql"><dir name="apt_salesrule_setup"><file name="mysql4-install-0.1.0.php" hash="23f06669a7baf644c14955df2497e0fe"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apt_SalesRule.xml" hash="868c2dfc61c7f5389589ca68fc2e6090"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>