0

Hi here am adding breadcrumbs but in product page its adding swap catagery.

until catagory its working goodenter image description here

in product page its swapping category that should not be addedenter image description here

this is my module.xml

<?xml version="1.0"?>
<page>
    <body>
    <referenceBlock name="breadcrumbs" remove="true" />
    <referenceContainer name="page.top">
        <block class="Harrigo\EverCrumbs\Block\Evercrumbs" 
        name="evercrumbs" as="evercrumbs" template="Harrigo_EverCrumbs::evercrumbs.phtml" />
    </referenceContainer>
    </body>
</page>

this is my evercrumbs.phtml file

<?php $crumbs = $block->getCrumbs(); ?>
<?php if ($crumbs && is_array($crumbs)) : ?>
<div class="breadcrumbs">
    <ul class="items">
        <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
            <li class="item <?= /* @escapeNotVerified */ $crumbName ?>">
            <?php if ($crumbInfo['link']) : ?>
                <a href="<?= /* @escapeNotVerified */ $crumbInfo['link'] ?>" title="<?= $block->escapeHtml($crumbInfo['title']) ?>"><?= $block->escapeHtml($crumbInfo['label']) ?></a>
            <?php else: ?>
                <?= $block->escapeHtml($crumbInfo['label']) ?>
            <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

this is layout file catalog_product_view.xml

public function getCrumbs()
        {
                $evercrumbs = array();

                $evercrumbs[] = array(
                        'label' => 'Home',
                        'title' => 'Go to Home Page',
                        'link' => $this->_storeManager->getStore()->getBaseUrl()
                );

                $path = $this->_catalogData->getBreadcrumbPath();
                $product = $this->registry->registry('current_product');

                $categoryCollection = clone $product->getCategoryCollection();
                $categoryCollection->clear();
                $categoryCollection->addAttributeToSort('level', $categoryCollection::SORT_ORDER_DESC)->addAttributeToFilter('path', array('like' => "1/" . $this->_storeManager->getStore()->getRootCategoryId() . "/%"));
                $categoryCollection->setPageSize(1);
                $breadcrumbCategories = $categoryCollection->getFirstItem()->getParentCategories();
                foreach ($breadcrumbCategories as $category) {
                        $evercrumbs[] = array(
                                'label' => $category->getName(),
                                'title' => $category->getName(),
                                'link' => $category->getUrl()
                        );
                }

                $evercrumbs[] = array(
                                'label' => $product->getName(),
                                'title' => $product->getName(),
                                'link' => ''
                        );

                return $evercrumbs;
        }

catalog_product_view.xml

<?xml version="1.0"?>
<page>
    <body>
    <referenceBlock name="breadcrumbs" remove="true" />
    <referenceContainer name="page.top">
        <block class="Harrigo\EverCrumbs\Block\Evercrumbs" 
        name="evercrumbs" as="evercrumbs" template="Harrigo_EverCrumbs::evercrumbs.phtml" />
    </referenceContainer>
    </body>
</page>

can i get help to solve it ? Thank you in advance

0

Having the same issue! Any update from you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.