Cart.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Controller\Adminhtml\Index;
  7. use Magento\Customer\Api\AccountManagementInterface;
  8. use Magento\Customer\Api\AddressRepositoryInterface;
  9. use Magento\Customer\Api\CustomerRepositoryInterface;
  10. use Magento\Customer\Api\Data\AddressInterfaceFactory;
  11. use Magento\Customer\Api\Data\CustomerInterfaceFactory;
  12. use Magento\Customer\Model\Address\Mapper;
  13. use Magento\Framework\DataObjectFactory as ObjectFactory;
  14. use Magento\Framework\Api\DataObjectHelper;
  15. /**
  16. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  17. * @deprecated 101.0.0
  18. */
  19. class Cart extends \Magento\Customer\Controller\Adminhtml\Index
  20. {
  21. /**
  22. * @var \Magento\Quote\Model\QuoteFactory
  23. */
  24. private $quoteFactory;
  25. /**
  26. * Constructor
  27. *
  28. * @param \Magento\Backend\App\Action\Context $context
  29. * @param \Magento\Framework\Registry $coreRegistry
  30. * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
  31. * @param \Magento\Customer\Model\CustomerFactory $customerFactory
  32. * @param \Magento\Customer\Model\AddressFactory $addressFactory
  33. * @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
  34. * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
  35. * @param \Magento\Customer\Helper\View $viewHelper
  36. * @param \Magento\Framework\Math\Random $random
  37. * @param CustomerRepositoryInterface $customerRepository
  38. * @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
  39. * @param Mapper $addressMapper
  40. * @param AccountManagementInterface $customerAccountManagement
  41. * @param AddressRepositoryInterface $addressRepository
  42. * @param CustomerInterfaceFactory $customerDataFactory
  43. * @param AddressInterfaceFactory $addressDataFactory
  44. * @param \Magento\Customer\Model\Customer\Mapper $customerMapper
  45. * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
  46. * @param DataObjectHelper $dataObjectHelper
  47. * @param ObjectFactory $objectFactory
  48. * @param \Magento\Framework\View\LayoutFactory $layoutFactory
  49. * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
  50. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  51. * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
  52. * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  53. * @param \Magento\Quote\Model\QuoteFactory|null $quoteFactory
  54. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  55. */
  56. public function __construct(
  57. \Magento\Backend\App\Action\Context $context,
  58. \Magento\Framework\Registry $coreRegistry,
  59. \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
  60. \Magento\Customer\Model\CustomerFactory $customerFactory,
  61. \Magento\Customer\Model\AddressFactory $addressFactory,
  62. \Magento\Customer\Model\Metadata\FormFactory $formFactory,
  63. \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
  64. \Magento\Customer\Helper\View $viewHelper,
  65. \Magento\Framework\Math\Random $random,
  66. CustomerRepositoryInterface $customerRepository,
  67. \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
  68. Mapper $addressMapper,
  69. AccountManagementInterface $customerAccountManagement,
  70. AddressRepositoryInterface $addressRepository,
  71. CustomerInterfaceFactory $customerDataFactory,
  72. AddressInterfaceFactory $addressDataFactory,
  73. \Magento\Customer\Model\Customer\Mapper $customerMapper,
  74. \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
  75. DataObjectHelper $dataObjectHelper,
  76. ObjectFactory $objectFactory,
  77. \Magento\Framework\View\LayoutFactory $layoutFactory,
  78. \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
  79. \Magento\Framework\View\Result\PageFactory $resultPageFactory,
  80. \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
  81. \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
  82. \Magento\Quote\Model\QuoteFactory $quoteFactory = null
  83. ) {
  84. parent::__construct(
  85. $context,
  86. $coreRegistry,
  87. $fileFactory,
  88. $customerFactory,
  89. $addressFactory,
  90. $formFactory,
  91. $subscriberFactory,
  92. $viewHelper,
  93. $random,
  94. $customerRepository,
  95. $extensibleDataObjectConverter,
  96. $addressMapper,
  97. $customerAccountManagement,
  98. $addressRepository,
  99. $customerDataFactory,
  100. $addressDataFactory,
  101. $customerMapper,
  102. $dataObjectProcessor,
  103. $dataObjectHelper,
  104. $objectFactory,
  105. $layoutFactory,
  106. $resultLayoutFactory,
  107. $resultPageFactory,
  108. $resultForwardFactory,
  109. $resultJsonFactory
  110. );
  111. $this->quoteFactory = $quoteFactory ?: $this->_objectManager->get(\Magento\Quote\Model\QuoteFactory::class);
  112. }
  113. /**
  114. * Handle and then get cart grid contents
  115. *
  116. * @return \Magento\Framework\View\Result\Layout
  117. */
  118. public function execute()
  119. {
  120. $customerId = $this->initCurrentCustomer();
  121. $websiteId = $this->getRequest()->getParam('website_id');
  122. // delete an item from cart
  123. $deleteItemId = $this->getRequest()->getPost('delete');
  124. if ($deleteItemId) {
  125. /** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
  126. $quoteRepository = $this->_objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
  127. /** @var \Magento\Quote\Model\Quote $quote */
  128. try {
  129. $quote = $quoteRepository->getForCustomer($customerId);
  130. } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
  131. $quote = $this->quoteFactory->create();
  132. }
  133. $quote->setWebsite(
  134. $this->_objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getWebsite($websiteId)
  135. );
  136. $item = $quote->getItemById($deleteItemId);
  137. if ($item && $item->getId()) {
  138. $quote->removeItem($deleteItemId);
  139. $quoteRepository->save($quote->collectTotals());
  140. }
  141. }
  142. $resultLayout = $this->resultLayoutFactory->create();
  143. $resultLayout->getLayout()->getBlock('admin.customer.view.edit.cart')->setWebsiteId($websiteId);
  144. return $resultLayout;
  145. }
  146. }