Boolean.php 921 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Attribute\Backend\Data;
  7. /**
  8. * Boolean customer attribute backend model
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Boolean extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
  13. {
  14. /**
  15. * Prepare data before attribute save
  16. *
  17. * @param \Magento\Customer\Model\Customer $customer
  18. * @return $this
  19. */
  20. public function beforeSave($customer)
  21. {
  22. $attributeName = $this->getAttribute()->getName();
  23. $inputValue = $customer->getData($attributeName);
  24. $inputValue = $inputValue === null ? $this->getAttribute()->getDefaultValue() : $inputValue;
  25. $sanitizedValue = !empty($inputValue) ? '1' : '0';
  26. $customer->setData($attributeName, $sanitizedValue);
  27. return $this;
  28. }
  29. }