ProductCreateform - Version 1.0.1

Version Notes

version 1.0.1

Download this release

Release Info

Developer Abhay
Extension ProductCreateform
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (22) hide show
  1. app/code/local/Product/Createform/Block/Adminhtml/Createform.php +12 -0
  2. app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit.php +45 -0
  3. app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Form.php +19 -0
  4. app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Tab/Form.php +58 -0
  5. app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Tabs.php +24 -0
  6. app/code/local/Product/Createform/Block/Adminhtml/Createform/Grid.php +116 -0
  7. app/code/local/Product/Createform/Block/Createform.php +17 -0
  8. app/code/local/Product/Createform/Helper/Data.php +6 -0
  9. app/code/local/Product/Createform/Model/Createform.php +10 -0
  10. app/code/local/Product/Createform/Model/Mysql4/Createform.php +10 -0
  11. app/code/local/Product/Createform/Model/Mysql4/Createform/Collection.php +10 -0
  12. app/code/local/Product/Createform/Model/Status.php +15 -0
  13. app/code/local/Product/Createform/controllers/Adminhtml/CreateformController.php +214 -0
  14. app/code/local/Product/Createform/controllers/IndexController.php +47 -0
  15. app/code/local/Product/Createform/etc/config.xml +127 -0
  16. app/code/local/Product/Createform/etc/system.xml +82 -0
  17. app/code/local/Product/Createform/sql/createform_setup/mysql4-install-0.1.0.php +23 -0
  18. app/design/adminhtml/default/default/layout/createform.xml +8 -0
  19. app/design/frontend/default/default/layout/createform.xml +13 -0
  20. app/design/frontend/default/default/template/createform/createform.phtml +51 -0
  21. app/etc/modules/Product_Createform.xml +9 -0
  22. package.xml +26 -0
