当前位置: 首页>>代码示例>>PHP>>正文


PHP Option::getIsRequire方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product\Option::getIsRequire方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::getIsRequire方法的具体用法?PHP Option::getIsRequire怎么用?PHP Option::getIsRequire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product\Option的用法示例。


在下文中一共展示了Option::getIsRequire方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * @param \Magento\Framework\Object $processingParams
  * @param \Magento\Catalog\Model\Product\Option $option
  * @return array
  * @throws LocalizedException
  * @throws ProductException
  * @throws \Exception
  * @throws \Magento\Framework\Exception\InputException
  * @throws \Magento\Framework\Validator\Exception
  * @throws \Zend_File_Transfer_Exception
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function validate($processingParams, $option)
 {
     $upload = $this->httpFactory->create();
     $file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file';
     try {
         $runValidation = $option->getIsRequire() || $upload->isUploaded($file);
         if (!$runValidation) {
             throw new \Magento\Framework\Validator\Exception(__('Validation failed. Required options were not filled or file was not uploaded.'));
         }
         $fileInfo = $upload->getFileInfo($file)[$file];
         $fileInfo['title'] = $fileInfo['name'];
     } catch (\Magento\Framework\Validator\Exception $e) {
         throw $e;
     } catch (\Exception $e) {
         // when file exceeds the upload_max_filesize, $_FILES is empty
         if ($this->validateContentLength()) {
             $value = $this->fileSize->getMaxFileSizeInMb();
             throw new LocalizedException(__('The file you uploaded is larger than %1 Megabytes allowed by server', $value));
         } else {
             throw new ProductException(__('Option required.'));
         }
     }
     /**
      * Option Validations
      */
     $upload = $this->buildImageValidator($upload, $option);
     /**
      * Upload process
      */
     $this->initFilesystem();
     $userValue = [];
     if ($upload->isUploaded($file) && $upload->isValid($file)) {
         $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
         $fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
         $dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
         $filePath = $dispersion;
         $tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
         $fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
         $filePath .= '/' . $fileHash . '.' . $extension;
         $fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
         $upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));
         if ($this->product !== null) {
             $this->product->getTypeInstance()->addFileQueue(['operation' => 'receive_uploaded_file', 'src_name' => $file, 'dst_name' => $fileFullPath, 'uploader' => $upload, 'option' => $this]);
         }
         $_width = 0;
         $_height = 0;
         if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) {
             $imageSize = getimagesize($fileInfo['tmp_name']);
             if ($imageSize) {
                 $_width = $imageSize[0];
                 $_height = $imageSize[1];
             }
         }
         $uri = $this->filesystem->getUri(DirectoryList::MEDIA);
         $userValue = ['type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $uri . $this->quotePath . $filePath, 'order_path' => $uri . $this->orderPath . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)];
     } elseif ($upload->getErrors()) {
         $errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option);
         if (count($errors) > 0) {
             throw new LocalizedException(__(implode("\n", $errors)));
         }
     } else {
         throw new LocalizedException(__('Please specify the product\'s required option(s).'));
     }
     return $userValue;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:78,代码来源:ValidatorFile.php

示例2: _createOptionDataObject

 /**
  * Create option data object
  *
  * @param \Magento\Catalog\Model\Product\Option $option
  * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option array
  */
 protected function _createOptionDataObject(\Magento\Catalog\Model\Product\Option $option)
 {
     $data = array(Data\Option::OPTION_ID => $option->getId(), Data\Option::TITLE => $option->getTitle(), Data\Option::TYPE => $option->getType(), Data\Option::IS_REQUIRE => $option->getIsRequire(), Data\Option::SORT_ORDER => $option->getSortOrder(), Data\Option::METADATA => $this->optionMetadataReader->read($option));
     return $this->optionBuilder->populateWithArray($data)->create();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:ReadService.php


注:本文中的Magento\Catalog\Model\Product\Option::getIsRequire方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。