I have created 5 Custom Input Fields (not Attributes) in the Product View Page.

The Customer can write his Values inside if he want to modify the Product Values.

I want to pass them to Cart, and later to Checkout. At the End I want to view the Values in the Order.

How can I achive this?


2 Answers 2


With the help of @AmitSaini i figured out.

I am currently using Magento 2.3.6

How to "add to cart" a product with custom input field and save it to Database?

Follow this link and check Renon Stewart answer.

If you get in Product View this error: {"message":"Unable to unserialize value. Error: Syntax error"}


if you get the jQuery error: Uncaught Error: [object Object]

Change in the inside of SalesModelServiceQuoteSubmitBeforeObserver.php and CheckoutCartProductAddAfterObserver.php :

serialize to json_encode


unserialize to json_decode

Now the next problem. If you tried before to go to the checkout with serialze and you were logged in with an user account, you need to delete the last quote item.

You need to delete in the database inside the quote table the last quote with the used e-mail.


$post = $this->_request->getParam('cloudways');

This line, parameter defines the "name" field inside the addtocart.phtml responsible for this input field:

<input type="text" name="cloudways[remarks]" id="remarks" maxlength="255" placeholder="Remarks" />

"remarks" in this case is the json configuration name field.

And one more thing.

If you can't complete the checkout process, change the SalesModelServiceQuoteSubmitBeforeObserver.php file on line 50:

if(count($additionalOptions) > 0) 


if(is_array($additionalOptions) && count($additionalOptions) > 0){

I don't know what is your goal, but you try using checkoutSession to do this.

Here an untested example:

declare(strict_types = 1);

namespace Vendor\Module\Controller\Demo;

class Demo extends \Magento\Framework\App\Action\Action

    protected $_checkoutSession;

    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->_checkoutSession = $checkoutSession;

    public function execute()
        $myValue = $this->_checkoutSession->getMyValue();


You can read more about the custom sessions of magento here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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