2

I want to Add new Field "Remark" in Cart Items Page. it is a purpose to "Remark" for product. When i save cart(Update cart) it will be saved in Quote items table. also "Procced To checkout" It will be saved in order detials. Also view in admin side

  • its unclear what you are asking , add sufficient details address the problem and feature – Manoj Deswal Sep 27 '17 at 10:45
  • 0 down vote favorite I want to Add new Field "Remark" in Cart Items Page. it is a purpose to "Remark" for product. When i save cart(Update cart) it will be saved in Quote items table. also "Procced To checkout" It will be saved in order detials. Also view in admin side – Divyesh Sep 27 '17 at 11:09
  • Have you found a solution to this? I also need to save an extra input field to a custom field I have added in to quote_item table. but I haven't figured out how. – Magento Learner Apr 7 '18 at 1:06
2

Magento provides additional attribute functionality to pass additional data. On cart page, create input field for remark then in custom module's events.xml, create an observer like below :

<?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_product_add_after">
        <observer name="customremark" instance="Companyname\Modulename\Observer\customremark" />
    </event>

</config>

Then in observer, you can get this remark field from request

<?php

namespace Companyname\Modulename\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class SetAdditionalOptions implements ObserverInterface
{
    /**
     * @var RequestInterface
     */
    protected $_request;

    /**
     * @param RequestInterface $request
     */
    public function __construct(
        RequestInterface $request
    ) {
        $this->_request = $request;
    }

    /**
     * @param \Magento\Framework\Event\Observer $observer
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        // Check and set information according to your need
        if ($this->_request->getFullActionName() == 'checkout_cart_add') { //checking when product is adding to cart
            $product = $observer->getProduct();
            $additionalOptions = [];
            $additionalOptions[] = array(
                'label' => "Remark",
                'value' => "Your Information",
            );
            $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));
        }
    }
}

Hope this helps.

  • 1
    This is not Dynemmically Corrent. I dont want to add "Custom Option". i just want to add field in Quote table..set Quote table . and add field in Order items table and Save in order system. that;s it – Divyesh Sep 27 '17 at 12:31
  • @Envision Ecommerce - Is this support cart proceed to checkout button. I think its a KO js request.I have added cutom fields to checkout page , its a long process. :( – Lasantha Jan 14 '18 at 13:57
  • thanks, adding to custom options is much less hassle than adding a field to quote item – Eugen Bogdanovich Apr 10 '18 at 11:25

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.