Beispiel #1
0
 /**
  * Validate
  *
  * @param mixed $data Data
  *
  * @return void
  */
 public function validate($data)
 {
     parent::validate($data);
     if (!\XLite\Core\Converter::isEmptyString($data)) {
         $entity = \XLite\Core\Database::getRepo('XLite\\Module\\XC\\ProductVariants\\Model\\ProductVariant')->findOneBySku($this->sanitize($data));
         if ($entity) {
             $this->throwVariantSKUError();
         }
     }
 }
Beispiel #2
0
 /**
  * Validate
  *
  * @param mixed $data Data
  *
  * @return void
  */
 public function validate($data)
 {
     if (!\XLite\Core\Converter::isEmptyString($data)) {
         $entity = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->findOneBySku($this->sanitize($data));
         // DO NOT use "!==" here
         if ($entity && (empty($this->productId) || $entity->getProductId() != $this->productId)) {
             $this->throwSKUError();
         }
     }
 }
Beispiel #3
0
 /**
  * Validate
  *
  * @param mixed $data Data
  *
  * @return void
  */
 public function validate($data)
 {
     if (!\XLite\Core\Converter::isEmptyString($data)) {
         $entity = \XLite\Core\Database::getRepo($this->fieldClass)->findOneBy(array($this->fieldName => $this->sanitize($data)));
         // DO NOT use "!==" here
         if ($entity && (empty($this->fieldValue) || $entity->{'get' . \XLite\Core\Converter::convertToCamelCase($this->fieldName)}() != $this->fieldValue)) {
             $this->throwSKUError();
         }
     }
 }
Beispiel #4
0
 /**
  * Validate
  *
  * @param mixed $data Data
  *
  * @return void
  * @throws \XLite\Core\Validator\Exception
  */
 public function validate($data)
 {
     if (!\XLite\Core\Converter::isEmptyString($data)) {
         parent::validate($data);
         $entity = \XLite\Core\Database::getRepo($this->class)->findOneByCleanURL($this->sanitize($data));
         // DO NOT use "!==" here
         if ($entity && (empty($this->id) || $entity->getUniqueIdentifier() != $this->id)) {
             $this->throwCleanURLError();
         }
     }
 }
Beispiel #5
0
 /**
  * Validate
  *
  * @param mixed $data Data
  *
  * @return void
  * @throws \XLite\Core\Validator\Exception
  */
 public function validate($data)
 {
     $data = $this->sanitize($data);
     if (!\XLite\Core\Converter::isEmptyString($data)) {
         parent::validate($data);
         /** @var \XLite\Model\Repo\CleanURL $repo */
         $repo = \XLite\Core\Database::getRepo('XLite\\Model\\CleanURL');
         $postedData = \XLite\Core\Request::getInstance()->postedData;
         if (!isset($postedData['forceCleanURL']) && !$repo->isURLUnique($data, $this->class, $this->id)) {
             $this->throwCleanURLError($data);
         }
     }
 }
Beispiel #6
0
 /**
  * Lifecycle callback
  *
  * @return void
  * @see    ____func_see____
  * @since  1.0.24
  *
  * @PrePersist
  * @PreUpdate
  */
 public function prepareBeforeSave()
 {
     if (\XLite\Core\Converter::isEmptyString($this->getCleanURL())) {
         $this->setCleanURL(null);
     }
 }
Beispiel #7
0
 /**
  * Update cleanURL
  *
  * @param \XLite\Model\AEntity $model Model
  * @param  string              $value Value
  *
  * @return void
  */
 protected function updateCleanURL(\XLite\Model\AEntity $model, $value)
 {
     if (!\XLite\Core\Converter::isEmptyString($value)) {
         $validator = new \XLite\Core\Validator\String\CleanURL(false, null, get_class($model), $model->getId());
         try {
             $validator->validate($value);
             $model->setCleanURL($value);
         } catch (\XLite\Core\Validator\Exception $exception) {
         }
     } else {
         $model->setCleanURL(null);
     }
 }
