Version Notes
Copy Categories extension
Download this release
Release Info
Developer | Team FireGento |
Extension | Ghrix_Copymerge |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge.php +12 -0
- app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Edit.php +32 -0
- app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Edit/Form.php +86 -0
- app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Grid.php +105 -0
- app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Renderer/Catname.php +15 -0
- app/code/community/Ghrix/Copymerge/Helper/Data.php +4 -0
- app/code/community/Ghrix/Copymerge/Model/Merge.php +168 -0
- app/code/community/Ghrix/Copymerge/Model/Mysql4/Merge.php +8 -0
- app/code/community/Ghrix/Copymerge/Model/Mysql4/Merge/Collection.php +8 -0
- app/code/community/Ghrix/Copymerge/controllers/Adminhtml/MergeController.php +435 -0
- app/code/community/Ghrix/Copymerge/etc/config.xml +77 -0
- app/code/community/Ghrix/Copymerge/sql/ghrix_copymerge_setup/mysql4-install-1.0.0.php +36 -0
- app/design/adminhtml/default/default/layout/ghrix/copymerge.xml +18 -0
- app/etc/modules/Ghrix_Copymerge.xml +9 -0
- js/ghrix/cat_merge.js +5 -0
- package.xml +18 -0
- skin/adminhtml/default/default/ghrix/cat_merge.css +30 -0
app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Block_Adminhtml_Merge extends Mage_Adminhtml_Block_Widget_Grid_Container
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
$this->_blockGroup = 'ghrix_copymerge';
|
7 |
+
$this->_controller = 'adminhtml_merge';
|
8 |
+
$this->_headerText = $this->__('Category Handler Log');
|
9 |
+
|
10 |
+
parent::__construct();
|
11 |
+
}
|
12 |
+
}
|
app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Edit.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Block_Adminhtml_Merge_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Init class
|
6 |
+
*/
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
$this->_blockGroup = 'ghrix_copymerge';
|
10 |
+
$this->_controller = 'adminhtml_merge';
|
11 |
+
|
12 |
+
parent::__construct();
|
13 |
+
|
14 |
+
$this->_updateButton('save', 'label', $this->__('Save Action'));
|
15 |
+
$this->_updateButton('delete', 'label', $this->__('Delete Action'));
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Get Header text
|
20 |
+
*
|
21 |
+
* @return string
|
22 |
+
*/
|
23 |
+
public function getHeaderText()
|
24 |
+
{
|
25 |
+
if (Mage::registry('ghrix_copymerge')->getId()) {
|
26 |
+
return $this->__('Edit Action');
|
27 |
+
}
|
28 |
+
else {
|
29 |
+
return $this->__('New Action');
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Edit/Form.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Block_Adminhtml_Merge_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Init class
|
6 |
+
*/
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
parent::__construct();
|
10 |
+
|
11 |
+
$this->setId('ghrix_copymerge_merge_form');
|
12 |
+
$this->setTitle($this->__('Category Handler Information'));
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Setup form fields for inserts/updates
|
17 |
+
*
|
18 |
+
* return Mage_Adminhtml_Block_Widget_Form
|
19 |
+
*/
|
20 |
+
protected function _prepareForm()
|
21 |
+
{
|
22 |
+
$model = Mage::registry('ghrix_copymerge');
|
23 |
+
|
24 |
+
$form = new Varien_Data_Form(array(
|
25 |
+
'id' => 'edit_form',
|
26 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
27 |
+
'method' => 'post'
|
28 |
+
));
|
29 |
+
|
30 |
+
$fieldset = $form->addFieldset('base_fieldset', array(
|
31 |
+
'legend' => Mage::helper('checkout')->__('Category Handler Information'),
|
32 |
+
'class' => 'fieldset-wide',
|
33 |
+
));
|
34 |
+
|
35 |
+
if ($model->getId()) {
|
36 |
+
$fieldset->addField('id', 'hidden', array(
|
37 |
+
'name' => 'id',
|
38 |
+
));
|
39 |
+
}
|
40 |
+
|
41 |
+
$fieldset->addField('cat1', 'select',
|
42 |
+
array(
|
43 |
+
'name' => 'cat1',
|
44 |
+
'label' => 'Source Category',
|
45 |
+
'title' => 'Source Category',
|
46 |
+
'required' => true,
|
47 |
+
'container_id' => 'custom_source',
|
48 |
+
'values' => Mage::getModel("ghrix_copymerge/merge")->toOptionArray()
|
49 |
+
|
50 |
+
));
|
51 |
+
|
52 |
+
$fieldset->addField('cat2', 'select',
|
53 |
+
array(
|
54 |
+
'name' => 'cat2',
|
55 |
+
'label' => 'Destination Category',
|
56 |
+
'title' => 'Destination Category',
|
57 |
+
'required' => true,
|
58 |
+
'container_id' => 'custom_destination',
|
59 |
+
'values' => Mage::getModel("ghrix_copymerge/merge")->toOptionArray()
|
60 |
+
));
|
61 |
+
|
62 |
+
$fieldset->addField('actionc', 'radios', array(
|
63 |
+
'label' => Mage::helper('checkout')->__('Action'),
|
64 |
+
'name' => 'actionc',
|
65 |
+
'onclick' => "",
|
66 |
+
'onchange' => "",
|
67 |
+
//'required' => true,
|
68 |
+
'values' => array(
|
69 |
+
array('value'=>'Copy','label'=>'Copy Products And Categories'),
|
70 |
+
array('value'=>'Move','label'=>'Move Products And Categories'),
|
71 |
+
),
|
72 |
+
'disabled' => false,
|
73 |
+
'readonly' => false,
|
74 |
+
'container_id' => 'custom_action',
|
75 |
+
//~ 'after_element_html' => '<small>Comments</small>',
|
76 |
+
'tabindex' => 1
|
77 |
+
));
|
78 |
+
|
79 |
+
|
80 |
+
$form->setValues($model->getData());
|
81 |
+
$form->setUseContainer(true);
|
82 |
+
$this->setForm($form);
|
83 |
+
|
84 |
+
return parent::_prepareForm();
|
85 |
+
}
|
86 |
+
}
|
app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Grid.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Block_Adminhtml_Merge_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
parent::__construct();
|
7 |
+
|
8 |
+
// Set some defaults for our grid
|
9 |
+
$this->setDefaultSort('id');
|
10 |
+
$this->setId('ghrix_copymerge_merge_grid');
|
11 |
+
$this->setDefaultDir('asc');
|
12 |
+
$this->setSaveParametersInSession(true);
|
13 |
+
}
|
14 |
+
|
15 |
+
protected function _getCollectionClass()
|
16 |
+
{
|
17 |
+
// This is the model we are using for the grid
|
18 |
+
return 'ghrix_copymerge/merge_collection';
|
19 |
+
}
|
20 |
+
|
21 |
+
protected function _prepareCollection()
|
22 |
+
{
|
23 |
+
// Get and set our collection for the grid
|
24 |
+
$collection = Mage::getResourceModel($this->_getCollectionClass());
|
25 |
+
$this->setCollection($collection);
|
26 |
+
|
27 |
+
return parent::_prepareCollection();
|
28 |
+
}
|
29 |
+
|
30 |
+
protected function _prepareColumns()
|
31 |
+
{
|
32 |
+
|
33 |
+
$Category=Mage::getModel('catalog/category')->load($cat);
|
34 |
+
$name=$Category->getName();
|
35 |
+
|
36 |
+
// Add the columns that should appear in the grid
|
37 |
+
$this->addColumn('id',
|
38 |
+
array(
|
39 |
+
'header'=> $this->__('ID'),
|
40 |
+
'align' =>'right',
|
41 |
+
'width' => '10px',
|
42 |
+
'index' => 'id'
|
43 |
+
)
|
44 |
+
);
|
45 |
+
|
46 |
+
$this->addColumn('date',
|
47 |
+
array(
|
48 |
+
'header'=> $this->__('Date'),
|
49 |
+
'width' => '20px',
|
50 |
+
'index' => 'date'
|
51 |
+
)
|
52 |
+
);
|
53 |
+
$this->addColumn('cat1', array(
|
54 |
+
'header' => $this->__('Source Category'),
|
55 |
+
'index' => 'cat1',
|
56 |
+
'width' => '20px',
|
57 |
+
'renderer' => 'Ghrix_Copymerge_Block_Adminhtml_Merge_Renderer_Catname'
|
58 |
+
));
|
59 |
+
$this->addColumn('cat2', array(
|
60 |
+
'header' => $this->__('Destination Category'),
|
61 |
+
'index' => 'cat2',
|
62 |
+
'width' => '20px',
|
63 |
+
'renderer' => 'Ghrix_Copymerge_Block_Adminhtml_Merge_Renderer_Catname'
|
64 |
+
));
|
65 |
+
|
66 |
+
$this->addColumn('actionc',
|
67 |
+
array(
|
68 |
+
'header'=> $this->__('Action'),
|
69 |
+
'width' => '20px',
|
70 |
+
'index' => 'actionc'
|
71 |
+
)
|
72 |
+
);
|
73 |
+
|
74 |
+
$this->addColumn('delete',
|
75 |
+
array(
|
76 |
+
'header' => Mage::helper('catalog')->__('Delete'),
|
77 |
+
'width' => '10px',
|
78 |
+
'type' => 'action',
|
79 |
+
'getter' => 'getId',
|
80 |
+
'actions' => array(
|
81 |
+
array(
|
82 |
+
'caption' => Mage::helper('catalog')->__('Delete'),
|
83 |
+
'url' => array(
|
84 |
+
'base'=>'*/*/delete',
|
85 |
+
'params'=>array('store'=>$this->getRequest()->getParam('store'))
|
86 |
+
),
|
87 |
+
'field' => 'id'
|
88 |
+
)
|
89 |
+
),
|
90 |
+
'filter' => false,
|
91 |
+
'sortable' => false,
|
92 |
+
'index' => 'stores',
|
93 |
+
));
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
return parent::_prepareColumns();
|
98 |
+
}
|
99 |
+
|
100 |
+
public function getRowUrl($row)
|
101 |
+
{
|
102 |
+
// This is where our row data will link to
|
103 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
104 |
+
}
|
105 |
+
}
|
app/code/community/Ghrix/Copymerge/Block/Adminhtml/Merge/Renderer/Catname.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Block_Adminhtml_Merge_Renderer_Catname extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
|
3 |
+
|
4 |
+
public function render(Varien_Object $row)
|
5 |
+
{
|
6 |
+
|
7 |
+
$catid = $row->getData($this->getColumn()->getIndex());
|
8 |
+
$Category=Mage::getModel('catalog/category')->load($catid);
|
9 |
+
$name=$Category->getName();
|
10 |
+
|
11 |
+
return $name;
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
}
|
app/code/community/Ghrix/Copymerge/Helper/Data.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
app/code/community/Ghrix/Copymerge/Model/Merge.php
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Model_Merge extends Mage_Core_Model_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct()
|
5 |
+
{
|
6 |
+
$this->_init('ghrix_copymerge/merge');
|
7 |
+
}
|
8 |
+
public function toOptionArray($addEmpty = true)
|
9 |
+
{
|
10 |
+
$cat = Mage::getModel('catalog/category')->load(2);
|
11 |
+
$subcats = $cat->getChildren();
|
12 |
+
$options[] = array(
|
13 |
+
'label' => '----Please select----',
|
14 |
+
'value' => '',
|
15 |
+
'selected' => 'selected'
|
16 |
+
);
|
17 |
+
foreach(explode(',',$subcats) as $subCatid)
|
18 |
+
{
|
19 |
+
$_category = Mage::getModel('catalog/category')->load($subCatid);
|
20 |
+
|
21 |
+
if($_category->getIsActive()) {
|
22 |
+
$options[] = array(
|
23 |
+
'label' => $_category->getName(),
|
24 |
+
'value' => $_category->getId(),
|
25 |
+
);
|
26 |
+
$sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
|
27 |
+
$sub_subcats = $sub_cat->getChildren();
|
28 |
+
foreach(explode(',',$sub_subcats) as $sub_subCatid)
|
29 |
+
{
|
30 |
+
$_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
|
31 |
+
if($_sub_category->getIsActive()) {
|
32 |
+
$options[] = array(
|
33 |
+
'label' => '---'.$_sub_category->getName(),
|
34 |
+
'value' => $_sub_category->getId()
|
35 |
+
);
|
36 |
+
$sub_sub_cat = Mage::getModel('catalog/category')->load($sub_subCatid);
|
37 |
+
$sub_sub_subcats = $sub_sub_cat->getChildren();
|
38 |
+
foreach(explode(',',$sub_sub_subcats) as $sub_sub_subCatid)
|
39 |
+
{
|
40 |
+
$_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_subCatid);
|
41 |
+
if($_sub_sub_category->getIsActive()) {
|
42 |
+
$options[] = array(
|
43 |
+
'label' => '-----'.$_sub_sub_category->getName(),
|
44 |
+
'value' => $_sub_sub_category->getId()
|
45 |
+
);
|
46 |
+
|
47 |
+
$sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_subCatid);
|
48 |
+
$sub_sub_sub_subcats = $sub_sub_sub_cat->getChildren();
|
49 |
+
foreach(explode(',',$sub_sub_sub_subcats) as $sub_sub_sub_subCatid)
|
50 |
+
{
|
51 |
+
$_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_subCatid);
|
52 |
+
if($_sub_sub_sub_category->getIsActive()) {
|
53 |
+
$options[] = array(
|
54 |
+
'label' => '-------'.$_sub_sub_sub_category->getName(),
|
55 |
+
'value' => $_sub_sub_sub_category->getId()
|
56 |
+
);
|
57 |
+
$sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_subCatid);
|
58 |
+
$sub_sub_sub_sub_subcats = $sub_sub_sub_sub_cat->getChildren();
|
59 |
+
foreach(explode(',',$sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_subCatid)
|
60 |
+
{
|
61 |
+
$_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_subCatid);
|
62 |
+
if($_sub_sub_sub_sub_category->getIsActive()) {
|
63 |
+
$options[] = array(
|
64 |
+
'label' => '---------'.$_sub_sub_sub_sub_category->getName(),
|
65 |
+
'value' => $_sub_sub_sub_sub_category->getId()
|
66 |
+
);
|
67 |
+
$sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_subCatid);
|
68 |
+
$sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_cat->getChildren();
|
69 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_subCatid)
|
70 |
+
{
|
71 |
+
$_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_subCatid);
|
72 |
+
if($_sub_sub_sub_sub_sub_category->getIsActive()) {
|
73 |
+
$options[] = array(
|
74 |
+
'label' => '-----------'.$_sub_sub_sub_sub_sub_category->getName(),
|
75 |
+
'value' => $_sub_sub_sub_sub_sub_category->getId()
|
76 |
+
);
|
77 |
+
$sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_subCatid);
|
78 |
+
$sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_cat->getChildren();
|
79 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_subCatid)
|
80 |
+
{
|
81 |
+
$_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_subCatid);
|
82 |
+
if($_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
83 |
+
$options[] = array(
|
84 |
+
'label' => '-------------'.$_sub_sub_sub_sub_sub_sub_category->getName(),
|
85 |
+
'value' => $_sub_sub_sub_sub_sub_sub_category->getId()
|
86 |
+
);
|
87 |
+
$sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_subCatid);
|
88 |
+
$sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
89 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_sub_subCatid)
|
90 |
+
{
|
91 |
+
$_sub_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_subCatid);
|
92 |
+
if($_sub_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
93 |
+
$options[] = array(
|
94 |
+
'label' => '---------------'.$_sub_sub_sub_sub_sub_sub_sub_category->getName(),
|
95 |
+
'value' => $_sub_sub_sub_sub_sub_sub_sub_category->getId()
|
96 |
+
);
|
97 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_subCatid);
|
98 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
99 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_sub_sub_subCatid)
|
100 |
+
{
|
101 |
+
$_sub_sub_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
102 |
+
if($_sub_sub_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
103 |
+
$options[] = array(
|
104 |
+
'label' => '-----------------'.$_sub_sub_sub_sub_sub_sub_sub_sub_category->getName(),
|
105 |
+
'value' => $_sub_sub_sub_sub_sub_sub_sub_sub_category->getId()
|
106 |
+
);
|
107 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
108 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
109 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid)
|
110 |
+
{
|
111 |
+
$_sub_sub_sub_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
112 |
+
if($_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
113 |
+
$options[] = array(
|
114 |
+
'label' => '-------------------'.$_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getName(),
|
115 |
+
'value' => $_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getId()
|
116 |
+
);
|
117 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
118 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
119 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid)
|
120 |
+
{
|
121 |
+
$_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
122 |
+
if($_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
123 |
+
$options[] = array(
|
124 |
+
'label' => '---------------------'.$_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getName(),
|
125 |
+
'value' => $_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getId()
|
126 |
+
);
|
127 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
128 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
129 |
+
foreach(explode(',',$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats) as $sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid)
|
130 |
+
{
|
131 |
+
$_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
132 |
+
if($_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getIsActive()) {
|
133 |
+
$options[] = array(
|
134 |
+
'label' => '-----------------------'.$_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getName(),
|
135 |
+
'value' => $_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_category->getId()
|
136 |
+
);
|
137 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat = Mage::getModel('catalog/category')->load($sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subCatid);
|
138 |
+
$sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_subcats = $sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_sub_cat->getChildren();
|
139 |
+
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
}
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
}
|
164 |
+
return $options;
|
165 |
+
}
|
166 |
+
|
167 |
+
}
|
168 |
+
|
app/code/community/Ghrix/Copymerge/Model/Mysql4/Merge.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Model_Mysql4_Merge extends Mage_Core_Model_Mysql4_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct()
|
5 |
+
{
|
6 |
+
$this->_init('ghrix_copymerge/merge', 'id');
|
7 |
+
}
|
8 |
+
}
|
app/code/community/Ghrix/Copymerge/Model/Mysql4/Merge/Collection.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Model_Mysql4_Merge_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct()
|
5 |
+
{
|
6 |
+
$this->_init('ghrix_copymerge/merge');
|
7 |
+
}
|
8 |
+
}
|
app/code/community/Ghrix/Copymerge/controllers/Adminhtml/MergeController.php
ADDED
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Ghrix_Copymerge_Adminhtml_MergeController extends Mage_Adminhtml_Controller_Action
|
3 |
+
{
|
4 |
+
public function indexAction()
|
5 |
+
{
|
6 |
+
// Let's call our initAction method which will set some basic params for each action
|
7 |
+
$this->_initAction()
|
8 |
+
->renderLayout();
|
9 |
+
}
|
10 |
+
|
11 |
+
public function newAction()
|
12 |
+
{
|
13 |
+
// We just forward the new action to a blank edit form
|
14 |
+
$this->_forward('edit');
|
15 |
+
}
|
16 |
+
|
17 |
+
public function editAction()
|
18 |
+
{
|
19 |
+
$this->_initAction();
|
20 |
+
|
21 |
+
// Get id if available
|
22 |
+
$id = $this->getRequest()->getParam('id');
|
23 |
+
$model = Mage::getModel('ghrix_copymerge/merge');
|
24 |
+
|
25 |
+
if ($id) {
|
26 |
+
// Load record
|
27 |
+
$model->load($id);
|
28 |
+
|
29 |
+
// Check if record is loaded
|
30 |
+
if (!$model->getId()) {
|
31 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('This action no longer exists.'));
|
32 |
+
$this->_redirect('*/*/');
|
33 |
+
|
34 |
+
return;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
$this->_title($model->getId() ? $model->getName() : $this->__('New Action'));
|
39 |
+
|
40 |
+
$data = Mage::getSingleton('adminhtml/session')->getMergeData(true);
|
41 |
+
if (!empty($data)) {
|
42 |
+
$model->setData($data);
|
43 |
+
}
|
44 |
+
|
45 |
+
Mage::register('ghrix_copymerge', $model);
|
46 |
+
|
47 |
+
$this->_addBreadcrumb($id ? $this->__('Edit Action') : $this->__('New Action'), $id ? $this->__('Edit Action') : $this->__('New Action'))
|
48 |
+
->_addContent($this->getLayout()->createBlock('ghrix_copymerge/adminhtml_merge_edit')->setData('action', $this->getUrl('*/*/save')))
|
49 |
+
->renderLayout();
|
50 |
+
}
|
51 |
+
|
52 |
+
public function saveAction()
|
53 |
+
{
|
54 |
+
if ($postData = $this->getRequest()->getPost()) {
|
55 |
+
|
56 |
+
$categoryId1c = $postData['cat1'];
|
57 |
+
$categoryId2c = $postData['cat2'];
|
58 |
+
|
59 |
+
|
60 |
+
//~ get parent categories of destination category
|
61 |
+
$categoryp = Mage::getModel('catalog/category')->load($categoryId2c);
|
62 |
+
|
63 |
+
$catnames = array();
|
64 |
+
foreach ($categoryp->getParentCategories() as $parent) {
|
65 |
+
$catnames[] = $parent->getID();
|
66 |
+
}
|
67 |
+
|
68 |
+
//~ get child categories of destination category
|
69 |
+
$children = Mage::getModel('catalog/category')->getCategories($categoryId2c);
|
70 |
+
|
71 |
+
foreach ($children as $category) {
|
72 |
+
$cname[]=$category->getName();
|
73 |
+
|
74 |
+
}
|
75 |
+
$Category=Mage::getModel('catalog/category')->load($categoryId1c);
|
76 |
+
$name=$Category->getName();
|
77 |
+
|
78 |
+
|
79 |
+
if($postData['actionc']=='Copy')
|
80 |
+
{
|
81 |
+
$categoryId1 = $postData['cat1'];
|
82 |
+
$categoryId2 = $postData['cat2'];
|
83 |
+
|
84 |
+
|
85 |
+
/********************Custom code for copy category*******************/
|
86 |
+
|
87 |
+
|
88 |
+
$allStores = Mage::app()->getStores();
|
89 |
+
$parentCategory = Mage::getModel('catalog/category')->load($categoryId2);
|
90 |
+
$parentCategoryId = $parentCategory->getId();
|
91 |
+
$category = Mage::getModel('catalog/category')->load($categoryId1); // The ID of the category you want to copy.
|
92 |
+
$copy = clone $category;
|
93 |
+
$copy->setId(null);
|
94 |
+
|
95 |
+
//~ ++++++++++++check if category already exist++++++++++++++++++//
|
96 |
+
$children = Mage::getModel('catalog/category')->getCategories($parentCategoryId);
|
97 |
+
|
98 |
+
foreach ($children as $category) {
|
99 |
+
$cname[]=$category->getName();
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
|
104 |
+
$Category=Mage::getModel('catalog/category')->load($categoryId1);
|
105 |
+
$name=$Category->getName();
|
106 |
+
//~ +++++++++++++++++check if category already exist+++++++++++++++++++++++++++//
|
107 |
+
|
108 |
+
if( in_array( $name ,$cname ) ){
|
109 |
+
//~ This category already exist under requested parent category.
|
110 |
+
}else{
|
111 |
+
|
112 |
+
//~ Copy and create new category
|
113 |
+
foreach ($allStores as $_eachStoreId => $val)
|
114 |
+
{
|
115 |
+
$storecategory = Mage::getModel('catalog/category')->setStoreId($_eachStoreId)->load($categoryId1);// The ID of the category you want to copy.
|
116 |
+
$copy->setStoreId($_eachStoreId);
|
117 |
+
$copy->setName($storecategory->getName());
|
118 |
+
$copy->save();
|
119 |
+
|
120 |
+
}
|
121 |
+
$customcopy=$copy->move($parentCategoryId);
|
122 |
+
$newcat= $customcopy['entity_id'];
|
123 |
+
|
124 |
+
|
125 |
+
/********************!Custom code for copy category*******************/
|
126 |
+
|
127 |
+
//***************merge two category products into one*************************//
|
128 |
+
|
129 |
+
//~ $category2Id = $postData['cat2'];
|
130 |
+
$categorymId = $postData['cat2'];
|
131 |
+
|
132 |
+
$category = new Mage_Catalog_Model_Category();
|
133 |
+
$category->load($categoryId1); //My cat id is
|
134 |
+
$prodCollection = $category->getProductCollection();
|
135 |
+
foreach ($prodCollection as $product) {
|
136 |
+
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
|
137 |
+
}
|
138 |
+
|
139 |
+
|
140 |
+
$category2 = new Mage_Catalog_Model_Category();
|
141 |
+
$category2->load($categorymId); //My cat id is
|
142 |
+
$prodCollection2 = $category2->getProductCollection();
|
143 |
+
foreach ($prodCollection2 as $product2) {
|
144 |
+
$prdIds2[] = $product2->getId(); ///Store all th eproduct id in $prdIds array
|
145 |
+
}
|
146 |
+
|
147 |
+
|
148 |
+
//merge the products into one big array
|
149 |
+
if($prdIds!='' && $prdIds2!='')
|
150 |
+
{
|
151 |
+
$merged = array_merge($prdIds, $prdIds2);
|
152 |
+
}
|
153 |
+
if($prdIds=='')
|
154 |
+
{
|
155 |
+
$merged = $prdIds2;
|
156 |
+
}
|
157 |
+
if($prdIds2=='')
|
158 |
+
{
|
159 |
+
$merged = $prdIds;
|
160 |
+
}
|
161 |
+
|
162 |
+
//Open Database Conenction
|
163 |
+
$resource = Mage::getSingleton('core/resource');
|
164 |
+
$writeConnection = $resource->getConnection('core_write');
|
165 |
+
$readConnection = $resource->getConnection('core_read');
|
166 |
+
|
167 |
+
for($i=1;$i<=count($merged);$i++)
|
168 |
+
{
|
169 |
+
|
170 |
+
$pid=$merged[$i-1];
|
171 |
+
|
172 |
+
$select= "SELECT `category_id`, `product_id`, `position` FROM catalog_category_product WHERE (category_id=$categorymId AND product_id=$pid) OR(category_id=$newcat AND product_id=$pid)";
|
173 |
+
|
174 |
+
|
175 |
+
$result1 = $readConnection->fetchAll($select);
|
176 |
+
$datacount=count($result1);
|
177 |
+
if($datacount == '0')
|
178 |
+
{
|
179 |
+
//echo 'yes';
|
180 |
+
|
181 |
+
$query1 = "insert into catalog_category_product (`category_id`,`product_id`,`position`) values($categorymId,$pid,1)";
|
182 |
+
$query2 = "insert into catalog_category_product (`category_id`,`product_id`,`position`) values($newcat,$pid,1)";
|
183 |
+
|
184 |
+
$result=$writeConnection->query($query1);
|
185 |
+
$result=$writeConnection->query($query2);
|
186 |
+
if($result)
|
187 |
+
{
|
188 |
+
//echo 'sucess';
|
189 |
+
|
190 |
+
}
|
191 |
+
}
|
192 |
+
else{
|
193 |
+
|
194 |
+
//echo 'no';
|
195 |
+
|
196 |
+
}
|
197 |
+
|
198 |
+
|
199 |
+
|
200 |
+
}
|
201 |
+
|
202 |
+
//***************merge two category products into one*************************//
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
+
|
207 |
+
}
|
208 |
+
}
|
209 |
+
if($postData['actionc']=='Move')
|
210 |
+
{
|
211 |
+
|
212 |
+
/********************Custom Move category*******************/
|
213 |
+
$categoryId = $postData['cat1'];
|
214 |
+
$parentId = $postData['cat2'];
|
215 |
+
|
216 |
+
$categoryp = Mage::getModel('catalog/category')->load($parentId);
|
217 |
+
|
218 |
+
$catnames = array();
|
219 |
+
foreach ($categoryp->getParentCategories() as $parent) {
|
220 |
+
$catnames[] = $parent->getID();
|
221 |
+
}
|
222 |
+
|
223 |
+
if(($categoryId == $parentId) || in_array( $categoryId ,$catnames ))
|
224 |
+
{
|
225 |
+
|
226 |
+
if(in_array( $categoryId ,$catnames ))
|
227 |
+
{
|
228 |
+
if($categoryId == $parentId)
|
229 |
+
{
|
230 |
+
echo 'here';
|
231 |
+
$emessage='Name of Source category and destination category should not be same.';
|
232 |
+
}else{
|
233 |
+
echo 'there';
|
234 |
+
$emessage='You cannot move parent category into its child category.';
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
$this->_getSession()->addError($this->__($emessage));
|
239 |
+
$id = $this->getRequest()->getParam('id');
|
240 |
+
if($id){
|
241 |
+
$this->_redirect('*/*/edit',array('id'=>$id));
|
242 |
+
}else{
|
243 |
+
$this->_redirect('*/*/new');
|
244 |
+
}
|
245 |
+
return;
|
246 |
+
|
247 |
+
}else{
|
248 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
249 |
+
$category->move($parentId, null);
|
250 |
+
$newcat= $parentId;
|
251 |
+
//~ exit;
|
252 |
+
|
253 |
+
/********************Custom Move category*******************/
|
254 |
+
//***************merge two category products into one*************************//
|
255 |
+
|
256 |
+
//~ $category2Id = $postData['cat2'];
|
257 |
+
$categorymId = $postData['cat2'];
|
258 |
+
|
259 |
+
$category = new Mage_Catalog_Model_Category();
|
260 |
+
$category->load($categoryId); //My cat id is
|
261 |
+
$prodCollection = $category->getProductCollection();
|
262 |
+
foreach ($prodCollection as $product) {
|
263 |
+
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
|
264 |
+
}
|
265 |
+
|
266 |
+
|
267 |
+
$category2 = new Mage_Catalog_Model_Category();
|
268 |
+
$category2->load($newcat); //My cat id is
|
269 |
+
$prodCollection2 = $category2->getProductCollection();
|
270 |
+
foreach ($prodCollection2 as $product2) {
|
271 |
+
$prdIds2[] = $product2->getId(); ///Store all th eproduct id in $prdIds array
|
272 |
+
}
|
273 |
+
|
274 |
+
|
275 |
+
//merge the products into one big array
|
276 |
+
if($prdIds!='' && $prdIds2!='')
|
277 |
+
{
|
278 |
+
$merged = array_merge($prdIds, $prdIds2);
|
279 |
+
}
|
280 |
+
if($prdIds=='')
|
281 |
+
{
|
282 |
+
$merged = $prdIds2;
|
283 |
+
}
|
284 |
+
if($prdIds2=='')
|
285 |
+
{
|
286 |
+
$merged = $prdIds;
|
287 |
+
}
|
288 |
+
|
289 |
+
//Open Database Conenction
|
290 |
+
$resource = Mage::getSingleton('core/resource');
|
291 |
+
$writeConnection = $resource->getConnection('core_write');
|
292 |
+
$readConnection = $resource->getConnection('core_read');
|
293 |
+
|
294 |
+
for($i=1;$i<=count($merged);$i++)
|
295 |
+
{
|
296 |
+
|
297 |
+
$pid=$merged[$i-1];
|
298 |
+
|
299 |
+
$select= "SELECT `category_id`, `product_id`, `position` FROM catalog_category_product WHERE category_id=$newcat AND product_id=$pid";
|
300 |
+
|
301 |
+
|
302 |
+
$result1 = $readConnection->fetchAll($select);
|
303 |
+
$datacount=count($result1);
|
304 |
+
if($datacount == '0')
|
305 |
+
{
|
306 |
+
//echo 'yes';
|
307 |
+
|
308 |
+
$query1 = "insert into catalog_category_product (`category_id`,`product_id`,`position`) values($newcat,$pid,1)";
|
309 |
+
|
310 |
+
$result=$writeConnection->query($query1);
|
311 |
+
|
312 |
+
if($result)
|
313 |
+
{
|
314 |
+
//echo 'sucess';
|
315 |
+
|
316 |
+
}
|
317 |
+
}
|
318 |
+
else{
|
319 |
+
|
320 |
+
//echo 'no';
|
321 |
+
|
322 |
+
}
|
323 |
+
|
324 |
+
|
325 |
+
|
326 |
+
}
|
327 |
+
|
328 |
+
//***************merge two category products into one*************************//
|
329 |
+
|
330 |
+
|
331 |
+
|
332 |
+
|
333 |
+
}
|
334 |
+
}
|
335 |
+
$model = Mage::getSingleton('ghrix_copymerge/merge');
|
336 |
+
$model->setData($postData);
|
337 |
+
|
338 |
+
try {
|
339 |
+
if( in_array( $name ,$cname )){
|
340 |
+
//~ This category already exist under requested parent category.
|
341 |
+
|
342 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Requested category already exist please try with another one'));
|
343 |
+
$id = $this->getRequest()->getParam('id');
|
344 |
+
if($id){
|
345 |
+
$this->_redirect('*/*/edit',array('id'=>$id));
|
346 |
+
}else{
|
347 |
+
$this->_redirect('*/*/new');
|
348 |
+
}
|
349 |
+
|
350 |
+
return;
|
351 |
+
}else{
|
352 |
+
|
353 |
+
$model->save();
|
354 |
+
|
355 |
+
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The action has been saved.'));
|
356 |
+
$this->_redirect('*/*/');
|
357 |
+
|
358 |
+
return;
|
359 |
+
}
|
360 |
+
}
|
361 |
+
catch (Mage_Core_Exception $e) {
|
362 |
+
//Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
363 |
+
|
364 |
+
}
|
365 |
+
catch (Exception $e) {
|
366 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this action.'));
|
367 |
+
}
|
368 |
+
|
369 |
+
Mage::getSingleton('adminhtml/session')->setMergeData($postData);
|
370 |
+
$this->_redirectReferer();
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
public function messageAction()
|
375 |
+
{
|
376 |
+
$data = Mage::getModel('ghrix_copymerge/merge')->load($this->getRequest()->getParam('id'));
|
377 |
+
echo $data->getContent();
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Initialize action
|
382 |
+
*
|
383 |
+
* Here, we set the breadcrumbs and the active menu
|
384 |
+
*
|
385 |
+
* @return Mage_Adminhtml_Controller_Action
|
386 |
+
*/
|
387 |
+
protected function _initAction()
|
388 |
+
{
|
389 |
+
$this->loadLayout()
|
390 |
+
// Make the active menu match the menu config nodes (without 'children' inbetween)
|
391 |
+
->_setActiveMenu('merge/ghrix_copymerge_merge')
|
392 |
+
->_title($this->__('Category Handler'))->_title($this->__('Category Handler'))
|
393 |
+
->_addBreadcrumb($this->__('Category Handler'), $this->__('Category Handler'))
|
394 |
+
->_addBreadcrumb($this->__('Category Handler'), $this->__('Category Handler'));
|
395 |
+
|
396 |
+
return $this;
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Check currently called action by permissions for current user
|
401 |
+
*
|
402 |
+
* @return bool
|
403 |
+
*/
|
404 |
+
protected function _isAllowed()
|
405 |
+
{
|
406 |
+
return Mage::getSingleton('admin/session')->isAllowed('merge/ghrix_copymerge_merge');
|
407 |
+
}
|
408 |
+
|
409 |
+
|
410 |
+
public function deleteAction() {
|
411 |
+
if( $this->getRequest()->getParam('id') > 0) {
|
412 |
+
try {
|
413 |
+
$deleteact = Mage::getModel('ghrix_copymerge/merge');
|
414 |
+
$deleteact->setId($this->getRequest()->getParam('id'))->delete();
|
415 |
+
Mage::getSingleton('adminhtml/session')->addSuccess('Deleted');
|
416 |
+
$this->_redirect('*/*/');
|
417 |
+
return;
|
418 |
+
}
|
419 |
+
catch (Mage_Core_Exception $e){
|
420 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
421 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
422 |
+
}
|
423 |
+
catch (Exception $e) {
|
424 |
+
Mage::getSingleton('adminhtml/session')->addError('There was an error deleteing.');
|
425 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
426 |
+
Mage::logException($e);
|
427 |
+
return;
|
428 |
+
}
|
429 |
+
}
|
430 |
+
Mage::getSingleton('adminhtml/session')->addError('Could not find record to delete.');
|
431 |
+
$this->_redirect('*/*/');
|
432 |
+
}
|
433 |
+
|
434 |
+
|
435 |
+
}
|
app/code/community/Ghrix/Copymerge/etc/config.xml
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ghrix_Copymerge>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Ghrix_Copymerge>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<helpers>
|
11 |
+
<ghrix_copymerge>
|
12 |
+
<class>Ghrix_Copymerge_Helper</class>
|
13 |
+
</ghrix_copymerge>
|
14 |
+
</helpers>
|
15 |
+
|
16 |
+
<blocks>
|
17 |
+
<ghrix_copymerge>
|
18 |
+
<class>Ghrix_Copymerge_Block</class>
|
19 |
+
</ghrix_copymerge>
|
20 |
+
</blocks>
|
21 |
+
|
22 |
+
<models>
|
23 |
+
<ghrix_copymerge>
|
24 |
+
<class>Ghrix_Copymerge_Model</class>
|
25 |
+
<resourceModel>ghrix_copymerge_mysql4</resourceModel>
|
26 |
+
</ghrix_copymerge>
|
27 |
+
<ghrix_copymerge_mysql4>
|
28 |
+
<class>Ghrix_Copymerge_Model_Mysql4</class>
|
29 |
+
<entities>
|
30 |
+
<merge>
|
31 |
+
<table>ghrix_copymerge_merge</table>
|
32 |
+
</merge>
|
33 |
+
</entities>
|
34 |
+
</ghrix_copymerge_mysql4>
|
35 |
+
</models>
|
36 |
+
<resources>
|
37 |
+
<ghrix_copymerge_setup>
|
38 |
+
<setup>
|
39 |
+
<module>Ghrix_Copymerge</module>
|
40 |
+
</setup>
|
41 |
+
</ghrix_copymerge_setup>
|
42 |
+
</resources>
|
43 |
+
</global>
|
44 |
+
|
45 |
+
<admin>
|
46 |
+
<routers>
|
47 |
+
<adminhtml>
|
48 |
+
<args>
|
49 |
+
<modules>
|
50 |
+
<Ghrix_Copymerge before="Mage_Adminhtml">Ghrix_Copymerge_Adminhtml</Ghrix_Copymerge>
|
51 |
+
</modules>
|
52 |
+
</args>
|
53 |
+
</adminhtml>
|
54 |
+
</routers>
|
55 |
+
</admin>
|
56 |
+
|
57 |
+
<adminhtml>
|
58 |
+
<layout>
|
59 |
+
<updates>
|
60 |
+
<ghrix_copymerge>
|
61 |
+
<file>ghrix/copymerge.xml</file>
|
62 |
+
</ghrix_copymerge>
|
63 |
+
</updates>
|
64 |
+
</layout>
|
65 |
+
<menu>
|
66 |
+
<ghrix_copymerge_merge translate="title" module="ghrix_copymerge">
|
67 |
+
<title>Category Handler</title>
|
68 |
+
<action>adminhtml/merge</action>
|
69 |
+
</ghrix_copymerge_merge>
|
70 |
+
<sort_order>2</sort_order>
|
71 |
+
</menu>
|
72 |
+
</adminhtml>
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
</config>
|
app/code/community/Ghrix/Copymerge/sql/ghrix_copymerge_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
3 |
+
$installer = $this;
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Create table 'ghrix_copymerge_merge'
|
8 |
+
*/
|
9 |
+
$table = $installer->getConnection()
|
10 |
+
// The following call to getTable('ghrix_copymerge/merge') will lookup the resource for ghrix_copymerge (ghrix_copymerge_mysql4), and look
|
11 |
+
// for a corresponding entity called merge. The table name in the XML is ghrix_copymerge_merge, so ths is what is created.
|
12 |
+
->newTable($installer->getTable('ghrix_copymerge/merge'))
|
13 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
14 |
+
'identity' => true,
|
15 |
+
'unsigned' => true,
|
16 |
+
'nullable' => false,
|
17 |
+
'primary' => true,
|
18 |
+
), 'ID')
|
19 |
+
->addColumn('date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
|
20 |
+
'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT
|
21 |
+
), 'Date')
|
22 |
+
->addColumn('cat1', Varien_Db_Ddl_Table::TYPE_CLOB, 0, array(
|
23 |
+
'nullable' => false,
|
24 |
+
), 'cat1')
|
25 |
+
->addColumn('cat2', Varien_Db_Ddl_Table::TYPE_CLOB, 0, array(
|
26 |
+
'nullable' => false,
|
27 |
+
), 'cat2')
|
28 |
+
->addColumn('actionc', Varien_Db_Ddl_Table::TYPE_CLOB, 0, array(
|
29 |
+
'nullable' => false,
|
30 |
+
), 'Action');
|
31 |
+
//~ ->addColumn('recursive', Varien_Db_Ddl_Table::TYPE_CLOB, 0, array(
|
32 |
+
//~ 'nullable' => false,
|
33 |
+
//~ ), 'Recursive');
|
34 |
+
$installer->getConnection()->createTable($table);
|
35 |
+
|
36 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/ghrix/copymerge.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
|
4 |
+
<default>
|
5 |
+
<reference name="head">
|
6 |
+
<action method="addCss">
|
7 |
+
<name>ghrix/cat_merge.css</name>
|
8 |
+
</action>
|
9 |
+
<action method="addJs"><script>ghrix/cat_merge.js</script></action>
|
10 |
+
</reference>
|
11 |
+
</default>
|
12 |
+
|
13 |
+
<adminhtml_merge_index>
|
14 |
+
<reference name="content">
|
15 |
+
<block type="ghrix_copymerge/adminhtml_merge" name="ghrix_copymerge_merge" />
|
16 |
+
</reference>
|
17 |
+
</adminhtml_merge_index>
|
18 |
+
</layout>
|
app/etc/modules/Ghrix_Copymerge.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ghrix_Copymerge>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Ghrix_Copymerge>
|
8 |
+
</modules>
|
9 |
+
</config>
|
js/ghrix/cat_merge.js
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
window.onload = function() {
|
2 |
+
document.getElementById("actioncCopy").checked=true;
|
3 |
+
document.getElementById("cat1").size="15";
|
4 |
+
document.getElementById("cat2").size="15";
|
5 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Ghrix_Copymerge</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>This extension for magento ecommerce used to copy or move source category with products to destination category.</summary>
|
10 |
+
<description>This extension for magento ecommerce used to copy or move source category with products to destination category.</description>
|
11 |
+
<notes>Copy Categories extension</notes>
|
12 |
+
<authors><author><name>Ghrix</name><user>Team</user><email>info@ghrix.com</email></author></authors>
|
13 |
+
<date>2017-01-17</date>
|
14 |
+
<time>10:58:25</time>
|
15 |
+
<contents><target name="magecommunity"><dir><dir name="Ghrix"><dir name="Copymerge"><dir name="Block"><dir name="Adminhtml"><dir name="Merge"><dir name="Edit"><file name="Form.php" hash="65f57bf2342db42afb218dcf9633d400"/></dir><file name="Edit.php" hash="69bd596b821427dbd64162e2e16ad9f6"/><file name="Grid.php" hash="e1992638d62ca328adaeaf4cb25a4274"/><dir name="Renderer"><file name="Catname.php" hash="41f77bbaa767133860af326a42757ac6"/></dir></dir><file name="Merge.php" hash="36d6485649bc28986dfc5fe97d84b367"/></dir></dir><dir name="Helper"><file name="Data.php" hash="105a7ac985467fbbef19007a94930d38"/></dir><dir name="Model"><file name="Merge.php" hash="e8d7e1c56af07bd9503a69ce4feba484"/><dir name="Mysql4"><dir name="Merge"><file name="Collection.php" hash="41b4720d267d0c688d050b3d8cffbb73"/></dir><file name="Merge.php" hash="6ce10de8e927ffd70120b6c37b902299"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="MergeController.php" hash="1b739810dd702276d4af6805a063b6d4"/></dir></dir><dir name="etc"><file name="config.xml" hash="ad9dc61bf010bf25ddc26a4f64687c25"/></dir><dir name="sql"><dir name="ghrix_copymerge_setup"><file name="mysql4-install-1.0.0.php" hash="7e9e95a830073cfc162bc38d9d90b870"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Ghrix_Copymerge.xml" hash="b7fcdba5e5ab2efaad9a46da781dd9fe"/></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="ghrix"><file name="copymerge.xml" hash="816fa5dd5ab9d73813bfbf5e12d9368c"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="ghrix"><file name="cat_merge.css" hash="d5b7a8ee8ea3e4086d3fd824958873ca"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="ghrix"><file name="cat_merge.js" hash="f14b57035dfdd69ed291131558bfee6c"/></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|
skin/adminhtml/default/default/ghrix/cat_merge.css
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#custom_source {
|
2 |
+
border-right: 1px solid #ddd;
|
3 |
+
display: block;
|
4 |
+
float: left;
|
5 |
+
padding: 0 20px 0 0;
|
6 |
+
height: auto;
|
7 |
+
}
|
8 |
+
#custom_destination {
|
9 |
+
display: block;
|
10 |
+
float: left;
|
11 |
+
padding: 0 0 0 20px;
|
12 |
+
width: auto;
|
13 |
+
height: auto;
|
14 |
+
}
|
15 |
+
#custom_date {
|
16 |
+
float: left;
|
17 |
+
margin: 10px 0;
|
18 |
+
width: 100%;
|
19 |
+
}
|
20 |
+
#custom_action {
|
21 |
+
float: left;
|
22 |
+
margin: 20px 0 0;
|
23 |
+
width: 100%;
|
24 |
+
}
|
25 |
+
#actioncCopy {
|
26 |
+
margin-right: 6px;
|
27 |
+
}
|
28 |
+
#actioncMove {
|
29 |
+
margin-right: 6px;
|
30 |
+
}
|