0

After upgrading to Magento 2.2.0, the Magehit bestseller module is causing the following exception. Can someone please help solving it?

Thanks

1 exception(s): Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magehit_Bestsellerproducts::html/bestsellerblock.phtml' in module: 'Magehit_Bestsellerproducts' block's name: 'bestseller_data'

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Magehit_Bestsellerproducts::html/bestsellerblock.phtml' in module: 'Magehit_Bestsellerproducts' block's name: 'bestseller_data'

#0 /var/www/vhosts/testdomain/staging.testdomain/generated/code/Magehit/Bestsellerproducts/Block/Home/BestsellerList/Interceptor.php(713): Magento\Framework\View\Element\Template->fetchView(false) #1 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Element/Template.php(300): Magehit\Bestsellerproducts\Block\Home\BestsellerList\Interceptor->fetchView(false) #2 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #3 /var/www/vhosts/testdomain/staging.testdomain/generated/code/Magehit/Bestsellerproducts/Block/Home/BestsellerList/Interceptor.php(1038): Magento\Framework\View\Element\AbstractBlock->toHtml() #4 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Layout.php(558): Magehit\Bestsellerproducts\Block\Home\BestsellerList\Interceptor->toHtml() #5 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('bestseller_data') #6 /var/www/vhosts/testdomain/staging.testdomain/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('bestseller_data') #7 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('bestseller_data') #8 /var/www/vhosts/testdomain/staging.testdomain/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('bestseller_data', true) #9 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('bestseller_data') #10 /var/www/vhosts/testdomain/staging.testdomain/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('content')

... further errors

  • can you paste template path? – Greg Jan 30 '18 at 22:15
  • @BareFeet: Searching for the bestsellerblock.phtml gives me these two paths: ./var/view_preprocessed/pub/static/app/code/Magehit/Bestsellerproducts/view/frontend/templates/bestsellerblock.phtml ./app/code/Magehit/Bestsellerproducts/view/frontend/templates/bestsellerblock.phtml – etacarina Jan 31 '18 at 8:36
  • I think what Barefeet means is can you post screenshot(s) of your entire file with regards to your module, it may make debugging a bit easier – John Feb 1 '18 at 10:56
0

I cannot write comments so I write this on answers.

Temporary removing Magehit/Bestsellerproducts/view/frontend/layout/cms_index_index.xml fix the problem and store work again.

I have same issue plus I found this on logs:

