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-downloadable
Model
Link
UpdateHandler.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Downloadable\Model\Link
;
7
8
use
Magento\Downloadable\Api\LinkRepositoryInterface
as LinkRepository;
9
use
Magento\Downloadable\Model\Product\Type
;
10
use
Magento\Framework\EntityManager\Operation\ExtensionInterface
;
11
15
class
UpdateHandler
implements
ExtensionInterface
16
{
20
protected
$linkRepository
;
21
25
public
function
__construct
(
LinkRepository
$linkRepository
)
26
{
27
$this->linkRepository =
$linkRepository
;
28
}
29
36
public
function
execute
(
$entity
,
$arguments
= [])
37
{
39
if
(
$entity
->getTypeId() !=
Type::TYPE_DOWNLOADABLE
) {
40
return
$entity
;
41
}
42
44
$links
=
$entity
->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
45
$updatedLinks = [];
46
$oldLinks = $this->linkRepository->getList(
$entity
->getSku());
47
foreach
(
$links
as
$link
) {
48
if
(
$link
->getId()) {
49
$updatedLinks[
$link
->getId()] =
true
;
50
}
51
$this->linkRepository->save(
$entity
->getSku(),
$link
, !(bool)
$entity
->getStoreId());
52
}
54
foreach
($oldLinks as
$link
) {
55
if
(!isset($updatedLinks[
$link
->getId()])) {
56
$this->linkRepository->delete(
$link
->getId());
57
}
58
}
59
60
return
$entity
;
61
}
62
}
Magento\Downloadable\Model\Link\UpdateHandler
Definition:
UpdateHandler.php:15
Magento\Framework\EntityManager\Operation\ExtensionInterface
Definition:
ExtensionInterface.php:11
Magento\Framework\EntityManager\Operation\ExtensionInterface\execute
execute($entity, $arguments=[])
Magento\Downloadable\Model\Link
Definition:
Builder.php:6
$link
$link
Definition:
quote_with_downloadable_product.php:27
Magento\Downloadable\Model\Link\UpdateHandler\$linkRepository
$linkRepository
Definition:
UpdateHandler.php:20
$links
$links
Definition:
downloadable_product_with_files_and_sample_url.php:39
Magento\Downloadable\Model\Product\Type
Definition:
Type.php:18
Magento\Downloadable\Model\LinkRepository
Definition:
LinkRepository.php:25
$entity
$entity
Definition:
element.phtml:22
$arguments
$arguments
Definition:
final_price.phtml:24
Magento\Downloadable\Model\Product\Type\TYPE_DOWNLOADABLE
const TYPE_DOWNLOADABLE
Definition:
Type.php:20
Magento\Downloadable\Api\LinkRepositoryInterface
Definition:
LinkRepositoryInterface.php:17
Magento\Downloadable\Model\Link\UpdateHandler\__construct
__construct(LinkRepository $linkRepository)
Definition:
UpdateHandler.php:25