Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Weight Class Reference
Inheritance diagram for Weight:
AbstractBackend BackendInterface

Public Member Functions

 __construct (\Magento\Framework\Locale\FormatInterface $localeFormat)
 
 validate ($object)
 
- Public Member Functions inherited from AbstractBackend
 setAttribute ($attribute)
 
 getAttribute ()
 
 getType ()
 
 isStatic ()
 
 getTable ()
 
 getEntityIdField ()
 
 setValueId ($valueId)
 
 setEntityValueId ($entity, $valueId)
 
 getValueId ()
 
 getEntityValueId ($entity)
 
 getDefaultValue ()
 
 validate ($object)
 
 afterLoad ($object)
 
 beforeSave ($object)
 
 afterSave ($object)
 
 beforeDelete ($object)
 
 afterDelete ($object)
 
 getAffectedFields ($object)
 
 isScalar ()
 

Protected Member Functions

 isPositiveOrZero ($value)
 

Protected Attributes

 $localeFormat
 
- Protected Attributes inherited from AbstractBackend
 $_attribute
 
 $_valueId
 
 $_valueIds = []
 
 $_table
 
 $_entityIdField
 
 $_defaultValue = null
 

Detailed Description

Definition at line 14 of file Weight.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Locale\FormatInterface  $localeFormat)
Parameters
\Magento\Framework\Locale\FormatInterface$localeFormat

Definition at line 25 of file Weight.php.

27  {
28  $this->localeFormat = $localeFormat;
29  }

Member Function Documentation

◆ isPositiveOrZero()

isPositiveOrZero (   $value)
protected

Returns whether the value is greater than, or equal to, zero

Parameters
mixed$value
Returns
bool

Definition at line 56 of file Weight.php.

57  {
58  $value = $this->localeFormat->getNumber($value);
59  $isNegative = $value < 0;
60  return !$isNegative;
61  }
$value
Definition: gender.phtml:16

◆ validate()

validate (   $object)

Validate

Parameters
\Magento\Catalog\Model\Product$object
Exceptions

Definition at line 38 of file Weight.php.

39  {
40  $attrCode = $this->getAttribute()->getAttributeCode();
41  $value = $object->getData($attrCode);
42  if (!$this->isPositiveOrZero($value)) {
43  throw new \Magento\Framework\Exception\LocalizedException(
44  __('Please enter a number 0 or greater in this field.')
45  );
46  }
47  return true;
48  }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16

Field Documentation

◆ $localeFormat

$localeFormat
protected

Definition at line 20 of file Weight.php.


The documentation for this class was generated from the following file: