Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Product Class Reference
Inheritance diagram for Product:
AbstractEntity AdvancedPricing StubProduct

Public Member Functions

 __construct (\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $config, \Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Psr\Log\LoggerInterface $logger, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory, \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig, \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryColFactory, \Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory $itemFactory, \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory, \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider, \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer, array $dateAttrCodes=[])
 
 _getHeaderColumns ()
 
 export ()
 
 filterAttributeCollection (\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection)
 
 getAttributeCollection ()
 
 getEntityTypeCode ()
 
- Public Member Functions inherited from AbstractEntity
 __construct (\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $config, ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager)
 
 addRowError ($errorCode, $errorRowNum)
 
 addMessageTemplate ($errorCode, $message)
 
 retrieveMessageTemplate ($errorCode)
 
 export ()
 
 filterAttributeCollection (\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection)
 
 getAttributeCollection ()
 
 getAttributeOptions (\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
 
 getEntityTypeCode ()
 
 getEntityTypeId ()
 
 getErrorMessages ()
 
 getErrorsCount ()
 
 getInvalidRowsCount ()
 
 getProcessedEntitiesCount ()
 
 getProcessedRowsCount ()
 
 getWriter ()
 
 setParameters (array $parameters)
 
 setWriter (AbstractAdapter $writer)
 
 __destruct ()
 

Data Fields

const VALUE_ALL = 'all'
 
const COL_STORE = '_store'
 
const COL_ATTR_SET = '_attribute_set'
 
const COL_TYPE = '_type'
 
const COL_PRODUCT_WEBSITES = '_product_websites'
 
const COL_CATEGORY = '_category'
 
const COL_ROOT_CATEGORY = '_root_category'
 
const COL_SKU = 'sku'
 
const COL_VISIBILITY = 'visibility'
 
const COL_MEDIA_IMAGE = '_media_image'
 
const COL_ADDITIONAL_ATTRIBUTES = 'additional_attributes'
 

Protected Member Functions

 initAttributeSets ()
 
 initCategories ()
 
 initTypeModels ()
 
 getMediaGallery (array $productIds)
 
 prepareCatalogInventory (array $productIds)
 
 prepareLinks (array $productIds)
 
 updateDataWithCategoryColumns (&$dataRow, &$rowCategories, $productId)
 
 setHeaderColumns ($customOptionsData, $stockItemRows)
 
 _getExportMainAttrCodes ()
 
 _getEntityCollection ($resetCollection=false)
 
 getItemsPerPage ()
 
 paginateCollection ($page, $pageSize)
 
 _prepareEntityCollection (\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
 
 getExportData ()
 
 loadCollection ()
 
 hasMultiselectData ($item, $storeId)
 
 collectMultiselectValues ($item, $attrCode, $storeId)
 
 isValidAttributeValue ($code, $value)
 
 addMultirowData ($dataRow, $multiRawData)
 
 _customFieldsMapping ($rowData)
 
 _customHeadersMapping ($rowData)
 
 optionRowToCellString ($option)
 
 getCustomOptionsData ($productIds)
 
 initAttributes ()
 
 getProductEntityLinkField ()
 
- Protected Member Functions inherited from AbstractEntity
 _initStores ()
 
 _getHeaderColumns ()
 
 _getEntityCollection ($resetCollection=false)
 
 _getExportAttrCodes ()
 
 _initAttrValues ()
 
 _prepareEntityCollection (\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
 

Protected Attributes

 $_bannedAttributes = ['media_gallery']
 
 $_attrSetIdToName = []
 
 $_categories = []
 
 $_rootCategories = []
 
 $_indexValueAttributes
 
 $collectedMultiselectsData = []
 
 $_permanentAttributes = [self::COL_SKU]
 
 $_productTypeModels = []
 
 $_storeIdToCode = []
 
 $_websiteIdToCode = []
 
 $_attributeTypes = []
 
 $_entityCollectionFactory
 
 $_entityCollection
 
 $_itemsPerPage = null
 
 $_headerColumns = []
 
 $_exportConfig
 
 $_logger
 
 $_productFactory
 
 $_attrSetColFactory
 
 $_categoryColFactory
 
 $_resourceModel
 
 $_itemFactory
 
 $_optionColFactory
 
 $_attributeColFactory
 
 $_typeFactory
 
 $_linkTypeProvider
 
 $rowCustomizer
 
 $_fieldsMap
 
 $dateAttrCodes
 
 $_exportMainAttrCodes
 
 $metadataPool
 
- Protected Attributes inherited from AbstractEntity
 $_attributeValues = []
 
 $_connection
 
 $_disabledAttrs = []
 
 $_entityTypeId
 
 $_errors = []
 
 $_errorsCount = 0
 
 $_errorsLimit = 100
 
 $_filter = []
 
 $_indexValueAttributes = []
 
 $_messageTemplates = []
 
 $_parameters = []
 
 $_specialAttributes = []
 
 $_permanentAttributes = []
 
 $_processedEntitiesCount = 0
 
 $_processedRowsCount = 0
 
 $_writer
 
 $_localeDate
 
 $_storeManager
 

Additional Inherited Members

- Static Protected Attributes inherited from AbstractEntity
static $attrCodes = null
 

Detailed Description

Export entity product model

@api

@SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 25 of file Product.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Stdlib\DateTime\TimezoneInterface  $localeDate,
\Magento\Eav\Model\Config  $config,
\Magento\Framework\App\ResourceConnection  $resource,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Psr\Log\LoggerInterface  $logger,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory  $collectionFactory,
\Magento\ImportExport\Model\Export\ConfigInterface  $exportConfig,
\Magento\Catalog\Model\ResourceModel\ProductFactory  $productFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory  $attrSetColFactory,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory  $categoryColFactory,
\Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory  $itemFactory,
\Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory  $optionColFactory,
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory  $attributeColFactory,
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory  $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider  $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface  $rowCustomizer,
array  $dateAttrCodes = [] 
)
Parameters
\Magento\Framework\Stdlib\DateTime\TimezoneInterface$localeDate
\Magento\Eav\Model\Config$config
\Magento\Framework\App\ResourceConnection$resource
\Magento\Store\Model\StoreManagerInterface$storeManager
\Psr\Log\LoggerInterface$logger
\Magento\Catalog\Model\ResourceModel\Product\Collection$collection
\Magento\ImportExport\Model\Export\ConfigInterface$exportConfig
\Magento\Catalog\Model\ResourceModel\ProductFactory$productFactory
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory$attrSetColFactory
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory$categoryColFactory
\Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory$itemFactory
\Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory$optionColFactory
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory$attributeColFactory
Product\Type\Factory$_typeFactory
\Magento\Catalog\Model\Product\LinkTypeProvider$linkTypeProvider
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface$rowCustomizer
array$dateAttrCodes@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 371 of file Product.php.

389  {
390  $this->_entityCollectionFactory = $collectionFactory;
391  $this->_exportConfig = $exportConfig;
392  $this->_logger = $logger;
393  $this->_productFactory = $productFactory;
394  $this->_attrSetColFactory = $attrSetColFactory;
395  $this->_categoryColFactory = $categoryColFactory;
396  $this->_resourceModel = $resource;
397  $this->_itemFactory = $itemFactory;
398  $this->_optionColFactory = $optionColFactory;
399  $this->_attributeColFactory = $attributeColFactory;
400  $this->_typeFactory = $_typeFactory;
401  $this->_linkTypeProvider = $linkTypeProvider;
402  $this->rowCustomizer = $rowCustomizer;
403  $this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
404 
405  parent::__construct($localeDate, $config, $resource, $storeManager);
406 
407  $this->initTypeModels()
408  ->initAttributes()
409  ->_initStores()
410  ->initAttributeSets()
411  ->initWebsites()
412  ->initCategories();
413  }
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$logger

Member Function Documentation

◆ _customFieldsMapping()

_customFieldsMapping (   $rowData)
protected

Custom fields mapping for changed purposes of fields and field names

Parameters
array$rowData
Returns
array

Definition at line 1310 of file Product.php.

1311  {
1312  foreach ($this->_fieldsMap as $systemFieldName => $fileFieldName) {
1313  if (isset($rowData[$systemFieldName])) {
1314  $rowData[$fileFieldName] = $rowData[$systemFieldName];
1315  unset($rowData[$systemFieldName]);
1316  }
1317  }
1318  return $rowData;
1319  }

◆ _customHeadersMapping()

_customHeadersMapping (   $rowData)
protected

Custom headers mapping for changed field names

Parameters
array$rowData
Returns
array

Definition at line 1328 of file Product.php.

1329  {
1330  foreach ($rowData as $key => $fieldName) {
1331  if (isset($this->_fieldsMap[$fieldName])) {
1332  $rowData[$key] = $this->_fieldsMap[$fieldName];
1333  }
1334  }
1335  return $rowData;
1336  }

◆ _getEntityCollection()

_getEntityCollection (   $resetCollection = false)
protected

{}

Definition at line 756 of file Product.php.

757  {
758  if ($resetCollection || empty($this->_entityCollection)) {
759  $this->_entityCollection = $this->_entityCollectionFactory->create();
760  }
762  }

◆ _getExportMainAttrCodes()

_getExportMainAttrCodes ( )
protected

Get attributes codes which are appropriate for export and not the part of additional_attributes.

Returns
array

Definition at line 748 of file Product.php.

◆ _getHeaderColumns()

_getHeaderColumns ( )

{}

Definition at line 697 of file Product.php.

698  {
699  return $this->_customHeadersMapping($this->rowCustomizer->addHeaderColumns($this->_headerColumns));
700  }

◆ _prepareEntityCollection()

_prepareEntityCollection ( \Magento\Eav\Model\Entity\Collection\AbstractCollection  $collection)
protected

{}

Since
100.2.0

Definition at line 864 of file Product.php.

865  {
866  $exportFilter = !empty($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP]) ?
868 
869  if (isset($exportFilter['category_ids'])
870  && trim($exportFilter['category_ids'])
871  && $collection instanceof \Magento\Catalog\Model\ResourceModel\Product\Collection
872  ) {
873  $collection->addCategoriesFilter(['in' => explode(',', $exportFilter['category_ids'])]);
874  }
875 
876  return parent::_prepareEntityCollection($collection);
877  }

◆ addMultirowData()

addMultirowData (   $dataRow,
  $multiRawData 
)
protected
Deprecated:
100.1.0
Parameters
array$dataRow
array$multiRawData
Returns
array

Definition at line 1297 of file Product.php.

1298  {
1299  $data = $this->appendMultirowData($dataRow, $multiRawData);
1300  return $data ? [$data] : [];
1301  }

◆ collectMultiselectValues()

collectMultiselectValues (   $item,
  $attrCode,
  $storeId 
)
protected
Parameters
\Magento\Catalog\Model\Product$item
string$attrCode
int$storeId
Returns
$this

Definition at line 1125 of file Product.php.

1126  {
1127  $attrValue = $item->getData($attrCode);
1129  $options = array_intersect_key(
1130  $this->_attributeValues[$attrCode],
1131  array_flip($optionIds)
1132  );
1133  $linkId = $item->getData($this->getProductEntityLinkField());
1134  if (!(isset($this->collectedMultiselectsData[Store::DEFAULT_STORE_ID][$linkId][$attrCode])
1135  && $this->collectedMultiselectsData[Store::DEFAULT_STORE_ID][$linkId][$attrCode] == $options)
1136  ) {
1137  $this->collectedMultiselectsData[$storeId][$linkId][$attrCode] = $options;
1138  }
1139 
1140  return $this;
1141  }

◆ export()

export ( )

Export process

Returns
string

Definition at line 829 of file Product.php.

830  {
831  //Execution time may be very long
832  set_time_limit(0);
833 
834  $writer = $this->getWriter();
835  $page = 0;
836  while (true) {
837  ++$page;
838  $entityCollection = $this->_getEntityCollection(true);
839  $entityCollection->setOrder('entity_id', 'asc');
840  $entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
841  $this->_prepareEntityCollection($entityCollection);
842  $this->paginateCollection($page, $this->getItemsPerPage());
843  if ($entityCollection->count() == 0) {
844  break;
845  }
846  $exportData = $this->getExportData();
847  if ($page == 1) {
848  $writer->setHeaderCols($this->_getHeaderColumns());
849  }
850  foreach ($exportData as $dataRow) {
851  $writer->writeRow($this->_customFieldsMapping($dataRow));
852  }
853  if ($entityCollection->getCurPage() >= $entityCollection->getLastPageNumber()) {
854  break;
855  }
856  }
857  return $writer->getContents();
858  }
_prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
Definition: Product.php:864
_getEntityCollection($resetCollection=false)
Definition: Product.php:756
$page
Definition: pages.php:8

◆ filterAttributeCollection()

filterAttributeCollection ( \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection  $collection)

Clean up already loaded attribute collection.

Parameters
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection$collection
Returns
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection

Definition at line 1431 of file Product.php.

1432  {
1433  $validTypes = array_keys($this->_productTypeModels);
1434  $validTypes = array_combine($validTypes, $validTypes);
1435 
1436  foreach (parent::filterAttributeCollection($collection) as $attribute) {
1437  if (in_array($attribute->getAttributeCode(), $this->_bannedAttributes)) {
1438  $collection->removeItemByKey($attribute->getId());
1439  continue;
1440  }
1441  $attrApplyTo = $attribute->getApplyTo();
1442  $attrApplyTo = array_combine($attrApplyTo, $attrApplyTo);
1443  $attrApplyTo = $attrApplyTo ? array_intersect_key($attrApplyTo, $validTypes) : $validTypes;
1444 
1445  if ($attrApplyTo) {
1446  foreach ($attrApplyTo as $productType) {
1447  // override attributes by its product type model
1448  if ($this->_productTypeModels[$productType]->overrideAttribute($attribute)) {
1449  break;
1450  }
1451  }
1452  } else {
1453  // remove attributes of not-supported product types
1454  $collection->removeItemByKey($attribute->getId());
1455  }
1456  }
1457  return $collection;
1458  }

◆ getAttributeCollection()

getAttributeCollection ( )

Entity attributes collection getter.

Returns
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection

Definition at line 1465 of file Product.php.

1466  {
1467  return $this->_attributeColFactory->create();
1468  }

◆ getCustomOptionsData()

getCustomOptionsData (   $productIds)
protected

Collect custom options data for products that will be exported.

Option name and type will be collected for all store views, all other data (which can't be changed on store view level will be collected for DEFAULT_STORE_ID only. Store view specified data will be saved to the additional store view row.

Parameters
int[]$productIds
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 1365 of file Product.php.

1366  {
1367  $customOptionsData = [];
1368 
1369  foreach (array_keys($this->_storeIdToCode) as $storeId) {
1370  $options = $this->_optionColFactory->create();
1371  /* @var Collection $options*/
1372  $options->reset()
1373  ->addOrder('sort_order', Collection::SORT_ORDER_ASC)
1374  ->addTitleToResult($storeId)
1375  ->addPriceToResult($storeId)
1376  ->addProductToFilter($productIds)
1377  ->addValuesToResult($storeId);
1378 
1379  foreach ($options as $option) {
1380  $row = [];
1381  $productId = $option['product_id'];
1382  $row['name'] = $option['title'];
1383  $row['type'] = $option['type'];
1385  $row['required'] = $option['is_require'];
1386  $row['price'] = $option['price'];
1387  $row['price_type'] = ($option['price_type'] === 'percent') ? 'percent' : 'fixed';
1388  $row['sku'] = $option['sku'];
1389  if ($option['max_characters']) {
1390  $row['max_characters'] = $option['max_characters'];
1391  }
1392 
1393  foreach (['file_extension', 'image_size_x', 'image_size_y'] as $fileOptionKey) {
1394  if (!isset($option[$fileOptionKey])) {
1395  continue;
1396  }
1397 
1398  $row[$fileOptionKey] = $option[$fileOptionKey];
1399  }
1400  }
1401  $values = $option->getValues();
1402 
1403  if ($values) {
1404  foreach ($values as $value) {
1405  $row['option_title'] = $value['title'];
1407  $row['option_title'] = $value['title'];
1408  $row['price'] = $value['price'];
1409  $row['price_type'] = ($value['price_type'] === 'percent') ? 'percent' : 'fixed';
1410  $row['sku'] = $value['sku'];
1411  }
1412  $customOptionsData[$productId][$storeId][] = $this->optionRowToCellString($row);
1413  }
1414  } else {
1415  $customOptionsData[$productId][$storeId][] = $this->optionRowToCellString($row);
1416  }
1417  $option = null;
1418  }
1419  $options = null;
1420  }
1421 
1422  return $customOptionsData;
1423  }
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16

