Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
UpdateSourceItemAtLegacyStockItemSavePlugin Class Reference

Public Member Functions

 __construct (UpdateSourceItemBasedOnLegacyStockItem $updateSourceItemBasedOnLegacyStockItem, ResourceConnection $resourceConnection, IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType, GetProductTypesBySkusInterface $getProductTypeBySku, GetSkusByProductIdsInterface $getSkusByProductIds, GetDefaultSourceItemBySku $getDefaultSourceItemBySku)
 
 aroundSave (ItemResourceModel $subject, callable $proceed, AbstractModel $legacyStockItem)
 

Detailed Description

Class provides around Plugin on \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::save to update data in Inventory source item based on legacy Stock Item data

Definition at line 24 of file UpdateSourceItemAtLegacyStockItemSavePlugin.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( UpdateSourceItemBasedOnLegacyStockItem  $updateSourceItemBasedOnLegacyStockItem,
ResourceConnection  $resourceConnection,
IsSourceItemManagementAllowedForProductTypeInterface  $isSourceItemManagementAllowedForProductType,
GetProductTypesBySkusInterface  $getProductTypeBySku,
GetSkusByProductIdsInterface  $getSkusByProductIds,
GetDefaultSourceItemBySku  $getDefaultSourceItemBySku 
)
Parameters
UpdateSourceItemBasedOnLegacyStockItem$updateSourceItemBasedOnLegacyStockItem
ResourceConnection$resourceConnection
IsSourceItemManagementAllowedForProductTypeInterface$isSourceItemManagementAllowedForProductType
GetProductTypesBySkusInterface$getProductTypeBySku
GetSkusByProductIdsInterface$getSkusByProductIds
GetDefaultSourceItemBySku$getDefaultSourceItemBySku

Definition at line 64 of file UpdateSourceItemAtLegacyStockItemSavePlugin.php.

71  {
72  $this->updateSourceItemBasedOnLegacyStockItem = $updateSourceItemBasedOnLegacyStockItem;
73  $this->resourceConnection = $resourceConnection;
74  $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
75  $this->getProductTypeBySku = $getProductTypeBySku;
76  $this->getSkusByProductIds = $getSkusByProductIds;
77  $this->getDefaultSourceItemBySku = $getDefaultSourceItemBySku;
78  }

Member Function Documentation

◆ aroundSave()

aroundSave ( ItemResourceModel  $subject,
callable  $proceed,
AbstractModel  $legacyStockItem 
)
Parameters
ItemResourceModel$subject
callable$proceed
AbstractModel$legacyStockItem
Returns
ItemResourceModel
Exceptions

Definition at line 89 of file UpdateSourceItemAtLegacyStockItemSavePlugin.php.

90  {
91  $connection = $this->resourceConnection->getConnection();
92  $connection->beginTransaction();
93  try {
94  // need to save configuration
95  $proceed($legacyStockItem);
96 
97  $typeId = $this->getTypeId($legacyStockItem);
98  if ($this->isSourceItemManagementAllowedForProductType->execute($typeId)) {
99  if ($this->shouldAlignDefaultSourceWithLegacy($legacyStockItem)) {
100  $this->updateSourceItemBasedOnLegacyStockItem->execute($legacyStockItem);
101  }
102  }
103 
104  $connection->commit();
105 
106  return $subject;
107  } catch (\Exception $e) {
108  $connection->rollBack();
109  throw $e;
110  }
111  }
$connection
Definition: bulk.php:13

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