2

After Adding a Product Redirect to Shopping Cart, Stores Config Section

So in the Magento2 admin, under Stores > Configuration > Sales > Checkout > Shopping Cart, I would like the "After Adding a Product Redirect to Shopping Cart" dropdown with the Yes/No option to either: -Only have the option to set it to "No". -Have a comment for the field, so that the customer only knows to set it to "No".

I see the field is created in the Magento2 vendor in this file: "vendor/magento/module-checkout/etc/adminhtml/system.xml" (in the code below, see the field tag with the id "redirect_to_cart", in the group tag with the id "cart".

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. 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>
        <section id="checkout" translate="label" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Checkout</label>
            <tab>sales</tab>
            <resource>Magento_Checkout::checkout</resource>
            <group id="options" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Checkout Options</label>
                <field id="onepage_checkout_enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable Onepage Checkout</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="guest_checkout" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Allow Guest Checkout</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="customer_must_be_logged" translate="label" type="select" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Require Customer To Be Logged In To Checkout</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="guest_checkout">0</field>
                    </depends>
                </field>
            </group>
            <group id="cart" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Shopping Cart</label>
                <field id="delete_quote_after" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Quote Lifetime (days)</label>
                </field>
                <field id="redirect_to_cart" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>After Adding a Product Redirect to Shopping Cart</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
            </group>
            <group id="cart_link" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="0">
                <label>My Cart Link</label>
                <field id="use_qty" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Display Cart Summary</label>
                    <source_model>Magento\Checkout\Model\Config\Source\Cart\Summary</source_model>
                </field>
            </group>
            <group id="sidebar" translate="label" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Shopping Cart Sidebar</label>
                <field id="display" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Display Shopping Cart Sidebar</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="count" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Maximum Display Recently Added Item(s)</label>
                </field>
            </group>
            <group id="payment_failed" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Payment Failed Emails</label>
                <field id="identity" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Payment Failed Email Sender</label>
                    <source_model>Magento\Config\Model\Config\Source\Email\Identity</source_model>
                </field>
                <field id="receiver" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Payment Failed Email Receiver</label>
                    <source_model>Magento\Config\Model\Config\Source\Email\Identity</source_model>
                </field>
                <field id="template" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Payment Failed Template</label>
                    <comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>
                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
                </field>
                <field id="copy_to" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Send Payment Failed Email Copy To</label>
                    <comment>Separate by ",".</comment>
                </field>
                <field id="copy_method" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Send Payment Failed Email Copy Method</label>
                    <source_model>Magento\Config\Model\Config\Source\Email\Method</source_model>
                </field>
            </group>
        </section>
    </system>
</config>
0

I found out how to add a comment to an existing field in Stores Configuration in the Admin! I just created a system.xml file in a new extension, and used the existing section id, group id, and field id. Here is my code in /etc/adminhtml/system.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="checkout" translate="label" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="cart" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <field id="redirect_to_cart" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <comment>Please only set value to "No".</comment>
                </field>
            </group>
        </section>
    </system>
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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