◆ getEntityTypeCode()

getEntityTypeCode ( )

EAV entity type code getter.

Returns
string

Definition at line 1475 of file Product.php.

1476  {
1477  return 'catalog_product';
1478  }

◆ getExportData()

getExportData ( )
protected

Get export data for collection

Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength) @SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 888 of file Product.php.

889  {
890  $exportData = [];
891  try {
892  $rawData = $this->collectRawData();
893  $multirawData = $this->collectMultirawData();
894 
895  $productIds = array_keys($rawData);
896  $stockItemRows = $this->prepareCatalogInventory($productIds);
897 
898  $this->rowCustomizer->prepareData(
899  $this->_prepareEntityCollection($this->_entityCollectionFactory->create()),
901  );
902 
903  $this->setHeaderColumns($multirawData['customOptionsData'], $stockItemRows);
904 
905  foreach ($rawData as $productId => $productData) {
906  foreach ($productData as $storeId => $dataRow) {
907  if ($storeId == Store::DEFAULT_STORE_ID && isset($stockItemRows[$productId])) {
908  $dataRow = array_merge($dataRow, $stockItemRows[$productId]);
909  }
910  $this->appendMultirowData($dataRow, $multirawData);
911  if ($dataRow) {
912  $exportData[] = $dataRow;
913  }
914  }
915  }
916  } catch (\Exception $e) {
917  $this->_logger->critical($e);
918  }
919  return $exportData;
920  }
_prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
Definition: Product.php:864
setHeaderColumns($customOptionsData, $stockItemRows)
Definition: Product.php:712
$productData

