예제 #1
0
 /**
  * Validate row attributes. Pass VALID row data ONLY as argument.
  *
  * @param array $rowData
  * @param int $rowNum
  * @param boolean $checkRequiredAttributes OPTIONAL Flag which can disable validation required values.
  * @return boolean
  */
 public function isRowValid(array $rowData, $rowNum, $checkRequiredAttributes = true)
 {
     $error = false;
     $rowScope = $this->_entityModel->getRowScope($rowData);
     if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_NULL != $rowScope) {
         foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
             // check value for non-empty in the case of required attribute?
             if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
                 $error |= !$this->_entityModel->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
             } elseif ($this->_isAttributeRequiredCheckNeeded($attrCode) && $checkRequiredAttributes && Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $rowScope && $attrParams['is_required']) {
                 $this->_entityModel->addRowError(Mage_ImportExport_Model_Import_Entity_Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
                 $error = true;
             }
         }
     }
     $error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
     return !$error;
 }
예제 #2
0
 /**
  * Validate row attributes. Pass VALID row data ONLY as argument.
  *
  * @param array $rowData
  * @param int $rowNum
  * @param boolean $isNewProduct OPTIONAL.
  * @return boolean
  */
 public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
 {
     $error = false;
     $rowScope = $this->_entityModel->getRowScope($rowData);
     if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_NULL != $rowScope) {
         foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
             // check value for non-empty in the case of required attribute?
             if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
                 $error |= !$this->_entityModel->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
             } elseif ($this->_isAttributeRequiredCheckNeeded($attrCode) && $attrParams['is_required']) {
                 // For the default scope - if this is a new product or
                 // for an old product, if the imported doc has the column present for the attrCode
                 if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $rowScope && ($isNewProduct || array_key_exists($attrCode, $rowData))) {
                     $this->_entityModel->addRowError(Mage_ImportExport_Model_Import_Entity_Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
                     $error = true;
                 }
             }
         }
     }
     $error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
     return !$error;
 }
예제 #3
0
파일: Option.php 프로젝트: nemphys/magento2
 /**
  * Validate one specific parameter
  *
  * @param string $typeParameter
  * @param array $rowData
  * @param int $rowNumber
  * @return bool
  */
 protected function _validateSpecificParameterData($typeParameter, array $rowData, $rowNumber)
 {
     $fieldName = self::COLUMN_PREFIX . $typeParameter;
     if ($typeParameter == 'price') {
         if (!empty($rowData[$fieldName]) && !is_numeric(rtrim($rowData[$fieldName], '%'))) {
             $this->_productEntity->addRowError(self::ERROR_INVALID_PRICE, $rowNumber);
             return false;
         }
     } elseif ($typeParameter == 'max_characters') {
         if (!empty($rowData[$fieldName]) && !ctype_digit((string) $rowData[$fieldName])) {
             $this->_productEntity->addRowError(self::ERROR_INVALID_MAX_CHARACTERS, $rowNumber);
             return false;
         }
     }
     return true;
 }