Data.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Multishipping\Helper;
  7. /**
  8. * Data helper
  9. */
  10. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  11. {
  12. /*
  13. * Xml paths for multishipping checkout
  14. *
  15. **/
  16. const XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE = 'multishipping/options/checkout_multiple';
  17. const XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY = 'multishipping/options/checkout_multiple_maximum_qty';
  18. /**
  19. * Checkout session
  20. *
  21. * @var \Magento\Checkout\Model\Session
  22. */
  23. protected $checkoutSession;
  24. /**
  25. * Construct
  26. *
  27. * @param \Magento\Framework\App\Helper\Context $context
  28. * @param \Magento\Checkout\Model\Session $checkoutSession
  29. */
  30. public function __construct(
  31. \Magento\Framework\App\Helper\Context $context,
  32. \Magento\Checkout\Model\Session $checkoutSession
  33. ) {
  34. $this->checkoutSession = $checkoutSession;
  35. parent::__construct($context);
  36. }
  37. /**
  38. * Retrieve checkout quote
  39. *
  40. * @return \Magento\Quote\Model\Quote
  41. */
  42. public function getQuote()
  43. {
  44. return $this->checkoutSession->getQuote();
  45. }
  46. /**
  47. * Get maximum quantity allowed for shipping to multiple addresses
  48. *
  49. * @return int
  50. */
  51. public function getMaximumQty()
  52. {
  53. return (int)$this->scopeConfig->getValue(
  54. self::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY,
  55. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  56. );
  57. }
  58. /**
  59. * Check if multishipping checkout is available
  60. * There should be a valid quote in checkout session. If not, only the config value will be returned
  61. *
  62. * @return bool
  63. */
  64. public function isMultishippingCheckoutAvailable()
  65. {
  66. $quote = $this->getQuote();
  67. $isMultiShipping = $this->scopeConfig->isSetFlag(
  68. self::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE,
  69. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  70. );
  71. if (!$quote || !$quote->hasItems()) {
  72. return $isMultiShipping;
  73. }
  74. return $isMultiShipping && !$quote->hasItemsWithDecimalQty() && $quote->validateMinimumAmount(
  75. true
  76. ) &&
  77. $quote->getItemsSummaryQty() - $quote->getItemVirtualQty() > 0 &&
  78. $quote->getItemsSummaryQty() <= $this->getMaximumQty();
  79. }
  80. }