magento how add dynamic url path in system.xml - magento

I am working on payment gateway. but i have problem i did google research but couldn't find any solution i hope i'll get solution here so i am posting here
following my system.xml code block
<title translate="label">
<label>Title</label>
<comment><![CDATA[<img src="/media/billmate/images/billmate_bank_s.png" />]]></comment>
<frontend_type>text</frontend_type>
<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>
</title>
in this block problem is in comment tag right now here i put static link /media/billmate/images/billmate_bank_s.png please anybody suggess me how to make it dynamic

An element from system.xml can have a dynamic comment. The comment can be rendered through a model.
You need to declare the comment field like this:
<comment>
<model>module/adminhtml_comment</model>
</comment>
Now you need to create the model with alias module/adminhtml_comment:
<?php
class Namespace_Module_Model_Adminhtml_Comment{
public function getCommentText(){ //this method must exits. It returns the text for the comment
return "Some text here";
}
}
like following
<title translate="label">
<label>Title</label>
<comment>
<model>module/adminhtml_comment</model>
</comment>
<frontend_type>text</frontend_type>
<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>
</title>
return value from the getCommentText method

Add into system.xml file
<field id="row_payment_us_free" translate="label" type="select" sortOrder="5" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
<label>Payment US Free</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><model>VendoreName\ModuleName\Model\SystemConfigComment</model></comment>
</field>
app/code/VendoreName/ModuleName/Model
SystemConfigComment.php
<?php
namespace VendoreName\ModuleName\Model;
use Magento\Framework\UrlInterface;
class SystemConfigComment implements \Magento\Config\Model\Config\CommentInterface
{
protected $urlInterface;
public function __construct(
UrlInterface $urlInterface
) {
$this->urlInterface = $urlInterface;
}
public function getCommentText($elementValue)
{
$url = $this->urlInterface->getUrl('adminhtml/system_config/edit/section/payment');
return 'Require to enable Zero Subtotal Checkoutpayment method for Zero Subtotal order.';
}
}

Related

Add option to Magento system admin

I would like to add a textbox to the Header block located inside System>Config>Design>Header, the location in the image below.
I know this has to be done in xml, but I am not sure where. Also how would I display that in an phtml file?
In code/core/Mage/Page/etc/system.xml you will find the configuration that Magento reads to show those fields, for example the "Small Logo Image src" is a field called logo_src_small. The needed is a module that will tell Magento about:
The extra field in the admin panel under header.
<config>
<sections>
<design>
<groups>
<header>
<fields>
<new_field translate="label">
<label>New Field</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</new_field>
</fields>
</header>
</groups>
</design>
</section>
</config>
Rewrite the block class code/core/Mage/Page/Block/Html/Header.php so you can add the method that will expose the new field.
In the app/design/frontend/{Package}/{Theme}/template/page/html/header.phtml you can easily call $this->getNewField() where getNewField() is the method you have in the class we overridden in point 2.
A couple of links to help you start:
http://excellencemagentoblog.com/blog/2011/09/22/magento-part8-series-systemxml/
http://www.ecomdev.org/2010/10/27/custom-configuration-fields-in-magento.html
http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/
https://magento.stackexchange.com/questions/78175/add-custom-field-in-admin-system-configuration-sales
First add a field in system.xml file which is located in
app/code/core/Mage/Page/etc/system.xml,under header section
<header translate="label">
..........
<welcome_massage translate="label">
<label>Welcome Massage</label>
<frontend_type>text</frontend_type>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</welcome_massage>
</fields>
</header>
Then add a method in header block , app/code/core/Mage/Page/Block/Html/Header.php
public function getWelcomeMassage()
{
return $this->_data['welcome_massage'] = Mage::getStoreConfig('design/header/welcome_massage') ;
}
Last call this method in header.phtml file, like that
<?php echo $this->getWelcomeMassage() ?>
Note : You see that I have code in core files. You should rewrite the
core files.
Overriding Magento blocks, models, helpers and controllers
Overwrite system.xml

Magento Add Event onlick on System Configuration Custom Module Field

Nowhere can I find a definition for which to search.
In mymodule namespace/modulename/etc/system.xml I have:
<faq_input translate="label">
<label>Question Collor: </label>
<comment>example: #000000</comment>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</faq_input>
I need add onclick event like:
<input type="text" onclik="code(myevent)" value="xxx" >
You need to use a <frontend_model>, for which you can find some examples in the core (eg in app/code/core/Mage/Catalog/etc/system.xml).
The frontend model must be a block inheriting from Mage_Adminhtml_Block_System_Config_Form_Field, which has a _getElementHtml() method where you can apply your own code to the form element before rendering it. Eg :
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$element->setOnclick('launchExample();');
$html = $element->getElementHtml();
$html .= '<script type="text/javascript">function launchExample(){ alert("This is an example"); }</script>';
return $html;
}

Successful registrations based of Customer group chosen

