Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Type Class Reference
Inheritance diagram for Type:
Virtual AbstractType

Public Member Functions

 __construct (\Magento\Catalog\Model\Product\Option $catalogProductOption, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Registry $coreRegistry, \Psr\Log\LoggerInterface $logger, ProductRepositoryInterface $productRepository, \Magento\Downloadable\Model\ResourceModel\SampleFactory $sampleResFactory, \Magento\Downloadable\Model\ResourceModel\Link $linkResource, \Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory $linksFactory, \Magento\Downloadable\Model\ResourceModel\Sample\CollectionFactory $samplesFactory, \Magento\Downloadable\Model\SampleFactory $sampleFactory, \Magento\Downloadable\Model\LinkFactory $linkFactory, \Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface $typeHandler, JoinProcessorInterface $extensionAttributesJoinProcessor, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 hasLinks ($product)
 
 hasOptions ($product)
 
 hasRequiredOptions ($product)
 
 getLinkSelectionRequired ($product)
 
 getSamples ($product)
 
 hasSamples ($product)
 
 checkProductBuyState ($product)
 
 getOrderOptions ($product)
 
 getSearchableData ($product)
 
 isSalable ($product)
 
 processBuyRequest ($product, $buyRequest)
 
 canConfigure ($product)
 
 hasWeight ()
 
 deleteTypeSpecificData (\Magento\Catalog\Model\Product $product)
 
- Public Member Functions inherited from Virtual
 isVirtual ($product)
 
 hasWeight ()
 
 deleteTypeSpecificData (\Magento\Catalog\Model\Product $product)
 
- Public Member Functions inherited from AbstractType
 deleteTypeSpecificData (\Magento\Catalog\Model\Product $product)
 
 __construct (\Magento\Catalog\Model\Product\Option $catalogProductOption, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Registry $coreRegistry, \Psr\Log\LoggerInterface $logger, ProductRepositoryInterface $productRepository, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 setTypeId ($typeId)
 
 getRelationInfo ()
 
 getChildrenIds ($parentId, $required=true)
 
 getParentIdsByChild ($childId)
 
 getSetAttributes ($product)
 
 attributesCompare ($attributeOne, $attributeTwo)
 
 getEditableAttributes ($product)
 
 getAttributeById ($attributeId, $product)
 
 isVirtual ($product)
 
 isSalable ($product)
 
 processConfiguration (\Magento\Framework\DataObject $buyRequest, $product, $processMode=self::PROCESS_MODE_LITE)
 
 prepareForCartAdvanced (\Magento\Framework\DataObject $buyRequest, $product, $processMode=null)
 
 prepareForCart (\Magento\Framework\DataObject $buyRequest, $product)
 
 addFileQueue ($queueOptions)
 
 getSpecifyOptionMessage ()
 
 checkProductBuyState ($product)
 
 getOrderOptions ($product)
 
 save ($product)
 
 beforeSave ($product)
 
 isComposite ($product)
 
 canConfigure ($product)
 
 canUseQtyDecimals ()
 
 getSku ($product)
 
 getOptionSku ($product, $sku='')
 
 getWeight ($product)
 
 hasOptions ($product)
 
 updateQtyOption ($options, \Magento\Framework\DataObject $option, $value, $product)
 
 hasRequiredOptions ($product)
 
 getStoreFilter ($product)
 
 setStoreFilter ($store, $product)
 
 getForceChildItemQtyChanges ($product)
 
 prepareQuoteItemQty ($qty, $product)
 
 assignProductToOption ($optionProduct, $option, $product)
 
 setConfig ($config)
 
 getSearchableData ($product)
 
 getProductsToPurchaseByReqGroups ($product)
 
 processBuyRequest ($product, $buyRequest)
 
 checkProductConfiguration ($product, $buyRequest)
 
 hasWeight ()
 
 setImageFromChildProduct (\Magento\Catalog\Model\Product $product)
 
 getIdentities (\Magento\Catalog\Model\Product $product)
 
 getAssociatedProducts ($product)
 
 isPossibleBuyFromList ($product)
 

Data Fields

const TYPE_DOWNLOADABLE = 'downloadable'
 
- Data Fields inherited from AbstractType
const CALCULATE_CHILD = 0
 
const CALCULATE_PARENT = 1
 
const SHIPMENT_SEPARATELY = 1
 
const SHIPMENT_TOGETHER = 0
 
const PROCESS_MODE_FULL = 'full'
 
const PROCESS_MODE_LITE = 'lite'
 
const OPTION_PREFIX = 'option_'
 

Protected Member Functions

 _prepareProduct (\Magento\Framework\DataObject $buyRequest, $product, $processMode)
 
 _createLink ()
 
 _createSample ()
 
- Protected Member Functions inherited from AbstractType
 _isStrictProcessMode ($processMode)
 
 _prepareOptions (\Magento\Framework\DataObject $buyRequest, $product, $processMode)
 
 _removeNotApplicableAttributes ($product)
 

Protected Attributes

 $_downloadableFile = null
 
 $_sampleResFactory
 
 $_linkResource
 
 $_linksFactory
 
 $_samplesFactory
 
 $_sampleFactory
 
 $_linkFactory
 
- Protected Attributes inherited from AbstractType
 $_typeId
 
 $_editableAttributes
 
 $_isComposite = false
 
 $_canConfigure = false
 
 $_canUseQtyDecimals = true
 
 $_fileQueue = []
 
 $_filesystem
 
 $_fileStorageDb
 
 $_cacheProductSetAttributes = '_cache_instance_product_set_attributes'
 
 $_coreRegistry
 
 $_eventManager
 
 $_logger
 
 $_catalogProductType
 
 $_eavConfig
 
 $_catalogProductOption
 
 $productRepository
 
 $serializer
 

Detailed Description

Downloadable product type model

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 18 of file Type.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Catalog\Model\Product\Option  $catalogProductOption,
\Magento\Eav\Model\Config  $eavConfig,
\Magento\Catalog\Model\Product\Type  $catalogProductType,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\MediaStorage\Helper\File\Storage\Database  $fileStorageDb,
\Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\Registry  $coreRegistry,
\Psr\Log\LoggerInterface  $logger,
ProductRepositoryInterface  $productRepository,
\Magento\Downloadable\Model\ResourceModel\SampleFactory  $sampleResFactory,
\Magento\Downloadable\Model\ResourceModel\Link  $linkResource,
\Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory  $linksFactory,
\Magento\Downloadable\Model\ResourceModel\Sample\CollectionFactory  $samplesFactory,
\Magento\Downloadable\Model\SampleFactory  $sampleFactory,
\Magento\Downloadable\Model\LinkFactory  $linkFactory,
\Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface  $typeHandler,
JoinProcessorInterface  $extensionAttributesJoinProcessor,
\Magento\Framework\Serialize\Serializer\Json  $serializer = null 
)

Construct

Parameters
\Magento\Catalog\Model\Product\Option$catalogProductOption
\Magento\Eav\Model\Config$eavConfig
\Magento\Catalog\Model\Product\Type$catalogProductType
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\MediaStorage\Helper\File\Storage\Database$fileStorageDb
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\Registry$coreRegistry
\Psr\Log\LoggerInterface$logger
ProductRepositoryInterface$productRepository
\Magento\Downloadable\Model\ResourceModel\SampleFactory$sampleResFactory
\Magento\Downloadable\Model\ResourceModel\Link$linkResource
\Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory$linksFactory
\Magento\Downloadable\Model\ResourceModel\Sample\CollectionFactory$samplesFactory
\Magento\Downloadable\Model\SampleFactory$sampleFactory
\Magento\Downloadable\Model\LinkFactory$linkFactory
TypeHandler\TypeHandlerInterface$typeHandler
JoinProcessorInterface$extensionAttributesJoinProcessor
\Magento\Framework\Serialize\Serializer\Json | null$serializer@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 92 of file Type.php.

111  {
112  $this->_sampleResFactory = $sampleResFactory;
113  $this->_linkResource = $linkResource;
114  $this->_linksFactory = $linksFactory;
115  $this->_samplesFactory = $samplesFactory;
116  $this->_sampleFactory = $sampleFactory;
117  $this->_linkFactory = $linkFactory;
118  $this->typeHandler = $typeHandler;
119  $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
120  parent::__construct(
121  $catalogProductOption,
122  $eavConfig,
123  $catalogProductType,
124  $eventManager,
125  $fileStorageDb,
126  $filesystem,
127  $coreRegistry,
128  $logger,
131  );
132  }
$logger
$filesystem

Member Function Documentation

◆ _createLink()

_createLink ( )
protected
Returns
\Magento\Downloadable\Model\Link

Definition at line 461 of file Type.php.

462  {
463  return $this->_linkFactory->create();
464  }

◆ _createSample()

_createSample ( )
protected
Returns
\Magento\Downloadable\Model\Sample

Definition at line 469 of file Type.php.

470  {
471  return $this->_sampleFactory->create();
472  }

◆ _prepareProduct()

_prepareProduct ( \Magento\Framework\DataObject  $buyRequest,
  $product,
  $processMode 
)
protected

Prepare product and its configuration to be added to some products list. Perform standard preparation process and then prepare options for downloadable links.

Parameters
\Magento\Framework\DataObject$buyRequest
\Magento\Catalog\Model\Product$product
string$processMode
Returns
\Magento\Framework\Phrase|array|string @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 418 of file Type.php.

419  {
420  $result = parent::_prepareProduct($buyRequest, $product, $processMode);
421 
422  if (is_string($result)) {
423  return $result;
424  }
425  // if adding product from admin area we add all links to product
426  $originalLinksPurchasedSeparately = null;
427  if ($product->getSkipCheckRequiredOption()) {
428  $originalLinksPurchasedSeparately = $product->getLinksPurchasedSeparately();
429  $product->setLinksPurchasedSeparately(false);
430  }
431  $preparedLinks = [];
432  if ($product->getLinksPurchasedSeparately()) {
433  if ($links = $buyRequest->getLinks()) {
434  foreach ($this->getLinks($product) as $link) {
435  if (in_array($link->getId(), $links)) {
436  $preparedLinks[] = $link->getId();
437  }
438  }
439  }
440  } else {
441  foreach ($this->getLinks($product) as $link) {
442  $preparedLinks[] = $link->getId();
443  }
444  }
445  if (null !== $originalLinksPurchasedSeparately) {
446  $product->setLinksPurchasedSeparately($originalLinksPurchasedSeparately);
447  }
448  if ($preparedLinks) {
449  $product->addCustomOption('downloadable_link_ids', implode(',', $preparedLinks));
450  return $result;
451  }
452  if ($this->getLinkSelectionRequired($product) && $this->_isStrictProcessMode($processMode)) {
453  return __('Please specify product link(s).')->render();
454  }
455  return $result;
456  }
__()
Definition: __.php:13
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ canConfigure()

canConfigure (   $product)

Check if downloadable product has links and they can be purchased separately

Parameters
\Magento\Catalog\Model\Product$product
Returns
bool

Definition at line 361 of file Type.php.

362  {
363  return $this->hasLinks($product) && $product->getLinksPurchasedSeparately();
364  }

◆ checkProductBuyState()

checkProductBuyState (   $product)

Check if product can be bought

Parameters
\Magento\Catalog\Model\Product$product
Returns
$this
Exceptions

Definition at line 251 of file Type.php.

252  {
253  parent::checkProductBuyState($product);
254  $option = $product->getCustomOption('info_buyRequest');
255  if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) {
256  $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($option->getValue()));
257  if (!$buyRequest->hasLinks()) {
258  if (!$product->getLinksPurchasedSeparately()) {
259  $allLinksIds = $this->_linksFactory->create()->addProductToFilter(
260  $product->getEntityId()
261  )->getAllIds();
262  $buyRequest->setLinks($allLinksIds);
263  $product->addCustomOption(
264  'info_buyRequest',
265  $this->serializer->serialize($buyRequest->getData())
266  );
267  } else {
268  throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).'));
269  }
270  }
271  }
272  return $this;
273  }
__()
Definition: __.php:13
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

