How to add Datetime picker to product attribute in admin? - magento2

I have added product attribute as follows
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'product_activation',
[
'type' => 'datetime',
'backend' => '',
'frontend' => '',
'label' => 'Product Activation Timestamp',
'input' => 'date',
'class' => '',
'source' => '',
'time' => true,
'date_format' => 'yyyy-MM-dd',
'time_format' => 'hh:mm:ss',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => ''
]
);
Still unable to get the datetime picker in my admin product form.
Please help me to solve this

Please try below code :
<?php
namespace Vendor\Module\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* Install attributes
*/
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
/**
* #var \Magento\Catalog\Setup\CategorySetupFactory
*/
protected $categorySetupFactory;
/**
* Init
*
* #param \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory
*/
public function __construct(
\Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory
) {
$this->categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$setup->startSetup();
$categorySetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'product_activation',
[
'type' => 'datetime',
'backend' => '',
'frontend' => 'Magento\Eav\Model\Entity\Attribute\Frontend\Datetime',
'label' => 'Product Activation Timestamp',
'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' => ''
]
);
$setup->endSetup();
}
}

Related

How to Hide or Show Custom attribute based on other custom attribute in Product detail/edit page from Adminpanel Magento 2.4?

I have created the Product's custom attributes programmatically(Setup->Installdata.php).
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_use_customer',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Issue By Customer Group',
'input' => 'boolean',
'class' => '',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 3,
'note' => 'Enable automatic issuing of codes based on customer group.'
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_customer_groups',
[
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Select Customer Groups',
'input' => 'multiselect',
'class' => '',
'source' => \Magento\Customer\Model\Customer\Attribute\Source\Group::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 4,
'note' => 'Customers in selected groups will be issued codes automatically when product is ordered.'
]
);
I want to Hide or Show a Custom attribute based on other custom attributes in the Product detail/edit page from Adminpanel Magento 2.4.x?
For example, there is a toggle on click (yes/no) the Customer Groups will be Hide / Show.
To hide custom product attributes from the admin product detail page you need to create UpgradeData.php in the My/Catalog/Setup directory.
Code:
$eavSetup->updateAttribute(Product::ENTITY, $attrCode, 'is_visible',
'0');

Disabling the past dates

I want to disable the past dates from the laravel-backpack component date-range-picker.
`$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
'timePicker' => true,
'format' => 'YYYY-MM-DD'
],
'allows_null' => true,
]);`
How can I do that?
$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
//'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
// options sent to daterangepicker.js
//'timePicker' => true,
'startDate' => date("Y-m-d"),
'endDate' => date("Y-m-d"),
'minDate'=> date("Y-m-d"),
'locale' => ['format' => 'YYYY-MM-DD']
],
'allows_null' => true,
]);

TYPO3 object storage add existing item

