1

I want to add remark input text field in checkout page I follow Magento 2 - Set custom attribute value on cart page to set custom attribute in quote_item.

In configurable.phtml

    <div class="field configurable required">
        <div class="control">
            <input type="text" name="remark" id="remark">
        </div>
    </div>

In catalog_attribute.xml

<group name="quote_item">
    <attribute name="remark"/>
</group>

In SalesQuoteItemSetCustomAttribute

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $product = $observer->getProduct();
    $quoteItem = $observer->getQuoteItem();
    $quoteItem->setRemark($product->getRemark());
}

But $product->getRemark() is null, inside /checkout/cart/add/ do I need to set remark in product directly from http request?

2 Answers 2

1
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="remark"/>
    </group>
</config>

Set the product attribute directly to $quoteItem. You don't have to set it manually.

Have a look inside $quoteItem->getData('remark') it should be already there.

0

Instead of using a magic method, try accessing the value through getData().

$product->getData('remark');

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.