◆ deleteTypeSpecificData()

deleteTypeSpecificData ( \Magento\Catalog\Model\Product  $product)

Delete data specific for Downloadable product type

Parameters
\Magento\Catalog\Model\Product$product
Returns
void

Definition at line 382 of file Type.php.

383  {
385  $downloadableData = $product->getDownloadableData();
386  $sampleItems = [];
387  if (isset($downloadableData['sample'])) {
388  foreach ($downloadableData['sample'] as $sample) {
389  $sampleItems[] = $sample['sample_id'];
390  }
391  }
392  if ($sampleItems) {
393  $this->_sampleResFactory->create()->deleteItems($sampleItems);
394  }
395  $linkItems = [];
396  if (isset($downloadableData['link'])) {
397  foreach ($downloadableData['link'] as $link) {
398  $linkItems[] = $link['link_id'];
399  }
400  }
401  if ($linkItems) {
402  $this->_linkResource->deleteItems($linkItems);
403  }
404  }
405  }

◆ getLinkSelectionRequired()

getLinkSelectionRequired (   $product)

Check if product cannot be purchased with no links selected

Parameters
\Magento\Catalog\Model\Product$product
Returns
boolean @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 207 of file Type.php.

208  {
209  return $product->getLinksPurchasedSeparately();
210  }

