init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Homepage\Model\Config\Source;
|
||||
|
||||
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class CatalogRule implements OptionSourceInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CollectionFactory $collectionFactory
|
||||
) {
|
||||
}
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$options = [
|
||||
['value' => '', 'label' => __('-- Please Select --')],
|
||||
];
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->setOrder('name', 'ASC');
|
||||
|
||||
foreach ($collection as $rule) {
|
||||
$status = $rule->getIsActive() ? __('Active') : __('Inactive');
|
||||
$options[] = [
|
||||
'value' => (int) $rule->getId(),
|
||||
'label' => sprintf(
|
||||
'#%d %s [%s]',
|
||||
(int) $rule->getId(),
|
||||
(string) $rule->getName(),
|
||||
(string) $status
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Homepage\Model\Config\Source;
|
||||
|
||||
use Esun\ImageManager\Model\ResourceModel\Category\CollectionFactory;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class ImageCategory implements OptionSourceInterface
|
||||
{
|
||||
public function __construct(private readonly CollectionFactory $collectionFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$options = [
|
||||
['value' => '', 'label' => __('Please select')],
|
||||
];
|
||||
$collection = $this->collectionFactory->create()
|
||||
->addFieldToFilter('status', 1)
|
||||
->setOrder('sort_order', 'ASC')
|
||||
->setOrder('name', 'ASC');
|
||||
foreach ($collection as $category) {
|
||||
$options[] = [
|
||||
'value' => (int) $category->getId(),
|
||||
'label' => (string) $category->getData('name'),
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user