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