Beispiel #8
0
 /**
  * Get posted data
  *
  * @param string $field Name of the field to retrieve OPTIONAL
  *
  * @return mixed
  */
 protected function getPostedData($field = null)
 {
     $value = parent::getPostedData($field);
     $time = \XLite\Core\Converter::time();
     if (!isset($field)) {
         if (isset($value['arrivalDate'])) {
             $value['arrivalDate'] = intval(strtotime($value['arrivalDate'])) ?: mktime(0, 0, 0, date('m', $time), date('j', $time), date('Y', $time));
         }
         if (isset($value['sku']) && \XLite\Core\Converter::isEmptyString($value['sku'])) {
             $value['sku'] = null;
         }
         if (isset($value['productClass'])) {
             $value['productClass'] = \XLite\Core\Database::getRepo('\\XLite\\Model\\ProductClass')->find($value['productClass']);
         }
         if (isset($value['taxClass'])) {
             $value['taxClass'] = \XLite\Core\Database::getRepo('\\XLite\\Model\\TaxClass')->find($value['taxClass']);
         }
     } elseif ('arrivalDate' === $field) {
         $value = intval(strtotime($value)) ?: mktime(0, 0, 0, date('m', $time), date('j', $time), date('Y', $time));
     } elseif ('sku' === $field) {
         $value = null;
     } elseif ('productClass' === $field) {
         $value = \XLite\Core\Database::getRepo('\\XLite\\Model\\ProductClass')->find($value);
     } elseif ('taxClass' === $field) {
         $value = \XLite\Core\Database::getRepo('\\XLite\\Model\\TaxClass')->find($value);
     }
     return $value;
 }
Beispiel #9
0
 /**
  * Prepare update date
  *
  * @return void
  *
  * @PreUpdate
  */
 public function prepareBeforeUpdate()
 {
     $this->setUpdateDate(\XLite\Core\Converter::time());
     if (\XLite\Core\Converter::isEmptyString($this->getSku())) {
         $this->setSKU(null);
     }
 }
Beispiel #10
0
 /**
  * Generate clean URL
  *
  * @param \XLite\Model\Product $model  Product
  * @param string               $value  Value OPTIONAL
  *
  * @return void
  */
 protected function generateCleanURL(\XLite\Model\Product $model, $value = '')
 {
     if (\XLite\Core\Converter::isEmptyString($value)) {
         if (!\XLite\Core\Converter::isEmptyString($this->currentRowData['name'])) {
             // Input cleanURL value is empty, trying to get product name from current row data
             $lngCodes = array_unique(array('en', $this->importer->getLanguageCode()));
             foreach ($lngCodes as $code) {
                 if (!empty($this->currentRowData['name'][$code])) {
                     $value = $this->currentRowData['name'][$code];
                     break;
                 }
             }
         }
         if (\XLite\Core\Converter::isEmptyString($value)) {
             // Try to get value from current product name
             $value = $model->getName();
         }
     } else {
         $value = preg_replace('/\\.html$/', '', $value);
     }
     /** @var \XLite\Model\Repo\CleanURL $repo */
     $repo = \XLite\Core\Database::getRepo('XLite\\Model\\CleanURL');
     $value = $repo->generateCleanURL($model, $value);
     if (!\XLite\Core\Converter::isEmptyString($value)) {
         $this->updateCleanURL($model, $value);
     }
 }
Beispiel #11
0
 /**
  * Normalize 'group' value
  *
  * @param mixed @value Value
  *
  * @return \XLite\Model\AttributeGroup
  */
 protected function normalizeGroupValue($value)
 {
     if (!\XLite\Core\Converter::isEmptyString($this->currentRowData['class'])) {
         $className = $this->getDefLangValue($this->currentRowData['class']);
         $productClass = \XLite\Core\Database::getRepo('XLite\\Model\\ProductClass')->findOneByName($className);
     } else {
         $productClass = null;
     }
     return $this->normalizeValueAsAttributeGroup($value, $productClass);
 }
Beispiel #12
0
 /**
  * Get posted data
  *
  * @param string $field Name of the field to retrieve OPTIONAL
  *
  * @return mixed
  */
 protected function getPostedData($field = null)
 {
     $value = parent::getPostedData($field);
     if (!isset($field)) {
         if (isset($value['arrivalDate'])) {
             $value['arrivalDate'] = intval(strtotime($value['arrivalDate'])) ?: time();
         }
         if (isset($value['sku']) && \XLite\Core\Converter::isEmptyString($value['sku'])) {
             $value['sku'] = null;
         }
     } elseif ('arrivalDate' === $field) {
         $value = intval(strtotime($value)) ?: time();
     } elseif ('sku' === $field) {
         $value = null;
     }
     return $value;
 }