Post by Meeker » Mon Nov 22, 2010 2:34 am

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?

User avatar
Active Member

Posts

Joined
Thu Sep 16, 2010 5:45 am

Post by fido-x » Mon Nov 22, 2010 8:12 am

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:

Code: Select all

if (isset($this->error['parent'])) {
    $this->data['error_parent'] = $this->error['parent'];
} else {
    $this->data['error_parent'] = '';
} 
Then, at around what is now line 309, insert the following in the vaidateForm() function:

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');
    }
} 
admin/language/english/catalog/category.php
Insert the following near the end of the file:

Code: Select all

$_['error_parent'] = 'Category can NOT be its own parent!'; 
admin/view/template/catalog/category_form.tpl
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>
Between the closing "</select>" and "</td>" at the end of this block, insert:

Code: Select all

<?php if (isset($error_parent)) { ?>
<span class="error"><?php echo $error_parent; ?></span>
<?php } ?>
So that the whole block looks something like:

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>

Image
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!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Meeker » Mon Nov 22, 2010 5:25 pm

Thanks, I will try this out now.

User avatar
Active Member

Posts

Joined
Thu Sep 16, 2010 5:45 am

Post by Meeker » Tue Nov 23, 2010 8:39 am

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.

User avatar
Active Member

Posts

Joined
Thu Sep 16, 2010 5:45 am

Post by Qphoria » Tue Nov 23, 2010 10:59 am

In chromiumcart, I just removed itself from loading in the list, that might be the best way

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by simple_one » Tue Nov 23, 2010 1:05 pm

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?

Nz Shipping problems maybe resolved here.


New member

Posts

Joined
Wed Oct 27, 2010 1:53 pm

Post by simple_one » Tue Nov 23, 2010 1:43 pm

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.

Nz Shipping problems maybe resolved here.


New member

Posts

Joined
Wed Oct 27, 2010 1:53 pm

Post by doctama7160515 » Tue Aug 28, 2012 12:19 pm

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.


Posts

Joined
Tue Aug 28, 2012 12:08 pm
Who is online

Users browsing this forum: No registered users and 6 guests