6 declare(strict_types=1);
37 private $downloadableHelper;
42 private $sampleCollection;
47 private $linkCollection;
57 DownloadableHelper $downloadableHelper,
58 SampleCollection $sampleCollection,
59 LinkCollection $linkCollection
61 $this->enumLookup = $enumLookup;
62 $this->downloadableHelper = $downloadableHelper;
63 $this->sampleCollection = $sampleCollection;
79 if (!isset(
$value[
'model'])) {
87 if (
$product->getTypeId() === Downloadable::TYPE_DOWNLOADABLE) {
88 if ($field->
getName() ===
'downloadable_product_links') {
89 $links = $this->linkCollection->addTitleToResult(
$product->getStoreId())
90 ->addPriceToResult(
$product->getStore()->getWebsiteId())
91 ->addProductToFilter(
$product->getId());
92 $data = $this->formatLinks(
95 }
elseif ($field->
getName() ===
'downloadable_product_samples') {
97 ->addProductToFilter(
$product->getId());
98 $data = $this->formatSamples(
113 private function formatLinks(LinkCollection
$links) : array
118 $resultData[$linkKey][
'id'] =
$link->getId();
119 $resultData[$linkKey][
'title'] =
$link->getTitle();
120 $resultData[$linkKey][
'sort_order'] =
$link->getSortOrder();
121 $resultData[$linkKey][
'is_shareable'] = $this->downloadableHelper->getIsShareable(
$link);
122 $resultData[$linkKey][
'price'] =
$link->getPrice();
123 $resultData[$linkKey][
'number_of_downloads'] =
$link->getNumberOfDownloads();
124 $sampleType =
$link->getSampleType();
125 $linkType =
$link->getLinkType();
127 if ($linkType !==
null) {
128 $resultData[$linkKey][
'link_type']
129 = $this->enumLookup->getEnumValueFromField(
'DownloadableFileTypeEnum', $linkType);
132 if ($sampleType !==
null) {
133 $resultData[$linkKey][
'sample_type']
134 = $this->enumLookup->getEnumValueFromField(
'DownloadableFileTypeEnum', $sampleType);
137 $resultData[$linkKey][
'sample_file'] =
$link->getSampleFile();
138 $resultData[$linkKey][
'sample_url'] =
$link->getSampleUrl();
149 private function formatSamples(Collection
$samples) : array
152 foreach (
$samples as $sampleKey => $sample) {
154 $resultData[$sampleKey][
'id'] = $sample->getId();
155 $resultData[$sampleKey][
'title'] = $sample->getTitle();
156 $resultData[$sampleKey][
'sort_order'] = $sample->getSortOrder();
157 $resultData[$sampleKey][
'sample_type']
158 = $this->enumLookup->getEnumValueFromField(
'DownloadableFileTypeEnum', $sample->getSampleType());
159 $resultData[$sampleKey][
'sample_file'] = $sample->getSampleFile();
160 $resultData[$sampleKey][
'sample_url'] = $sample->getSampleUrl();
elseif(isset( $params[ 'redirect_parent']))
__construct(EnumLookup $enumLookup, DownloadableHelper $downloadableHelper, SampleCollection $sampleCollection, LinkCollection $linkCollection)
foreach( $_productCollection as $_product)() ?>" class $info
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)