app/code/local/Product/Createform/Block/Adminhtml/Createform.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Createform_Block_Adminhtml_Createform extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_createform';
7
+ $this->_blockGroup = 'createform';
8
+ $this->_headerText = Mage::helper('createform')->__('Item Manager');
9
+ $this->_addButtonLabel = Mage::helper('createform')->__('Add Item');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Block_Adminhtml_Createform_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'createform';
11
+ $this->_controller = 'adminhtml_createform';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('createform')->__('Save Item'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('createform')->__('Delete Item'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('createform_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'createform_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'createform_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('createform_data') && Mage::registry('createform_data')->getId() ) {
40
+ return Mage::helper('createform')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('createform_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('createform')->__('Add Item');
43
+ }
44
+ }
45
+ }
app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Block_Adminhtml_Createform_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Tab/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Block_Adminhtml_Createform_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+ $fieldset = $form->addFieldset('createform_form', array('legend'=>Mage::helper('createform')->__('Item information')));
10
+
11
+ $fieldset->addField('title', 'text', array(
12
+ 'label' => Mage::helper('createform')->__('Title'),
13
+ 'class' => 'required-entry',
14
+ 'required' => true,
15
+ 'name' => 'title',
16
+ ));
17
+
18
+ $fieldset->addField('filename', 'file', array(
19
+ 'label' => Mage::helper('createform')->__('File'),
20
+ 'required' => false,
21
+ 'name' => 'filename',
22
+ ));
23
+
24
+ $fieldset->addField('status', 'select', array(
25
+ 'label' => Mage::helper('createform')->__('Status'),
26
+ 'name' => 'status',
27
+ 'values' => array(
28
+ array(
29
+ 'value' => 1,
30
+ 'label' => Mage::helper('createform')->__('Enabled'),
31
+ ),
32
+
33
+ array(
34
+ 'value' => 2,
35
+ 'label' => Mage::helper('createform')->__('Disabled'),
36
+ ),
37
+ ),
38
+ ));
39
+
40
+ $fieldset->addField('content', 'editor', array(
41
+ 'name' => 'content',
42
+ 'label' => Mage::helper('createform')->__('Content'),
43
+ 'title' => Mage::helper('createform')->__('Content'),
44
+ 'style' => 'width:700px; height:500px;',
45
+ 'wysiwyg' => false,
46
+ 'required' => true,
47
+ ));
48
+
49
+ if ( Mage::getSingleton('adminhtml/session')->getCreateformData() )
50
+ {
51
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getCreateformData());
52
+ Mage::getSingleton('adminhtml/session')->setCreateformData(null);
53
+ } elseif ( Mage::registry('createform_data') ) {
54
+ $form->setValues(Mage::registry('createform_data')->getData());
55
+ }
56
+ return parent::_prepareForm();
57
+ }
58
+ }
app/code/local/Product/Createform/Block/Adminhtml/Createform/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Block_Adminhtml_Createform_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('createform_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('createform')->__('Item Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('createform')->__('Item Information'),
18
+ 'title' => Mage::helper('createform')->__('Item Information'),
19
+ 'content' => $this->getLayout()->createBlock('createform/adminhtml_createform_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/Product/Createform/Block/Adminhtml/Createform/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Block_Adminhtml_Createform_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('createformGrid');
9
+ $this->setDefaultSort('createform_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('createform/createform')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('createform_id', array(
24
+ 'header' => Mage::helper('createform')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'createform_id',
28
+ ));
29
+
30
+ $this->addColumn('title', array(
31
+ 'header' => Mage::helper('createform')->__('Title'),
32
+ 'align' =>'left',
33
+ 'index' => 'title',
34
+ ));
35
+
36
+ /*
37
+ $this->addColumn('content', array(
38
+ 'header' => Mage::helper('createform')->__('Item Content'),
39
+ 'width' => '150px',
40
+ 'index' => 'content',
41
+ ));
42
+ */
43
+
44
+ $this->addColumn('status', array(
45
+ 'header' => Mage::helper('createform')->__('Status'),
46
+ 'align' => 'left',
47
+ 'width' => '80px',
48
+ 'index' => 'status',
49
+ 'type' => 'options',
50
+ 'options' => array(
51
+ 1 => 'Enabled',
52
+ 2 => 'Disabled',
53
+ ),
54
+ ));
55
+
56
+ $this->addColumn('action',
57
+ array(
58
+ 'header' => Mage::helper('createform')->__('Action'),
59
+ 'width' => '100',
60
+ 'type' => 'action',
61
+ 'getter' => 'getId',
62
+ 'actions' => array(
63
+ array(
64
+ 'caption' => Mage::helper('createform')->__('Edit'),
65
+ 'url' => array('base'=> '*/*/edit'),
66
+ 'field' => 'id'
67
+ )
68
+ ),
69
+ 'filter' => false,
70
+ 'sortable' => false,
71
+ 'index' => 'stores',
72
+ 'is_system' => true,
73
+ ));
74
+
75
+ $this->addExportType('*/*/exportCsv', Mage::helper('createform')->__('CSV'));
76
+ $this->addExportType('*/*/exportXml', Mage::helper('createform')->__('XML'));
77
+
78
+ return parent::_prepareColumns();
79
+ }
80
+
81
+ protected function _prepareMassaction()
82
+ {
83
+ $this->setMassactionIdField('createform_id');
84
+ $this->getMassactionBlock()->setFormFieldName('createform');
85
+
86
+ $this->getMassactionBlock()->addItem('delete', array(
87
+ 'label' => Mage::helper('createform')->__('Delete'),
88
+ 'url' => $this->getUrl('*/*/massDelete'),
89
+ 'confirm' => Mage::helper('createform')->__('Are you sure?')
90
+ ));
91
+
92
+ $statuses = Mage::getSingleton('createform/status')->getOptionArray();
93
+
94
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
95
+ $this->getMassactionBlock()->addItem('status', array(
96
+ 'label'=> Mage::helper('createform')->__('Change status'),
97
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
98
+ 'additional' => array(
99
+ 'visibility' => array(
100
+ 'name' => 'status',
101
+ 'type' => 'select',
102
+ 'class' => 'required-entry',
103
+ 'label' => Mage::helper('createform')->__('Status'),
104
+ 'values' => $statuses
105
+ )
106
+ )
107
+ ));
108
+ return $this;
109
+ }
110
+
111
+ public function getRowUrl($row)
112
+ {
113
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
114
+ }
115
+
116
+ }
app/code/local/Product/Createform/Block/Createform.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Createform_Block_Createform extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getCreateform()
10
+ {
11
+ if (!$this->hasData('createform')) {
12
+ $this->setData('createform', Mage::registry('createform'));
13
+ }
14
+ return $this->getData('createform');
15
+
16
+ }
17
+ }
app/code/local/Product/Createform/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Product/Createform/Model/Createform.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Model_Createform extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('createform/createform');
9
+ }
10
+ }
app/code/local/Product/Createform/Model/Mysql4/Createform.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Model_Mysql4_Createform extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the createform_id refers to the key field in your database table.
8
+ $this->_init('createform/createform', 'createform_id');
9
+ }
10
+ }
app/code/local/Product/Createform/Model/Mysql4/Createform/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Model_Mysql4_Createform_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('createform/createform');
9
+ }
10
+ }
app/code/local/Product/Createform/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('createform')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('createform')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/local/Product/Createform/controllers/Adminhtml/CreateformController.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Product_Createform_Adminhtml_CreateformController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ protected function _initAction() {
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('createform/items')
9
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction() {
15
+ $this->_initAction()
16
+ ->renderLayout();
17
+ }
18
+
19
+ public function editAction() {
20
+ $id = $this->getRequest()->getParam('id');
21
+ $model = Mage::getModel('createform/createform')->load($id);
22
+
23
+ if ($model->getId() || $id == 0) {
24
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
25
+ if (!empty($data)) {
26
+ $model->setData($data);
27
+ }
28
+
29
+ Mage::register('createform_data', $model);
30
+
31
+ $this->loadLayout();
32
+ $this->_setActiveMenu('createform/items');
33
+
34
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
35
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
36
+
37
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
38
+
39
+ $this->_addContent($this->getLayout()->createBlock('createform/adminhtml_createform_edit'))
40
+ ->_addLeft($this->getLayout()->createBlock('createform/adminhtml_createform_edit_tabs'));
41
+
42
+ $this->renderLayout();
43
+ } else {
44
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('createform')->__('Item does not exist'));
45
+ $this->_redirect('*/*/');
46
+ }
47
+ }
48
+
49
+ public function newAction() {
50
+ $this->_forward('edit');
51
+ }
52
+
53
+ public function saveAction() {
54
+ if ($data = $this->getRequest()->getPost()) {
55
+
56
+ if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
57
+ try {
58
+ /* Starting upload */
59
+ $uploader = new Varien_File_Uploader('filename');
60
+
61
+ // Any extention would work
62
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
63
+ $uploader->setAllowRenameFiles(false);
64
+
65
+ // Set the file upload mode
66
+ // false -> get the file directly in the specified folder
67
+ // true -> get the file in the product like folders
68
+ // (file.jpg will go in something like /media/f/i/file.jpg)
69
+ $uploader->setFilesDispersion(false);
70
+
71
+ // We set media as the upload dir
72
+ $path = Mage::getBaseDir('media') . DS ;
73
+ $uploader->save($path, $_FILES['filename']['name'] );
74
+
75
+ } catch (Exception $e) {
76
+
77
+ }
78
+
79
+ //this way the name is saved in DB
80
+ $data['filename'] = $_FILES['filename']['name'];
81
+ }
82
+
83
+
84
+ $model = Mage::getModel('createform/createform');
85
+ $model->setData($data)
86
+ ->setId($this->getRequest()->getParam('id'));
87
+
88
+ try {
89
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
90
+ $model->setCreatedTime(now())
91
+ ->setUpdateTime(now());
92
+ } else {
93
+ $model->setUpdateTime(now());
94
+ }
95
+
96
+ $model->save();
97
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('createform')->__('Item was successfully saved'));
98
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
99
+
100
+ if ($this->getRequest()->getParam('back')) {
101
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
102
+ return;
103
+ }
104
+ $this->_redirect('*/*/');
105
+ return;
106
+ } catch (Exception $e) {
107
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
108
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
109
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
110
+ return;
111
+ }
112
+ }
113
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('createform')->__('Unable to find item to save'));
114
+ $this->_redirect('*/*/');
115
+ }
116
+
117
+ public function deleteAction() {
118
+ if( $this->getRequest()->getParam('id') > 0 ) {
119
+ try {
120
+ $model = Mage::getModel('createform/createform');
121
+
122
+ $model->setId($this->getRequest()->getParam('id'))
123
+ ->delete();
124
+
125
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
126
+ $this->_redirect('*/*/');
127
+ } catch (Exception $e) {
128
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
129
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
130
+ }
131
+ }
132
+ $this->_redirect('*/*/');
133
+ }
134
+
135
+ public function massDeleteAction() {
136
+ $createformIds = $this->getRequest()->getParam('createform');
137
+ if(!is_array($createformIds)) {
138
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
139
+ } else {
140
+ try {
141
+ foreach ($createformIds as $createformId) {
142
+ $createform = Mage::getModel('createform/createform')->load($createformId);
143
+ $createform->delete();
144
+ }
145
+ Mage::getSingleton('adminhtml/session')->addSuccess(
146
+ Mage::helper('adminhtml')->__(
147
+ 'Total of %d record(s) were successfully deleted', count($createformIds)
148
+ )
149
+ );
150
+ } catch (Exception $e) {
151
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
152
+ }
153
+ }
154
+ $this->_redirect('*/*/index');
155
+ }
156
+
157
+ public function massStatusAction()
158
+ {
159
+ $createformIds = $this->getRequest()->getParam('createform');
160
+ if(!is_array($createformIds)) {
161
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
162
+ } else {
163
+ try {
164
+ foreach ($createformIds as $createformId) {
165
+ $createform = Mage::getSingleton('createform/createform')
166
+ ->load($createformId)
167
+ ->setStatus($this->getRequest()->getParam('status'))
168
+ ->setIsMassupdate(true)
169
+ ->save();
170
+ }
171
+ $this->_getSession()->addSuccess(
172
+ $this->__('Total of %d record(s) were successfully updated', count($createformIds))
173
+ );
174
+ } catch (Exception $e) {
175
+ $this->_getSession()->addError($e->getMessage());
176
+ }
177
+ }
178
+ $this->_redirect('*/*/index');
179
+ }
180
+
181
+ public function exportCsvAction()
182
+ {
183
+ $fileName = 'createform.csv';
184
+ $content = $this->getLayout()->createBlock('createform/adminhtml_createform_grid')
185
+ ->getCsv();
186
+
187
+ $this->_sendUploadResponse($fileName, $content);
188
+ }
189
+
190
+ public function exportXmlAction()
191
+ {
192
+ $fileName = 'createform.xml';
193
+ $content = $this->getLayout()->createBlock('createform/adminhtml_createform_grid')
194
+ ->getXml();
195
+
196
+ $this->_sendUploadResponse($fileName, $content);
197
+ }
198
+
199
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
200
+ {
201
+ $response = $this->getResponse();
202
+ $response->setHeader('HTTP/1.1 200 OK','');
203
+ $response->setHeader('Pragma', 'public', true);
204
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
205
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
206
+ $response->setHeader('Last-Modified', date('r'));
207
+ $response->setHeader('Accept-Ranges', 'bytes');
208
+ $response->setHeader('Content-Length', strlen($content));
209
+ $response->setHeader('Content-type', $contentType);
210
+ $response->setBody($content);
211
+ $response->sendResponse();
212
+ die;
213
+ }
214
+ }
app/code/local/Product/Createform/controllers/IndexController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Product_Createform_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $this->loadLayout();
7
+ $this->renderLayout();
8
+ }
9
+
10
+ public function createAction()
11
+ {
12
+ $post = $this->getRequest()->getParams();
13
+ $categoryid= Mage::getStoreConfig('createform/createform/category_id');
14
+ //print_r($post);
15
+ //exit;
16
+ if($post){
17
+ $product = new Mage_Catalog_Model_Product();
18
+ $product->setSku($post['name']."_new");
19
+ $product->setAttributeSetId(9);
20
+ $product->setTypeId('simple');
21
+ $product->setName($post['name']);
22
+ $product->setCategoryIds(array($categoryid)); # some cat id's, fill in backend
23
+ $product->setWebsiteIDs(array(1)); # Website id, my is 1 (default frontend)
24
+ $product->setDescription('Full description here');
25
+ $product->setShortDescription('Short description here');
26
+ $product->setPrice(39.99); # Set some price[put static temporary]
27
+
28
+ //Default Magento attribute
29
+ $product->setWeight(4.0000);
30
+ $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
31
+ $product->setStatus(1);
32
+ $product->setTaxClassId(0); # My default tax class[static]
33
+ $product->setStockData(array('is_in_stock' => 1,'qty' => 99999 ));
34
+
35
+ $product->save();
36
+ if($product->save()){
37
+ Mage::getSingleton('customer/session')->addSuccess("Your product was submitted.Thank you");
38
+ $this->_redirect('*/index');
39
+ return;
40
+ }else{
41
+ Mage::getSingleton('customer/session')->addError("there are already product exist in our website");
42
+ $this->_redirect('*/index');
43
+ return;
44
+ }
45
+ }
46
+ }
47
+ }
app/code/local/Product/Createform/etc/config.xml ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Product_Createform>
5
+ <version>0.1.0</version>
6
+ </Product_Createform>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <createform>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Product_Createform</module>
14
+ <frontName>createform</frontName>
15
+ </args>
16
+ </createform>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <createform>
21
+ <file>createform.xml</file>
22
+ </createform>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <admin>
27
+ <routers>
28
+ <createform>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>Product_Createform</module>
32
+ <frontName>createform</frontName>
33
+ </args>
34
+ </createform>
35
+ </routers>
36
+ </admin>
37
+ <adminhtml>
38
+ <!-- <menu>
39
+ <createform module="createform">
40
+ <title>Createform</title>
41
+ <sort_order>71</sort_order>
42
+ <children>
43
+ <items module="createform">
44
+ <title>Manage Items</title>
45
+ <sort_order>0</sort_order>
46
+ <action>createform/adminhtml_createform</action>
47
+ </items>
48
+ </children>
49
+ </createform>
50
+ </menu> -->
51
+ <acl>
52
+ <resources>
53
+ <all>
54
+ <title>Allow Everything</title>
55
+ </all>
56
+ <admin>
57
+ <children>
58
+ <system>
59
+ <children>
60
+ <config>
61
+ <children>
62
+ <Product_Createform>
63
+ <title>testimonial - All</title>
64
+ </Product_Createform>
65
+ </children>
66
+ </config>
67
+ </children>
68
+ </system>
69
+ </children>
70
+ </admin>
71
+ </resources>
72
+ </acl>
73
+ <layout>
74
+ <updates>
75
+ <createform>
76
+ <file>createform.xml</file>
77
+ </createform>
78
+ </updates>
79
+ </layout>
80
+ </adminhtml>
81
+ <global>
82
+ <models>
83
+ <createform>
84
+ <class>Product_Createform_Model</class>
85
+ <resourceModel>createform_mysql4</resourceModel>
86
+ </createform>
87
+ <createform_mysql4>
88
+ <class>Product_Createform_Model_Mysql4</class>
89
+ <entities>
90
+ <createform>
91
+ <table>createform</table>
92
+ </createform>
93
+ </entities>
94
+ </createform_mysql4>
95
+ </models>
96
+ <resources>
97
+ <createform_setup>
98
+ <setup>
99
+ <module>Product_Createform</module>
100
+ </setup>
101
+ <connection>
102
+ <use>core_setup</use>
103
+ </connection>
104
+ </createform_setup>
105
+ <createform_write>
106
+ <connection>
107
+ <use>core_write</use>
108
+ </connection>
109
+ </createform_write>
110
+ <createform_read>
111
+ <connection>
112
+ <use>core_read</use>
113
+ </connection>
114
+ </createform_read>
115
+ </resources>
116
+ <blocks>
117
+ <createform>
118
+ <class>Product_Createform_Block</class>
119
+ </createform>
120
+ </blocks>
121
+ <helpers>
122
+ <createform>
123
+ <class>Product_Createform_Helper</class>
124
+ </createform>
125
+ </helpers>
126
+ </global>
127
+ </config>
app/code/local/Product/Createform/etc/system.xml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <createform translate="label" module="createform">
5
+ <label>Create Product Options</label>
6
+ <tab>general</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>80</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <createform translate="label">
14
+ <label>Create Product</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>10</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <enabled translate="label">
22
+ <label>Enable to Create Product From Frontend</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <backend_model>contacts/system_config_backend_links</backend_model>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </enabled>.
31
+ <category_id translate="label">
32
+ <label>Category Id</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>10</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </category_id>
39
+ </fields>
40
+ </createform>
41
+ </groups>
42
+ <groups>
43
+ <email_settings translate="label">
44
+ <label>Email Settings</label>
45
+ <frontend_type>text</frontend_type>
46
+ <sort_order>40</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ <fields>
51
+ <email_sender translate="label">
52
+ <label>Email Sender</label>
53
+ <frontend_type>select</frontend_type>
54
+ <source_model>adminhtml/system_config_source_email_identity</source_model>
55
+ <sort_order>10</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ </email_sender>
60
+ <email_subject translate="label">
61
+ <label>Email Subject for Client</label>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>50</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>1</show_in_store>
67
+ </email_subject>
68
+ <email_template_client translate="label">
69
+ <label>Email Template For Client</label>
70
+ <frontend_type>select</frontend_type>
71
+ <source_model>adminhtml/system_config_source_email_template</source_model>
72
+ <sort_order>60</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ </email_template_client>
77
+ </fields>
78
+ </email_settings>
79
+ </groups>
80
+ </createform>
81
+ </sections>
82
+ </config>
app/code/local/Product/Createform/sql/createform_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('createform')};
10
+ CREATE TABLE {$this->getTable('createform')} (
11
+ `createform_id` int(11) unsigned NOT NULL auto_increment,
12
+ `title` varchar(255) NOT NULL default '',
13
+ `filename` varchar(255) NOT NULL default '',
14
+ `content` text NOT NULL default '',
15
+ `status` smallint(6) NOT NULL default '0',
16
+ `created_time` datetime NULL,
17
+ `update_time` datetime NULL,
18
+ PRIMARY KEY (`createform_id`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
+
21
+ ");
22
+
23
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/createform.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <createform_adminhtml_createform_index>
4
+ <reference name="content">
5
+ <block type="createform/adminhtml_createform" name="createform" />
6
+ </reference>
7
+ </createform_adminhtml_createform_index>
8
+ </layout>
app/design/frontend/default/default/layout/createform.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ </default>
5
+ <createform_index_index>
6
+ <reference name="root">
7
+ <action method="setTemplate"><template>page/1column.phtml</template></action>
8
+ </reference>
9
+ <reference name="content">
10
+ <block type="createform/createform" name="createform" template="createform/createform.phtml" />
11
+ </reference>
12
+ </createform_index_index>
13
+ </layout>
app/design/frontend/default/default/template/createform/createform.phtml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * DISCLAIMER
6
+ *
7
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
8
+ * versions in the future. If you wish to customize Magento for your
9
+ * needs please refer to http://www.magentocommerce.com for more information.
10
+ *
11
+ * @category design
12
+ * @package default_default
13
+ * @copyright abhaykhatariay@magentodeveloper
14
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
15
+ */
16
+ ?>
17
+ <?php if(Mage::getStoreConfig('createform/createform/enabled')=="1"): ?>
18
+ <div id="messages_product_view">
19
+ <?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true));
20
+ echo $this->getMessagesBlock()->getGroupedHtml(); ?>
21
+ </div>
22
+ <div class="page-title">
23
+ <h1><?php echo Mage::helper('createform')->__('Submit Product Name Form') ?></h1>
24
+ </div>
25
+ <form action="<?php echo $this->getUrl('createform/index/create'); ?>" id="createform" method="post">
26
+ <div class="fieldset">
27
+ <ul class="form-list">
28
+ <li class="fields">
29
+ <div class="field">
30
+ <label for="name" class="required"><em>*</em><?php echo Mage::helper('createform')->__('Product Name') ?></label>
31
+ <div class="input-box">
32
+ <input name="name" id="name" title="<?php echo Mage::helper('createform')->__('Product Name') ?>" value="" class="input-text required-entry" type="text" />
33
+ </div>
34
+ </div>
35
+ </li>
36
+ <div class="buttons-set" style="border: 0 none;">
37
+ <button style="text-align: left" type="submit" title="<?php echo Mage::helper('createform')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('createform')->__('Submit') ?></span></span></button>
38
+ </div>
39
+ </ul>
40
+ </div>
41
+ </form>
42
+ <script type="text/javascript">
43
+ //<![CDATA[
44
+ var createform = new VarienForm('createform', true);
45
+ //]]>
46
+ </script>
47
+ <?php else: ?>
48
+ <div id="messages_product_view">
49
+ <?php echo $this->__('You are no enable to submit'); ?>
50
+ </div>
51
+ <?php endif; ?>
app/etc/modules/Product_Createform.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Product_Createform>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Product_Createform>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ProductCreateform</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>this plugin use for those product who want to give opportunity to customer for create product in website&#xD;
10
+ </summary>
11
+ <description>this plugin use for those product who want to give opportunity to customer for create product in website&#xD;
12
+ &#xD;
13
+ &#xD;
14
+ &#xD;
15
+ use above plugin to give opportunity to create product name so when customer submit productname it will create in admin catalog/manageproduct with non visibility options&#xD;
16
+ &#xD;
17
+ for more details please contact &#xD;
18
+ http://abhaykhatariya.blogspot.com</description>
19
+ <notes>version 1.0.1</notes>
20
+ <authors><author><name>Abhay</name><user>abhay5683</user><email>abhay5683@gmail.com</email></author></authors>
21
+ <date>2013-12-23</date>
22
+ <time>11:44:07</time>
23
+ <contents><target name="magelocal"><dir name="Product"><dir name="Createform"><dir name="Block"><dir name="Adminhtml"><dir name="Createform"><dir name="Edit"><file name="Form.php" hash="49dea4cca08c3e8134d0017c13d43b88"/><dir name="Tab"><file name="Form.php" hash="fbbc9ccf6ba47af7dcafb2ee6d29af7c"/></dir><file name="Tabs.php" hash="53d198909f1c849724e862fda0d2f1ae"/></dir><file name="Edit.php" hash="fa32ca50b603f75451913f2f2117db3e"/><file name="Grid.php" hash="0e8b6685ce30aae7c637d809af982a9a"/></dir><file name="Createform.php" hash="70a1fac8fdd90d0a3f262b058c1ddb69"/></dir><file name="Createform.php" hash="d288254b7e656f4197b3733ec51a0b5b"/></dir><dir name="Helper"><file name="Data.php" hash="b6d2bf51be0dacc2d514f54c3bf68290"/></dir><dir name="Model"><file name="Createform.php" hash="e4fd1d687abafd8f81ac4e75165ebb5f"/><dir name="Mysql4"><dir name="Createform"><file name="Collection.php" hash="ea541d8eaa558ba07a0081733972f84b"/></dir><file name="Createform.php" hash="afb95c6e290dd9fe1931f8d985fbfb12"/></dir><file name="Status.php" hash="3d09ae900bcc1d0dd65bf5913898946d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="CreateformController.php" hash="f8c7fdb7011f718652e08930d2c6ac5e"/></dir><file name="IndexController.php" hash="b33913810d70290b6c6f62ddb5ef7d3c"/></dir><dir name="etc"><file name="config.xml" hash="b623feea34dc8afb4520f0ff28fbe95a"/><file name="system.xml" hash="bdf5ebb6b7dfabe8801392d812aa4281"/></dir><dir name="sql"><dir name="createform_setup"><file name="mysql4-install-0.1.0.php" hash="8dbd6bea027f846154cf66a4a9879988"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Product_Createform.xml" hash="ae9989f2eb668c13996f660c949076fc"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="createform.xml" hash="0f53056e27968b96e99ac96ad9150db9"/></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="createform.xml" hash="13be78a6d63b9b835b77dfc2686d7d5d"/></dir><dir name="template"><dir name="createform"><file name="createform.phtml" hash="af210f14f363e929085c399cb922220a"/></dir></dir></dir></dir></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>5.1.0</min><max>5.4.10</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7.0.2</max></package></required></dependencies>
26
+ </package>