![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog/Model/Product/Attribute/Backend/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /** * Catalog product weight backend attribute model * * @author Magento Core Team <[email protected]> */ namespace Magento\Catalog\Model\Product\Attribute\Backend; class Weight extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend { /** * @var \Magento\Framework\Locale\FormatInterface */ protected $localeFormat; /** * @param \Magento\Framework\Locale\FormatInterface $localeFormat */ public function __construct( \Magento\Framework\Locale\FormatInterface $localeFormat ) { $this->localeFormat = $localeFormat; } /** * Validate * * @param \Magento\Catalog\Model\Product $object * @throws \Magento\Framework\Exception\LocalizedException * @return bool */ public function validate($object) { $attrCode = $this->getAttribute()->getAttributeCode(); $value = $object->getData($attrCode); if (!$this->isPositiveOrZero($value)) { throw new \Magento\Framework\Exception\LocalizedException( __('Please enter a number 0 or greater in this field.') ); } return true; } /** * Returns whether the value is greater than, or equal to, zero * * @param mixed $value * @return bool */ protected function isPositiveOrZero($value) { $value = $this->localeFormat->getNumber($value); $isNegative = $value < 0; return !$isNegative; } }