multidiscount - Version 0.1.1

Version Notes

No notes so far.

Download this release

Release Info

Developer Kingshuk deb
Extension multidiscount
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/local/Multidiscount/Couponcode/Block/Adminhtml/Promo/Quote/Edit/Options.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * description
29
+ *
30
+ * @category Mage
31
+ * @category Mage
32
+ * @package Mage_Adminhtml
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Multidiscount_Couponcode_Block_Adminhtml_Promo_Quote_Edit_Options
36
+ extends Mage_Adminhtml_Block_Widget
37
+ implements Varien_Data_Form_Element_Renderer_Interface
38
+ {
39
+ /**
40
+ * Initialize block
41
+ */
42
+ public function __construct()
43
+ {
44
+ $this->setTemplate('promo/options.phtml');
45
+ }
46
+
47
+ /**
48
+ * Render HTML
49
+ *
50
+ * @param Varien_Data_Form_Element_Abstract $element
51
+ * @return string
52
+ */
53
+ public function render(Varien_Data_Form_Element_Abstract $element)
54
+ {
55
+ $this->setElement($element);
56
+ return $this->toHtml();
57
+ }
58
+
59
+ protected function _prepareLayout()
60
+ {
61
+ $this->setChild('delete_button',
62
+ $this->getLayout()->createBlock('adminhtml/widget_button')
63
+ ->setData(array(
64
+ 'label' => Mage::helper('eav')->__('Delete'),
65
+ 'class' => 'delete delete-option'
66
+ )));
67
+
68
+ $this->setChild('add_button',
69
+ $this->getLayout()->createBlock('adminhtml/widget_button')
70
+ ->setData(array(
71
+ 'label' => Mage::helper('eav')->__('Add Option'),
72
+ 'class' => 'add',
73
+ 'id' => 'add_new_option_button'
74
+ )));
75
+ return parent::_prepareLayout();
76
+ }
77
+
78
+ /**
79
+ * Retrieve HTML of delete button
80
+ *
81
+ * @return string
82
+ */
83
+ public function getDeleteButtonHtml()
84
+ {
85
+ return $this->getChildHtml('delete_button');
86
+ }
87
+
88
+ /**
89
+ * Retrieve HTML of add button
90
+ *
91
+ * @return string
92
+ */
93
+ public function getAddNewButtonHtml()
94
+ {
95
+ return $this->getChildHtml('add_button');
96
+ }
97
+
98
+ public function getOptionsData(){
99
+ $this->_model = Mage::registry('current_promo_quote_rule');
100
+ if($this->_model->getId()){
101
+ return unserialize($this->_model->getCartpercentSerialized());
102
+ }
103
+ }
104
+
105
+ public function getCurrentOption(){
106
+ if($this->_model->getId()){
107
+ return $this->_model->getSimpleAction();
108
+ }
109
+ }
110
+ }
app/code/local/Multidiscount/Couponcode/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Multidiscount_Couponcode_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/Multidiscount/Couponcode/Model/Observer.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Multidiscount_Couponcode_Model_Observer extends Mage_Core_Model_Abstract
3
+ {
4
+
5
+ /**
6
+ * Add an option which will be selected for further coupon process
7
+ *
8
+ * @param Varien_Event_Observer $observer
9
+ */
10
+ public function addOptionToDropdown($observer)
11
+ {
12
+ $field = $observer->getForm()->getElement('simple_action');
13
+ $options = $field->getValues();
14
+ $options[] = array(
15
+ 'value' => Multidiscount_Couponcode_Model_Percentconst::CART_PERCENT_ACTION,
16
+ 'label' => Mage::helper('couponcode')->__('Percent amount discount for whole cart')
17
+ );
18
+ $field->setValues($options);
19
+
20
+ $fieldset = $observer->getForm()->addFieldset('cart_percentage', array('legend'=>Mage::helper('couponcode')->__('Cart percentage discount')));
21
+ $percentField = $fieldset->addField('percentdiscount', 'text', array(
22
+ 'name' => 'percentdiscount',
23
+ 'label' => Mage::helper('couponcode')->__('Percent Discount'),
24
+ 'required' => false,
25
+ ));
26
+
27
+ $percentField = $observer->getForm()->getElement('percentdiscount');
28
+
29
+ $percentField->setRenderer(
30
+ Mage::app()->getLayout()->createBlock('couponcode/adminhtml_promo_quote_edit_options')
31
+ );
32
+ }
33
+ }
app/code/local/Multidiscount/Couponcode/Model/Percentconst.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Freeproduct Module
5
+ *
6
+ * This module can be used free of carge to extend a magento system. Any other
7
+ * usage requires prior permission of the code4business Software GmbH. The module
8
+ * comes without any kind of warranty.
9
+ *
10
+ * @category C4B
11
+ * @package C4B_Freeproduct
12
+ * @author Nikolai Krambrock <freeproduct@code4business.de>
13
+ * @copyright code4business Software GmbH
14
+ * @version 0.1.0
15
+ */
16
+ class Multidiscount_Couponcode_Model_Percentconst
17
+ {
18
+ const CART_PERCENT_ACTION = 'cart_percent';
19
+ }
app/code/local/Multidiscount/Couponcode/controllers/Adminhtml/Promo/QuoteController.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once "Mage/Adminhtml/controllers/Promo/QuoteController.php";
3
+ class Multidiscount_Couponcode_Adminhtml_Promo_QuoteController extends Mage_Adminhtml_Promo_QuoteController{
4
+
5
+ /**
6
+ * Promo quote save action
7
+ *
8
+ */
9
+ public function saveAction()
10
+ {
11
+ if ($this->getRequest()->getPost()) {
12
+ try {
13
+ /** @var $model Mage_SalesRule_Model_Rule */
14
+ $model = Mage::getModel('salesrule/rule');
15
+ Mage::dispatchEvent(
16
+ 'adminhtml_controller_salesrule_prepare_save',
17
+ array('request' => $this->getRequest()));
18
+ $data = $this->getRequest()->getPost();
19
+ $data = $this->_filterDates($data, array('from_date', 'to_date'));
20
+ $id = $this->getRequest()->getParam('rule_id');
21
+ if ($id) {
22
+ $model->load($id);
23
+ if ($id != $model->getId()) {
24
+ Mage::throwException(Mage::helper('salesrule')->__('Wrong rule specified.'));
25
+ }
26
+ }
27
+
28
+ $session = Mage::getSingleton('adminhtml/session');
29
+
30
+ $validateResult = $model->validateData(new Varien_Object($data));
31
+ if ($validateResult !== true) {
32
+ foreach($validateResult as $errorMessage) {
33
+ $session->addError($errorMessage);
34
+ }
35
+ $session->setPageData($data);
36
+ $this->_redirect('*/*/edit', array('id'=>$model->getId()));
37
+ return;
38
+ }
39
+
40
+ if (isset($data['simple_action']) && $data['simple_action'] == 'by_percent'
41
+ && isset($data['discount_amount'])) {
42
+ $data['discount_amount'] = min(100,$data['discount_amount']);
43
+ }
44
+ if (isset($data['rule']['conditions'])) {
45
+ $data['conditions'] = $data['rule']['conditions'];
46
+ }
47
+ if (isset($data['rule']['actions'])) {
48
+ $data['actions'] = $data['rule']['actions'];
49
+ }
50
+ //print_r($data['option']['value']); exit;
51
+ if (isset($data['option']['value'])) {
52
+ $data['cartpercent_serialized'] = serialize($data['option']['value']);
53
+ }else{
54
+ $data['cartpercent_serialized'] = '';
55
+ }
56
+ unset($data['rule']);
57
+ $model->loadPost($data);
58
+
59
+ $useAutoGeneration = (int)!empty($data['use_auto_generation']);
60
+ $model->setUseAutoGeneration($useAutoGeneration);
61
+
62
+ $session->setPageData($model->getData());
63
+ //echo'<pre>';print_r($model->getData()); exit;
64
+ $model->save();
65
+ $session->addSuccess(Mage::helper('salesrule')->__('The rule has been saved.'));
66
+ $session->setPageData(false);
67
+ if ($this->getRequest()->getParam('back')) {
68
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
69
+ return;
70
+ }
71
+ $this->_redirect('*/*/');
72
+ return;
73
+ } catch (Mage_Core_Exception $e) {
74
+ $this->_getSession()->addError($e->getMessage());
75
+ $id = (int)$this->getRequest()->getParam('rule_id');
76
+ if (!empty($id)) {
77
+ $this->_redirect('*/*/edit', array('id' => $id));
78
+ } else {
79
+ $this->_redirect('*/*/new');
80
+ }
81
+ return;
82
+
83
+ } catch (Exception $e) {
84
+ $this->_getSession()->addError(
85
+ Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.'));
86
+ Mage::logException($e);
87
+ Mage::getSingleton('adminhtml/session')->setPageData($data);
88
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('rule_id')));
89
+ return;
90
+ }
91
+ }
92
+ $this->_redirect('*/*/');
93
+ }
94
+ }
95
+
app/code/local/Multidiscount/Couponcode/etc/config.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Multidiscount_Couponcode>
5
+ <version>0.1.0</version>
6
+ </Multidiscount_Couponcode>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <couponcode>
11
+ <class>Multidiscount_Couponcode_Block</class>
12
+ </couponcode>
13
+ </blocks>
14
+ <models>
15
+ <couponcode>
16
+ <class>Multidiscount_Couponcode_Model</class>
17
+ </couponcode>
18
+ </models>
19
+ <helpers>
20
+ <couponcode>
21
+ <class>Multidiscount_Couponcode_Helper</class>
22
+ </couponcode>
23
+ </helpers>
24
+ <resources>
25
+ <couponcode_setup>
26
+ <setup>
27
+ <module>Multidiscount_Couponcode</module>
28
+ </setup>
29
+ <connection>
30
+ <use>core_setup</use>
31
+ </connection>
32
+ </couponcode_setup>
33
+ <couponcode_write>
34
+ <connection>
35
+ <use>core_write</use>
36
+ </connection>
37
+ </couponcode_write>
38
+ <couponcode_read>
39
+ <connection>
40
+ <use>core_read</use>
41
+ </connection>
42
+ </couponcode_read>
43
+ </resources>
44
+ </global>
45
+ <admin>
46
+ <routers>
47
+ <adminhtml>
48
+ <args>
49
+ <modules>
50
+ <Multidiscount_Couponcode_Adminhtml before="Mage_Adminhtml">Multidiscount_Couponcode_Adminhtml</Multidiscount_Couponcode_Adminhtml>
51
+ </modules>
52
+ </args>
53
+ </adminhtml>
54
+ </routers>
55
+ </admin>
56
+ <adminhtml>
57
+ <events>
58
+ <adminhtml_block_salesrule_actions_prepareform>
59
+ <observers>
60
+ <multidiscount>
61
+ <type>model</type>
62
+ <class>couponcode/observer</class>
63
+ <method>addOptionToDropdown</method>
64
+ </multidiscount>
65
+ </observers>
66
+ </adminhtml_block_salesrule_actions_prepareform>
67
+ </events>
68
+ </adminhtml>
69
+ </config>
app/code/local/Multidiscount/Couponcode/sql/couponcode_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $installer->getConnection()
6
+ ->addColumn($installer->getTable('salesrule'),'cartpercent_serialized', array(
7
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
8
+ 'nullable' => yes,
9
+ 'after' => 'actions_serialized', // column name to insert new column after
10
+ 'default' => NULL,
11
+ 'comment' => 'Cart percent rule'
12
+ ));
13
+ $installer->endSetup();
app/etc/modules/Multidiscount_Couponcode.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Multidiscount_Couponcode>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Multidiscount_Couponcode>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Multidiscount_Couponcode</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>Use same coupon code for multiple discounts based on cart total</summary>
10
+ <description>Its an extension which will provide you the ability to create a coupon code with multiple discount percentages.&#xD;
11
+ Like if you want to provide discount for &#xD;
12
+ &#xD;
13
+ 100-500 discount will be 10%&#xD;
14
+ 500-1000 discount will be 20%&#xD;
15
+ 1000-2000 discount will be 30%&#xD;
16
+ &#xD;
17
+ and so on.&#xD;
18
+ &#xD;
19
+ You just need to create a single coupon code and need to add from what amount to what amount how much discount you want to provide.</description>
20
+ <notes>No notes so far.</notes>
21
+ <authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
22
+ <date>2016-06-13</date>
23
+ <time>20:26:15</time>
24
+ <contents><target name="magelocal"><dir name="Multidiscount"><dir name="Couponcode"><dir name="Block"><dir name="Adminhtml"><dir name="Promo"><dir name="Quote"><dir name="Edit"><file name="Options.php" hash="b251dd1751fb49adaa0143fe63b357e4"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="16e670874b16e6ea0f0a318fbae54c05"/></dir><dir name="Model"><file name="Observer.php" hash="cc58c72bed15cd57dedf24e0e64cf22d"/><file name="Percentconst.php" hash="c566016651e421e291039314231e1eb1"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Promo"><file name="QuoteController.php" hash="630cf0a5e3daa42a1f1b32edb6378197"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="4bd72e17b68dcc4afa981ae32462820b"/></dir><dir name="sql"><dir name="couponcode_setup"><file name="mysql4-install-0.1.0.php" hash="dcaebeba905eb8719f5e218fd91e8794"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Multidiscount_Couponcode.xml" hash="c30e1bd8c3f55c2710f2aa2f360c98f0"/></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
27
+ </package>