magento2.3 – How to show a form in an additional step in checkout process

I have created a new step to checkout page. This is the template:

<li id="billing_info" data-bind="fadeVisible: isVisible">
    <div class="step-title" data-bind="i18n: 'Billing Info'" data-role="title"></div>
    <div id="checkout-step-billing"
         class="checkout-shipping-method"
         data-role="content">

        <div id="billing-form" class="step-content" data-role="content">
            <!-- ko foreach: getRegion('billing-form-container') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>

        <form data-bind="submit: navigateToNextStep" novalidate="novalidate">
            <div class="actions-toolbar">
                <div class="primary">
                    <button data-role="opc-continue" type="submit" class="button action continue primary">
                        <span><!-- ko i18n: 'Next'--><!-- /ko --></span>
                    </button>
                </div>
            </div>
        </form>
    </div>
</li>

As you know, all checkout steps let knockout to retrieve fields dynamically and this is not the exception.

This is the checkout_index_index.xml file:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <!-- The new step you add -->
                                        <item name="billingstep" xsi:type="array">
                                            <item name="component" xsi:type="string">Example_Checkout/js/view/billing-information-step</item>
                                            <!--To display step content before shipping step "sortOrder" value should be < 1-->
                                            <!--To display step content between shipping step and payment step  1 < "sortOrder" < 2 -->
                                            <!--To display step content after payment step "sortOrder" > 2 -->
                                            <item name="sortOrder" xsi:type="string">2</item>
                                            <item name="children" xsi:type="array">  
                                                <item name="billing-form-container" xsi:type="array">
                                                    <!-- Add this item to configure your js file  -->
                                                    <item name="component" xsi:type="string">Example_Checkout/js/view/billing-information-form</item>
                                                    <item name="displayArea" xsi:type="string">billing-form-fields</item>
                                                    <item name="children" xsi:type="array">
                                                        <!-- Here we will add the form fields  -->
                                                        <item name="text_field" xsi:type="array">
                                                            <item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
                                                            <item name="config" xsi:type="array">
                                                                <!-- customScope is used to group elements within a single form (e.g. they can be validated separately) -->
                                                                <item name="customScope" xsi:type="string">customCheckoutForm</item>
                                                                <item name="template" xsi:type="string">ui/form/field</item>
                                                                <item name="elementTmpl" xsi:type="string">ui/form/element/input</item>
                                                            </item>
                                                            <item name="provider" xsi:type="string">checkoutProvider</item>
                                                            <item name="dataScope" xsi:type="string">customCheckoutForm.text_field</item>
                                                            <item name="label" xsi:type="string">Text Field</item>
                                                            <item name="sortOrder" xsi:type="string">1</item>
                                                            <item name="validation" xsi:type="array">
                                                                <item name="required-entry" xsi:type="string">true</item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

The new step is shown, but the form is not placed in it.

Thanks
Jaime

magento2.3 – Magento Admin display Exception #0 (MagentoFrameworkExceptionInputException): Please correct the target currency

After a lot of struggle , I could finally install Magento 2.3.5 p2 but now when I try to login to magento admin , it shows me the error message given below :
Exception #0 (MagentoFrameworkExceptionInputException): Pleaseenter image description here correct the target currency.

Please help me resolve this issue as I tried searching it everywhere.

multistore – Wanting to remove multi stores and go back to single store view scope in Magento2.3

Is it possible to switch our store back to single store mode? Is this possible now? It says,

“This setting will not be taken into account if system has more than
one store view.”

We have two stores on Magento2.3.5. However, we are wanting to remove one of these stores and its views from admin, since we never use it. No products and not much data has been saved on the other store view. However, switching to single store mode in does not do anything and I take it because it still sees the other store views so it does not take that setting into account.

Would I have to remove 2nd stores website? I did not see an option to remove store.

enter image description here

magento2.3 – Magento2: How can you check/set which Elasticsearch index is currently being used

