43 parent::__construct($context, $scopeConfig, $checkoutSession,
$storeManager, $formKeyValidator,
$cart);
51 $orderItemIds = $this->
getRequest()->getPost(
'order_items');
52 if (is_array($orderItemIds)) {
53 $itemsCollection = $this->_objectManager->create(\
Magento\Sales\Model\Order\Item::class)
55 ->addIdFilter($orderItemIds)
58 foreach ($itemsCollection as
$item) {
60 $this->addOrderItem(
$item);
62 if ($this->_checkoutSession->getUseNotice(
true)) {
63 $this->messageManager->addNoticeMessage($e->getMessage());
65 $this->messageManager->addErrorMessage($e->getMessage());
68 $this->messageManager->addExceptionMessage(
70 __(
'We can\'t add this item to your shopping cart right now.')
72 $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
92 $session = $this->cart->getCustomerSession();
94 $orderCustomerId =
$item->getOrder()->getCustomerId();
95 $currentCustomerId =
$session->getCustomer()->getId();
96 if ($orderCustomerId == $currentCustomerId) {
97 $this->cart->addOrderItem(
$item, 1);
98 if (!$this->cart->getQuote()->getHasError()) {
100 'You added %1 to your shopping cart.',
101 $this->escaper->escapeHtml(
$item->getName())
103 $this->messageManager->addSuccessMessage(
$message);
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart, Escaper $escaper=null)