28 protected $path =
'custom_options';
97 $this->random = $random
131 $upload = $this->httpFactory->create();
132 $file = $processingParams->getFilesPrefix() .
'options_' .
$option->getId() .
'_file';
134 $runValidation =
$option->getIsRequire() || $upload->isUploaded($file);
135 if (!$runValidation) {
136 throw new \Magento\Framework\Validator\Exception(
138 'The validation failed. ' 139 .
'Make sure the required options are entered and the file is uploaded, then try again.' 144 $fileInfo = $upload->getFileInfo($file)[$file];
151 $value = $this->fileSize->getMaxFileSizeInMb();
154 "The file was too big and couldn't be uploaded. " 155 .
"Use a file smaller than %1 MBs and try to upload again.",
160 throw new ProductException(
__(
"The required option wasn't entered. Enter the option and try again."));
175 if ($upload->isUploaded($file) && $upload->isValid($file)) {
179 $filePath = $dispersion;
183 $fileRandomName = $this->random->getRandomString(32);
184 $filePath .=
'/' .$fileRandomName;
185 $fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
189 if ($this->product !==
null) {
190 $this->product->getTypeInstance()->addFileQueue(
192 'operation' =>
'receive_uploaded_file',
194 'dst_name' => $fileFullPath,
195 'uploader' => $upload,
206 if ($this->isImageValidator->isValid(
$fileInfo[
'tmp_name'])) {
213 if (!empty($imageSize)) {
222 'quote_path' => $this->quotePath . $filePath,
223 'order_path' => $this->orderPath . $filePath,
224 'fullpath' => $fileFullPath,
228 'secret_key' => substr($fileHash, 0, 20),
230 }
elseif ($upload->getErrors()) {
238 __(
"The product's required option(s) weren't entered. Make sure the options are entered and try again.")
252 $this->mediaDirectory->create($this->path);
253 $this->mediaDirectory->create($this->quotePath);
254 $this->mediaDirectory->create($this->orderPath);
257 $path = $this->path .
'/.htaccess';
258 if (!$this->mediaDirectory->isFile(
$path)) {
259 $this->mediaDirectory->writeFile(
$path,
"Order deny,allow\nDeny from all");
271 return isset($_SERVER[
'CONTENT_LENGTH']) && $_SERVER[
'CONTENT_LENGTH'] > $this->fileSize->getMaxFileSize();
getValidatorErrors($errors, $fileInfo, $option)
elseif(isset( $params[ 'redirect_parent']))
setProduct(Product $product)
static getCorrectFileName($fileName)
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\File\Size $fileSize, \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory, \Magento\Framework\Validator\File\IsImage $isImageValidator, Random $random=null)
buildImageValidator($object, $option, $fileFullPath=null)
validate($processingParams, $option)
static getDispersionPath($fileName)