Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-inventory-grouped-product-admin-ui
Plugin
Catalog
Model
Product
Link
ProcessSourceItemsAfterSaveAssociatedLinks.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
namespace
Magento\InventoryGroupedProductAdminUi\Plugin\Catalog\Model\Product\Link
;
9
10
use
Magento\Catalog\Api\Data\ProductInterface
;
11
use
Magento\Catalog\Model\Product\Link
;
12
use
Magento\GroupedProduct\Model\Product\Type\Grouped
as
GroupedProductType
;
13
use
Magento\InventoryApi\Api\Data\SourceItemInterface
;
14
use
Magento\InventoryApi\Api\GetSourceItemsBySkuInterface
;
15
use
Magento\InventoryCatalogAdminUi\Observer\SourceItemsProcessor
;
16
20
class
ProcessSourceItemsAfterSaveAssociatedLinks
21
{
25
private
$getSourceItemsBySku;
26
30
private
$sourceItemsProcessor;
31
36
public
function
__construct
(
37
GetSourceItemsBySkuInterface
$getSourceItemsBySku,
38
SourceItemsProcessor
$sourceItemsProcessor
39
) {
40
$this->getSourceItemsBySku =
$getSourceItemsBySku
;
41
$this->sourceItemsProcessor = $sourceItemsProcessor;
42
}
43
51
public
function
afterSaveProductRelations
(
52
Link
$subject,
53
Link
$result
,
54
ProductInterface
$product
55
):
Link
{
56
if
(
$product
->getTypeId() !== GroupedProductType::TYPE_CODE) {
57
return
$result
;
58
}
59
60
foreach
(
$product
->getProductLinks() as
$productLink
) {
61
if
(
$productLink
->getLinkType() ===
'associated'
) {
62
$this->processSourceItemsForSku(
$productLink
->getLinkedProductSku());
63
}
64
}
65
66
return
$result
;
67
}
68
75
private
function
processSourceItemsForSku(
string
$sku): void
76
{
77
$processData = [];
78
79
foreach
($this->getSourceItemsBySku->execute($sku) as
$sourceItem
) {
80
$processData[] = [
81
SourceItemInterface::SOURCE_CODE
=>
$sourceItem
->getSourceCode(),
82
SourceItemInterface::QUANTITY
=>
$sourceItem
->getQuantity(),
83
SourceItemInterface::STATUS
=>
$sourceItem
->getStatus()
84
];
85
}
86
87
if
(!empty($processData)) {
88
$this->sourceItemsProcessor->process($sku, $processData);
89
}
90
}
91
}
Magento\InventoryApi\Api\Data\SourceItemInterface\QUANTITY
const QUANTITY
Definition:
SourceItemInterface.php:27
$result
$result
Definition:
product_configurable_not_available_rollback.php:26
Magento\InventoryApi\Api\Data\SourceItemInterface\STATUS
const STATUS
Definition:
SourceItemInterface.php:28
Magento\GroupedProduct\Model\Product\Type\Grouped
Definition:
Backend.php:6
$getSourceItemsBySku
$getSourceItemsBySku
Definition:
set_simples_out_of_stock.php:18
Magento\Catalog\Model\Product\Link
Definition:
Converter.php:6
Magento\InventoryApi\Api\Data\SourceItemInterface\SOURCE_CODE
const SOURCE_CODE
Definition:
SourceItemInterface.php:26
Magento\InventoryGroupedProductAdminUi\Plugin\Catalog\Model\Product\Link\ProcessSourceItemsAfterSaveAssociatedLinks\afterSaveProductRelations
afterSaveProductRelations(Link $subject, Link $result, ProductInterface $product)
Definition:
ProcessSourceItemsAfterSaveAssociatedLinks.php:51
Magento\InventoryApi\Api\Data\SourceItemInterface
Definition:
SourceItemInterface.php:20
Magento\InventoryGroupedProductAdminUi\Plugin\Catalog\Model\Product\Link\ProcessSourceItemsAfterSaveAssociatedLinks\__construct
__construct(GetSourceItemsBySkuInterface $getSourceItemsBySku, SourceItemsProcessor $sourceItemsProcessor)
Definition:
ProcessSourceItemsAfterSaveAssociatedLinks.php:36
$product
$product
Definition:
bundle_product_with_not_visible_children.php:22
Magento\InventoryApi\Api\GetSourceItemsBySkuInterface
Definition:
GetSourceItemsBySkuInterface.php:15
Magento\Catalog\Model\Product\Link
Definition:
Link.php:26
Magento\InventoryGroupedProductAdminUi\Plugin\Catalog\Model\Product\Link\ProcessSourceItemsAfterSaveAssociatedLinks
Definition:
ProcessSourceItemsAfterSaveAssociatedLinks.php:20
Magento\InventoryGroupedProductAdminUi\Plugin\Catalog\Model\Product\Link
Definition:
ProcessSourceItemsAfterSaveAssociatedLinks.php:8
Magento\Catalog\Api\Data\ProductInterface
Definition:
ProductInterface.php:14
$productLink
$productLink
Definition:
products_crosssell.php:23
Magento\InventoryCatalogAdminUi\Observer\SourceItemsProcessor
Definition:
SourceItemsProcessor.php:25
$sourceItem
$sourceItem
Definition:
set_product_bundle_out_of_stock.php:24