I have typo3 7.6.18. I need to add an existing item to an object storage. I see that it doesn't add the item.
$editUser = $this->userRepository->findByUid($userUid);
$newSmile = $this->serviceRepository->findByUid($smileUid);
if ($editUser && $newSmile) {
$smileUid = $newSmile->getUid();
$editUser->addSmile($newSmile);
$this->userRepository->update($editUser);
$persistenceManager->persistAll();
}
Help me please.
Model user, all that touch smile object storage. I added my User model. Sorry I must write something. I must write more.
/**
* smiles
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Service>
*/
protected $smile = '';
/**
* Returns the smiles
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Service> $smile
*/
public function getSmile()
{
return $this->smile;
}
/**
* Sets the smile
*
* #return void
*/
public function setSmile($smile)
{
$this->smile = $smile;
}
/**
* Adds a smile to the smile
*
* #param \Fhk\Feusersplus\Domain\Model\Service $smile
* #return void
* #api
*/
public function addSmile(\Fhk\Feusersplus\Domain\Model\Service $smile)
{
$this->smile->attach($smile);
}
/**
* Removes a smile from the smile
*
* #param \Fhk\Feusersplus\Domain\Model\Service $smile
* #return void
* #api
*/
public function removeSmile(\Fhk\Feusersplus\Domain\Model\Service $smile)
{
$this->smile->detach($smile);
}
TCA of table tx_feusersplus_domain_model_usersmile
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:userSmile',
'label' => 'uid_local',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'sortby' => 'sorting',
'hideTable' => true,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('feusersplus') . 'Resources/Public/Icons/tx_feusersplus_domain_model_hut.gif'
],
'interface' => [
'showRecordFieldList' => 'uid_local,uid_foreign'
],
'types' => [
'1' => ['showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource;;1, uid_local, uid_foreign,--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access'],
],
'palettes' => [
'1' => ['showitem' => ''],
],
'columns' => [
'sys_language_uid' => [
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => [
['LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1],
['LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0]
],
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'items' => [
['', 0],
],
'foreign_table' => 'tx_fefiles_domain_model_photo',
'foreign_table_where' => 'AND tx_fefiles_domain_model_photo.pid=###CURRENT_PID### AND tx_fefiles_domain_model_photo.sys_language_uid IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
't3ver_label' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
]
],
'uid_local' => [
'exclude' => 1,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:user',
'config' => [
'type' => 'select',
'foreign_table' => 'fe_users',
'minitems' => 1,
'maxitems' => 1,
]
],
'uid_foreign' => [
'exclude' => 1,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:smile',
'config' => [
'type' => 'select',
'foreign_table' => 'tx_feusersplus_domain_model_service',
// 'foreign_field' => 'uid',
// 'foreign_table_where' => 'AND tx_feusersplus_domain_model_service.sys_language_uid=###REC_FIELD_sys_language_uid### ',
'foreign_match_fields' => [
'type' => 1
],
'minitems' => 1,
'maxitems' => 1,
]
],
'crdate' => array(
'exclude' => 0,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:crdate',
'config' => array(
'type' => 'input',
'size' => 10,
'max' => 20,
'eval' => 'date',
'checkbox' => '0',
'default' => ''
)
),
],
];
By the way, I use this table for MM relation.
You need to initialize every object storage in your model by:
public function __construct()
{
$this->smile = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}

ApiGility - Getting validation errors with PUT

I am new to ApiGility and am attempting to update my shopping cart via an API call as apposed to a route. I am using Zend Framework 2 with a code connected api.
The problem I am currently facing is that no matter what I try, I am unable to put the information to the api without validation errors.
My module.config:
Updatecart settings:
'Api\\V1\\Rest\\Updatecart\\Controller' => array(
'listener' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartResource',
'route_name' => 'api.rest.updatecart',
'route_identifier_name' => 'updatecart_id',
'collection_name' => 'updatecart',
'entity_http_methods' => array(
0 => 'GET',
1 => 'PATCH',
2 => 'PUT',
3 => 'DELETE',
),
'collection_http_methods' => array(
0 => 'GET',
1 => 'POST',
2 => 'PUT',
3 => 'PATCH',
4 => 'DELETE',
),
'collection_query_whitelist' => array(
0 => 'prod_id',
1 => 'quantity',
2 => 'quantity_accumulation',
3 => 'tax',
),
'page_size' => 25,
'page_size_param' => null,
'entity_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartEntity',
'collection_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartCollection',
'service_name' => 'updatecart',
),
Relevant filter settings:
'Api\\V1\\Rest\\Updatecart\\Validator' => array(
0 => array(
'name' => 'prod_id',
'required' => true,
'filters' => array(
0 => array(
'name' => 'Zend\\Filter\\Int',
'options' => array(),
),
),
'validators' => array(),
'description' => 'The id of the product in the cart to be updated',
'error_message' => 'Missing product id',
'allow_empty' => false,
'continue_if_empty' => false,
),
1 => array(
'name' => 'quantity',
'required' => true,
'filters' => array(),
'validators' => array(),
'description' => 'quantity of product',
'error_message' => 'You must include a quantity',
'allow_empty' => false,
'continue_if_empty' => false,
),
2 => array(
'name' => 'tax',
'required' => true,
'filters' => array(),
'validators' => array(),
'description' => 'Add the VAT, GST, Sales Tax that will be applicable to this item. Use 0.00 for no value.',
'error_message' => 'Please add a tax value, 0.00 for no value.',
'allow_empty' => false,
'continue_if_empty' => false,
),
3 => array(
'name' => 'quantity_accumulation',
'required' => true,
'filters' => array(
0 => array(
'name' => 'Zend\\Filter\\Boolean',
'options' => array(),
),
),
'validators' => array(),
'description' => 'Either accumulate the entered quantity to the current basket quantity or set as the entered quantity.',
'allow_empty' => false,
'continue_if_empty' => false,
'error_message' => 'Quantity accumulation field error.',
),
),
When calling the PUT method:
https://cloud.mysite.dev:8890/api/updatecart/1?prod_id=1&quantity=1&update_type=1&tax=0.00
I keep getting Failed Validation errors:
{
"validation_messages": {
"prod_id": [
"Missing product id"
],
"quantity": [
"You must include a quantity"
],
"tax": [
"Please add a tax value, 0.00 for no value."
],
"quantity_accumulation": [
"Quantity accumulation field error."
]
},
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Unprocessable Entity",
"status": 422,
"detail": "Failed Validation"
}
You need to supply your data as http body (payload) in json format.
Make the call to the URI without the query params.
https://cloud.mysite.dev:8890/api/updatecart/1
{
"prod_id": 1,
"quantity": 1,
"update_type": 1,
"tax": "0.00"
}
Also make sure you supply the right request headers:
Accept: application/json
Content-Type: application/json