We have a large catalog (400k products) that takes a day or two to reindex.

Occasionally I’ve had something go wrong with the indexing process and then nothing is searchable (code errors). I don’t want the site down for days if this happens, so I’d like to clone the current index, then start the Magento reindexing, and if something goes haywire, restore the backup index.

I can’t find how to see/overwrite which version of the index is currently being used.

magento2.3 – magento 2.3 get cart item related to applied cart rule

Situation:

  • There are 4 products in the cart
  • One of these products causes a cart rule to apply

By getting the cart items via code, I need to be able to identify the one item that is causing the rule to apply.

My problem is that I cannot find a way to separate this item from the others in the cart, they all return the same results.

My code so far:

foreach($quote->getItems() as $quoteItem) {

$itemAppliedRulesId = $quoteItem->getAppliedRuleIds(); // I expect this to  give a result only for the one item that matches the cart rule, instead all the items returns the rule id

$product = $quoteItem->getProduct();
$result = $rule->getActions()->validate($product); // see comment above, same result

}

My question:

Is there a way I can get the items of the cart that cause one or more rules to apply?

magento2.3 – Magento 2.3.0: Web Setup Wizard Page, Nothing happens after Fresh Install

This is a fresh installation. I have two issues:

  1. I keep on getting 500 Internal server error till i do not rename .htaccess to .htaccess1, is this normal, if not how can it be fixed?
  2. Admin panel shows 404 error, while the env.php shows the correct backend name
  3. Front end shows the following message:

Welcome to Magento Admin, your online store headquarters.
To use the Magento setup wizard sign into your Admin account and navigate to System => Tools => Web Setup Wizard

on the URL: https://example.com/setup/index.php/session/unlogin

All file and folder permissions are set as:

find . -type f -exec chmod 644 {} ;

find . -type d -exec chmod 755 {} ;

find ./var -type d -exec chmod 777 {} ;

find ./pub/media -type d -exec chmod 777 {} ;

find ./pub/static -type d -exec chmod 777 {} ;

chmod 777 ./app/etc

chmod 644 ./app/etc/*.xml

I do not see the front end nor the backend. Please suggest.

Regards,
Aashish

magento2.3 – Coupon code should not apply if action condition fit or not discount happen

Please help me with this

There are conditions and Action tab in the coupon code add/edit page and there is a conditional option where we select on which product this code should apply or not like we set SKU or something or set condition buy x and get y for this much.

My question is how can a coupon code refuse to set if the discount is zero?

For now, the coupon code gets set but the discount won’t get so it makes little confusion for the users

Hoping for Good.
Thanks

magento2.3 – Magento 2 Fonts Preload head

I am adding the fonts as specified in magento 2.3 documentation however i am getting the error

Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'font': This element is not expected. Expected is one of ( title, css, link, meta, script, remove, attribute ).

I am adding font as

<font src="fonts/opensans/light/opensans-300.woff2"/>

magento2.3 – Is it possible to handle db_schema.xml differently for different versions of Magento

Is there a way to handle version or use different db_schema.xml for different version of magento?

The issue is that setup:upgrade will require foreign key constraints to match exactly. But how do you package a module for all versions when the referenced field might change.

I noticed this problem in the difference between 2.3.7 and 2.4.2 with the quote address id.

Magento 2.3.7: module-quote/etc/db_schema.xml

<table name="quote_address_item" resource="checkout" engine="innodb" comment="Sales Flat Quote Address Item">
        <column xsi:type="int" name="address_item_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Address Item ID"/>

Magento 2.4.2: module-quote/etc/db_schema.xml

<table name="quote_address_item" resource="checkout" engine="innodb" comment="Sales Flat Quote Address Item">
        <column xsi:type="int" name="address_item_id" unsigned="true" nullable="false" identity="true"
                comment="Address Item ID"/>

MyModule/etc/db_schema.xml

<column xsi:type="int" name="quote_address_id" unsigned="true" nullable="false" default="0" comment="Quote Address Id"/>
<constraint xsi:type="foreign" referenceId="MYTABLE_QUOTE_ADDRESS_ID_QUOTE_ADDRESS_ID" table="myshipping_quote"
                    column="quote_address_id" referenceTable="quote_address" referenceColumn="address_id" onDelete="CASCADE"/>
        <index referenceId="MYTABLE_QUOTE_QUOTE_ADDRESS_ID" indexType="btree">
            <column name="quote_address_id"/>
        </index>

Because the padding=”10″ is missing from my db_schema.xml, this cannot install on Magento 2.3.7.

What is the best way to handle this? Is there a way to use different db_schema.xml files for different versions? Is there a way to check for version?

magento2.3 – How to add custom select options in a custom admin form

Try with below code

Create source provider for email values

VendorModuleModelEmailOptions.php

<?php

namespace VendorModuleModelEmail;

class Options implements MagentoFrameworkOptionArrayInterface
{ 
    /**
     * Return array of options as value-label pairs, eg. value => label
     *
     * @return array
     */
    public function toOptionArray()
    {
        // You can write your code to fetch email values from custom table and convert it to as value => label pair
        return (
            'value' => 'Label',
            'demo@mail.com' => 'demo@mail.com',
            'demo1@mail.com' => 'demo@mail.com',
        );
    }
}

