Jump to content
thirty bees forum
  • 0

Breadcrumb Issues


Question

Posted

Hello all,

I've just recently experienced an issue with the breadcrumb generation within thirty bees 1.4.

The Issue: I moved a whole category (with subcategories) of items from one top-level category to a different top-level category. Now when I browse to any of those sub-categories OR their products, the breadcrumb shows the OLD category (in the appropriate spot of the crumbs) instead of the NEW category that it should. I had this problem not that long ago, but for the life of me I cannot figure out how I fixed that one.

---

Yes, I have tried purging the cache via backoffice as well as manually deleting the class_index.php file from the cache folder.

It appears that the whatever is going on with the breadcrumb string, may have something to do with updating the cache, because the category menu on the left column shows the correct "tree" to the categories/products as expected.

Also, I've tried restoring the original breadcrumb.tpl file as well as the Category.php and FrontController.php (which has an override to load the custom stylesheet last for css proximity) files with cache purges at each step and none of this seems to correct the breadcrumb issue.

So, what am I missing?

Is there another class file or something that builds the breadcrumb string that I have forgotten about or is there a caching bug in the breadcrumb routine somewhere in the code?

Thanks in advance!

 

category move not updating breadcrumb output..jpg

4 answers to this question

Recommended Posts

  • 0
Posted (edited)
16 hours ago, yaniv14 said:

maybe you can try to manually run Category::regenerateEntireNtree()

Thanks for putting me on the path...

So, for anyone with a similar issue in the future - this appears to have been the problem. I have modified a module that will regen the tree, originally written by Gianluca Randazzo (v1.0 for PrestaShop 1.4), to work with Thirty Bees 1.4 (as version 1.1.0). As soon as I am done testing everything, I plan to upload the TB modified version to this thread (or wherever) so that others at least have a utility module that will fix the nleft/nright bug that exists somewhere in the backoffice code.

 

Edited by Obi
clarity
  • 0
Posted (edited)

Ok, here's the module to regen the category tree if you have the problem presented in this thread.

My recommendation is that you add the module via the backoffice [Module and Services] section, click the install button, then when you click configure on the module list (after installing it), there will be a button to regenerate the category tree.

That's it, nothing fancy, just regen the tree and breadcrumb malfunctions from nleft/nright not being updated when you move a category (with children - I suppose is the trigger for the bug), the nleft/nright values get reset to 0 and then regenerated using the Category::regenerateEntireNtree() class.

AFTER THE INSTALL:

Screenshot_1.thumb.jpg.0ef9026362553f1f46b8fde91d12e992.jpg

 

USING THE TOOL:

Screenshot_2.thumb.jpg.08d45303875517eb8d348f956b9da168.jpg

categorytreeregen.zip

Edited by Obi
  • 0
Posted

Can you describe more detailed repro steps for this bug?

I'm unable to replicate it for now.



EDIT: Never mind, I replicated it. We should move the category on the same level and we should not have a category with the same position in the new place.

Can you try this if it's working for you so I can make a PR?

Category::update

public function update($nullValues = false)
{
    if ($this->id_parent == $this->id) {
        throw new PrestaShopException('a category cannot be its own parent');
    }

    if (PageCache::isEnabled()) {
        PageCache::invalidateEntity('category', $this->id);
    }

    // Read current persisted parent (and level) before we write anything
    $row = Db::readOnly()->getRow(
        (new DbQuery())
            ->select('`id_parent`, `level_depth`')
            ->from('category')
            ->where('`id_category` = ' . (int) $this->id)
    );
    $oldParentId   = $row ? (int) $row['id_parent'] : 0;
    $oldLevelDepth = $row ? (int) $row['level_depth'] : null;

    if ($this->is_root_category && $this->id_parent != (int) Configuration::get('PS_ROOT_CATEGORY')) {
        $this->is_root_category = 0;
    }

    // Update group selection, if provided
    if (is_array($this->groupBox)) {
        $this->updateGroup($this->groupBox);
    }

    // Compute target depth from the new parent
    $calculatedLevelDepth = $this->calcLevelDepth(); // throws if parent invalid
    $parentChanged        = ($oldParentId !== (int) $this->id_parent);
    $levelChanged         = ($oldLevelDepth === null) ? true : ($oldLevelDepth !== (int) $calculatedLevelDepth);
    $this->level_depth    = $calculatedLevelDepth;

    // If parent changed we must reseat position; otherwise do it only if duplicate exists
    $needReposition = $parentChanged || (bool) $this->getDuplicatePosition();

    // === Multistore-safe shop list to touch ===
    $shopIdsToTouch = [];
    if ($needReposition) {
        if (Tools::isSubmit('checkBoxShopAsso_category')) {
            // Admin form posted: only the explicitly associated shops
            $assoc = Tools::getArrayValue('checkBoxShopAsso_category');
            $shopIdsToTouch = array_map('intval', array_keys((array) $assoc));
        } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) {
            // Single shop context
            $shopIdsToTouch = [ (int) Context::getContext()->shop->id ];
        } else {
            // Fallback: only shops already associated with the category
            $rows = static::getShopsByCategory((int) $this->id);
            foreach ($rows as $r) {
                $shopIdsToTouch[] = (int) $r['id_shop'];
            }
            if (!$shopIdsToTouch) {
                // If somehow none, at least touch default shop to keep data consistent
                $shopIdsToTouch = [ (int) Configuration::get('PS_SHOP_DEFAULT') ];
            }
        }

        // Reseat position per associated shop
        foreach ($shopIdsToTouch as $idShop) {
            $this->addPosition((int) static::getLastPosition((int) $this->id_parent, (int) $idShop), (int) $idShop);
        }
    }

    $ret = parent::update($nullValues);

    if ($ret) {
        // Clean positions in both branches when moved; always clean in the new parent when we reseated
        if ($needReposition) {
            static::cleanPositions((int) $this->id_parent);
            if ($parentChanged && $oldParentId) {
                static::cleanPositions((int) $oldParentId);
            }
        }

        // Any parent change or depth change requires a full ntree rebuild
        if ((!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree) && ($parentChanged || $levelChanged || $needReposition)) {
            static::regenerateEntireNtree();
            $this->recalculateLevelDepth($this->id); // fix depths of descendants
        }

        Hook::triggerEvent('actionCategoryUpdate', ['category' => $this]);
    }

    return $ret;
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...