0

I am new to this Magento platform.

I want to create a custom widget to retrieve the price so that I can use it just by calling the widget on the front page.

May anyone help me?

1 Answer 1

0

You can create one block file in your custom module like

path app/code/YourVendor/YourModule/Block/PriceWidget.php

<?php
namespace YourVendor\YourModule\Block;

use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;

class PriceWidget extends Template implements BlockInterface
{
    // Implement logic here to retrieve the product price.
}

create widget.xml in the following path

app/code/YourVendor/YourModule/etc/widget.xml

<?xml version="1.0"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:widget:1.0">
    <widget id="yourmodule_price_widget" class="YourVendor\YourModule\Block\PriceWidget">
        <label translate="true">Price Widget</label>
        <description translate="true">Display product price.</description>
        <parameters>
            <!-- Add widget parameters here if needed -->
        </parameters>
    </widget>
</widgets>

In the Magento Admin Panel, you can now insert your custom widget into a CMS page or block. Go to the CMS page or block where you want to display the price and use the widget insertion tool to add your custom widget.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.