b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Amasty / Paction / Model / Command /
Filename/home/dev2.destoffenstraat.com/app/code/Amasty/Paction/Model/Command/Removeoptions.php
Size2.53 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified26-Jul-2025 18:05
Last accessed23-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) 2023 Amasty (https://www.amasty.com)
* @package Mass Product Actions for Magento 2
*/

namespace Amasty\Paction\Model\Command;

use Amasty\Paction\Model\Command;
use Amasty\Paction\Model\EntityResolver;
use Amasty\Paction\Model\GetProductCollectionByIds;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
use Magento\Framework\Phrase;

class Removeoptions extends Command
{
public const TYPE = 'removeoptions';

/**
* @var EntityResolver
*/
private $entityResolver;

/**
* @var ProductCustomOptionRepositoryInterface
*/
private $customOptionRepository;

/**
* @var GetProductCollectionByIds
*/
private $getProductCollectionByIds;

public function __construct(
EntityResolver $entityResolver,
ProductCustomOptionRepositoryInterface $customOptionRepository,
GetProductCollectionByIds $getProductCollectionByIds
) {
$this->entityResolver = $entityResolver;
$this->customOptionRepository = $customOptionRepository;
$this->getProductCollectionByIds = $getProductCollectionByIds;

$this->type = self::TYPE;
$this->info = [
'confirm_title' => __('Remove Custom Options')->render(),
'confirm_message' => __('Are you sure you want to remove custom options?')->render(),
'type' => $this->type,
'label' => __('Remove Custom Options')->render(),
'fieldLabel' => ''
];
}

public function execute(array $ids, int $storeId, string $val): Phrase
{
$num = 0;
$entityIdName = $this->entityResolver->getEntityLinkField(ProductInterface::class);

foreach ($this->getProductCollectionByIds->get($ids, $entityIdName) as $product) {
try {
$options = $product->getOptions();

if (empty($options)) {
continue;
}
foreach ($options as $option) {
$this->customOptionRepository->delete($option);
}
++$num;
} catch (\Exception $e) {
$this->errors[] = __(
'Can not remove the options to the product ID=%1, the error is: %2',
$product->getId(),
$e->getMessage()
);
}
}

return __('Total of %1 products(s) have been successfully updated.', $num);
}
}