Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param RequestInterface $request
- */
- public function __construct(
- RequestInterface $request
- ) {
- $this->_request = $request;
- }
- /**
- * @param MagentoFrameworkEventObserver $observer
- */
- public function execute(MagentoFrameworkEventObserver $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' => "Some Label",
- 'value' => "good product",
- );
- $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));
- }
- }
Add Comment
Please, Sign In to add comment