Guest User

Untitled

a guest
Aug 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /**
  2. * @param RequestInterface $request
  3. */
  4. public function __construct(
  5. RequestInterface $request
  6. ) {
  7. $this->_request = $request;
  8. }
  9.  
  10. /**
  11. * @param MagentoFrameworkEventObserver $observer
  12. */
  13. public function execute(MagentoFrameworkEventObserver $observer)
  14. {
  15. // Check and set information according to your need
  16. if ($this->_request->getFullActionName() == 'checkout_cart_add') { //checking when product is adding to cart
  17. $product = $observer->getProduct();
  18. $additionalOptions = [];
  19. $additionalOptions[] = array(
  20. 'label' => "Some Label",
  21. 'value' => "good product",
  22. );
  23. $observer->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));
  24. }
  25. }
Add Comment
Please, Sign In to add comment