I need to create custom action for the Catalog Price Rule. Not the whole custom Catalog Rule, but just action, which I can select. The purpose of this action is simply recalculating product prices based on some criterias.
How can I achieve it?
To achieve your requirement try with the below steps.
In your custom module override the catalog_rule_form.xml
Inside catalog_rule_form.xml find the below fieldset
<fieldset name="actions" sortOrder="30">
Inside the above actions fieldset, you can find the existing rules which are predefined and then add your custom rule as below.
<rule name="4">
<value>custom_action</value>
<actions>
<action name="0">
<target>catalog_rule_form.catalog_rule_form
.actions.discount_amount</target>
<callback>setValidation</callback>
<params>
<param name="0" xsi:type="string">validate-number-range</param>
<param name="1" xsi:type="string">false</param>
</params>
</action>
</actions>
</rule>
2) Next Override
Magento\CatalogRule\Model\Rule\Action\SimpleActionOptionsProvider.php
<?php
namespace Magento\CatalogRule\Model\Rule\Action;
class SimpleActionOptionsProvider implements
\Magento\Framework\Data\OptionSourceInterface
{
/**
* #return array
*/
public function toOptionArray()
{
return [
[
'label' => __('Apply as percentage of original'),
'value' => 'by_percent'
],
[
'label' => __('Apply as fixed amount'),
'value' => 'by_fixed'
],
[
'label' => __('Adjust final price to this percentage'),
'value' => 'to_percent'
],
[
'label' => __('Adjust final price to discount value'),
'value' => 'to_fixed'
],
[
'label' => __('Custom Action'),
'value' => 'custom_action'
]
];
}
}
Result:
[enter image description here][1]
[1]: https://i.stack.imgur.com/EjG19.png
Related
Using Magento 2.3.0
Whenever trying to save customer I get errors that newly created attributes are required, even when I set their values.
etc/extend_attributes.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="customershipping_enabled" type="string" />
<attribute code="customershipping_price" type="string" />
</extension_attributes>
</config>
Setup/InstallData.php
<?php
namespace <vendor>\<module_name>\Setup;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface {
private $customerSetupFactory;
public function __construct(
\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$customerSetup =$this->customerSetupFactory->create(['setup'=>$setup]);
$setup->startSetup();
$customerSetup->addAttribute('customer', 'customershipping_enabled', [
'label'=>'Customer Shipping Enabled',
'type' => 'int',
'input' => 'select',
'source' => Boolean::class,
'required'=>true,
'visible'=>true,
'default' => 0,
'position' => 198,
]);
$customerSetup->addAttribute('customer', 'customershipping_price', [
'label'=>'Customer Shipping Price',
'type'=>'decimal',
'input' => 'text',
'required'=>true,
'visible'=>true,
'default' => 0,
'position' => 199,
]);
$enabledAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customershipping_enabled');
$enabledAttribute->setData('used_in_forms', ['adminhtml_customer']);
$enabledAttribute->save();
$priceAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customershipping_price');
$priceAttribute->setData('used_in_forms', ['adminhtml_customer']);
$priceAttribute->save();
$setup->endSetup();
}
}
I have read many tutorials and documentation on this, and I believe this should be working correctly, am I missing something?
Whenever I try to add new customer or update existing customer, it says that these 2 attributes are required values, save fails.
Also looks identical to this post:
mage2gen.com/snippets/customerattribute
I had similar issue recently, try to add this in 'used_in_forms'.
You might have to remove the attribute and reinstall it:
'used_in_forms' => ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
edit
Oh I think this should solve the issue, just checked my installData and upgradeData scripts and they all have system => 0. Just add it in.
$customerSetup->addAttribute('customer', 'customershipping_enabled', [
'label'=>'Customer Shipping Enabled',
'type' => 'int',
'input' => 'select',
'source' => Boolean::class,
'required'=>true,
'visible'=>true,
'default' => 0,
'position' => 198,
'system' => 0
]);
It'll be related to this issue:
https://apiworks.net/magento2/magento-2-is-not-saving-the-customer-attribute/
The function getCustomAttributesMetadata is looping through all EAV
attributes and checking if the attribute is marked as “is_system”
inside the “customer_eav_attribute” table, which was the case with my
custom attribute.
Solution:
By default, Magento flagged my custom attribute as is_system = 1, so I
just needed to add ‘system’ => false in my upgrade script and execute
it again (after I removed the original attribute directly from the
database. ).
Root cause of this issue is design behavior of magento 2.
If custom attribute is set as a required one than it must be configured to be shown on storefront and to be shown in all the forms.
If you wants a custom attribute to be required only on some certain forms, then an extension attribute should be used instead with 'required'=>false.
Extension attributes are used to extend functionality of custom attributes.
You just need to replace
'required'=>true,
with
'required'=>false,
For more details please refer the link:
Click here
I am using Magento 2.2.3 and i added a new checkbox field with require validation in address onepage checkout form by custom plugin.
I follow this guide:
https://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_field.html
Now I display checkbox but validation does not work well.
Require validation only works when customer uncheck the field after checking it.
I need validation to work even when checkbox has never been checked like on first load of the form
Below is my code of LayoutProcessor:
class LayoutProcessor
{
/**
* #param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* #param array $jsLayout
* #return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
$customAttributeCode = 'custom_field';
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']
['shipping-address-fieldset']['children'][$customAttributeCode] = [
'component' => 'Magento_Ui/js/form/element/single-checkbox',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/components/single/checkbox',
],
'label' => 'Bla bla bla bla.....',
'dataScope' => 'shippingAddress.custom_attributes' . '.' . $customAttributeCode,
'provider' => 'checkoutProvider',
'sortOrder' => 251,
'required' => true,
'validation' => [
'required-entry' => true
],
'description'=>null,
'value' => '1',
];
return $jsLayout;
}
}
I've been searching for quite a while but couldn't find what I was looking for.
I've created two custom content-elements: parallax_content and bg_image.
In the backend for the time being I have the fields of a standard textmedia-element the code for which is as follows (from tt_content):
array('showitem' => '
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;
general,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.header;
header,
rowDescription,
bodytext;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
assets,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.imagelinks;
imagelinks,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
layout;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:layout_formlabel,
--palette--;
LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.mediaAdjustments;mediaAdjustments,
--palette--;
LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.gallerySettings;
gallerySettings,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.appearanceLinks;appearanceLinks,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access,
hidden;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:field.default.hidden,
--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.access;
access,
--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.extended,
--div--;
LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category,
categories',
'columnsOverrides' => array(
'bodytext' => array(
'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
)
)
)
For my element parallax_content I would need the following fields:
Header
a checkbox "insert Logo"
a bodytext
an image selecting field
For image_bg I would need:
an image selecting field
a dropdown list with 2 items
But I'm struggling with understanding the code and how I would neet to adapt it so it would work. I've looked at the documentation but it doesn't really answer my question as it only shows one example of code with some lines but no explanation. I couldn't find the other documentation again where I gained just as "much" information as in the one linked above. I do understand some parts, for example the palette.header creates the whole header palette with header, header-link, alignment, date etc.
So my questions are:
Can someone explain to me how the code above works exaclty? Where does one element start and where does it end? what do "--palette--" and "--div--" do? how are the tabs created (e.g. general, media etc)? Is it possible to create my fields as listed above with these palettes? Can I create my own palette? If yes how? Or is there maybe a typoscript I can use/make to create my custom fields? Or would I need to create an extension for each of these elements? If possible I'd like to avoid this.
Yes, it's quite a lot of questions, I'm a novice in TYPO3 and not only trying to work with TYPO3 but also understand it as far as possible (at least for the things I need). My utmost priority is to understand the code above, but any pointers, explanations, help or even links to documentations (which I might not have seen so far) which could lead to a solution for my request I would greatly appreciate. Thanks in advance!
in my current project I added a parallax effect to the textmedia element in the tt_content.
First I override the tt_content TCA:
'background_media' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:background_media',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'background_media',
array(
'minitems' => 0,
'maxitems' => 1,
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:add_media',
'showAllLocalizationLink' => 1,
),
'foreign_match_fields' => array(
'fieldname' => 'background_media',
'tablenames' => 'tt_content',
'table_local' => 'sys_file',
),
// custom configuration for displaying fields in the overlay/reference table
// to use the newsPalette and imageoverlayPalette instead of the basicoverlayPalette
'foreign_types' => array(
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette,
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
),
)
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
)
),
'effects' => [
'exclude' => true,
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:effects',
'config' => [
'type' => 'select',
'itemsProcFunc' => 'VENDOR\Extension\UserFunction\ProviderField->createEffectItems',
'renderType' => 'selectCheckBox',
'multiple' => true,
'minitems' => 0,
'maxitems' => 999,
'items' => []
]
],...
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $additionalColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'background_media,effects', 'textmedia', 'after:layout');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'image_classes,text_classes', 'textmedia', 'after:layout');
Now I have 2 additional fields:
- Background Image (FAL)
- Selct Box (UserFunc) for own styles
My UserFunc (VENDOR\Extension\UserFunction\ProviderField->createEffectItems)
/**
* #param ConfigurationService $configurationService
* #return void
*/
public function injectConfigurationService(ConfigurationService $configurationService) {
$this->configurationService = $configurationService;
}
public function createEffectItems($config) {
$settings = $this->configurationService->getSettingsForExtensionName('extension');
$classNames = json_decode($settings['container']['effects'],true);
if (!is_array($classNames)) return $config;
$optionList = array();
foreach ($classNames as $key => $val) {
$optionList[] = [$val, $key];
}
$config['items'] = array_merge($config['items'], $optionList);
return $config;
}
Now I can define my own CSS classes in Typoscript setting...
Last but not least the FluidStyleContent Part:
I overrride the Fluid_tyled_content template Textmedia.html and Layout Detaulf.html.
<v:content.resources.fal uid="{data.uid}" table="tt_content" field="background_media" as="ceBackground">
<f:if condition="{ceBackground}">
{v:uri.image(treatIdAsReference: 1, src: ceBackground.0.id, maxW: 1920) -> v:variable.set(name: 'parallaxBg')}
</f:if>
</v:content.resources.fal>
<div id="c{data.uid}" {f:if(condition: '{parallaxBg}', then: 'style="background-image: url(\'{parallaxBg}\');" ')}">
</div>
For a multiple classes use: {data.effects -> v:format.replace(substring: ',', replacement: ' ')}
Best regards
I have the following problem and I'm sure some of you will mark this question as duplicate but I couldn't find a specific answer for my problem.
I have an extension and I want to add images / pdf's etc. using the FAL.
According to tutorials I have to config the TCA. Well, the docs are sh.. about that point and the tutorials are based on the knowledge of TCA.
I also have to use some TypoScript, which I haven't used to this point.
Ok, as far as I got here's my question:
Where do I edit the TCA?
I have a file named ext_tables where I can see $GLOBALS['TCA'].
I also have a directory TCA with some files in it (only filled with $GLOBALES['TCA'].
And after that, how do I access these datas? I need to build a tree in the inside of a modal (pop-up is also possible)
I know these questions sound horribly easy but I couldn't find a tutorial which could explain anything at all.
I appreciate all help :)
Thanks a lot.
Your question is king of vague:
What exactly did you try so far?
Which files did you change?
Do you need the files inside your FLUIDTEMPLATE, inside your extbase controller or somewhere else?
Steps to add FAL fields to your extension
Extend the database (typo3conf/ext/yourExtFolder/ext_tables.sql):
CREATE TABLE your_database_table (
your_fal_field int(11) unsigned DEFAULT '0' NOT NULL
)
Extend the TCA:
If you extend an existing table from another extension you have the extend the TCA inside typo3conf/ext/yourExtFolder/Configuration/TCA/Overrides/your_database_table.php
Example (extend tt_content):
$newColumn = [
'field_name' => [
'image' => [
'label' => 'Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
],
'minitems' => 0,
'maxitems' => 1,
], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $newColumn);
If you add the field to your own extension your have to extend typo3conf/ext/yourExtFolder/Configuration/TCA/your_database_table.php.
Example (from TYPO3 core be_users TCA - shortened version):
return [
'ctrl' => [
'label' => 'username',
'descriptionColumn' => 'description',
],
'columns' => [
'username' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:be_users.username',
'config' => [
'type' => 'input',
'size' => 20,
'max' => 50,
'eval' => 'nospace,trim,lower,unique,required',
'autocomplete' => false,
]
],
'avatar' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:be_users.avatar',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'avatar',
['maxitems' => 1],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
)
],
],
// Removed more `columns`, `types` and `palettes` config
];
The important part is the definition of avatar which uses the getFileFieldTCAConfig function.
Extend your extbase model (typo3conf/ext/yourExtFolder/Classes/Domain/Model/YourClass.php)
Simplified snippet from keinerweiss.de:
class YourClass extends TheModelYouWantToExtend or \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
// ...
/**
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $yourField;
/**
* Returns the image
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
*/
public function getYourField() {
return $this->yourField;
}
/**
* Sets the image
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
* #return void
*/
public function setYourField($image) {
$this->yourField = $yourField;
}
}
Use your images in Fluid (From t3-developer.com):
<f:for each="{mymodel.mypictures}" as="picture">
<f:image src="{mypicture.image.uid}" alt="" treatIdAsReference="TRUE" />
</f:for>
More links (english):
https://gist.github.com/maddy2101/5668835
http://blog.scwebs.in/typo3/typo3-fal-file-abstraction-layer-in-extbasefluid-extension
More links(german):
http://keinerweiss.de/755-typo3-fal-in-einer-eigenen-extbasefluid-extension-einsetzen.html
http://t3-developer.com/ext-programmierung/techniken-in-extensions/fal-in-typo3-extensions-verwenden/
http://t3g.at/extbase-bilder-fal-in-extension-integrieren/
i have created one simple Module. i have created system.xml. there is one field Multiselect i want to add custom Value in multiselect field.
is it possible to add custom Value in multiselect field ?
<Data translate="label">
<label>Select Socail Media</label>
<comment>Select Social Media To fdisplay ion Front Side</comment>
<front_end_type>multiselect</front_end_type>
<source_model>adminhtml/system_config_source_country</source_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</Data>
in Multiselect Options i want to add my Custom Option like: Data1, Data2 , Data3 etc..
how can i do that? is it possible?
yes you can create like this way add below code to system.xml
<fields>
<view_style translate="label">
<label>Display Settings</label>
<frontend_type>multiselect</frontend_type>
<source_model>yourmodule/system_config_source_view</source_model>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
</view_style>
</fields>
create one file for multiselect option in your module in this path
your_namespace/yourmodel/Model/System/Config/Source/View.php
Add below code in your View.php
class YourNamespace_YourModule_Model_System_Config_Source_View
{
/**
* Options getter
*
* #return array
*/
public function toOptionArray()
{
return array(
array('value' => 0, 'label' => Mage::helper('adminhtml')->__('Data1')),
array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Data2')),
array('value' => 2, 'label' => Mage::helper('adminhtml')->__('Data3')),
);
}
/**
* Get options in "key-value" format
*
* #return array
*/
public function toArray()
{
return array(
0 => Mage::helper('adminhtml')->__('Data1'),
1 => Mage::helper('adminhtml')->__('Data2'),
3 => Mage::helper('adminhtml')->__('Data3'),
);
}
}
Also for more detail use this link
hope this will sure help you.