12 use \Magento\Store\Model\Store;
19 class Downloadable extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
110 self::ERROR_OPTIONS_NOT_FOUND =>
'Options for downloadable products not found',
111 self::ERROR_GROUP_TITLE_NOT_FOUND =>
'Group titles not found for downloadable products',
112 self::ERROR_OPTION_NO_TITLE =>
'Option no title',
113 self::ERROR_MOVE_FILE =>
'Error move file',
114 self::ERROR_COLS_IS_EMPTY =>
'Missing sample and links data for the downloadable product' 148 'product_id' =>
null,
149 'sample_url' =>
null,
150 'sample_file' =>
null,
151 'sample_type' =>
null,
173 'product_id' =>
null,
180 'sample_url' =>
null,
181 'sample_file' =>
null,
182 'sample_type' => null
214 'sortorder' =>
'sort_order',
215 'downloads' =>
'number_of_downloads',
216 'shareable' =>
'is_shareable',
218 'file' =>
'link_file',
227 'sortorder' =>
'sort_order',
228 'url' =>
'sample_url',
229 'file' =>
'sample_file',
268 $this->parameters = $this->_entityModel->getParameters();
281 $newSku = $this->_entityModel->getNewSku();
282 while ($bunch = $this->_entityModel->getNextBunch()) {
283 foreach ($bunch as
$rowNum => $rowData) {
284 if (!$this->_entityModel->isRowAllowedToImport($rowData,
$rowNum)) {
287 $rowSku = strtolower($rowData[ImportProduct::COL_SKU]);
294 if (!empty($this->cachedOptions[
'sample']) || !empty($this->cachedOptions[
'link'])) {
317 if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData)) {
318 $this->_entityModel->addRowError(self::ERROR_OPTIONS_NOT_FOUND, $this->rowNum);
321 if ($this->downloadableHelper->isRowDownloadableEmptyOptions($rowData)) {
322 $this->_entityModel->addRowError(self::ERROR_COLS_IS_EMPTY, $this->rowNum);
340 if (isset($rowData[self::COL_DOWNLOADABLE_SAMPLES])
341 && $rowData[self::COL_DOWNLOADABLE_SAMPLES] !=
'' 343 $this->_entityModel->addRowError(self::ERROR_GROUP_TITLE_NOT_FOUND, $this->rowNum);
346 if (isset($rowData[self::COL_DOWNLOADABLE_SAMPLES])
347 && $rowData[self::COL_DOWNLOADABLE_SAMPLES] !=
'') {
362 if (isset($rowData[self::COL_DOWNLOADABLE_LINKS]) &&
363 $rowData[self::COL_DOWNLOADABLE_LINKS] !=
'' &&
366 $this->_entityModel->addRowError(self::ERROR_GROUP_TITLE_NOT_FOUND, $this->rowNum);
369 if (isset($rowData[self::COL_DOWNLOADABLE_LINKS]) &&
370 $rowData[self::COL_DOWNLOADABLE_LINKS] !=
'' 387 if (!array_key_exists(
'title',
$option)) {
388 $this->_entityModel->addRowError(self::ERROR_OPTION_NO_TITLE, $this->rowNum);
404 $resultAttrs = parent::prepareAttributesWithDefaultValueForSave($rowData, $withDefaultValue);
422 'purchased_separately',
423 self::DEFAULT_PURCHASED_SEPARATELY
439 if (isset($rowData[self::COL_DOWNLOADABLE_LINKS])) {
441 ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
442 $rowData[self::COL_DOWNLOADABLE_LINKS]
464 if (isset($rowData[self::COL_DOWNLOADABLE_SAMPLES])) {
466 ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
467 $rowData[self::COL_DOWNLOADABLE_SAMPLES]
471 if (isset($arr[
'group_title'])) {
489 $this->productIds[] = $entityId;
490 if (isset($rowData[self::COL_DOWNLOADABLE_LINKS])) {
491 $this->cachedOptions[
'link'] = array_merge(
492 $this->cachedOptions[
'link'],
493 $this->
prepareLinkData($rowData[self::COL_DOWNLOADABLE_LINKS], $entityId)
496 if (isset($rowData[self::COL_DOWNLOADABLE_SAMPLES])) {
497 $this->cachedOptions[
'sample'] = array_merge(
499 $this->cachedOptions[
'sample']
515 $existingOptions = $this->connection->fetchAll(
516 $this->connection->select()->from(
517 $this->_resource->getTableName(
'downloadable_sample')
525 foreach ($existingOptions as $existingOption) {
526 if (
$option[
'sample_url'] == $existingOption[
'sample_url']
527 &&
$option[
'sample_file'] == $existingOption[
'sample_file']
528 &&
$option[
'sample_type'] == $existingOption[
'sample_type']
529 &&
$option[
'product_id'] == $existingOption[
'product_id']) {
530 $result[] = array_replace($this->dataSampleTitle,
$option, $existingOption);
551 $existingOptions = $this->connection->fetchAll(
552 $this->connection->select()->from(
553 $this->_resource->getTableName(
'downloadable_link')
560 $existOption = $this->downloadableHelper->fillExistOptions(
$base,
$option, $existingOptions);
561 if (empty($existOption)) {
579 $existingOptions = $this->connection->fetchAll(
580 $this->connection->select()->from(
581 [
'dl' => $this->_resource->getTableName(
'downloadable_link')],
586 'number_of_downloads',
596 [
'dlp' => $this->_resource->getTableName(
'downloadable_link_price')],
598 [
'price_id',
'website_id']
605 $existOption = $this->downloadableHelper->fillExistOptions($this->dataLinkTitle,
$option, $existingOptions);
606 if (!empty($existOption)) {
607 $result[
'title'][] = $existOption;
609 $existOption = $this->downloadableHelper->fillExistOptions($this->dataLinkPrice,
$option, $existingOptions);
610 if (!empty($existOption)) {
611 $result[
'price'][] = $existOption;
627 if (
$option[
'sample_file'] !==
null) {
645 if (
$option[
'sample_file'] !==
null) {
648 if (
$option[
'link_file'] !==
null) {
682 $this->connection->insertOnDuplicate(
683 $this->_resource->getTableName(
'downloadable_sample'),
684 $this->downloadableHelper->prepareDataForSave($this->dataSample,
$dataSample)
687 $this->connection->insertOnDuplicate(
688 $this->_resource->getTableName(
'downloadable_sample_title'),
689 $this->downloadableHelper->prepareDataForSave($this->dataSampleTitle, $titleSample)
703 $this->connection->insertOnDuplicate(
704 $this->_resource->getTableName(
'downloadable_link'),
705 $this->downloadableHelper->prepareDataForSave($this->dataLink,
$dataLink)
708 $this->connection->insertOnDuplicate(
709 $this->_resource->getTableName(
'downloadable_link_title'),
710 $this->downloadableHelper->prepareDataForSave($this->dataLinkTitle,
$dataLink[
'title'])
713 $this->connection->insertOnDuplicate(
714 $this->_resource->getTableName(
'downloadable_link_price'),
715 $this->downloadableHelper->prepareDataForSave($this->dataLinkPrice,
$dataLink[
'price'])
732 ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
738 [
'product_id' => $entityId],
756 ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
762 [
'product_id' => $entityId],
778 foreach (
$values as $keyValue) {
779 $keyValue = trim($keyValue);
780 $pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR);
781 if (
$pos !==
false) {
782 $key = substr($keyValue, 0,
$pos);
784 if ($key ==
'sample') {
785 $option[
'sample_type'] = $this->downloadableHelper->getTypeByValue(
$value);
788 if ($key == self::URL_OPTION_VALUE || $key == self::FILE_OPTION_VALUE) {
791 if ($key ==
'downloads' &&
$value ==
'unlimited') {
794 if (isset($this->optionLinkMapping[$key])) {
795 $key = $this->optionLinkMapping[$key];
812 foreach (
$values as $keyValue) {
813 $keyValue = trim($keyValue);
814 $pos = strpos($keyValue, self::PAIR_VALUE_SEPARATOR);
815 if (
$pos !==
false) {
816 $key = substr($keyValue, 0,
$pos);
818 if ($key == self::URL_OPTION_VALUE || $key == self::FILE_OPTION_VALUE) {
821 if (isset($this->optionSampleMapping[$key])) {
822 $key = $this->optionSampleMapping[$key];
842 $res = $this->uploaderHelper->getUploader(
$type, $this->parameters)->move(
$fileName, $renameFileOff);
844 }
catch (\Exception $e) {
845 $this->_entityModel->addRowError(self::ERROR_MOVE_FILE, $this->rowNum);
857 $this->cachedOptions = [
861 $this->productIds = [];
const DOWNLOADABLE_PATCH_LINK_SAMPLES
parseLinkOption(array $values)
const DOWNLOADABLE_PATCH_SAMPLES
const COL_DOWNLOADABLE_LINKS
const DOWNLOADABLE_PATCH_LINKS
uploadDownloadableFiles($fileName, $type='links', $renameFileOff=false)
linksAdditionalAttributes(array $rowData, $attribute, $defaultValue)
const ERROR_OPTIONS_NOT_FOUND
const ERROR_GROUP_TITLE_NOT_FOUND
isRowValidLink(array $rowData)
getProductEntityLinkField()
isRowValidSample(array $rowData)
const ERROR_COLS_IS_EMPTY
const DEFAULT_GROUP_TITLE
const DEFAULT_PURCHASED_SEPARATELY
const DEFAULT_NUMBER_OF_DOWNLOADS
fillDataLink(array $base, array $options)
fillDataTitleLink(array $options)
const ERROR_OPTION_NO_TITLE
prepareAttributesWithDefaultValueForSave(array $rowData, $withDefaultValue=true)
isRowValid(array $rowData, $rowNum, $isNewProduct=true)
parseOptions(array $rowData, $entityId)
parseSampleOption($values)
const DEFAULT_IS_SHAREABLE
prepareLinkData($rowCol, $entityId=null)
sampleGroupTitle(array $rowData)
uploadSampleFiles(array $options)
const COL_DOWNLOADABLE_SAMPLES
prepareSampleData($rowCol, $entityId=null)
fillDataSample(array $base, array $options)
addAdditionalAttributes(array $rowData)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
__construct(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFac, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $prodAttrColFac, \Magento\Framework\App\ResourceConnection $resource, array $params, \Magento\DownloadableImportExport\Helper\Uploader $uploaderHelper, \Magento\DownloadableImportExport\Helper\Data $downloadableHelper, MetadataPool $metadataPool=null)
uploadLinkFiles(array $options)
const PAIR_VALUE_SEPARATOR