◆ getOrderOptions()

getOrderOptions (   $product)

Prepare additional options/information for order item which will be created from this product

Parameters
\Magento\Catalog\Model\Product$product
Returns
array

Definition at line 282 of file Type.php.

283  {
284  $options = parent::getOrderOptions($product);
285  if ($linkIds = $product->getCustomOption('downloadable_link_ids')) {
286  $linkOptions = [];
287  $links = $this->getLinks($product);
288  foreach (explode(',', $linkIds->getValue()) as $linkId) {
289  if (isset($links[$linkId])) {
290  $linkOptions[] = $linkId;
291  }
292  }
293  $options = array_merge($options, ['links' => $linkOptions]);
294  }
295  $options = array_merge(
296  $options,
297  ['is_downloadable' => true, 'real_product_type' => self::TYPE_DOWNLOADABLE]
298  );
299  return $options;
300  }

◆ getSamples()

getSamples (   $product)

Get downloadable product samples

Parameters
\Magento\Catalog\Model\Product$product
Returns
\Magento\Downloadable\Model\ResourceModel\Sample\Collection

Definition at line 218 of file Type.php.

219  {
220  if ($product->getDownloadableSamples() === null) {
221  $sampleCollection = $this->_samplesFactory->create()->addProductToFilter(
222  $product->getEntityId()
223  )->addTitleToResult(
224  $product->getStoreId()
225  );
226  $this->extensionAttributesJoinProcessor->process($sampleCollection);
227  $product->setDownloadableSamples($sampleCollection);
228  }
229 
230  return $product->getDownloadableSamples();
231  }

