4

I want to get specific widget configuration in phtml or block.

In that phtml/block i want to load custom product collection with filter using that widget data.

I want to create a same page like product listing(category page) after getting that collection.

I also referred below solution.

Use product list template with my own product collection?

Biren Patel
  • 940
  • 7
  • 28

3 Answers3

3

I used ObjectManager but using the below code you can convert.

<?php
use \Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap     = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$instance      = \Magento\Framework\App\ObjectManager::getInstance();
$state         = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$widgetCollection = $objectManager->create('Magento\Widget\Model\Widget\Instance');
//$data = $widgetCollection->load(instanceId);
$data = $widgetCollection->load('1');
echo "<pre/>";
print_r($data->getData());

Result enter image description here

Kushal Dani
  • 2,114
  • 2
  • 17
  • 49
  • let me try once – Biren Patel Jan 09 '20 at 09:03
  • Yes its working for me – Biren Patel Jan 09 '20 at 09:05
  • Array ( [instance_id] => 169 [instance_type] => Vendor\Customwidget\Block\Widget\CustomwidgetCollection [theme_id] => 5 [title] => Deal Of The Week [store_ids] => 2 [widget_parameters] => {"block_title":"\u0635\u0641\u0642\u0629 \u0627\u0644\u0623\u0633\u0628\u0648\u0639","block_type":"best_deal","past_days":"1000","limit":"20","all_category":"1"} [sort_order] => 0 ) – Biren Patel Jan 09 '20 at 09:05
2

use parameters in widget.xml

    <parameters>
        <parameter name="category_id" sort_order="10" visible="true" xsi:type="text">
            <label>124</label>
        </parameter>
    </parameters>

you can get this value in .phtml like

<?php echo $block->getData('category_id'); ?>

hope this will work for you.

liyakat
  • 3,995
  • 7
  • 27
  • 35
0

this link has how you can get it data from phtml https://www.mageplaza.com/devdocs/magento-2-create-widget/