◆ getItemsPerPage()

getItemsPerPage ( )
protected

Get items per page

Returns
int

Definition at line 769 of file Product.php.

770  {
771  if ($this->_itemsPerPage === null) {
772  $memoryLimitConfigValue = trim(ini_get('memory_limit'));
773  $lastMemoryLimitLetter = strtolower($memoryLimitConfigValue[strlen($memoryLimitConfigValue) - 1]);
774  $memoryLimit = (int) $memoryLimitConfigValue;
775  switch ($lastMemoryLimitLetter) {
776  case 'g':
777  $memoryLimit *= 1024;
778  // fall-through intentional
779  case 'm':
780  $memoryLimit *= 1024;
781  // fall-through intentional
782  case 'k':
783  $memoryLimit *= 1024;
784  break;
785  default:
786  // minimum memory required by Magento
787  $memoryLimit = 250000000;
788  }
789 
790  // Tested one product to have up to such size
791  $memoryPerProduct = 500000;
792  // Decrease memory limit to have supply
793  $memoryUsagePercent = 0.8;
794  // Minimum Products limit
795  $minProductsLimit = 500;
796  // Maximal Products limit
797  $maxProductsLimit = 5000;
798 
799  $this->_itemsPerPage = intval(
800  ($memoryLimit * $memoryUsagePercent - memory_get_usage(true)) / $memoryPerProduct
801  );
802  if ($this->_itemsPerPage < $minProductsLimit) {
803  $this->_itemsPerPage = $minProductsLimit;
804  }
805  if ($this->_itemsPerPage > $maxProductsLimit) {
806  $this->_itemsPerPage = $maxProductsLimit;
807  }
808  }
809  return $this->_itemsPerPage;
810  }

