I want to create custom datetime product attribute with "start from" and "start to" and want to show timer with calculation of both date. I am using custom module and creating attribute by below code in "InstallData.php":
<?php
namespace Mymodule\Countdown\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
/**
* EAV setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* Init
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->startSetup();
/**
* Add attributes to the eav/attribute
*/
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'countdown_enabled',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Show Countdown',
'input' => 'boolean',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'course_start_from',
[
'type' => 'datetime',
'backend' => '',
'frontend' => 'Magento\Eav\Model\Entity\Attribute\Frontend\Datetime',
'label' => 'Delivery time from',
'input' => 'date',
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => true,
'user_defined' => false,
'default' => '',
'sort_order' => 9,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'course_start_end',
[
'type' => 'datetime',
'backend' => '',
'frontend' => 'Magento\Eav\Model\Entity\Attribute\Frontend\Datetime',
'label' => 'Delivery time to',
'input' => 'date',
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => true,
'user_defined' => false,
'default' => '',
'sort_order' => 9,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
$eavSetup->endSetup();
}
}
but datetime attribute in not creating in admin. Anyone have an idea for that?