1

Widget-Block: app/code/Gworks/Recentviewed/Block/Widget/Recent.php

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Gworks\Recentviewed\Block\Widget;

/**
 * Reports Recently Viewed Products Widget
 */
class Recent extends \Magento\Reports\Block\Product\Viewed implements \Magento\Widget\Block\BlockInterface
{
    /**
     * Internal constructor
     *
     * @return void
     */
    protected function _construct()
    {
    parent::_construct();
    $this->addColumnCountLayoutDepend('1column', 5)
        ->addColumnCountLayoutDepend('2columns-left', 4)
        ->addColumnCountLayoutDepend('2columns-right', 4)
        ->addColumnCountLayoutDepend('3columns', 3);
    }

}

Widget-Tempalte: app/code/Gworks/Recentviewed/view/frontend/templates/widget/recently_widget.phtml

<?php
/**
 * @var $block \Magento\Reports\Block\Product\Viewed
 */
?>
<?php
if ($exist = ($block->getRecentlyViewedProducts() && $block->getRecentlyViewedProducts()->getSize())) {
    $type = 'widget-viewed';
    $mode = 'grid';

    $type = $type . '-' . $mode;

    $image = 'recently_viewed_products_grid_content_widget';
    $title = __('Recently Viewed');
    $items = $block->getRecentlyViewedProducts();

    $showWishlist = true;
    $showCompare = true;
    $showCart = true;
    $rating = 'short';
    $description = ($mode == 'list') ? true : false;
}
?>

<?php
if($exist)
{
    echo "success";
}
else
{
    echo "unsuccess";
}
?>

Behaviour-1

When I insert widget in cms static block

{{widget type="Gworks\Recentviewed\Block\Widget\Recent" template="widget/recently_widget.phtml" c_recent_count="3"}}

I got unsuccess message

Behaviour -2

When I add through content->widget->add widget set to CMS home page

I got success message.

I am looking getting success in both of the way.

can anyone suggest me to why it is behave like this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.