◆ getSearchableData()

getSearchableData (   $product)

Retrieve additional searchable data from type instance Using based on product id and store_id data

Parameters
\Magento\Catalog\Model\Product$product
Returns
array

Definition at line 309 of file Type.php.

310  {
311  $searchData = parent::getSearchableData($product);
312 
313  $linkSearchData = $this->_createLink()->getSearchableData($product->getEntityId(), $product->getStoreId());
314  if ($linkSearchData) {
315  $searchData = array_merge($searchData, $linkSearchData);
316  }
317 
318  $sampleSearchData = $this->_createSample()->getSearchableData($product->getEntityId(), $product->getStoreId());
319  if ($sampleSearchData) {
320  $searchData = array_merge($searchData, $sampleSearchData);
321  }
322 
323  return $searchData;
324  }

◆ hasLinks()

hasLinks (   $product)

Check if product has links

Parameters
\Magento\Catalog\Model\Product$product
Returns
boolean

Definition at line 169 of file Type.php.

170  {
171  $hasLinks = $product->getData('links_exist');
172  if (null === $hasLinks) {
173  $hasLinks = (count($this->getLinks($product)) > 0);
174  }
175  return $hasLinks;
176  }

◆ hasOptions()

hasOptions (   $product)

Check if product has options

Parameters
\Magento\Catalog\Model\Product$product
Returns
boolean

Definition at line 184 of file Type.php.

185  {
186  return parent::hasOptions($product) || $this->hasLinks($product);
187  }

◆ hasRequiredOptions()

hasRequiredOptions (   $product)

Check if product has required options

Parameters
\Magento\Catalog\Model\Product$product
Returns
bool

Definition at line 195 of file Type.php.

196  {
197  return (parent::hasRequiredOptions($product) || $product->getLinksPurchasedSeparately());
198  }

◆ hasSamples()

hasSamples (   $product)

Check if product has samples

Parameters
\Magento\Catalog\Model\Product$product
Returns
boolean

Definition at line 239 of file Type.php.

240  {
241  return count($this->getSamples($product)) > 0;
242  }

◆ hasWeight()

hasWeight ( )

Check that product of this type has weight

Returns
bool

Definition at line 371 of file Type.php.

372  {
373  return false;
374  }

◆ isSalable()

isSalable (   $product)

Check is product available for sale

Parameters
\Magento\Catalog\Model\Product$product
Returns
bool

Definition at line 332 of file Type.php.

333  {
334  return $this->hasLinks($product) && parent::isSalable($product);
335  }

◆ processBuyRequest()

processBuyRequest (   $product,
  $buyRequest 
)

Prepare selected options for downloadable product

Parameters
\Magento\Catalog\Model\Product$product
\Magento\Framework\DataObject$buyRequest
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 345 of file Type.php.

346  {
347  $links = $buyRequest->getLinks();
348  $links = is_array($links) ? array_filter($links, 'intval') : [];
349 
350  $options = ['links' => $links];
351 
352  return $options;
353  }
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest

Field Documentation

◆ $_downloadableFile

$_downloadableFile = null
protected

Definition at line 27 of file Type.php.

◆ $_linkFactory

$_linkFactory
protected

Definition at line 57 of file Type.php.

◆ $_linkResource

$_linkResource
protected

Definition at line 37 of file Type.php.

◆ $_linksFactory

$_linksFactory
protected

Definition at line 42 of file Type.php.

◆ $_sampleFactory

$_sampleFactory
protected

Definition at line 52 of file Type.php.

◆ $_sampleResFactory

$_sampleResFactory
protected

Definition at line 32 of file Type.php.

◆ $_samplesFactory

$_samplesFactory
protected

Definition at line 47 of file Type.php.

◆ TYPE_DOWNLOADABLE

const TYPE_DOWNLOADABLE = 'downloadable'

Definition at line 20 of file Type.php.


The documentation for this class was generated from the following file: