I seem to have a problem. I created a sub-category and accidentally assigned its parent category as itself. Now, it has dissappeared from the category list in the admin panel.
I can still see it under brands and when I click there, I can see the sub-categoryitself as a sub-list - bizarre.
Any ideas on how to un-assign itself?
I can still see it under brands and when I click there, I can see the sub-categoryitself as a sub-list - bizarre.
Any ideas on how to un-assign itself?
You'll have to log in to your database with phpMyAdmin (or something similar) and edit the parent field of the relevant category.
To prevent it from happening again, you will need to edit the following 3 files:
admin/controller/catalog/category.php
admin/language/english/catalog/category.php
admin/view/template/catalog/category_form.tpl
admin/controller/catalog/category.php
Insert the following at around line 181:
Then, at around what is now line 309, insert the following in the vaidateForm() function:
admin/language/english/catalog/category.php
Insert the following near the end of the file:
admin/view/template/catalog/category_form.tpl
Find the following (at around lines 51 to 60):
Between the closing "</select>" and "</td>" at the end of this block, insert:
So that the whole block looks something like:
To prevent it from happening again, you will need to edit the following 3 files:
admin/controller/catalog/category.php
admin/language/english/catalog/category.php
admin/view/template/catalog/category_form.tpl
admin/controller/catalog/category.php
Insert the following at around line 181:
Code: Select all
if (isset($this->error['parent'])) {
$this->data['error_parent'] = $this->error['parent'];
} else {
$this->data['error_parent'] = '';
}
Code: Select all
if (isset($this->request->get['category_id'])) {
if ($this->request->post['parent_id'] == $this->request->get['category_id']) {
$this->error['parent'] = $this->language->get('error_parent');
}
}
Insert the following near the end of the file:
Code: Select all
$_['error_parent'] = 'Category can NOT be its own parent!';
Find the following (at around lines 51 to 60):
Code: Select all
<td><select name="parent_id">
<option value="0"><?php echo $text_none; ?></option>
<?php foreach ($categories as $category) { ?>
<?php if ($category['category_id'] == $parent_id) { ?>
<option value="<?php echo $category['category_id']; ?>" selected="selected"><?php echo $category['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option>
<?php } ?>
<?php } ?>
</select></td>
Code: Select all
<?php if (isset($error_parent)) { ?>
<span class="error"><?php echo $error_parent; ?></span>
<?php } ?>
Code: Select all
<td><select name="parent_id">
<option value="0"><?php echo $text_none; ?></option>
<?php foreach ($categories as $category) { ?>
<?php if ($category['category_id'] == $parent_id) { ?>
<option value="<?php echo $category['category_id']; ?>" selected="selected"><?php echo $category['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php if (isset($error_parent)) { ?>
<span class="error"><?php echo $error_parent; ?></span>
<?php } ?></td>
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Thanks for your help Fido. For some reason your code did not stop the error repeating.
On a side-note, when I edited the Parent field and restored its setting, this did not make it appear in the Admin console. The way to do that was to insert a dummy category in the Admin console belonging to the same parent. Then it instantly materialised! After that, I deleted the dummy and I fine.
On a side-note, when I edited the Parent field and restored its setting, this did not make it appear in the Admin console. The way to do that was to insert a dummy category in the Admin console belonging to the same parent. Then it instantly materialised! After that, I deleted the dummy and I fine.
add another small problem to this thread.
If you create 2 Categories say cat1 and cat2
then create 2 sub categories for each one named sub1 and sub2
the result being;
cat1
cat1 > sub1
cat1 > sub2
cat2
cat2 > sub1
cat2 > sub2
then I have noticed that either one of the child sub categories will not function.
for example I have no products in any category except one which I have assigned to cat1 > sub1 > Product
cat1 > sub1 > product > is visible and functions normally
cat1 > sub2 > displays message > There are no products to list in this category. > which is correct
cat2 > sub1 > Freezes > no message ^ or anything happens
cat2 > sub2 > Freezes > no message ^ or anything happens
any ideas what is causing this?
If you create 2 Categories say cat1 and cat2
then create 2 sub categories for each one named sub1 and sub2
the result being;
cat1
cat1 > sub1
cat1 > sub2
cat2
cat2 > sub1
cat2 > sub2
then I have noticed that either one of the child sub categories will not function.
for example I have no products in any category except one which I have assigned to cat1 > sub1 > Product
cat1 > sub1 > product > is visible and functions normally
cat1 > sub2 > displays message > There are no products to list in this category. > which is correct
cat2 > sub1 > Freezes > no message ^ or anything happens
cat2 > sub2 > Freezes > no message ^ or anything happens
any ideas what is causing this?
by removing the 2nd Category and redoing it , seemed to have solved my problem for the time being.
Iam not sure weather the bug will resurface later however.
fingers crossed.
Iam not sure weather the bug will resurface later however.
fingers crossed.
How come can i validate category in admin opencart in terms of if i have a parent category and it has different sub category under this certain category, how come to prevent to delete the parent category it is because it has sub category. I want to validate it if there is sub category under parent category prevent to delete the parent category. Thank you. Im trying figure out it seems to be difficult since opencart has his own framework. I can figure out this if OC is made in codeigniter as itself. Hope to help regarding this matter.
Who is online
Users browsing this forum: No registered users and 7 guests