Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. use MagentoFrameworkAppActionContext;
  2. use MagentoFrameworkViewResultPageFactory;
  3. use MagentoQuoteModelQuoteFactory;
  4. use MagentoCheckoutModelCart;
  5. use MagentoCatalogModelProductFactory;
  6. class Copyquote extends MagentoFrameworkAppActionAction
  7. {
  8. protected $_resultPageFactory;
  9. protected $quoteFactory;
  10. protected $formKey;
  11. protected $cart;
  12. protected $product;
  13. public function __construct(Context $context,
  14. PageFactory $resultPageFactory,
  15. QuoteFactory $quoteFactory,
  16. Cart $cart,
  17. ProductFactory $product)
  18. {
  19. $this->_resultPageFactory = $resultPageFactory;
  20. $this->quoteFactory = $quoteFactory;
  21. $this->cart = $cart;
  22. $this->product = $product;
  23. parent::__construct($context);
  24. }
  25. public function execute()
  26. {
  27. try
  28. {
  29. $id = ‘YOUR QUOTE ID’
  30. if($id > 0)
  31. {
  32. $quote = $this->quoteFactory->create()->load($id);
  33. $items = $quote->getAllVisibleItems();
  34.  
  35. foreach ($items as $item)
  36. {
  37. $productId =$item->getProductId();
  38. $_product = $this->product->create()->load($productId);
  39.  
  40. $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
  41.  
  42. $info = $options['info_buyRequest'];
  43. $request1 = new MagentoFrameworkDataObject();
  44. $request1->setData($info);
  45.  
  46. $this->cart->addProduct($_product, $request1);
  47. }
  48. $this->cart->save();
  49. }
  50. }
  51. catch (Exception $e)
  52. {
  53. $this->messageManager->addError( __($e->getMessage()) );
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement