Add a block to programmatically generated widget

I need to generate a widget block with upgradeData.php and assign a block to this widget how can I do this? Folowing is my code for widget generation: Setup/UpgradeData.php public function __construct( \Magento\Cms\Model\BlockFactory $blockFactory, \Magento\Widget\Model\Widget\InstanceFactory $widgetFactory, \Magento\Framework\App\State $state ) { $this->blockFactory = $blockFactory; $this->widgetFactory = $widgetFactory; $this->state = $state; } /** * Upgrade data for…

Store the date value in a variable

Below code is used to add datepicker in magento2 front end. I need to store the selected date value in a varriable. how to do that echo $this->getLayout()->createBlock(‘Magento\Framework\View\Element\Html\Date’ )->setName( ‘date-range[from]’ )->setId( ‘from-date’ )->setValue( ” )->setImage( $this->getViewFileUrl(‘Magento_Theme::calendar.png’) )->setDateFormat( ‘y-MM-dd’ )->getHtml();

Magento 2.3.3 Store Switcher error

I have created multiple stores with multiple domains but when I select a store from frontend than giving below error. I have attached the screenshot of the error. Store Cookies does not set on multiple domains I have debugged and checked the code and print($fromStoreCode) but give blank. Magento\Store\Controller\Store\SwitchAction.php $fromStoreCode = $this->_request->getParam( ‘___from_store’, $this->storeCookieManager->getStoreCodeFromCookie() );…

How to write an observer with verification of existing id

I have bundle products on which I display selects with some data <?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Select */ ?> <?php $_option = $block->getOption(); ?> <?php $_selections = $_option->getSelections(); ?> <?php $_default = $_option->getDefaultSelection(); ?> <?php list($_defaultQty, $_canChangeQty) = $block->getDefaultValues(); ?> <div class=”field option <?php echo ($_option->getRequired()) ? ‘ required’ : ”; ?>”> <label class=”label” for=”bundle-option-<?php…