Skip to content

show custom price related attribute show on the MiniCart and the checkout

This is my Product attribute

<?php
namespace VendorModuleSetupPatchData;

use MagentoCatalogModelProduct;
use MagentoEavModelEntityAttributeScopedAttributeInterface;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;

class CustomAttribute implements DataPatchInterface
{    /**
 * ModuleDataSetupInterface
 *
 * @var ModuleDataSetupInterface
 */
    private ModuleDataSetupInterface $moduleDataSetup;
    /**
     * EavSetupFactory
     *
     * @var EavSetupFactory
     */
    private EavSetupFactory $eavSetupFactory;
    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory          $eavSetupFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function apply()
    {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
        $eavSetup->addAttribute(
            Product::ENTITY,
            'custom_price',
            [
                'type' => 'decimal',
                'backend' => '',
                'frontend' => '',
                'label' => 'Custom Price',
                'input' => 'price',
                'class' => '',
                'source' => '',
                'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '',
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => true,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => ''
            ]
        );
    }
        public static function getDependencies(): array
        {
            return [];
        }
        /**
         * {@inheritdoc}
         */
        public function getAliases(): array
        {
            return [];
        }

}

My this attribute is saving in the quote, quote_item , sales_order_item and sales_order.

I want to show this attribute on the MiniCart and on the checkout with the grand total.