Thursday, 18 July 2019

Magento 2 : Adding additional store email addresses in the store admin

Magento 2 allows you to set five email addresses in the store admin:

  1. 1.General Contact
  2. Sales Representative
  3. Customer Support
  4. Custom Email 1
  5. Custom Email 2


add more
  • Custom Email 3
  • Custom Email 4
  • Custom Email 5
  • .
  • .
  • .
  • .
  • more.........


Need to create a new module using the below steps
Mycompany/Additionalstoreemail/

registration.php
composer.json
etc/module.xml
etc/adminhtml/system.xml

registration.php
<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mycompany_Additionalstoreemail',
    __DIR__
);
------------------------------------------------------
composer.json

{
    "name": "mycompany\/additionalstoreemail",
    "description": "Magento 2 Additional Store Email Address",
     "require": {
        "php": "~5.5.22|~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0",
        "magento/framework": "100.0.*|100.1.*|101.0.*"
    },
    "type": "magento2-module",
    "version": "1.0.1",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Mycompany\\Additionalstoreemail\\": ""
        }
    }
}

------------------------------------------------------
etc/module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mycompany_Additionalstoreemail" setup_version="1.0.1" />
</config>

------------------------------------------------------
etc/adminhtml/system.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="general" translate="label" sortOrder="100">
            <label>General</label>
        </tab>             
        <section id="trans_email" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                   
            <group id="ident_custom3" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 3</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>
           
            <group id="ident_custom4" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 4</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>
           
            <group id="ident_custom5" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 5</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>           
           
        </section>       
    </system>
</config>

Wednesday, 3 July 2019

Magento 2 : Add WYSISYG Editor Admin Form In Custom Module

<?php
namespace [VENDOR]\[EXTENSION]\Block\Adminhtml\[CUSTOM]\Edit\Tab;

class Form extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
protected $_wysiwygConfig;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory, 
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
array $data = []
)
{
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $registry, $formFactory, $data);
}

protected function _prepareForm()
{
$model = $this->_coreRegistry->registry('EXTENSIONKEY');

/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();

$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('YOUR FORM TITLE')]);

$fieldset->addField('storycontent', 'editor', [
  'name'      => 'storycontent',
  'label'   => 'Story Content',
  'config'    => $this->_wysiwygConfig->getConfig(),
  'wysiwyg'   => true,
  'required'  => false,
  'after_element_html' => '<small>YOURCOMMENT.</small>',
  'value' => $model->getStorycontent()
]);

$this->setForm($form);
return parent::_prepareForm();
}
}
?>

Monday, 1 July 2019

Magento 2 : Modal Popup Window Call Anywhere

Modal Popup Window Call Anywhere

<a href="#" id="click-header">View Video</a></div>

<div id="header-mpdal" style="display:none;">
<div class="videoWrapper">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/code_hear" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
</div>
</div>

<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                title: '',
                buttons: [{
                    text: $.mage.__('Close'),
                    class: '',
                    click: function () {
                        this.closeModal();
                    }
                }]
            };

            var popup = modal(options, $('#header-mpdal'));
            $("#click-header").on('click',function(){
                $("#header-mpdal").modal("openModal");
            });

        }
    );
</script>

Magento 2: How to Call a CMS Static Block in Phtml File

Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,
Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,

<?php
    echo $block->getLayout()
               ->createBlock('Magento\Cms\Block\Block')
               ->setBlockId('block_identifier')
               ->toHtml();
?>
Display CMS Static Block In CMS Content:

Here the code to show CMS Static Block in any other CMS static block/page in Magento 2,
1

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Display CMS Static Block In XML:

Here the code to show CMS Static Block in any layout (XML) file in Magento 2,

<referenceContainer name="content">
    <block class="Magento\Cms\Block\Block" name="block_identifier">
        <arguments>
            <argument name="block_id" xsi:type="string">block_identifier</argument>
        </arguments>
    </block>
</referenceContainer>