Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /**
  2. * @param string $email
  3. * @return bool
  4. */
  5. function deleteCustomerQuote($email) {
  6. // vendormagentomodule-customeretcdi.xml : MagentoCustomerApiCustomerRepositoryInterface = MagentoCustomerModelResourceModelCustomerRepository
  7. // vendormagentomodule-quoteetcdi.xml : MagentoQuoteApiCartRepositoryInterface = MagentoQuoteModelQuoteRepository
  8. /** @var MagentoFrameworkAppObjectManager $objectManager */
  9. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  10. /** @var MagentoCustomerApiCustomerRepositoryInterface $customerRepository */
  11. $customerRepository = $objectManager->get('MagentoCustomerApiCustomerRepositoryInterface');
  12. /** @var MagentoQuoteApiCartRepositoryInterface $cartRepository */
  13. $cartRepository = $objectManager->get('MagentoQuoteApiCartRepositoryInterface');
  14. try {
  15. $customer = $customerRepository->get($email);
  16. $cart = $cartRepository->getForCustomer($customer->getId()); // MagentoQuoteApiDataCartInterface
  17. $cartRepository->delete($cart);
  18. return true;
  19. } catch (Exception $exception) {
  20. return false;
  21. }
  22. }
  23.  
  24. /**
  25. * @param string $email
  26. * @return bool
  27. */
  28. function deleteAllCustomerQuotes($email) {
  29. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  30. /** @var MagentoCustomerApiCustomerRepositoryInterface $customerRepository */
  31. $customerRepository = $objectManager->get('MagentoCustomerApiCustomerRepositoryInterface');
  32. /** @var MagentoQuoteModelResourceModelQuoteCollectionFactory $quoteCollectionFactory */
  33. $quoteCollectionFactory = $objectManager->get('MagentoQuoteModelResourceModelQuoteCollectionFactory');
  34. /** @var MagentoQuoteApiCartRepositoryInterface $cartRepository */
  35. $cartRepository = $objectManager->get('MagentoQuoteApiCartRepositoryInterface');
  36. try {
  37. $customer = $customerRepository->get($email);
  38. $customerId = $customer->getId();
  39. $quoteCollection = $quoteCollectionFactory->create()->addFieldToFilter('customer_id', $customerId);
  40. if ( $quoteCollection->getSize() ) {
  41. /** @var MagentoQuoteModelQuote $item */
  42. foreach ( $quoteCollection as $item ) {
  43. $cartRepository->delete($item);
  44. }
  45. }
  46. return true;
  47. } catch (Exception $exception) {
  48. return false;
  49. }
  50. }
Add Comment
Please, Sign In to add comment