◆ getMediaGallery()

getMediaGallery ( array  $productIds)
protected

Prepare products media gallery

Parameters
int[]$productIds
Returns
array

Definition at line 518 of file Product.php.

519  {
520  if (empty($productIds)) {
521  return [];
522  }
523  $select = $this->_connection->select()->from(
524  ['mgvte' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value_to_entity')],
525  [
526  "mgvte.{$this->getProductEntityLinkField()}",
527  'mgvte.value_id'
528  ]
529  )->joinLeft(
530  ['mg' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery')],
531  '(mg.value_id = mgvte.value_id)',
532  [
533  'mg.attribute_id',
534  'filename' => 'mg.value',
535  ]
536  )->joinLeft(
537  ['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
538  '(mg.value_id = mgv.value_id)',
539  [
540  'mgv.label',
541  'mgv.position',
542  'mgv.disabled',
543  'mgv.store_id',
544  ]
545  )->where(
546  "mgvte.{$this->getProductEntityLinkField()} IN (?)",
548  );
549 
550  $rowMediaGallery = [];
551  $stmt = $this->_connection->query($select);
552  while ($mediaRow = $stmt->fetch()) {
553  $rowMediaGallery[$mediaRow[$this->getProductEntityLinkField()]][] = [
554  '_media_attribute_id' => $mediaRow['attribute_id'],
555  '_media_image' => $mediaRow['filename'],
556  '_media_label' => $mediaRow['label'],
557  '_media_position' => $mediaRow['position'],
558  '_media_is_disabled' => $mediaRow['disabled'],
559  '_media_store_id' => $mediaRow['store_id'],
560  ];
561  }
562 
563  return $rowMediaGallery;
564  }

◆ getProductEntityLinkField()

getProductEntityLinkField ( )
protected

Get product entity link field

Returns
string
Since
100.1.0

Definition at line 1518 of file Product.php.

1519  {
1520  if (!$this->productEntityLinkField) {
1521  $this->productEntityLinkField = $this->getMetadataPool()
1522  ->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
1523  ->getLinkField();
1524  }
1525  return $this->productEntityLinkField;
1526  }

◆ hasMultiselectData()

hasMultiselectData (   $item,
  $storeId 
)
protected
Parameters
\Magento\Catalog\Model\Product$item
int$storeId
Returns
bool
Deprecated:
100.2.3

Definition at line 1113 of file Product.php.

1114  {
1115  $linkId = $item->getData($this->getProductEntityLinkField());
1116  return !empty($this->collectedMultiselectsData[$storeId][$linkId]);
1117  }

◆ initAttributes()

initAttributes ( )
protected

Initialize attribute option values and types.

Returns
$this

Definition at line 1485 of file Product.php.

1486  {
1487  foreach ($this->getAttributeCollection() as $attribute) {
1488  $this->_attributeValues[$attribute->getAttributeCode()] = $this->getAttributeOptions($attribute);
1489  $this->_attributeTypes[$attribute->getAttributeCode()] =
1491  if ($attribute->getIsUserDefined()) {
1492  $this->userDefinedAttributes[] = $attribute->getAttributeCode();
1493  }
1494  }
1495  return $this;
1496  }
static getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
Definition: Import.php:345
getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)

◆ initAttributeSets()

initAttributeSets ( )
protected

Initialize attribute sets code-to-id pairs.

Returns
$this

Definition at line 420 of file Product.php.

421  {
422  $productTypeId = $this->_productFactory->create()->getTypeId();
423  foreach ($this->_attrSetColFactory->create()->setEntityTypeFilter($productTypeId) as $attributeSet) {
424  $this->_attrSetIdToName[$attributeSet->getId()] = $attributeSet->getAttributeSetName();
425  }
426  return $this;
427  }

◆ initCategories()

initCategories ( )
protected

Initialize categories ID to text-path hash.

Returns
$this

Definition at line 434 of file Product.php.

435  {
436  $collection = $this->_categoryColFactory->create()->addNameToResult();
437  /* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
438  foreach ($collection as $category) {
439  $structure = preg_split('#/+#', $category->getPath());
440  $pathSize = count($structure);
441  if ($pathSize > 1) {
442  $path = [];
443  for ($i = 1; $i < $pathSize; $i++) {
444  $name = $collection->getItemById($structure[$i])->getName();
445  $path[] = $this->quoteCategoryDelimiter($name);
446  }
447  $this->_rootCategories[$category->getId()] = array_shift($path);
448  if ($pathSize > 2) {
449  $this->_categories[$category->getId()] = implode(CategoryProcessor::DELIMITER_CATEGORY, $path);
450  }
451  }
452  }
453  return $this;
454  }
$i
Definition: gallery.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ initTypeModels()

initTypeModels ( )
protected

Initialize product type models.

Exceptions

Definition at line 462 of file Product.php.

463  {
464  $productTypes = $this->_exportConfig->getEntityTypes($this->getEntityTypeCode());
465  foreach ($productTypes as $productTypeName => $productTypeConfig) {
466  if (!($model = $this->_typeFactory->create($productTypeConfig['model']))) {
467  throw new \Magento\Framework\Exception\LocalizedException(
468  __('Entity type model \'%1\' is not found', $productTypeConfig['model'])
469  );
470  }
471  if (!$model instanceof \Magento\CatalogImportExport\Model\Export\Product\Type\AbstractType) {
472  throw new \Magento\Framework\Exception\LocalizedException(
473  __(
474  'Entity type model must be an instance of'
475  . ' \Magento\CatalogImportExport\Model\Export\Product\Type\AbstractType'
476  )
477  );
478  }
479  if ($model->isSuitable()) {
480  $this->_productTypeModels[$productTypeName] = $model;
481  $this->_disabledAttrs = array_merge($this->_disabledAttrs, $model->getDisabledAttrs());
482  $this->_indexValueAttributes = array_merge(
483  $this->_indexValueAttributes,
484  $model->getIndexValueAttributes()
485  );
486  }
487  }
488  if (!$this->_productTypeModels) {
489  throw new \Magento\Framework\Exception\LocalizedException(
490  __('There are no product types available for export.')
491  );
492  }
493  $this->_disabledAttrs = array_unique($this->_disabledAttrs);
494 
495  return $this;
496  }
__()
Definition: __.php:13

◆ isValidAttributeValue()

isValidAttributeValue (   $code,
  $value 
)
protected
Parameters
string$code
mixed$value
Returns
bool

Definition at line 1148 of file Product.php.

1149  {
1150  $isValid = true;
1151  if (!is_numeric($value) && empty($value)) {
1152  $isValid = false;
1153  }
1154 
1155  if (!isset($this->_attributeValues[$code])) {
1156  $isValid = false;
1157  }
1158 
1159  return $isValid;
1160  }
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ loadCollection()

loadCollection ( )
protected

Load products' data from the collection and filter it (if needed).

Returns
array Keys are product IDs, values arrays with keys as store IDs and values as store-specific versions of Product entity.
Since
100.2.1

Definition at line 930 of file Product.php.

930  : array
931  {
932  $data = [];
933 
935  foreach (array_keys($this->_storeIdToCode) as $storeId) {
936  $collection->setStoreId($storeId);
937  foreach ($collection as $itemId => $item) {
938  $data[$itemId][$storeId] = $item;
939  }
940  }
941  $collection->clear();
942 
943  return $data;
944  }
_getEntityCollection($resetCollection=false)
Definition: Product.php:756

◆ optionRowToCellString()

optionRowToCellString (   $option)
protected
Parameters
array$option
Returns
string

Definition at line 1342 of file Product.php.

1343  {
1344  $result = [];
1345 
1346  foreach ($option as $key => $value) {
1347  $result[] = $key . ImportProduct::PAIR_NAME_VALUE_SEPARATOR . $value;
1348  }
1349 
1351  }
$value
Definition: gender.phtml:16

◆ paginateCollection()

paginateCollection (   $page,
  $pageSize 
)
protected

Set page and page size to collection

Parameters
int$page
int$pageSize
Returns
void

Definition at line 819 of file Product.php.

820  {
821  $this->_getEntityCollection()->setPage($page, $pageSize);
822  }
_getEntityCollection($resetCollection=false)
Definition: Product.php:756
$page
Definition: pages.php:8

◆ prepareCatalogInventory()

prepareCatalogInventory ( array  $productIds)
protected

Prepare catalog inventory

Parameters
int[]$productIds
Returns
array

Definition at line 572 of file Product.php.

573  {
574  if (empty($productIds)) {
575  return [];
576  }
577  $select = $this->_connection->select()->from(
578  $this->_itemFactory->create()->getMainTable()
579  )->where(
580  'product_id IN (?)',
582  );
583 
584  $stmt = $this->_connection->query($select);
585  $stockItemRows = [];
586  while ($stockItemRow = $stmt->fetch()) {
587  $productId = $stockItemRow['product_id'];
588  unset(
589  $stockItemRow['item_id'],
590  $stockItemRow['product_id'],
591  $stockItemRow['low_stock_date'],
592  $stockItemRow['stock_id'],
593  $stockItemRow['stock_status_changed_auto']
594  );
595  $stockItemRows[$productId] = $stockItemRow;
596  }
597  return $stockItemRows;
598  }

◆ prepareLinks()

prepareLinks ( array  $productIds)
protected

Prepare product links

Parameters
int[]$productIds
Returns
array

Definition at line 606 of file Product.php.

607  {
608  if (empty($productIds)) {
609  return [];
610  }
611  $select = $this->_connection->select()->from(
612  ['cpl' => $this->_resourceModel->getTableName('catalog_product_link')],
613  [
614  'cpl.product_id',
615  'cpe.sku',
616  'cpl.link_type_id',
617  'position' => 'cplai.value',
618  'default_qty' => 'cplad.value'
619  ]
620  )->joinLeft(
621  ['cpe' => $this->_resourceModel->getTableName('catalog_product_entity')],
622  '(cpe.entity_id = cpl.linked_product_id)',
623  []
624  )->joinLeft(
625  ['cpla' => $this->_resourceModel->getTableName('catalog_product_link_attribute')],
626  $this->_connection->quoteInto(
627  '(cpla.link_type_id = cpl.link_type_id AND cpla.product_link_attribute_code = ?)',
628  'position'
629  ),
630  []
631  )->joinLeft(
632  ['cplaq' => $this->_resourceModel->getTableName('catalog_product_link_attribute')],
633  $this->_connection->quoteInto(
634  '(cplaq.link_type_id = cpl.link_type_id AND cplaq.product_link_attribute_code = ?)',
635  'qty'
636  ),
637  []
638  )->joinLeft(
639  ['cplai' => $this->_resourceModel->getTableName('catalog_product_link_attribute_int')],
640  '(cplai.link_id = cpl.link_id AND cplai.product_link_attribute_id = cpla.product_link_attribute_id)',
641  []
642  )->joinLeft(
643  ['cplad' => $this->_resourceModel->getTableName('catalog_product_link_attribute_decimal')],
644  '(cplad.link_id = cpl.link_id AND cplad.product_link_attribute_id = cplaq.product_link_attribute_id)',
645  []
646  )->where(
647  'cpl.link_type_id IN (?)',
648  array_values($this->_linkTypeProvider->getLinkTypes())
649  )->where(
650  'cpl.product_id IN (?)',
652  );
653 
654  $stmt = $this->_connection->query($select);
655  $linksRows = [];
656  while ($linksRow = $stmt->fetch()) {
657  $linksRows[$linksRow['product_id']][$linksRow['link_type_id']][] = [
658  'sku' => $linksRow['sku'],
659  'position' => $linksRow['position'],
660  'default_qty' => $linksRow['default_qty'],
661  ];
662  }
663 
664  return $linksRows;
665  }

◆ setHeaderColumns()

setHeaderColumns (   $customOptionsData,
  $stockItemRows 
)
protected

Set headers columns

Parameters
array$customOptionsData
array$stockItemRows
Returns
void
Deprecated:
100.2.0 Logic will be moved to _getHeaderColumns in future release

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 712 of file Product.php.

713  {
714  if (!$this->_headerColumns) {
715  $this->_headerColumns = array_merge(
716  [
717  self::COL_SKU,
718  self::COL_STORE,
719  self::COL_ATTR_SET,
720  self::COL_TYPE,
721  self::COL_CATEGORY,
722  self::COL_PRODUCT_WEBSITES,
723  ],
724  $this->_getExportMainAttrCodes(),
725  [self::COL_ADDITIONAL_ATTRIBUTES],
726  reset($stockItemRows) ? array_keys(end($stockItemRows)) : [],
727  [
728  'related_skus',
729  'related_position',
730  'crosssell_skus',
731  'crosssell_position',
732  'upsell_skus',
733  'upsell_position',
734  'additional_images',
735  'additional_image_labels',
736  'hide_from_product_page',
737  'custom_options'
738  ]
739  );
740  }
741  }

◆ updateDataWithCategoryColumns()

updateDataWithCategoryColumns ( $dataRow,
$rowCategories,
  $productId 
)
protected

Update data row with information about categories. Return true, if data row was updated

Parameters
array&$dataRow
array&$rowCategories
int$productId
Returns
bool

Definition at line 675 of file Product.php.

676  {
677  if (!isset($rowCategories[$productId])) {
678  return false;
679  }
680  $categories = [];
681  foreach ($rowCategories[$productId] as $categoryId) {
682  $categoryPath = $this->_rootCategories[$categoryId];
683  if (isset($this->_categories[$categoryId])) {
684  $categoryPath .= '/' . $this->_categories[$categoryId];
685  }
686  $categories[] = $categoryPath;
687  }
689  unset($rowCategories[$productId]);
690 
691  return true;
692  }
$categories

Field Documentation

◆ $_attributeColFactory

$_attributeColFactory
protected

Definition at line 214 of file Product.php.

◆ $_attributeTypes

$_attributeTypes = []
protected

Definition at line 133 of file Product.php.

◆ $_attrSetColFactory

$_attrSetColFactory
protected

Definition at line 189 of file Product.php.

◆ $_attrSetIdToName

$_attrSetIdToName = []
protected

Definition at line 70 of file Product.php.

◆ $_bannedAttributes

$_bannedAttributes = ['media_gallery']
protected

Definition at line 32 of file Product.php.

◆ $_categories

$_categories = []
protected

Definition at line 77 of file Product.php.

◆ $_categoryColFactory

$_categoryColFactory
protected

Definition at line 194 of file Product.php.

◆ $_entityCollection

$_entityCollection
protected

Definition at line 154 of file Product.php.

◆ $_entityCollectionFactory

$_entityCollectionFactory
protected

Definition at line 147 of file Product.php.

◆ $_exportConfig

$_exportConfig
protected

Definition at line 174 of file Product.php.

◆ $_exportMainAttrCodes

$_exportMainAttrCodes
protected

Definition at line 288 of file Product.php.

◆ $_fieldsMap

$_fieldsMap
protected
Initial value:
= [
'image' => 'base_image',
'image_label' => "base_image_label",
'thumbnail' => 'thumbnail_image',
'thumbnail_label' => 'thumbnail_image_label',
self::COL_MEDIA_IMAGE => 'additional_images',
'_media_image_label' => 'additional_image_labels',
self::COL_STORE => 'store_view_code',
self::COL_ATTR_SET => 'attribute_set_code',
self::COL_TYPE => 'product_type',
self::COL_CATEGORY => 'categories',
self::COL_PRODUCT_WEBSITES => 'product_websites',
'status' => 'product_online',
'news_from_date' => 'new_from_date',
'news_to_date' => 'new_to_date',
'options_container' => 'display_product_options_in',
'minimal_price' => 'map_price',
'msrp' => 'msrp_price',
'msrp_enabled' => 'map_enabled',
'special_from_date' => 'special_price_from_date',
'special_to_date' => 'special_price_to_date',
'min_qty' => 'out_of_stock_qty',
'backorders' => 'allow_backorders',
'min_sale_qty' => 'min_cart_qty',
'max_sale_qty' => 'max_cart_qty',
'notify_stock_qty' => 'notify_on_stock_below',
'meta_keyword' => 'meta_keywords',
'tax_class_id' => 'tax_class_name',
]

Definition at line 238 of file Product.php.

◆ $_headerColumns

$_headerColumns = []
protected

Definition at line 169 of file Product.php.

◆ $_indexValueAttributes

$_indexValueAttributes
protected
Initial value:
= [
'status',
]

Definition at line 91 of file Product.php.

◆ $_itemFactory

$_itemFactory
protected

Definition at line 204 of file Product.php.

◆ $_itemsPerPage

$_itemsPerPage = null
protected

Definition at line 161 of file Product.php.

◆ $_linkTypeProvider

$_linkTypeProvider
protected

Definition at line 226 of file Product.php.

◆ $_logger

$_logger
protected

Definition at line 179 of file Product.php.

◆ $_optionColFactory

$_optionColFactory
protected

Definition at line 209 of file Product.php.

◆ $_permanentAttributes

$_permanentAttributes = [self::COL_SKU]
protected

Definition at line 105 of file Product.php.

◆ $_productFactory

$_productFactory
protected

Definition at line 184 of file Product.php.

◆ $_productTypeModels

$_productTypeModels = []
protected

Definition at line 112 of file Product.php.

◆ $_resourceModel

$_resourceModel
protected

Definition at line 199 of file Product.php.

◆ $_rootCategories

$_rootCategories = []
protected

Definition at line 84 of file Product.php.

◆ $_storeIdToCode

$_storeIdToCode = []
protected

Definition at line 119 of file Product.php.

◆ $_typeFactory

$_typeFactory
protected

Definition at line 219 of file Product.php.

◆ $_websiteIdToCode

$_websiteIdToCode = []
protected

Definition at line 126 of file Product.php.

◆ $collectedMultiselectsData

$collectedMultiselectsData = []
protected

Definition at line 98 of file Product.php.

◆ $dateAttrCodes

$dateAttrCodes
protected
Initial value:
= [
'special_from_date',
'special_to_date',
'news_from_date',
'news_to_date',
'custom_design_from',
'custom_design_to'
]

Definition at line 274 of file Product.php.

◆ $metadataPool

$metadataPool
protected

Definition at line 342 of file Product.php.

◆ $rowCustomizer

$rowCustomizer
protected

Definition at line 231 of file Product.php.

◆ COL_ADDITIONAL_ATTRIBUTES

const COL_ADDITIONAL_ATTRIBUTES = 'additional_attributes'

Definition at line 63 of file Product.php.

◆ COL_ATTR_SET

const COL_ATTR_SET = '_attribute_set'

Definition at line 47 of file Product.php.

◆ COL_CATEGORY

const COL_CATEGORY = '_category'

Definition at line 53 of file Product.php.

◆ COL_MEDIA_IMAGE

const COL_MEDIA_IMAGE = '_media_image'

Definition at line 61 of file Product.php.

◆ COL_PRODUCT_WEBSITES

const COL_PRODUCT_WEBSITES = '_product_websites'

Definition at line 51 of file Product.php.

◆ COL_ROOT_CATEGORY

const COL_ROOT_CATEGORY = '_root_category'

Definition at line 55 of file Product.php.

◆ COL_SKU

const COL_SKU = 'sku'

Definition at line 57 of file Product.php.

◆ COL_STORE

const COL_STORE = '_store'

Permanent column names.

Names that begins with underscore is not an attribute. This name convention is for to avoid interference with same attribute name.

Definition at line 45 of file Product.php.

◆ COL_TYPE

const COL_TYPE = '_type'

Definition at line 49 of file Product.php.

◆ COL_VISIBILITY

const COL_VISIBILITY = 'visibility'

Definition at line 59 of file Product.php.

◆ VALUE_ALL

const VALUE_ALL = 'all'

Value that means all entities (e.g. websites, groups etc.)

Definition at line 37 of file Product.php.


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