About jontas

I like to make things that people find useful.

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

Send mail to several to-addresses

To send email to several recipients use

name <name@example.com>, name2 <name2@example.com>

the part inside the brackes (< & >) is the adress, the part before the < is the name shown as the recipient. The separation char for several addresses is “,”

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

Forcing a fsck at next reboot

Sometimes you wish to make fsck run at the next time (after the computer is powered up/rebooted).
This can be achieved by

Passing F to shutdown

By passing the option “F” to shutdown it will force a file system check at the next boot up.

shutdown -rF now

By creating a /forcefsck file

If the file “/forcefsck” exists then a fsck is forced at boot up.

touch /forcefsck

Turning off auto fsck at boot time

A Linux machine will auto check the file system if the last shutdown was unclean (the system was powered off before the file system was unmounted) or if it has passed to much time since the last check.

This can be turned off in a few ways, here are some.

[never check] From /etc/fstab

If the sixth option is not 0 (or missing) then fsck will do automatic checking, so change the sixth option to a 0.
As root edit the /etc/fstab (use your favorite text editor or vi).

/dev/sda1		/home/files			ext3	defaults	0 0

[never check] By passing arguments via GRUB

It is possible to pass the option fastboot to the kernel at boot time, this will also prevent fsck from running at boot time.
Edit /boot/grub/menu.lst (use your favorite text editor or vi) [might also be called /etc/grub.conf]
So an example of this would look like

title           Debian GNU/Linux, kernel 2.6.26-1-686
root            (hd0,0)
kernel          /vmlinuz-2.6.26-1-686 root=/dev/mapper/root-root--volume ro fastboot
initrd          /initrd.img-2.6.26-1-686

[only skip once] By passing options to shutdown

If you only wish to bypass the automatic testing of the file system once, but keep the automatic settings saved you can use the shutdown command with the option “f”.
For instance to reboot without checking

shutdown -rf now

Apache2 changing charset using .htaccess

If you do not wish to change character encoding for the entire server, but only one site (or only one directory) then this is possible to do using .htaccess.

AddDefaultCharset UTF-8

If you only wish to do this to php or htm files (and not all files)

<FilesMatch "\.(htm|php)$">
AddDefaultCharset UTF-8
</FilesMatch>

If you wish to modify the mime-type as well as the encoding (on html files in this example)

AddType 'text/html; charset=UTF-8' html

Magento: Magento connect broken after moving to another path (www.example.com/test -> www.example.com)

The Magento Connect uses values stored in the directory downloader to know where to connect, where to save files etc. The problem is that these paths are hard coded into files at the installation of Magento.

If you wish to move your installation to a new path then this will break the Magento Connect in the admin panel.

The version that I find easiest to do on the new server is to log in using ssh and then run “./pear mage-setup .” That will reset the aboslute paths that are stored in the downloader directory.

Another option would be to re install magneto:

  • Upload a fresh copy of Magento onto the new server (don’t run the installer yet)
  • Copy over your Themes/Templates, Skins, Images, and Custom Modules
  • Dump the database from the original, and import the database to the new site
  • Run the installer – and enter all the necessary info
  • Go into the Magento Connect Manager, and install this extension: magento-core/Mage_All_Latest
  • 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]