Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use MagentoFrameworkAppActionContext;
- use MagentoFrameworkViewResultPageFactory;
- use MagentoQuoteModelQuoteFactory;
- use MagentoCheckoutModelCart;
- use MagentoCatalogModelProductFactory;
- class Copyquote extends MagentoFrameworkAppActionAction
- {
- protected $_resultPageFactory;
- protected $quoteFactory;
- protected $formKey;
- protected $cart;
- protected $product;
- public function __construct(Context $context,
- PageFactory $resultPageFactory,
- QuoteFactory $quoteFactory,
- Cart $cart,
- ProductFactory $product)
- {
- $this->_resultPageFactory = $resultPageFactory;
- $this->quoteFactory = $quoteFactory;
- $this->cart = $cart;
- $this->product = $product;
- parent::__construct($context);
- }
- public function execute()
- {
- try
- {
- $id = ‘YOUR QUOTE ID’
- if($id > 0)
- {
- $quote = $this->quoteFactory->create()->load($id);
- $items = $quote->getAllVisibleItems();
- foreach ($items as $item)
- {
- $productId =$item->getProductId();
- $_product = $this->product->create()->load($productId);
- $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
- $info = $options['info_buyRequest'];
- $request1 = new MagentoFrameworkDataObject();
- $request1->setData($info);
- $this->cart->addProduct($_product, $request1);
- }
- $this->cart->save();
- }
- }
- catch (Exception $e)
- {
- $this->messageManager->addError( __($e->getMessage()) );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement