Textbox Below Size Attribute in product pageIs there a way to automatically select the first colour swatch on the product page?Add promo message to product pageMagento 1.9.3.0 product page design is reverted to base/defaultMagento 1 : Show custom attribute on product page and make it popup on clickAdd new button in product page in M2set custom attribute value according to product category in magento2Magento 2.3: Sort Product Attribute Set Groups in AdminUnable to add product attribute using backend (Magento 2.3)Display Custom Attribute Multiplace Place on Products Details Page Magento 2Magento 2 how to add image field in product attribute dropdown?
Gold Battle KoTH
A conjectural trigonometric identity
Accurately recalling the key - can everyone do it?
Can living where magnetic ore is abundant provide any protection from cosmic radiation?
Password management for kids - what's a good way to start?
How can a class have multiple methods without breaking the single responsibility principle
Why don't short runways use ramps for takeoff?
Should I put my name first or last in the team members list?
Should 2FA be enabled on service accounts?
Is there a general term for the items in a directory?
Conflict between senior and junior members
Went to a big 4 but got fired for underperformance in a year recently - Now every one thinks I'm pro - How to balance expectations?
Please explain the difference in the order of naming Tzelafchad's daughters
Does the problem of P vs NP come under the category of Operational Research?
How do I respond appropriately to an overseas company that obtained a visa for me without hiring me?
Should students have access to past exams or an exam bank?
Skipping same old introductions
Feedback diagram
Derivative is just speed of change?
Adding a (stair/baby) gate without facing walls
Is this mechanically safe?
A game of red and black
Word for giving preference to the oldest child
How do I find SFDX CLI default installation folder on Mac?
Textbox Below Size Attribute in product page
Is there a way to automatically select the first colour swatch on the product page?Add promo message to product pageMagento 1.9.3.0 product page design is reverted to base/defaultMagento 1 : Show custom attribute on product page and make it popup on clickAdd new button in product page in M2set custom attribute value according to product category in magento2Magento 2.3: Sort Product Attribute Set Groups in AdminUnable to add product attribute using backend (Magento 2.3)Display Custom Attribute Multiplace Place on Products Details Page Magento 2Magento 2 how to add image field in product attribute dropdown?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i want to add textbox names like notes under size in products page.
Could you please any one tell me how to do. i have tried to via attribute but it doesn't help me.
magento2.3 product-page
add a comment |
i want to add textbox names like notes under size in products page.
Could you please any one tell me how to do. i have tried to via attribute but it doesn't help me.
magento2.3 product-page
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06
add a comment |
i want to add textbox names like notes under size in products page.
Could you please any one tell me how to do. i have tried to via attribute but it doesn't help me.
magento2.3 product-page
i want to add textbox names like notes under size in products page.
Could you please any one tell me how to do. i have tried to via attribute but it doesn't help me.
magento2.3 product-page
magento2.3 product-page
edited Jul 23 at 12:10
Mohit Rane
1,17718 bronze badges
1,17718 bronze badges
asked Jul 23 at 10:25
amyamy
62 bronze badges
62 bronze badges
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06
add a comment |
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06
add a comment |
1 Answer
1
active
oldest
votes
I have created a Module for this question
STEP1: Create a module using required files as
app/code/Vendor/Test/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Test',
__DIR__
);
app/code/Vendor/Test/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Test" setup_version="0.0.1"></module>
</config>
STEP2: Create text box under qty text box in
app/design/frontend/Vendor/Themename/Magento_Catalog/templates/product/view/addtocart.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* @escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<!-- Your gift message custom field here -->
<input type="text"
name="gift_message"
id="gift_message"
value=""
title="<?= /* @escapeNotVerified */ __('Gift messages') ?>"
class="input-text"
/>
<!-- Your gift message custom field here -->
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
"#product_addtocart_form":
"Magento_Catalog/js/validate-product":
</script>
STEP3: Create gift_message
column in quote_item
and sales_order_item
tables using setup files
app/code/Vendor/Test/Setup/UpgradeSchema.php
<?php
namespace VendorTestSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '0.0.1') < 0)
$setup->startSetup();
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('quote_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$connection->addColumn(
$setup->getTable('sales_order_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$setup->endSetup();
STEP4: Create an event checkout_cart_add_product_complete
to save custom field value on addtocart
app/code/Vendor/Test/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_add_product_complete">
<observer name="save_gift_message_to_cart" instance="VendorTestObserverAddProductAfterObserver" />
</event>
</config>
app/code/Vendor/Test/Observer/AddProductAfterObserver.php
<?php
namespace VendorTestObserver;
use MagentoFrameworkEventObserverInterface;
class AddProductAfterObserver implements ObserverInterface
/**
* @var MagentoCheckoutModelSession
*/
protected $checkoutSession;
/**
* @param MagentoCheckoutModelSession $checkoutSession
* @codeCoverageIgnore
*/
public function __construct(
MagentoCheckoutModelSession $checkoutSession
)
$this->_checkoutSession = $checkoutSession;
/**
* @param MagentoFrameworkEventObserver $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(MagentoFrameworkEventObserver $observer)
$product = $observer->getEvent()->getProduct();
$giftMessages = $observer->getEvent()->getRequest()->getParam('gift_message');
if(!empty($giftMessages))
/** @var MagentoQuoteModelQuoteItem $item */
$item = $this->_checkoutSession->getQuote()->getItemByProduct($product);
$item->setGiftMessage($giftMessages);
$item->save();
STEP5: Create a plugin for move quote table gift_message data to sales_order_item table column
app/code/Vendor/Test/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelQuoteItemToOrderItem">
<plugin name="quote_item_to_order_item" type="VendorTestPluginQuoteToOrderItem"/>
</type>
</config>
app/code/Vendor/Test/Plugin/QuoteToOrderItem.php
<?php
namespace VendorTestPlugin;
class QuoteToOrderItem
/**
* @param MagentoQuoteModelQuoteItemToOrderItem $subject
* @param Closure $proceed
* @param MagentoQuoteModelQuoteItemAbstractItem $item
* @param array $additional
*
* @return object $orderItem
*/
public function aroundConvert(
MagentoQuoteModelQuoteItemToOrderItem $subject,
Closure $proceed,
MagentoQuoteModelQuoteItemAbstractItem $item,
$additional = []
)
$orderItem = $proceed($item, $additional);
$orderItem->setGiftMessage($item->getGiftMessage());
return $orderItem;
STEP6: Display the custom gift_messge field value in adminpanel->sales->orders->specific order->orderitems
app/code/Vendor/Test/view/adminhtml/layout/sales_order_view.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="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">Gift message</item>
</argument>
</arguments>
<referenceBlock name="default_order_items_renderer">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">col-giftmessage</item>
</argument>
</arguments>
</referenceBlock>
<block class="MagentoSalesBlockAdminhtmlItemsColumnDefaultColumn"
name="column_gift_message"
template="Vendor_Test::gift_message.phtml" group="column" />
</referenceBlock>
</body>
</page>
app/code/Vendor/Test/view/adminhtml/templates/gift_message.phtml
<?php
$_item = $block->getItem();
$giftMessage = $_item->getGiftMessage();
if( !empty($giftMessage) )
echo $_item->getGiftMessage();
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282990%2ftextbox-below-size-attribute-in-product-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have created a Module for this question
STEP1: Create a module using required files as
app/code/Vendor/Test/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Test',
__DIR__
);
app/code/Vendor/Test/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Test" setup_version="0.0.1"></module>
</config>
STEP2: Create text box under qty text box in
app/design/frontend/Vendor/Themename/Magento_Catalog/templates/product/view/addtocart.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* @escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<!-- Your gift message custom field here -->
<input type="text"
name="gift_message"
id="gift_message"
value=""
title="<?= /* @escapeNotVerified */ __('Gift messages') ?>"
class="input-text"
/>
<!-- Your gift message custom field here -->
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
"#product_addtocart_form":
"Magento_Catalog/js/validate-product":
</script>
STEP3: Create gift_message
column in quote_item
and sales_order_item
tables using setup files
app/code/Vendor/Test/Setup/UpgradeSchema.php
<?php
namespace VendorTestSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '0.0.1') < 0)
$setup->startSetup();
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('quote_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$connection->addColumn(
$setup->getTable('sales_order_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$setup->endSetup();
STEP4: Create an event checkout_cart_add_product_complete
to save custom field value on addtocart
app/code/Vendor/Test/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_add_product_complete">
<observer name="save_gift_message_to_cart" instance="VendorTestObserverAddProductAfterObserver" />
</event>
</config>
app/code/Vendor/Test/Observer/AddProductAfterObserver.php
<?php
namespace VendorTestObserver;
use MagentoFrameworkEventObserverInterface;
class AddProductAfterObserver implements ObserverInterface
/**
* @var MagentoCheckoutModelSession
*/
protected $checkoutSession;
/**
* @param MagentoCheckoutModelSession $checkoutSession
* @codeCoverageIgnore
*/
public function __construct(
MagentoCheckoutModelSession $checkoutSession
)
$this->_checkoutSession = $checkoutSession;
/**
* @param MagentoFrameworkEventObserver $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(MagentoFrameworkEventObserver $observer)
$product = $observer->getEvent()->getProduct();
$giftMessages = $observer->getEvent()->getRequest()->getParam('gift_message');
if(!empty($giftMessages))
/** @var MagentoQuoteModelQuoteItem $item */
$item = $this->_checkoutSession->getQuote()->getItemByProduct($product);
$item->setGiftMessage($giftMessages);
$item->save();
STEP5: Create a plugin for move quote table gift_message data to sales_order_item table column
app/code/Vendor/Test/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelQuoteItemToOrderItem">
<plugin name="quote_item_to_order_item" type="VendorTestPluginQuoteToOrderItem"/>
</type>
</config>
app/code/Vendor/Test/Plugin/QuoteToOrderItem.php
<?php
namespace VendorTestPlugin;
class QuoteToOrderItem
/**
* @param MagentoQuoteModelQuoteItemToOrderItem $subject
* @param Closure $proceed
* @param MagentoQuoteModelQuoteItemAbstractItem $item
* @param array $additional
*
* @return object $orderItem
*/
public function aroundConvert(
MagentoQuoteModelQuoteItemToOrderItem $subject,
Closure $proceed,
MagentoQuoteModelQuoteItemAbstractItem $item,
$additional = []
)
$orderItem = $proceed($item, $additional);
$orderItem->setGiftMessage($item->getGiftMessage());
return $orderItem;
STEP6: Display the custom gift_messge field value in adminpanel->sales->orders->specific order->orderitems
app/code/Vendor/Test/view/adminhtml/layout/sales_order_view.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="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">Gift message</item>
</argument>
</arguments>
<referenceBlock name="default_order_items_renderer">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">col-giftmessage</item>
</argument>
</arguments>
</referenceBlock>
<block class="MagentoSalesBlockAdminhtmlItemsColumnDefaultColumn"
name="column_gift_message"
template="Vendor_Test::gift_message.phtml" group="column" />
</referenceBlock>
</body>
</page>
app/code/Vendor/Test/view/adminhtml/templates/gift_message.phtml
<?php
$_item = $block->getItem();
$giftMessage = $_item->getGiftMessage();
if( !empty($giftMessage) )
echo $_item->getGiftMessage();
add a comment |
I have created a Module for this question
STEP1: Create a module using required files as
app/code/Vendor/Test/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Test',
__DIR__
);
app/code/Vendor/Test/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Test" setup_version="0.0.1"></module>
</config>
STEP2: Create text box under qty text box in
app/design/frontend/Vendor/Themename/Magento_Catalog/templates/product/view/addtocart.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* @escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<!-- Your gift message custom field here -->
<input type="text"
name="gift_message"
id="gift_message"
value=""
title="<?= /* @escapeNotVerified */ __('Gift messages') ?>"
class="input-text"
/>
<!-- Your gift message custom field here -->
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
"#product_addtocart_form":
"Magento_Catalog/js/validate-product":
</script>
STEP3: Create gift_message
column in quote_item
and sales_order_item
tables using setup files
app/code/Vendor/Test/Setup/UpgradeSchema.php
<?php
namespace VendorTestSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '0.0.1') < 0)
$setup->startSetup();
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('quote_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$connection->addColumn(
$setup->getTable('sales_order_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$setup->endSetup();
STEP4: Create an event checkout_cart_add_product_complete
to save custom field value on addtocart
app/code/Vendor/Test/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_add_product_complete">
<observer name="save_gift_message_to_cart" instance="VendorTestObserverAddProductAfterObserver" />
</event>
</config>
app/code/Vendor/Test/Observer/AddProductAfterObserver.php
<?php
namespace VendorTestObserver;
use MagentoFrameworkEventObserverInterface;
class AddProductAfterObserver implements ObserverInterface
/**
* @var MagentoCheckoutModelSession
*/
protected $checkoutSession;
/**
* @param MagentoCheckoutModelSession $checkoutSession
* @codeCoverageIgnore
*/
public function __construct(
MagentoCheckoutModelSession $checkoutSession
)
$this->_checkoutSession = $checkoutSession;
/**
* @param MagentoFrameworkEventObserver $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(MagentoFrameworkEventObserver $observer)
$product = $observer->getEvent()->getProduct();
$giftMessages = $observer->getEvent()->getRequest()->getParam('gift_message');
if(!empty($giftMessages))
/** @var MagentoQuoteModelQuoteItem $item */
$item = $this->_checkoutSession->getQuote()->getItemByProduct($product);
$item->setGiftMessage($giftMessages);
$item->save();
STEP5: Create a plugin for move quote table gift_message data to sales_order_item table column
app/code/Vendor/Test/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelQuoteItemToOrderItem">
<plugin name="quote_item_to_order_item" type="VendorTestPluginQuoteToOrderItem"/>
</type>
</config>
app/code/Vendor/Test/Plugin/QuoteToOrderItem.php
<?php
namespace VendorTestPlugin;
class QuoteToOrderItem
/**
* @param MagentoQuoteModelQuoteItemToOrderItem $subject
* @param Closure $proceed
* @param MagentoQuoteModelQuoteItemAbstractItem $item
* @param array $additional
*
* @return object $orderItem
*/
public function aroundConvert(
MagentoQuoteModelQuoteItemToOrderItem $subject,
Closure $proceed,
MagentoQuoteModelQuoteItemAbstractItem $item,
$additional = []
)
$orderItem = $proceed($item, $additional);
$orderItem->setGiftMessage($item->getGiftMessage());
return $orderItem;
STEP6: Display the custom gift_messge field value in adminpanel->sales->orders->specific order->orderitems
app/code/Vendor/Test/view/adminhtml/layout/sales_order_view.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="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">Gift message</item>
</argument>
</arguments>
<referenceBlock name="default_order_items_renderer">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">col-giftmessage</item>
</argument>
</arguments>
</referenceBlock>
<block class="MagentoSalesBlockAdminhtmlItemsColumnDefaultColumn"
name="column_gift_message"
template="Vendor_Test::gift_message.phtml" group="column" />
</referenceBlock>
</body>
</page>
app/code/Vendor/Test/view/adminhtml/templates/gift_message.phtml
<?php
$_item = $block->getItem();
$giftMessage = $_item->getGiftMessage();
if( !empty($giftMessage) )
echo $_item->getGiftMessage();
add a comment |
I have created a Module for this question
STEP1: Create a module using required files as
app/code/Vendor/Test/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Test',
__DIR__
);
app/code/Vendor/Test/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Test" setup_version="0.0.1"></module>
</config>
STEP2: Create text box under qty text box in
app/design/frontend/Vendor/Themename/Magento_Catalog/templates/product/view/addtocart.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* @escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<!-- Your gift message custom field here -->
<input type="text"
name="gift_message"
id="gift_message"
value=""
title="<?= /* @escapeNotVerified */ __('Gift messages') ?>"
class="input-text"
/>
<!-- Your gift message custom field here -->
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
"#product_addtocart_form":
"Magento_Catalog/js/validate-product":
</script>
STEP3: Create gift_message
column in quote_item
and sales_order_item
tables using setup files
app/code/Vendor/Test/Setup/UpgradeSchema.php
<?php
namespace VendorTestSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '0.0.1') < 0)
$setup->startSetup();
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('quote_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$connection->addColumn(
$setup->getTable('sales_order_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$setup->endSetup();
STEP4: Create an event checkout_cart_add_product_complete
to save custom field value on addtocart
app/code/Vendor/Test/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_add_product_complete">
<observer name="save_gift_message_to_cart" instance="VendorTestObserverAddProductAfterObserver" />
</event>
</config>
app/code/Vendor/Test/Observer/AddProductAfterObserver.php
<?php
namespace VendorTestObserver;
use MagentoFrameworkEventObserverInterface;
class AddProductAfterObserver implements ObserverInterface
/**
* @var MagentoCheckoutModelSession
*/
protected $checkoutSession;
/**
* @param MagentoCheckoutModelSession $checkoutSession
* @codeCoverageIgnore
*/
public function __construct(
MagentoCheckoutModelSession $checkoutSession
)
$this->_checkoutSession = $checkoutSession;
/**
* @param MagentoFrameworkEventObserver $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(MagentoFrameworkEventObserver $observer)
$product = $observer->getEvent()->getProduct();
$giftMessages = $observer->getEvent()->getRequest()->getParam('gift_message');
if(!empty($giftMessages))
/** @var MagentoQuoteModelQuoteItem $item */
$item = $this->_checkoutSession->getQuote()->getItemByProduct($product);
$item->setGiftMessage($giftMessages);
$item->save();
STEP5: Create a plugin for move quote table gift_message data to sales_order_item table column
app/code/Vendor/Test/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelQuoteItemToOrderItem">
<plugin name="quote_item_to_order_item" type="VendorTestPluginQuoteToOrderItem"/>
</type>
</config>
app/code/Vendor/Test/Plugin/QuoteToOrderItem.php
<?php
namespace VendorTestPlugin;
class QuoteToOrderItem
/**
* @param MagentoQuoteModelQuoteItemToOrderItem $subject
* @param Closure $proceed
* @param MagentoQuoteModelQuoteItemAbstractItem $item
* @param array $additional
*
* @return object $orderItem
*/
public function aroundConvert(
MagentoQuoteModelQuoteItemToOrderItem $subject,
Closure $proceed,
MagentoQuoteModelQuoteItemAbstractItem $item,
$additional = []
)
$orderItem = $proceed($item, $additional);
$orderItem->setGiftMessage($item->getGiftMessage());
return $orderItem;
STEP6: Display the custom gift_messge field value in adminpanel->sales->orders->specific order->orderitems
app/code/Vendor/Test/view/adminhtml/layout/sales_order_view.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="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">Gift message</item>
</argument>
</arguments>
<referenceBlock name="default_order_items_renderer">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">col-giftmessage</item>
</argument>
</arguments>
</referenceBlock>
<block class="MagentoSalesBlockAdminhtmlItemsColumnDefaultColumn"
name="column_gift_message"
template="Vendor_Test::gift_message.phtml" group="column" />
</referenceBlock>
</body>
</page>
app/code/Vendor/Test/view/adminhtml/templates/gift_message.phtml
<?php
$_item = $block->getItem();
$giftMessage = $_item->getGiftMessage();
if( !empty($giftMessage) )
echo $_item->getGiftMessage();
I have created a Module for this question
STEP1: Create a module using required files as
app/code/Vendor/Test/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Test',
__DIR__
);
app/code/Vendor/Test/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Test" setup_version="0.0.1"></module>
</config>
STEP2: Create text box under qty text box in
app/design/frontend/Vendor/Themename/Magento_Catalog/templates/product/view/addtocart.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block MagentoCatalogBlockProductView */
?>
<?php $_product = $block->getProduct(); ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* @escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<!-- Your gift message custom field here -->
<input type="text"
name="gift_message"
id="gift_message"
value=""
title="<?= /* @escapeNotVerified */ __('Gift messages') ?>"
class="input-text"
/>
<!-- Your gift message custom field here -->
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* @escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* @escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
"#product_addtocart_form":
"Magento_Catalog/js/validate-product":
</script>
STEP3: Create gift_message
column in quote_item
and sales_order_item
tables using setup files
app/code/Vendor/Test/Setup/UpgradeSchema.php
<?php
namespace VendorTestSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '0.0.1') < 0)
$setup->startSetup();
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('quote_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$connection->addColumn(
$setup->getTable('sales_order_item'),
'gift_message',
[
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Gift Message'
]
);
$setup->endSetup();
STEP4: Create an event checkout_cart_add_product_complete
to save custom field value on addtocart
app/code/Vendor/Test/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_add_product_complete">
<observer name="save_gift_message_to_cart" instance="VendorTestObserverAddProductAfterObserver" />
</event>
</config>
app/code/Vendor/Test/Observer/AddProductAfterObserver.php
<?php
namespace VendorTestObserver;
use MagentoFrameworkEventObserverInterface;
class AddProductAfterObserver implements ObserverInterface
/**
* @var MagentoCheckoutModelSession
*/
protected $checkoutSession;
/**
* @param MagentoCheckoutModelSession $checkoutSession
* @codeCoverageIgnore
*/
public function __construct(
MagentoCheckoutModelSession $checkoutSession
)
$this->_checkoutSession = $checkoutSession;
/**
* @param MagentoFrameworkEventObserver $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(MagentoFrameworkEventObserver $observer)
$product = $observer->getEvent()->getProduct();
$giftMessages = $observer->getEvent()->getRequest()->getParam('gift_message');
if(!empty($giftMessages))
/** @var MagentoQuoteModelQuoteItem $item */
$item = $this->_checkoutSession->getQuote()->getItemByProduct($product);
$item->setGiftMessage($giftMessages);
$item->save();
STEP5: Create a plugin for move quote table gift_message data to sales_order_item table column
app/code/Vendor/Test/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelQuoteItemToOrderItem">
<plugin name="quote_item_to_order_item" type="VendorTestPluginQuoteToOrderItem"/>
</type>
</config>
app/code/Vendor/Test/Plugin/QuoteToOrderItem.php
<?php
namespace VendorTestPlugin;
class QuoteToOrderItem
/**
* @param MagentoQuoteModelQuoteItemToOrderItem $subject
* @param Closure $proceed
* @param MagentoQuoteModelQuoteItemAbstractItem $item
* @param array $additional
*
* @return object $orderItem
*/
public function aroundConvert(
MagentoQuoteModelQuoteItemToOrderItem $subject,
Closure $proceed,
MagentoQuoteModelQuoteItemAbstractItem $item,
$additional = []
)
$orderItem = $proceed($item, $additional);
$orderItem->setGiftMessage($item->getGiftMessage());
return $orderItem;
STEP6: Display the custom gift_messge field value in adminpanel->sales->orders->specific order->orderitems
app/code/Vendor/Test/view/adminhtml/layout/sales_order_view.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="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">Gift message</item>
</argument>
</arguments>
<referenceBlock name="default_order_items_renderer">
<arguments>
<argument name="columns" xsi:type="array">
<item name="gift_message" xsi:type="string" translate="true">col-giftmessage</item>
</argument>
</arguments>
</referenceBlock>
<block class="MagentoSalesBlockAdminhtmlItemsColumnDefaultColumn"
name="column_gift_message"
template="Vendor_Test::gift_message.phtml" group="column" />
</referenceBlock>
</body>
</page>
app/code/Vendor/Test/view/adminhtml/templates/gift_message.phtml
<?php
$_item = $block->getItem();
$giftMessage = $_item->getGiftMessage();
if( !empty($giftMessage) )
echo $_item->getGiftMessage();
answered Jul 25 at 9:21
RanganathanRanganathan
1,2776 silver badges21 bronze badges
1,2776 silver badges21 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282990%2ftextbox-below-size-attribute-in-product-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
pls provide more info....why you need textbox here?
– Ranganathan
Jul 23 at 12:09
i want to allow option for enter some text from user for gift message
– amy
Jul 23 at 13:37
Guide me if I'm wrong. My idea is...you need to create additional column in quote_item table and sales_order_item table, after addtocart you need to save it in quote_item and after placed order you need to move it to sales_order_item from quote_item. And display it in admin order item section..Pls let me know if you need any code examples.
– Ranganathan
Jul 24 at 4:24
yes give me some samples. because i m new to this magento.
– amy
Jul 24 at 10:06