I am building an Magento site. Currently on the account registration form I have built it so there is drop down box which allows customers to choose their ‘Customer Group’.
If there are for example four different customer groups there are four different success emails the default Magento one, and 3 which I would create). What I need is based on which customer group is chosen the appropriate email is sent.
I have found the function which sends the new email in AccountController.php :
$customer->sendNewAccountEmail(
$isJustConfirmed ? 'confirmed' : 'registered',
'',
Mage::app()->getStore()->getId()
);
My initial thought would be to create the other email files in app/locale/en_US/template/email
But I don’t know which file/function chooses ‘account_new.html’ as the default email file so I could maybe implement some checks based of the customer group id.
I am unsure of the next steps to approach this such as how to edit this file and where to create the different success emails.
You'll likely need to overwrite the Mage_Customer_Model_Customer class to take control of the function sendNewAccountEmail(). This function is how the system decides which email to send and in theory you could override this function.
You probably know how to do an override, but just in case:
<models>
<customer>
<rewrite>
<customer>Namespace_Module_Model_Customer</customer>
</rewrite>
</customer>
</models>
Next, you'll want to create system configuration values, System.xml, you'll need to create a new entry for each "group" you have. This is no the most elegant solution as this is a static list and your groups could be dynamic. But to assign a template you'd either need a whole new module or update this file. But, now you can create transactional emails and assign it to each group in this system.xml file.
<?xml version="1.0"?>
<config>
<sections>
<yourmodule translate="label" module="yourmodule">
<class>separator-top</class>
<label>your module</label>
<tab>general</tab>
<frontend_type>text</frontend_type>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<email translate="label">
<label>Email Templates</label>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<fields>
<group1_template translate="label comment">
<label>Group 1 Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</group1_template>
<group2_template translate="label comment">
<label>Group 2 Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</group2_template>
</fields>
</email>
</groups>
</yourmodule>
</sections>
</config>
Finally, the override for your sendNewAccountEmail():
class Namespace_Module_Model_Customer {
public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
{
$types = array(
'registered' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE, // welcome email, when confirmation is disabled
'confirmed' => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, // welcome email, when confirmation is enabled
'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE, // email with confirmation link
'group1' => 'yourmodule/email/group1_template',
'group2' => 'yourmodule/email/group2_template',
);
if (!isset($types[$type])) {
Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type'));
}
if (!$storeId) {
$storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
}
$this->_sendEmailTemplate($types[$type], self::XML_PATH_REGISTER_EMAIL_IDENTITY,
array('customer' => $this, 'back_url' => $backUrl), $storeId);
return $this;
}
}
Obviously there is a lot of room for improvement, namely coming up with a way to dynamically pull customer groups and created configurations from that and additionally adding those same dynamic checks to this function, but this is a simple static solution.

Onchange event in system.xml magento

Can anyone tell me how i can do that.I created custom module with system.xml.In system.xml I create two elements, one select option and other text-box.I want to display text-box on specific value of select option. My code is :
Select option
<email_sender translate="label">
<label>E-mail Sender</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_identity</source_model>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</email_sender>
Textbox that want to be displayed on select option is :
<interval translate="label">
<label>Interval</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
.
While for select i use this chunk of code in model
public function toOptionArray()
{
return array(
array('value'=>'show_txtbx', 'label'=>Mage::helper('mymodule')->__('Show Textbox')),
array('value'=>'hide', 'label'=>Mage::helper('mymodule')->__('Hide')),
);
}
How can i do that.Thanks in advance.
Hi all I got my answer after some extra search.Thanks to Alan for such nice tutorials .Here is the link where I got my answer.Click Here
I tried above-given link but in my case, it didn't work with that syntax.
The core concept of adding dependency is correct, but the syntax is somewhat different I guess. You need to add
<depends>
<field id="custom">1</field>
</depends>
Here is a link which worked for me :
https://webkul.com/blog/create-dependant-field-admin-configuration-magento-2/

magento payment methods - enable for admin only

I need to enable the Cheque / Money Order payment method to enable our clients call centre team to create orders in the admin.
However we do not want customers buying online through the website to use this payment method.
Does anybody know how I might be able to do this?
Regards,
Fiona
Two options:
1)
Override (using never change the original or add a /local/Mage/ override) the payment method (or just modify it if it's your own method), and add this:
protected $_canUseInternal = true;
protected $_canUseCheckout = false;
protected $_canUseForMultishipping = false;
2)
Create an observer on the frontend for "payment_method_is_active" event, and set to inactive the methods you don't want to show on the frontend:
<config>
<frontend>
<events>
<payment_method_is_active>
<observers>
... your observer here
public function your_observer($event){
$method = $event->getMethodInstance();
$result = $event->getResult();
if( $method should not be active in frontend ){
$result->isAvailable = false;
}
}
If you enable it in the global config-view and then disable it for your store/website view does that work? (Don't have a system handy to test...)
I tried Enriques solution # 1 to hide one payment method in frontend, only to show it in admin:
protected $_canUseInternal = true;
protected $_canUseCheckout = false;
protected $_canUseForMultishipping = false;
Seems to work fine when I am testing, and in general..
BUT.. I still sometimes get normal orders that uses my "hidden" payment method. Like Magento sometimes fails to use the piece of code above.
Anyone knows why this happens, and how to avoid?
Thanks
-Espen
Check config setting like below example.
If you want to check that customcarrier_fastways is active then use code similar to this:
$shippingMethod="customcarrier_fastways";
$shippingMethodActive= Mage::getStoreConfig('carriers/'.$shippingMethod.'/active', Mage::app()->getStore()->getId());
$showAtFront= Mage::getStoreConfig('carriers/'.$shippMethod.'/showatfront', Mage::app()->getStore()->getId());
if($shippingMethodActive && $showAtFront){
// do something here...
}
While variables is defined in xml file as below:
<carriers translate="label" module="shipping">
<groups>
<customcarrier_fastways translate="label">
<label>Fastways</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<showatfront translate="label">
<label>Show on checkout</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</showatfront>
</fields>
</customcarrier_fastways>
</groups>
</carriers>
Just found this, looks like it's what you're after:
http://www.magentocommerce.com/boards/viewthread/38765/P15/

Resources