import_export_cart_price_rules_coupon - Version 0.1.0

Version Notes

Import Export Coupon with Shopping Cart Price Rules

Download this release

Release Info

Developer Praful Rajput
Extension import_export_cart_price_rules_coupon
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Bdt/Coupon/Block/Adminhtml/Promo/Quote.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
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) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+
27
+ /**
28
+ * Catalog price rules
29
+ *
30
+ * @category Mage
31
+ * @category Mage
32
+ * @package Mage_Adminhtml
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+
36
+ class Bdt_Coupon_Block_Adminhtml_Promo_Quote extends Mage_Adminhtml_Block_Promo_Quote
37
+ {
38
+ public function __construct()
39
+ {
40
+ $this->_addButton('import', array(
41
+ 'label' => Mage::helper('coupon')->__('Import Coupons'),
42
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/import') .'\')',
43
+ 'class' => 'import',
44
+ ));
45
+ parent::__construct();
46
+
47
+ }
48
+ }
app/code/local/Bdt/Coupon/Block/Adminhtml/Promo/Quote/Grid.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
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) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+
27
+ /**
28
+ Override by Developer
29
+ */
30
+ class Bdt_Coupon_Block_Adminhtml_Promo_Quote_Grid extends Mage_Adminhtml_Block_Promo_Quote_Grid
31
+ {
32
+ /**
33
+ * Initialize grid
34
+ * Set sort settings
35
+ */
36
+ public function __construct()
37
+ {
38
+ parent::__construct();
39
+ $this->setId('promo_quote_grid');
40
+ $this->setDefaultSort('sort_order');
41
+ $this->setDefaultDir('ASC');
42
+ $this->setSaveParametersInSession(true);
43
+ }
44
+
45
+ /**
46
+ * Add websites to sales rules collection
47
+ * Set collection
48
+ *
49
+ * @return Mage_Adminhtml_Block_Promo_Quote_Grid
50
+ */
51
+ protected function _prepareCollection()
52
+ {
53
+ /** @var $collection Mage_SalesRule_Model_Mysql4_Rule_Collection */
54
+ $collection = Mage::getModel('salesrule/rule')
55
+ ->getResourceCollection();
56
+ $collection->addWebsitesToResult();
57
+ $this->setCollection($collection);
58
+
59
+ parent::_prepareCollection();
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Add grid columns
65
+ *
66
+ * @return Mage_Adminhtml_Block_Promo_Quote_Grid
67
+ */
68
+ protected function _prepareColumns()
69
+ {
70
+ $this->addColumn('rule_id', array(
71
+ 'header' => Mage::helper('salesrule')->__('ID'),
72
+ 'align' =>'right',
73
+ 'width' => '50px',
74
+ 'index' => 'rule_id',
75
+ ));
76
+
77
+ $this->addColumn('name', array(
78
+ 'header' => Mage::helper('salesrule')->__('Rule Name'),
79
+ 'align' =>'left',
80
+ 'index' => 'name',
81
+ ));
82
+
83
+ $this->addColumn('coupon_code', array(
84
+ 'header' => Mage::helper('salesrule')->__('Coupon Code'),
85
+ 'align' => 'left',
86
+ 'width' => '150px',
87
+ 'index' => 'code',
88
+ ));
89
+
90
+ $this->addColumn('from_date', array(
91
+ 'header' => Mage::helper('salesrule')->__('Date Start'),
92
+ 'align' => 'left',
93
+ 'width' => '120px',
94
+ 'type' => 'date',
95
+ 'index' => 'from_date',
96
+ ));
97
+
98
+ $this->addColumn('to_date', array(
99
+ 'header' => Mage::helper('salesrule')->__('Date Expire'),
100
+ 'align' => 'left',
101
+ 'width' => '120px',
102
+ 'type' => 'date',
103
+ 'default' => '--',
104
+ 'index' => 'to_date',
105
+ ));
106
+
107
+ $this->addColumn('is_active', array(
108
+ 'header' => Mage::helper('salesrule')->__('Status'),
109
+ 'align' => 'left',
110
+ 'width' => '80px',
111
+ 'index' => 'is_active',
112
+ 'type' => 'options',
113
+ 'options' => array(
114
+ 1 => 'Active',
115
+ 0 => 'Inactive',
116
+ ),
117
+ ));
118
+
119
+ if (!Mage::app()->isSingleStoreMode()) {
120
+ $this->addColumn('rule_website', array(
121
+ 'header' => Mage::helper('salesrule')->__('Website'),
122
+ 'align' =>'left',
123
+ 'index' => 'website_ids',
124
+ 'type' => 'options',
125
+ 'sortable' => false,
126
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(),
127
+ 'width' => 200,
128
+ ));
129
+ }
130
+
131
+ $this->addColumn('sort_order', array(
132
+ 'header' => Mage::helper('salesrule')->__('Priority'),
133
+ 'align' => 'right',
134
+ 'index' => 'sort_order',
135
+ 'width' => 100,
136
+ ));
137
+ $this->addColumn('times_used', array(
138
+ 'header' => Mage::helper('salesrule')->__('Times Used'),
139
+ 'align' =>'left',
140
+ 'index' => 'times_used',
141
+ 'width' => 100,
142
+ ));
143
+
144
+ $this->addExportType('*/*/exportCsv', Mage::helper('coupon')->__('CSV'));
145
+ // $this->addExportType('*/*/exportXml', Mage::helper('coupon')->__('XML'));
146
+ parent::_prepareColumns();
147
+ return $this;
148
+ }
149
+
150
+ /**
151
+ * Retrieve row click URL
152
+ *
153
+ * @param Varien_Object $row
154
+ *
155
+ * @return string
156
+ */
157
+ public function getRowUrl($row)
158
+ {
159
+ return $this->getUrl('*/*/edit', array('id' => $row->getRuleId()));
160
+ }
161
+
162
+ }
app/code/local/Bdt/Coupon/Block/Adminhtml/Promo/Quote/Import.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mirasvit
4
+ *
5
+ * This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/.
6
+ * Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
7
+ * If you wish to customize this module for your needs.
8
+ * Please refer to http://www.magentocommerce.com for more information.
9
+ *
10
+ * @category Mirasvit
11
+ * @package Sphinx Search Ultimate
12
+ * @version 2.3.2
13
+ * @build 939
14
+ * @copyright Copyright (C) 2014 Mirasvit (http://mirasvit.com/)
15
+ */
16
+
17
+
18
+ /**
19
+ * Блок импорта синонимов
20
+ *
21
+ * @category Mirasvit
22
+ * @package Mirasvit_SearchSphinx
23
+ */
24
+ class Bdt_Coupon_Block_Adminhtml_Promo_Quote_Import extends Mage_Adminhtml_Block_Widget_Form_Container
25
+ {
26
+
27
+ protected $_buttomLabel = '';
28
+
29
+ public function __construct ()
30
+ {
31
+ parent::__construct();
32
+ $this->_objectId = 'id';
33
+ $this->_controller = 'adminhtml_promo_quote';
34
+ $this->_mode = 'import';
35
+ $this->_blockGroup = 'coupon';
36
+
37
+ $this->getDictionaries();
38
+
39
+ $this->_updateButton('save', 'label', $this->getLabel());
40
+ return $this;
41
+ }
42
+
43
+ public function getHeaderText ()
44
+ {
45
+ return Mage::helper('coupon')->__('Import Coupons');
46
+ }
47
+ protected function getDictionaries()
48
+ {
49
+ $values = array();
50
+ $path = Mage::getBaseDir('media').DS.'import'.DS.'coupon'.DS;
51
+ if (file_exists($path)) {
52
+ if ($handle = opendir($path)) {
53
+ while (false !== ($entry = readdir($handle))) {
54
+ if (substr($entry, 0, 1) != '.' ) {
55
+ $r = pathinfo($entry);
56
+ if($r['extension'] == 'csv') {
57
+ $values[] = array(
58
+ 'label' => $entry,
59
+ 'value' => $path . DS . $entry
60
+ );
61
+ }
62
+ }
63
+ }
64
+ closedir($handle);
65
+ }
66
+ if (count($values) == 0) {
67
+ $this->_buttomLabel = Mage::helper('coupon')->__('Save & Continue');
68
+ return;
69
+ }
70
+ } else {
71
+ $this->_buttomLabel = Mage::helper('coupon')->__('Save & Continue');
72
+ return;
73
+ }
74
+ $this->_buttomLabel = Mage::helper('coupon')->__('Import Coupons');
75
+ return;
76
+ }
77
+
78
+ public function getLabel(){
79
+ return $this->_buttomLabel;
80
+ }
81
+ }
app/code/local/Bdt/Coupon/Block/Adminhtml/Promo/Quote/Import/Form.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mirasvit
4
+ *
5
+ * This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/.
6
+ * Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
7
+ * If you wish to customize this module for your needs.
8
+ * Please refer to http://www.magentocommerce.com for more information.
9
+ *
10
+ * @category Mirasvit
11
+ * @package Sphinx Search Ultimate
12
+ * @version 2.3.2
13
+ * @build 939
14
+ * @copyright Copyright (C) 2014 Mirasvit (http://mirasvit.com/)
15
+ */
16
+
17
+
18
+ /**
19
+ * Форма импорта синонимов
20
+ *
21
+ * @category Mirasvit
22
+ * @package Mirasvit_SearchSphinx
23
+ */
24
+ class Bdt_Coupon_Block_Adminhtml_Promo_Quote_Import_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+
27
+ protected function _prepareForm()
28
+ {
29
+
30
+ $form = new Varien_Data_Form(array(
31
+ 'id' => 'edit_form',
32
+ 'action' => $this->getData('action'),
33
+ 'method' => 'post',
34
+ 'enctype' => 'multipart/form-data',
35
+ ));
36
+
37
+ $fieldset = $form->addFieldset('general', array('legend' => Mage::helper('coupon')->__('Import')));
38
+
39
+ $dictionaries = $this->getDictionaries();
40
+ if (!is_array($dictionaries)) {
41
+ $fieldset->addField('label', 'label', array(
42
+ 'value' => '',
43
+ 'note' => $dictionaries,
44
+ ));
45
+ $fieldset->addField('file', 'file', array(
46
+ 'name' => 'file',
47
+ 'label' => Mage::helper('coupon')->__('File'),
48
+ 'value' => '',
49
+ 'note' => 'Please upload CSV file.',
50
+ ));
51
+ } else {
52
+ $fieldset->addField('file', 'select', array(
53
+ 'name' => 'file',
54
+ 'label' => Mage::helper('coupon')->__('File'),
55
+ 'required' => true,
56
+ 'values' => $dictionaries,
57
+ ));
58
+ }
59
+
60
+
61
+
62
+ $form->setAction($this->getUrl('*/*/massImport'));
63
+ $form->setUseContainer(true);
64
+ $this->setForm($form);
65
+
66
+ return parent::_prepareForm();
67
+ }
68
+
69
+ protected function getDictionaries()
70
+ {
71
+ $values = array();
72
+ $path = Mage::getBaseDir('media').DS.'import'.DS.'coupon'.DS;
73
+ if (file_exists($path)) {
74
+ if ($handle = opendir($path)) {
75
+ while (false !== ($entry = readdir($handle))) {
76
+ if (substr($entry, 0, 1) != '.' ) {
77
+ $r = pathinfo($entry);
78
+ if($r['extension'] == 'csv') {
79
+ $values[] = array(
80
+ 'label' => $entry,
81
+ 'value' => $path . DS . $entry
82
+ );
83
+ }
84
+ }
85
+ }
86
+ closedir($handle);
87
+ }
88
+ if (count($values) == 0) {
89
+ $values = "Can't find any files in folder $path";
90
+ // $values = "<div id='messages'><ul class='messages'><li class='success-msg'><ul><li><span>Cant find any files in folder $path</span></li></ul></li></ul></div>";
91
+ }
92
+ } else {
93
+ $values = "Can't find folder $path";
94
+ }
95
+
96
+ return $values;
97
+ }
98
+
99
+ public function __construct()
100
+ {
101
+ parent::__construct();
102
+ $this->setId('promo_quote_form');
103
+ $this->setTitle(Mage::helper('salesrule')->__('Rule Information'));
104
+ }
105
+
106
+
107
+ }
app/code/local/Bdt/Coupon/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bdt_Coupon_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Bdt/Coupon/Model/Coupon.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mirasvit
4
+ *
5
+ * This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/.
6
+ * Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
7
+ * If you wish to customize this module for your needs.
8
+ * Please refer to http://www.magentocommerce.com for more information.
9
+ *
10
+ * @category Mirasvit
11
+ * @package Sphinx Search Ultimate
12
+ * @version 2.3.2
13
+ * @build 939
14
+ * @copyright Copyright (C) 2014 Mirasvit (http://mirasvit.com/)
15
+ */
16
+
17
+
18
+ /**
19
+ * Модель для работы с синонимами
20
+ *
21
+ * @category Mirasvit
22
+ * @package Mirasvit_SearchSphinx
23
+ */
24
+ class Bdt_Coupon_Model_Coupon extends Mage_Core_Model_Abstract
25
+ {
26
+ protected function _construct()
27
+ {
28
+ $this->_init('coupon/coupon');
29
+ }
30
+
31
+ public function import($filename){
32
+ try{
33
+ if(file_exists($filename)){
34
+ $fp = fopen($filename,'r') or die("can't open file");
35
+ $count = 0;
36
+ $countNotImpt = 0;
37
+ $i = 0;
38
+ $fields = array_flip(fgetcsv($fp,1024,","));
39
+
40
+ while($csv_line = fgetcsv($fp,1024,",")) {
41
+ if($csv_line[$fields['status']] == 1) {
42
+ $options['rule_name'] = $rulename = $csv_line[$fields['rule_name']];
43
+ $options['description'] =$desc = $csv_line[$fields['description']];
44
+ $options['status'] =$status = $csv_line[$fields['status']];
45
+ $options['customer_group'] =$customerGroups = $csv_line[$fields['customer_group']];
46
+ $options['coupon_code'] =$couponCode = $csv_line[$fields['coupon_code']];
47
+ $options['from_date'] =$fromDate = $csv_line[$fields['from_date']];
48
+ $options['to_date'] =$toDate = $csv_line[$fields['to_date']];
49
+ $options['discount_type'] =$discountType = $csv_line[$fields['discount_type']];
50
+ $options['discount_amount'] =$discountAmount = $csv_line[$fields['discount_amount']];
51
+ $options['user_per_coupon'] =$userPerCoupon = $csv_line[$fields['user_per_coupon']];
52
+ $options['stop_rules_processing'] =$stopRulesProcessing = $csv_line[$fields['stop_rules_processing']];
53
+ $options['uses_per_customer'] =$usesPerCustomer = $csv_line[$fields['uses_per_customer']];
54
+ $options['simple_free_shipping'] =$simpleFreeShipping = $csv_line[$fields['simple_free_shipping']];
55
+ $options['website'] =$simpleFreeShipping = $csv_line[$fields['website']];
56
+ $options['discount_qty'] = ($csv_line[$fields['discount_qty']] > 0) ? $csv_line[$fields['discount_qty']] : 0;
57
+ if($this->generateRule($options)) {
58
+ $count++;
59
+ }
60
+ else{
61
+ $countNotImpt++;
62
+ }
63
+ }
64
+ $i++;
65
+ }
66
+ fclose($fp) or die("can't close file");
67
+
68
+ $message['count']= $count;
69
+ $message['countNotImpt']= $countNotImpt;
70
+
71
+ $archives = Mage::getBaseDir('media'). DS . 'import' . DS . 'coupon' . DS . 'archives' . DS . date('ymd').'_coupon.csv';
72
+ copy($filename, $archives) or die("can't move file");
73
+
74
+ unlink($filename) or die("can't delete file");
75
+
76
+ }else{
77
+ echo $filename . '<br/>File is not available.';
78
+ }
79
+ }catch (Exception $e){
80
+ echo $e->getMessage();
81
+ }
82
+
83
+ return $message;
84
+ }
85
+
86
+ public function generateRule($options){
87
+
88
+ $couponCheck = Mage::getModel('salesrule/rule')->getCollection()
89
+ ->addFieldToFilter('code',$options['coupon_code'])
90
+ ->load();
91
+ $couponCheckArr = $couponCheck->getData();
92
+ if(count($couponCheckArr)>0) {
93
+ return false;
94
+ }
95
+ $rule = Mage::getModel('salesrule/rule');
96
+ $rule->setName($options['rule_name']);
97
+ $rule->setDescription($options['description']);
98
+ $rule->setFromDate($options['from_date']);//starting today
99
+ if($options['from_date'] !="") {
100
+ $rule->setToDate($options['from_date']);//if you need an expiration date
101
+ }
102
+ $rule->setCouponCode($options['coupon_code']);
103
+ $rule->setUsesPerCoupon($options['user_per_coupon']);//number of allowed uses for this coupon
104
+ $rule->setUsesPerCustomer($options['uses_per_customer']);//number of allowed uses for this coupon for each customer
105
+ $customerGroups = explode(',',$options['customer_group']);
106
+ $rule->setCustomerGroupIds($customerGroups);//if you want only certain groups replace getAllCustomerGroups() with an array of desired ids
107
+ $rule->setIsActive($options['status']);
108
+ $rule->setStopRulesProcessing($options['stop_rules_processing']);//set to 1 if you want all other rules after this to not be processed
109
+ $rule->setIsRss(0);//set to 1 if you want this rule to be public in rss
110
+ $rule->setIsAdvanced(1);//have no idea what it means :)
111
+ $rule->setProductIds('');
112
+ $rule->setSortOrder(0);// order in which the rules will be applied
113
+ $rule->setSimpleAction($options['discount_type']);
114
+ $rule->setDiscountAmount($options['discount_amount']);//the discount amount/percent. if SimpleAction is by_percent this value must be <= 100
115
+ $rule->setDiscountQty($options['discount_qty']);//Maximum Qty Discount is Applied to
116
+ $rule->setDiscountStep(0);//used for buy_x_get_y; This is X
117
+ $rule->setSimpleFreeShipping($options['simple_free_shipping']);//set to 1 for Free shipping
118
+ $rule->setApplyToShipping(0);//set to 0 if you don't want the rule to be applied to shipping
119
+ $websites = explode(',',$options['website']);
120
+ $rule->setWebsiteIds($websites);//if you want only certain websites replace getAllWbsites() with an array of desired ids
121
+
122
+ $conditions = array();
123
+ $conditions[1] = array(
124
+ 'type' => 'salesrule/rule_condition_combine',
125
+ 'aggregator' => 'all',
126
+ 'value' => 1,
127
+ 'new_child' => ''
128
+ );
129
+
130
+ $rule->setData('conditions',$conditions);
131
+ $rule->loadPost($rule->getData());
132
+ $rule->setCouponType(2); // No Coupon=>1, Specific Coupon=>2, Auto=>3
133
+ if($rule->save()) {
134
+
135
+ return true;
136
+ }
137
+ else {
138
+ return false;
139
+ }
140
+ }
141
+ }
app/code/local/Bdt/Coupon/controllers/Adminhtml/Promo/QuoteController.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'Mage/Adminhtml/controllers/Promo/QuoteController.php';
4
+ class Bdt_Coupon_Adminhtml_Promo_QuoteController extends Mage_Adminhtml_Promo_QuoteController
5
+ {
6
+
7
+ public function importAction()
8
+ {
9
+ $this->_initAction()
10
+ ->_title($this->__('Import Coupon'));
11
+
12
+ $this->_addContent($this->getLayout()->createBlock('coupon/adminhtml_promo_quote_import'));
13
+
14
+ $this->renderLayout();
15
+ }
16
+ public function massImportAction()
17
+ {
18
+ if ($data = $this->getRequest()->getPost()) {
19
+ try {
20
+ if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') {
21
+ try
22
+ {
23
+ $path = Mage::getBaseDir('media'). DS . 'import' . DS . 'coupon' . DS; // . date('ymd').'_pe_loyalty_voucher.csv';
24
+ //$path = Mage::getBaseDir().DS.'csv'.DS; //desitnation directory
25
+ $fname = $_FILES['file']['name']; //file name
26
+ $fullname = $path.$fname;
27
+ $uploader = new Varien_File_Uploader('file'); //load class
28
+ $uploader->setAllowedExtensions(array('CSV','csv')); //Allowed extension for file
29
+ $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
30
+ $uploader->setAllowRenameFiles(false);
31
+ $uploader->setFilesDispersion(false);
32
+ $uploader->save($path, $fname); //save the
33
+
34
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('coupon')->__("File has been uploaded successfully."));
35
+ $this->_redirect('*/*/import');
36
+ return;
37
+
38
+ }
39
+ catch (Exception $e)
40
+ {
41
+ $fileType = "Invalid file format";
42
+ }
43
+ }
44
+
45
+ if ($fileType == "Invalid file format") {
46
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('foundation')->__($fname." Invalid file format"));
47
+ $this->_redirect('*/*/');
48
+ return;
49
+ }
50
+
51
+ $result = Mage::getSingleton('coupon/coupon')->import($data['file']);
52
+
53
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('coupon')->__('%s coupon(s) imported successfully.<br/> %s coupon(s) were already exists.', $result['count'],$result['countNotImpt']));
54
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
55
+ $this->_redirect('*/*/');
56
+
57
+ } catch (Exception $e) {
58
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
59
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
60
+ $this->_redirect('*/*/import');
61
+ }
62
+
63
+ }
64
+ }
65
+ public function exportCsvAction()
66
+ {
67
+ $fileName = 'coupon.csv';
68
+ $content = $this->getLayout()->createBlock('coupon/adminhtml_promo_quote_grid')
69
+ ->getCsv();
70
+ //echo "<pre>";
71
+ print_r($content);die;
72
+
73
+ $this->_sendUploadResponse($fileName, $content);
74
+ }
75
+
76
+ public function exportXmlAction()
77
+ {
78
+ $fileName = 'coupon.xml';
79
+ $content = $this->getLayout()->createBlock('coupon/adminhtml_promo_quote_grid')
80
+ ->getXml();
81
+
82
+
83
+ $this->_sendUploadResponse($fileName, $content);
84
+ }
85
+
86
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
87
+ {
88
+ $response = $this->getResponse();
89
+ $response->setHeader('HTTP/1.1 200 OK','');
90
+ $response->setHeader('Pragma', 'public', true);
91
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
92
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
93
+ $response->setHeader('Last-Modified', date('r'));
94
+ $response->setHeader('Accept-Ranges', 'bytes');
95
+ $response->setHeader('Content-Length', strlen($content));
96
+ $response->setHeader('Content-type', $contentType);
97
+ $response->setBody($content);
98
+ $response->sendResponse();
99
+ die;
100
+ }
101
+ }
app/code/local/Bdt/Coupon/etc/config.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bdt_Coupon>
5
+ <version>0.1.0</version>
6
+ </Bdt_Coupon>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <adminhtml>
11
+ <args>
12
+ <modules>
13
+ <Bdt_Coupon before="Mage_Adminhtml">Bdt_Coupon_Adminhtml</Bdt_Coupon>
14
+ </modules>
15
+ </args>
16
+ </adminhtml>
17
+ </routers>
18
+ </admin>
19
+ <global>
20
+ <models>
21
+ <coupon>
22
+ <class>Bdt_Coupon_Model</class>
23
+ </coupon>
24
+ </models>
25
+ <blocks>
26
+ <coupon>
27
+ <class>Bdt_Coupon_Block</class>
28
+ </coupon>
29
+ <adminhtml>
30
+ <rewrite>
31
+ <promo_quote>Bdt_Coupon_Block_Adminhtml_Promo_Quote</promo_quote>
32
+ <promo_quote_grid>Bdt_Coupon_Block_Adminhtml_Promo_Quote_Grid</promo_quote_grid>
33
+ </rewrite>
34
+ </adminhtml>
35
+ </blocks>
36
+ <helpers>
37
+ <coupon>
38
+ <class>Bdt_Coupon_Helper</class>
39
+ </coupon>
40
+ </helpers>
41
+ </global>
42
+ </config>
app/etc/modules/Bdt_Coupon.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Bdt_Coupon>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Bdt_Coupon>
8
+ </modules>
9
+ </config>
media/import/coupon/sample_coupon.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ rule_name,description,status,customer_group,coupon_code,from_date,to_date,discount_type,discount_amount,user_per_coupon,stop_rules_processing,uses_per_customer,simple_free_shipping,website,discount_qty
2
+ 20% Off,20% Off,1,"0,1,2,4",20%OFF,7/20/2015,7/30/2015,by_percent,20,1,1,1,0,"1,2",
3
+ FLAT10OFF,FLAT $10 off on whole cart,1,4,FLAT10OFF,7/20/2015,7/30/2015,cart_fixed,10,1,1,1,0,2,
4
+ $5 Off,$5 Off,1,"0,1,2,4",$5OFF,7/20/2015,7/30/2015,by_fixed,5,1,1,1,0,"1,2",2
package.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>import_export_cart_price_rules_coupon</name>
4
+ <version>0.1.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>Quick and easy solution for importing custom coupon codes in Magento&amp;lt;br&amp;gt;&#xD;
10
+ Import hundreds of coupon at once with your shopping cart price rules&amp;lt;br&amp;gt;&#xD;
11
+ Simplt create CSV as in given format.&#xD;
12
+ Import coupons as well as shopping cart price rules with all conditions provide by Magento&amp;lt;br&amp;gt;&#xD;
13
+ Import an unlimited amount of coupon codes in easiest way.</summary>
14
+ <description>&amp;lt;h3&amp;gt;Bulk import custom Magento coupons &amp;amp; shopping cart price rules with easy&amp;lt;/h3&amp;gt;&#xD;
15
+ &#xD;
16
+ &amp;lt;p&amp;gt;Our Coupon Import extension for Magento provides a &amp;lt;strong&amp;gt;simple and quick solution for importing custom coupon codes with shopping cart price rules.&amp;lt;/strong&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &#xD;
17
+ &#xD;
18
+ Maybe you&amp;apos;d like to import coupons received for marketing campaigns or other purpose. With Coupon Import for Magento you can bulk upload your custom coupons in a less time, whether it&amp;apos;s just a couple or thousands coupons at once!&amp;lt;/p&amp;gt;&#xD;
19
+ &#xD;
20
+ &amp;lt;h3&amp;gt;Upload thousands of coupon codes in a snap&amp;lt;/h3&amp;gt;&#xD;
21
+ &#xD;
22
+ &amp;lt;p&amp;gt;Coupon Import for Magento offers two ways of bulk importing your custom coupons in your shopping cart price rule.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&#xD;
23
+ &#xD;
24
+ All your import CSV file will uploaded under /media/import/coupon/&#xD;
25
+ Once you will import that CSV file it will move to archives with rename it prefix by [ymd]_coupon.csv under /media/import/coupon/archives/ymd_coupon.csv for your future backup or reused.&#xD;
26
+ &#xD;
27
+ Shopping Cart Price Rules grid have field to display no. of usage of coupons.&#xD;
28
+ &#xD;
29
+ &amp;lt;h3&amp;gt;Export&amp;lt;/h3&amp;gt;&#xD;
30
+ We have implemented default grid export functionality to Shopping Cart Price Rules.&#xD;
31
+ So, this export csv file field names will be change. So do not use exported CSV file directly to import.&#xD;
32
+ You have to refer sample coupon CSV format for import. You will found it under /media/import/coupon/sample_coupon.csv&#xD;
33
+ Below are some of field explanation with their values.&#xD;
34
+ &#xD;
35
+ rule_name : Specify rule name&#xD;
36
+ description : Specify rule description&#xD;
37
+ status : 0 for Inactive, 1 for Active&#xD;
38
+ customer_group : Customer Group Id, if more than one group then put comma separated value. eg. 1,2,3&#xD;
39
+ coupon_code : coupon code (numeric or Alphanumeric)&#xD;
40
+ from_date : Date should be in format like 7/20/2015&#xD;
41
+ to_date : Date should be in format like 7/30/2015&#xD;
42
+ discount_type : the value should be by_percent, cart_fixed, by_fixed.&#xD;
43
+ discount_amount : If you selected by_percent then value no more than 100.&#xD;
44
+ user_per_coupon : Number of user per coupon&#xD;
45
+ stop_rules_processing : 0 for No, 1 for Yes &#xD;
46
+ uses_per_customer : No. of usage per coupon&#xD;
47
+ simple_free_shipping : 0 for No, 1 for Yes&#xD;
48
+ website : Mention website id. If more than one then put comma separated value. e.g. 1,2,3&#xD;
49
+ discount_qty : If you selected discount_type as by_fixed then you have to set this value otherwise it will apply each qty of cart item.</description>
50
+ <notes>Import Export Coupon with Shopping Cart Price Rules</notes>
51
+ <authors><author><name>Praful Rajput</name><user>vasuscoin</user><email>rajput.praful@gmail.com</email></author></authors>
52
+ <date>2015-07-28</date>
53
+ <time>10:51:11</time>
54
+ <contents><target name="magelocal"><dir name="Bdt"><dir name="Coupon"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Promo"><dir name="Quote"><file name="Grid.php" hash="310c61f1d0f4bca36a72c635bb3a6430"/><dir name="Import"><file name="Form.php" hash="b1bdf4add4b60c89df0b90024f716de9"/></dir><file name="Import.php" hash="77aba2a1631bb0d817f9b72bfe9e3e17"/></dir><file name="Quote.php" hash="aff3e0f94fa6160e978a8c08e90536e2"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="ff05635d5ecda82cc01343fee1cef358"/></dir><dir name="Model"><file name="Coupon.php" hash="813dc1faf8cb94d58f2087a4ffb8fd9c"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Promo"><file name="QuoteController.php" hash="8991f27427bb334abd8a9de95eece613"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="96a81e7379db047058f4f610ffb2613c"/></dir></dir></dir></dir></target><target name="magemedia"><dir name="import"><dir name="coupon"><file name="sample_coupon.csv" hash="6b101feb99a5375036ed80bc2ad98338"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bdt_Coupon.xml" hash="828e75964a12d9396a1bcc11a5de0526"/></dir></target></contents>
55
+ <compatible/>
56
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
57
+ </package>