How to override magento 2 order/items/renderer/default.phtml?

We can override default.phtml file using below way,
Create sales_order_item_renderers.xml in your module layout folder,
File path will be in your module,
app/code/Rbj/Training/view/frontend/layout/sales_order_item_renderers.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="sales.order.items.renderers">
            <block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer"
                   name="sales.order.items.renderer.default.configurable" as="configurable"
                   template="Rbj_Training::order/items/renderer/default.phtml"/>
            <block class="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer"
                   name="sales.order.items.renderer.default.simple" as="simple"
                   template="Rbj_Training::order/items/renderer/default.phtml"/>
            <block class="Magento\Downloadable\Block\Sales\Order\Item\Renderer\Downloadable"
                   name="sales.order.items.renderer.downloadable" as="downloadable"
                   template="Rbj_Training::order/items/renderer/default.phtml"/>
            <block class="Magento\Bundle\Block\Sales\Order\Items\Renderer"
                   name="sales.order.items.renderers.bundle" as="bundle"
                   template="Rbj_Training::order/items/renderer/bundle/renderer.phtml"/>
            <block class="Magento\GroupedProduct\Block\Order\Item\Renderer\Grouped"
                   name="sales.order.items.renderers.grouped" as="grouped"
                   template="Rbj_Training::order/items/renderer/default.phtml"/>
        </referenceBlock>
    </body>
</page>

Replace Rbj_Training with your actual module name.

Clear Cache and check your file will be overridden.

How to send image attachment with email template in Magento 2.4

Magento 2.4 Send Email with image attachment in the email template file.

This solution should work 2.4.* and a higher version.

For Attach an image in the email template, you need to override TransportBuilder Class from Magento\Framework\Mail\Template\TransportBuilder

For Send Custom Email with simple raw data refer link,  Send Mail from Custom module Magento 2

To Override the TransportBuilder class in Magento 2, you need to create a di.xml file. With this XML file, you can write syntax to override the Model class.

Continue reading “How to send image attachment with email template in Magento 2.4”

How to create database table with Install Schema in Magento 2?

In Magento 2, You need to create an InstallSchema.php file in the Setup folder under your module. In my case, the Module name is Rbj_Training,

Below code snippets are created database table name of create_form.

<?php
namespace Rbj\Training\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{
    public function install(
        SchemaSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        //Your install script

        $createform = $setup->getConnection()->newTable($setup->getTable('create_form'));

        $createform->addColumn(
            'entity_id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['identity' => true,'nullable' => false,'primary' => true,'unsigned' => true,],
            'Entity ID'
        );

        $createform->addColumn(
            'name',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            50,
            [],
            'name'
        );

        $createform->addColumn(
            'phone_no',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            20,
            [],
            'phone_no'
        );

        $createform->addColumn(
            'image',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            [],
            'Image'
        );

        $setup->getConnection()->createTable($createform);
    }
}

Above script create create_form table with 4 fields, entity_id, name, phone_no, image

entity_id is an auto-increment field, a name is for name display, phone_no is used for phone and image is for image name store.