Symfony2 Looping Same field in form

I have a problem in symfony2 form.
I have a same field in a form. I create one by one by changing the name.
$formBuilderUpload = $this->createFormBuilder()->setAction($this->generateUrl('bsi_bkpm_backend_uploadfile_create'));
$formBuilder = $formBuilderUpload;
$formBuilder->add('file_1','file', array('required'=> false, 'label'=> 'File 1'))
->add('filename_1' , 'text', array(
'required' => false,
'label' => 'Subject 1'
))
->add('description_1','text',array('required'=> false, 'label'=>' Description 1'))
->add('file_2','file', array('required'=> false, 'label'=> 'File 2'))
->add('filename_2' , 'text', array(
'required' => false,
'label' => 'Subject 2'))
->add('description_2','text',array('required'=> false, 'label'=>' Description 2'))
->add('file_3','file', array('required'=> false, 'label'=> 'File 2'))
->add('filename_3' , 'text', array(
'required' => false,
'label' => 'Subject 3'))
->add('description_3','text',array('required'=> false, 'label'=>' Description 4'))
->add('file_4','file', array('required'=> false, 'label'=> 'File 2'))
->add('filename_4' , 'text', array(
'required' => false,
'label' => 'Subject 4'))
->add('description_4','text',array('required'=> false, 'label'=>' Description 4'))
->add('file_5','file', array('required'=> false, 'label'=> 'File 5'))
->add('filename_5' , 'text', array(
'required' => false,
'label' => 'Subject 5'))
->add('description_5','text',array('required'=> false, 'label'=>' Description 5'))
// add submit button
->add('submit', 'submit', array('label' => 'Create'));
//Create the form
$form = $formBuilder->getForm();
return $form;
But I want the code become efficient by looping it. Does anyone know how to looping it?
Best regards,
hendrawan
This seems like a pretty easy one, just loop over a for loop like so...
$limit = 5;
for ($i = 1; $i <= $limit; $i++) {
$builder
->add('file_'.$i, 'file', array(
'required' => false,
'label' => 'File '.$i,
))
->add('filename_'.$i, 'text', array(
'required' => false,
'label' => 'Subject '.$i,
))
->add('description_'.$i, 'text', array(
'required' => false,
'label' => 'Description '.$i,
))
;
}