Magento – using etc/system.xml to controll a modules visibility in the admin interface

In the admin interface it is possible to alter setting on a “default”, “website” or “store” level.
Whether or not the module is visible [and configurable] in these is controlled by the modules config file (most commonly saved as “etc/system.xml”)

There are some lines that looks like:

<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>

The variables are fairly self explanatory; 0 is don’t show, 1 is show [I have also seen 2 but I haven’t figured that one out yet]

Magento admin, make it possible to enter DIBS login information on a per store basis

If you are using the DIBS module from MagentoConnect it is possible to set up DIBS accounts as default configuration (all sites & stores) and website (and all stores under that).

If you would like to be able to set up one DIBS account per store, then you should edit the app/code/local/Mage/Dibs/etc/system.xml
Find the lines that look like

                        <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>

and alter them to

                        <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>1</show_in_store>

This should be done in several locations (this is controlled for each option in the plugin so make sure you edit it for all the options you wish to alter on a store level).

Magento: Sending the info in the contact form to several email addresses

By default Magento only has one filed to input the recipient of the contact form (in admin).
If you would like to get this sent to several email addresses then a small hack is required as Magento adds some encding to address in this field.

Use

mail@example1.com>, name <mail@example2.com

to send to two recipients. name is the name shown as the address in the second mail.

Send contact form to two mail addressesv

To send to 3 addresses use

mail@example1.com>, name <mail@example2.com>,name2<mail@example3.com

To sent to 4 or more, just add more as in the 3 addresses example

Magento: Set shipping address to billing address by default (but retain the possibility to change it)

This will set the delivery address to the billing address and with no other changes to the code, the user will still be able to change the delivery address by using the right menu. This simply updates the default behavior of what needs to be entered.

In “app/design/frontend/default/blank/template/checkout/onepage/billing.phtml”
Find the section that looks like:

123
124
125
126
127
128
129
130
131
132
    <?php if ($this->canShip()): ?>
        <li>
            <<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo  $this->__('Ship to this address') ?></label>
            <input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
        </li>
    <?php endif; ?>
    </ul>
    <?php if (!$this->canShip()): ?>
        <input type="hidden" name="billing[use_for_shipping]" value="1" />
    <?php endif; ?>

And simply replace it by;

123
124
    </ul>
    <input type="hidden" name="billing[use_for_shipping]" value="1" />

Magento: Changing the url “continue shopping” points at

If you wish to repoint the “continue shopping” button in the shopping cart, then the file
app/code/core/Mage/Checkout/Block/Cart.php (and don’t forget that the modified file should be copied to app/code/local/Mage/Checkout/Block/Cart.php ) is one place to do that from. (The code example below gives different results based on if the cart is empty or not)

71
72
73
74
75
76
77
78
79
80
81
82
83
    public function getContinueShoppingUrl()
    {
	//Mage::getUrl(page name in CMS under admin)
       //if the cart is not empty, return the user to the shop
	if (Mage::helper('checkout/cart')->getCart()->getItemsCount() > 0)
		$url = Mage::getUrl('home');
	//if the cart is empty, return the user to the portal home.
	else
		$url = Mage::getUrl('portal');
        $this->setData('continue_shopping_url', $url);
 
        return $url;
    }

Also you should edit the file app/design/frontend/default/blank/template/checkout/cart/noItems.phtml (blank is my skin)

33
<p><?php echo $this->__('Please <a href="%s">continue shopping</a>.', Mage::getUrl('portal')) ?></p>

[This was done to Magento version 1.3.2.4]

Magento: Send a email to store owner when a order is placed.

It is not hard to set up a Magento multi store environment so when a order is placed in a store, a owner (one owner per store) gets a order confirmation email.
Doing like this will give a copy of the mail that is sent to the customer, and that might not be nice – but this is quick.

In admin, select the store you wish to enter the email address to, and under system > config > sales > sales e-mail override the site default with the email address you would like for this store.

It is also possible to send copies of shipment notices, credit mails etc (basically all mail that is sent from the store).

[Tested with v1.3.2.4]

Magento: Problem with the Fontis WYSIWYG editor (FCKeditor) and {{store url=””}}

The problem is that a link like <a href="{{store url=""}}"> gets converted to <a href="{{store url="> and that is a problem (it makes the link much longer and the page seams to be lacking a lot of text.

One solution is to replace the "" (2 ") where the second disappears with ” (2 ‘).

It is probably a very good idea to make this change on all " inside {{ }} to ‘s.

However it is still a good idea to do this change in the code mode of the editor or it will do some of its magic on it.

Magento: Problem with the Fontis WYSIWYG editor (FCKeditor) and custom database predix

We were having lots of trouble getting the Configuration JavaScript working.
The problem turned out to be that we are having a prefix in our database of magento, and the code was not handling this case.
While setting up views in the db would have been one workaround…

To find out if you are suffering from this issue as well, open the fontis_custom_config.php file in an browser – and if you see mysql errors then there is a problem – and below is a solution that worked for us.

We did some edits to the js/fontis/fckeditor/fontis_custom_config.php file to make it handle database prefixes.
added:

28
29
    $prefix = $xml->global->resources->db->table_prefix;
    $tablename = $prefix . "core_config_data";

And then simply replace all the following instances of ‘core_config_data’ (without ‘s) with ‘” . $tablename .”‘ (again without ‘s) (as for insance)

35
            "SELECT * FROM " . $tablename . " WHERE path = 'fontis_wysiwyg/fckeditor/usecustomtoolbarjs'"));

Magento: Problem with DIBS module

Using the DIBS module (from Magento connect); we had the “slight” problem that if the order was payed using the test visa card (from DIBS 10 steps) viewing the order was not possible.
The page only partially rendered but most of it was not shown.

We “fixed” this by adding two things to app/code/local/Mage/Adminhtml/Block/Sales/Order/View/Tab/Info.php

We figured out the problem lied in the “switch($paytype)” statement in the “function printLogo($paytype)”

We started by editing the “default:” statement to read

$res = 'no image for ' . $paytype;

instead of the old statement of

$res = '<img src="' . $paytype;

was what broke the page rendering as that img tag was not ended.

We also added an extra case for the card that didn’t exist in the old switch:

case 'VISA,V-DK':  {
                $res = '<img alt="" />getSkinUrl('images/dibs/visa.gif') . '" border="0" />';  break;
            }

Magento: Adding tax (Swedish moms for example)

There is 4 momsclasses in Sweden (25%, 12%, 6% and 0%).

Under Sales-Tax-Manage tax zones & rates:

Create one rule per momsclass for Sweden with * as region and * as Zip.

Create one rule for customers.

Create one rules per momsclass for products.

Create one Tax rule for each momsclass.

Make sure that the products in the catalog have tax set (if there are product in the catalog).

Under System-Config-Tax make the appropriate settings. (defines if the prices are including or excluding tax, if tax should be added on shipping or not etc)