[2018-04-09 18:55:04] main.INFO: Broken reference: the 'bestsellerproducts.left' tries to reorder itself towards '', but their parents are different: 'div.sidebar.additional' and '' respectively. [] []
[2018-04-09 18:55:04] main.INFO: Broken reference: the 'new.link3' tries to reorder itself towards 'new-link2', but their parents are different: 'header-custom-link' and '' respectively. [] []
[2018-04-09 18:55:04] main.INFO: Broken reference: the 'new.link2' tries to reorder itself towards 'new-link', but their parents are different: 'header-custom-link' and '' respectively. [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'bestsellerproducts.left' element cannot be added as child to 'div.sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'paypal.partner.right.logo' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'bml.right.logo' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2018-04-09 18:55:06] main.INFO: Broken reference: the 'bestsellerproducts.left' tries to reorder itself towards '', but their parents are different: 'div.sidebar.additional' and '' respectively. [] []

This is bestsellerblock.phtml

<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\App\Action\Action;

?>
<?php
$enableModule = $block->getSectionStatus();
if($this->getSlideAuto() == 1) $slide_auto = 'true'; else $slide_auto = 'false';
if($this->getPagination() == 1) $slide_pagination = 'true'; else $slide_pagination = 'false';
if($this->getNavigation() == 1) $slide_navigation = 'true'; else $slide_navigation = 'false';
if ($enableModule) {
    $block_title = $block->getPageTitle();
    $_productCollection = $block->getLoadedProductCollection();
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\Image');
    ?>
    <?php if (!$_productCollection->count()): ?>
        <div class="message info empty"><div><?php echo __('We can\'t find products matching the selection.') ?></div></div>
    <?php else: ?>
        <?php
        if ($block->getMode() == 'grid') {
            $viewMode = 'grid';
            $image = 'category_page_grid';
            $showDescription = false;
            $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
        } else {
            $viewMode = 'list';
            $image = 'category_page_list';
            $showDescription = true;
            $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
        }
        $pos = $block->getPositioned();
        $position = '';
        if ($pos != null) {
            $position = ' style="left:' . $block->getVar("{$image}:width") . 'px;'
                    . 'top:' . $block->getVar("{$image}:height") . 'px;"';
        }
        ?>
        <div class="pad-main-bottom wrapper <?php echo $viewMode; ?> products-<?php echo $viewMode; ?>">
            <div class="block-title-main">
                <h2><?php echo $block_title ?></h2>
                <div class="title-border"></div>
            </div>
            <?php $iterator = 1; ?>
            <ol class="products list items product-items bestsellerproducts">
                <?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
                <?php foreach ($_productCollection as $_product): ?>
                    <?php echo($iterator++ == 1) ? '<li style="margin-top:20px;" class="item product product-item">' : '</li><li style="margin-top:20px;" class="item product product-item">' ?>
                    <div class="product-item-info" data-container="product-grid">
                        <?php // Product Image    ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
                            <span style="width:240px;" class="product-image-container">
                                <span style="padding-bottom: 137%;" class="product-image-wrapper">
                                    <?php
                                    $imageUrl = $this->helper('Magento\Catalog\Helper\Image')
                                            ->init($_product, 'product_page_image_large')
                                            ->constrainOnly(FALSE)
                                            ->keepAspectRatio(TRUE)
                                            ->keepFrame(FALSE)
                                            ->resize(270, 371)
                                            ->getUrl();
                                    ?>
                                    <img class="product-image-photo" src="<?php echo $imageUrl; ?>" />
                                    <!--<img class="product-image-photo" src="<?php //echo $this->helper('Magento\Catalog\Helper\Image')->init($_product, 'image');                          ?>"height="240" width="240" />-->
                                </span>
                            </span>
                        </a>

                        <div class="product details product-item-details">
                            <div style="padding: 0 2px;"><?php echo $block->getProductDetailsHtml($_product); ?></div>
                            <?php
                            $_productNameStripped = $block->stripTags($_product->getName(), null, true);
                            ?>
                            <strong class="product name product-item-name">
                                <a class="product-item-link"
                                   href="<?php echo $_product->getProductUrl() ?>">
                                       <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                                </a>
                            </strong>
                            <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
                            <?php echo $block->getProductPrice($_product) ?>

                            <div class="">
                                <div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
                                    <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
                                        <?php if ($_product->isSaleable()): ?>
                                            <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                            <form data-role="tocart-form" action="<?php echo $postParams['action']; ?>" method="post">
                                                <input type="hidden" name="product" value="<?php echo $postParams['data']['product']; ?>">
                                                <input type="hidden" name="<?php echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                                <?php echo $block->getBlockHtml('formkey') ?>
                                                <button type="submit"
                                                        title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                        class="action tocart primary">
                                                    <span><?php echo __('Add to Cart') ?></span>
                                                </button>
                                            </form>
                                        <?php else: ?>
                                            <?php if ($_product->getIsSalable()): ?>
                                                <div class="stock available"><span><?php echo __('In stock') ?></span></div>
                                            <?php else: ?>
                                                <div class="stock unavailable"><span><?php echo __('Out of stock') ?></span></div>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    </div>
                                    <div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
                                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                                            <a href="#"
                                               class="action towishlist"
                                               title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                               aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                               data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
                                               data-action="add-to-wishlist"
                                               role="button">
                                                <span><?php echo __('Add to Wish List') ?></span>
                                            </a>
                                        <?php endif; ?>
                                        <?php
                                        $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                                        ?>
                                        <a href="#"
                                           class="action tocompare"
                                           title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                           aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                           data-post='<?php echo $compareHelper->getPostDataParams($_product); ?>'
                                           role="button">
                                            <span><?php echo __('Add to Compare') ?></span>
                                        </a>
                                    </div>
                                </div>
                                <?php if ($showDescription): ?>
                                    <div class="product description product-item-description">
                                        <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>"
                                           class="action more"><?php echo __('Learn More') ?></a>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <?php echo($iterator == count($_productCollection) + 1) ? '</li>' : '' ?>
                <?php endforeach; ?>
            </ol>
            <div class="view-all"><a href="<?php echo $this->getUrl('bestsellerproducts') ?>"><?php echo __('View all') ?></a></div>
        </div>
        <?php if (!$block->isRedirectToCartEnabled()) : ?>
            <script type="text/x-magento-init">
                {
                "[data-role=tocart-form], .form.map.checkout": {
                "catalogAddToCart": {}
                }
                }
            </script>
        <?php endif; ?>
    <?php endif; ?>

    <script>
        require(['jquery', 'cpowlcarousel'], function () {
            jQuery(document).ready(function () {
                jQuery(".bestsellerproducts").owlCarousel({
                    items: 5,
                    itemsDesktop: [1080, 4],
                    itemsDesktopSmall: [860, 4],
                    itemsTablet: [768,3],
                    itemsTabletSmall: [639, 2],
                    itemsMobile: [360, 1],
                    pagination: <?php echo $slide_pagination ?>,
                    navigation: <?php echo $slide_navigation ?>,
                    lazyLoad : true,
                    navigationText: ["<div class='prev-btn'>previours</div>", "<div class='next-btn'>next</div>"],
                    autoPlay : <?php echo $slide_auto ?>,
                });
            });
        });
    </script>
    <?php
}
?>

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.