/** * @param \Magento\Framework\Object $object * @return bool */ public function validate($object) { $password = $object->getPassword(); if ($password && $password == $object->getPasswordConfirm()) { return true; } return parent::validate($object); }
/** * Implode data for validation * * @param \Magento\Catalog\Model\Product $object * @return bool */ public function validate($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); if (is_array($data)) { $object->setData($attributeCode, implode(',', array_filter($data))); } return parent::validate($object); }
/** * Validate * * @param \Magento\Catalog\Model\Product $object * @throws \Magento\Framework\Model\Exception * @return bool */ public function validate($object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); if (empty($value)) { return parent::validate($object); } if (!preg_match('/^\\d*(\\.|,)?\\d{0,4}$/i', $value) || $value < 0) { throw new \Magento\Framework\Model\Exception(__('Please enter a number 0 or greater in this field.')); } return true; }
/** * Validate * * @param \Magento\Catalog\Model\Product $object * @throws \Magento\Framework\Exception\LocalizedException * @return bool */ public function validate($object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); if (empty($value)) { return parent::validate($object); } if (!$this->isPositiveOrZero($value)) { throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a number 0 or greater in this field.')); } return true; }