VendorModuleBlockAdminhtmlGridEditForm.php

<?php
namespace VendorModuleBlockAdminhtmlGridEdit;

/**
 * Adminhtml Add New Row Form.
 */
class Form extends MagentoBackendBlockWidgetFormGeneric
{
    /**
     * @var MagentoStoreModelSystemStore
     */
    protected $_systemStore;

    /**
     * @var VendorModuleModelEmailOptions
     */
    protected $_emailOptions;

    /**
     * @param MagentoBackendBlockTemplateContext $context
     * @param MagentoFrameworkRegistry             $registry
     * @param MagentoFrameworkDataFormFactory     $formFactory
     * @param array                                   $data
     */
    public function __construct(MagentoBackendBlockTemplateContext $context, MagentoFrameworkRegistry $registry, MagentoFrameworkDataFormFactory $formFactory, MagentoCmsModelWysiwygConfig $wysiwygConfig, VendorModuleModelStatus $options, VendorModuleModelEmailOptions $emailOptions, array $data = ())
    {
        $this->_options = $options;
        $this->_wysiwygConfig = $wysiwygConfig;
        $this->_emailOptions = $emailOptions;
        parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
     * Prepare form.
     *
     * @return $this
     */
    protected function _prepareForm()
    {

        $dateFormat = $this
            ->_localeDate
            ->getDateFormat(IntlDateFormatter::SHORT);
        $model = $this
            ->_coreRegistry
            ->registry('row_data');
        $form = $this
            ->_formFactory
            ->create(('data' => ('id' => 'edit_form', 'enctype' => 'multipart/form-data', 'action' => $this->getData('action') , 'method' => 'post')));

        $form->setHtmlIdPrefix('question_');

        $fieldset->addField(
            'name',
            'text',
            (
                'name' => 'name',
                'label' => __('NAME'),
                'id' => 'name',
                'title' => __('NAME'),
                'class' => 'required-entry',
                'required' => true,
            )
        );

        $fieldset->addField(
            'email',
            'select',
            (
                'name' => 'email',
                'label' => __('Email'),
                'id' => 'email',
                'title' => __('Email'),
                'values' => $this->_emailOptions->toOptionArray() 'class' => 'select', 'required' => true, ));

        $fieldset->addField('is_answered', 'select', 
        (
          'name' => 'is_answered',
          'label' => __('Status'),
          'options' => ('1' => __('Pending By Seller'), '0' => __('Pending By Admin')),
          'required' => true,
        ));

        $form->setValues($model->getData());
        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();
    }
}

Thanks!