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?

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

3
  • let me try once Jan 9 '20 at 9:03
  • Yes its working for me Jan 9 '20 at 9: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 ) Jan 9 '20 at 9: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.

2
0

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

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.