Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
SkuProcessor Class Reference

Public Member Functions

 __construct (\Magento\Catalog\Model\ProductFactory $productFactory)
 
 setTypeModels ($typeModels)
 
 getOldSkus ()
 
 reloadOldSkus ()
 
 addNewSku ($sku, $data)
 
 setNewSkuData ($sku, $key, $data)
 
 getNewSku ($sku=null)
 

Protected Member Functions

 _getSkus ()
 

Protected Attributes

 $productFactory
 
 $oldSkus
 
 $newSkus
 
 $productTypeModels
 

Detailed Description

Class SkuProcessor

@api

Since
100.0.2

Definition at line 14 of file SkuProcessor.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Catalog\Model\ProductFactory  $productFactory)
Parameters
\Magento\Catalog\Model\ProductFactory$productFactory

Definition at line 69 of file SkuProcessor.php.

Member Function Documentation

◆ _getSkus()

_getSkus ( )
protected

Get skus data.

Returns
array

Definition at line 155 of file SkuProcessor.php.

156  {
157  $oldSkus = [];
158  $columns = ['entity_id', 'type_id', 'attribute_set_id', 'sku'];
159  if ($this->getProductEntityLinkField() != $this->getProductIdentifierField()) {
160  $columns[] = $this->getProductEntityLinkField();
161  }
162  foreach ($this->productFactory->create()->getProductEntitiesInfo($columns) as $info) {
163  $typeId = $info['type_id'];
164  $sku = strtolower($info['sku']);
165  $oldSkus[$sku] = [
166  'type_id' => $typeId,
167  'attr_set_id' => $info['attribute_set_id'],
168  'entity_id' => $info['entity_id'],
169  'supported_type' => isset($this->productTypeModels[$typeId]),
170  $this->getProductEntityLinkField() => $info[$this->getProductEntityLinkField()],
171  ];
172  }
173  return $oldSkus;
174  }
$columns
Definition: default.phtml:15
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ addNewSku()

addNewSku (   $sku,
  $data 
)
Parameters
string$sku
array$data
Returns
$this

Definition at line 115 of file SkuProcessor.php.

116  {
117  $sku = strtolower($sku);
118  $this->newSkus[$sku] = $data;
119  return $this;
120  }

◆ getNewSku()

getNewSku (   $sku = null)
Parameters
null | string$sku
Returns
array|null

Definition at line 141 of file SkuProcessor.php.

142  {
143  if ($sku !== null) {
144  $sku = strtolower($sku);
145  return $this->newSkus[$sku] ?? null;
146  }
147  return $this->newSkus;
148  }

◆ getOldSkus()

getOldSkus ( )

Get old skus array.

Returns
array

Definition at line 90 of file SkuProcessor.php.

91  {
92  if (!$this->oldSkus) {
93  $this->oldSkus = $this->_getSkus();
94  }
95  return $this->oldSkus;
96  }

◆ reloadOldSkus()

reloadOldSkus ( )

Reload old skus.

Returns
$this

Definition at line 103 of file SkuProcessor.php.

104  {
105  $this->oldSkus = $this->_getSkus();
106 
107  return $this;
108  }

◆ setNewSkuData()

setNewSkuData (   $sku,
  $key,
  $data 
)
Parameters
string$sku
string$key
mixed$data
Returns
$this

Definition at line 128 of file SkuProcessor.php.

129  {
130  $sku = strtolower($sku);
131  if (isset($this->newSkus[$sku])) {
132  $this->newSkus[$sku][$key] = $data;
133  }
134  return $this;
135  }

◆ setTypeModels()

setTypeModels (   $typeModels)
Parameters
array$typeModels
Returns
$this

Definition at line 79 of file SkuProcessor.php.

80  {
81  $this->productTypeModels = $typeModels;
82  return $this;
83  }

Field Documentation

◆ $newSkus

$newSkus
protected

Definition at line 38 of file SkuProcessor.php.

◆ $oldSkus

$oldSkus
protected

Definition at line 24 of file SkuProcessor.php.

◆ $productFactory

$productFactory
protected

Definition at line 19 of file SkuProcessor.php.

◆ $productTypeModels

$productTypeModels
protected

Definition at line 43 of file SkuProcessor.php.


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